migrate nav panel items to actionbar

Fixes #1819
Closes #1839
// FREEBIE
This commit is contained in:
Jake McGinty 2014-08-14 23:11:06 -07:00 committed by Moxie Marlinspike
parent dee23b266f
commit 020d61dd6e
10 changed files with 50 additions and 228 deletions

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/fragment_content"
@ -11,14 +11,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:background="?navigation_drawer_background"/>
<!--<TextView android:id="@android:id/empty"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="fill_parent"-->
@ -27,4 +19,4 @@
<!--android:textColor="?conversation_text_secondary_color"-->
<!--android:text="Empty message list" />-->
</android.support.v4.widget.DrawerLayout>
</LinearLayout>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:minHeight="48dp">
<ImageView android:id="@+id/navigation_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dip"
android:layout_marginLeft="16dip"
android:contentDescription="Navigation Image"/>
<TextView android:id="@+id/navigation_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginRight="26dp"
android:textColor="?navigation_drawer_text_color"/>
</LinearLayout>

View File

@ -17,6 +17,14 @@
android:id="@+id/menu_mark_all_read"
android:icon="@android:drawable/ic_menu_set_as" />
<item android:title="@string/arrays__import_export"
android:id="@+id/menu_import_export"
android:icon="@android:drawable/ic_menu_upload" />
<item android:title="@string/arrays__my_identity_key"
android:id="@+id/menu_my_identity"
android:icon="@android:drawable/ic_menu_view" />
<item android:title="@string/text_secure_normal__menu_settings"
android:id="@+id/menu_settings"
android:icon="@android:drawable/ic_menu_preferences" />

View File

@ -124,24 +124,4 @@
<item>3000,3000</item>
<item>custom</item>
</string-array>
<string-array name="navigation_drawer_text">
<item>@string/arrays__import_export</item>
<item>@string/arrays__my_identity_key</item>
</string-array>
<string-array name="navigation_drawer_values" translatable="false">
<item>import_export</item>
<item>my_identity_key</item>
</string-array>
<string-array name="navigation_drawer_icons_light">
<item>@drawable/import_export_light</item>
<item>@drawable/my_identity_light</item>
</string-array>
<string-array name="navigation_drawer_icons_dark">
<item>@drawable/import_export_dark</item>
<item>@drawable/my_identity_dark</item>
</string-array>
</resources>

View File

@ -52,11 +52,6 @@
<attr name="contact_selection_label_text" format="reference|color" />
<attr name="conversation_selection_header_text" format="reference|color" />
<attr name="navigation_drawer_background" format="reference|color"/>
<attr name="navigation_drawer_text_color" format="color"/>
<attr name="navigation_drawer_icons" format="reference"/>
<attr name="navigation_drawer_shadow" format="reference"/>
<attr name="reminder_header_background" format="color"/>
<attr name="menu_new_conversation_icon" format="reference" />

View File

@ -668,7 +668,7 @@
<string name="AndroidManifest__log_submit">Submit debug logs</string>
<!-- arrays.xml -->
<string name="arrays__import_export">Import / Export</string>
<string name="arrays__import_export">Import / export</string>
<string name="arrays__my_identity_key">My identity key</string>
<!-- preferences.xml -->

View File

@ -83,17 +83,6 @@
<item name="reminder_header_background">#ff5a8800</item>
</style>
<style name="TextSecure.LightTheme.NavigationDrawer"
parent="@style/TextSecure.LightTheme"
tools:ignore="NewApi">
<item name="android:homeAsUpIndicator">@drawable/ic_drawer</item>
<item name="homeAsUpIndicator">@drawable/ic_drawer</item>
<item name="navigation_drawer_background">@color/abs__background_holo_light</item>
<item name="navigation_drawer_text_color">#ff333333</item>
<item name="navigation_drawer_icons">@array/navigation_drawer_icons_light</item>
<item name="navigation_drawer_shadow">@drawable/drawer_shadow_light</item>
</style>
<style name="TextSecure.DarkTheme" parent="@style/TextSecure.Dark">
<item name="conversation_list_item_background_read">@drawable/conversation_list_item_background_read_dark</item>
<item name="conversation_list_item_background_unread">@drawable/conversation_list_item_background_unread_dark</item>
@ -166,17 +155,6 @@
<item name="reminder_header_background">#ff385400</item>
</style>
<style name="TextSecure.DarkTheme.NavigationDrawer"
parent="@style/TextSecure.DarkTheme"
tools:ignore="NewApi">
<item name="android:homeAsUpIndicator">@drawable/ic_drawer</item>
<item name="homeAsUpIndicator">@drawable/ic_drawer</item>
<item name="navigation_drawer_background">#ff333333</item>
<item name="navigation_drawer_text_color">#ffdddddd</item>
<item name="navigation_drawer_icons">@array/navigation_drawer_icons_dark</item>
<item name="navigation_drawer_shadow">@drawable/drawer_shadow_dark</item>
</style>
<style name="TextSecure.LightTheme.ConversationActivity"
parent="@style/TextSecure.LightTheme">
<item name="android:windowBackground">@null</item>

View File

@ -1,23 +1,27 @@
/**
* Copyright (C) 2014 Open Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Intent;
import android.content.res.TypedArray;
import android.database.ContentObserver;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.Telephony;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
@ -25,7 +29,6 @@ import com.actionbarsherlock.view.MenuItem;
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
@ -34,26 +37,18 @@ import org.thoughtcrime.securesms.service.SendReceiveService;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.MemoryCleaner;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.crypto.MasterSecret;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ConversationListActivity extends PassphraseRequiredSherlockFragmentActivity
implements ConversationListFragment.ConversationSelectedListener,
ListView.OnItemClickListener
implements ConversationListFragment.ConversationSelectedListener
{
private final DynamicTheme dynamicTheme = new DynamicTheme ();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private ConversationListFragment fragment;
private MasterSecret masterSecret;
private DrawerLayout drawerLayout;
private DrawerToggle drawerToggle;
private ListView drawerList;
private ContentObserver observer;
@Override
@ -66,7 +61,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
getSupportActionBar().setTitle(R.string.app_name);
initializeNavigationDrawer();
initializeSenderReceiverService();
initializeResources();
initializeContactUpdatesReceiver();
@ -77,7 +71,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
@Override
public void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
drawerToggle.syncState();
}
@Override
@ -115,40 +108,18 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
return true;
}
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
String[] values = getResources().getStringArray(R.array.navigation_drawer_values);
String selected = values[position];
Intent intent;
if (selected.equals("import_export")) {
intent = new Intent(this, ImportExportActivity.class);
intent.putExtra("master_secret", masterSecret);
} else if (selected.equals("my_identity_key")) {
intent = new Intent(this, ViewLocalIdentityActivity.class);
intent.putExtra("master_secret", masterSecret);
} else {
return;
}
drawerLayout.closeDrawers();
startActivity(intent);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
int defaultType = ThreadDatabase.DistributionTypes.DEFAULT;
switch (item.getItemId()) {
case R.id.menu_new_message: openSingleContactSelection(); return true;
case R.id.menu_new_group: createGroup(); return true;
case R.id.menu_settings: handleDisplaySettings(); return true;
case R.id.menu_clear_passphrase: handleClearPassphrase(); return true;
case R.id.menu_mark_all_read: handleMarkAllRead(); return true;
case android.R.id.home: handleNavigationDrawerToggle(); return true;
case R.id.menu_import_export: handleImportExport(); return true;
case R.id.menu_my_identity: handleMyIdentity(); return true;
}
return false;
@ -181,14 +152,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
startActivity(intent);
}
private void handleNavigationDrawerToggle() {
if (drawerLayout.isDrawerOpen(drawerList)) {
drawerLayout.closeDrawer(drawerList);
} else {
drawerLayout.openDrawer(drawerList);
}
}
private void handleDisplaySettings() {
Intent preferencesIntent = new Intent(this, ApplicationPreferencesActivity.class);
preferencesIntent.putExtra("master_secret", masterSecret);
@ -201,6 +164,18 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
startService(intent);
}
private void handleImportExport() {
final Intent intent = new Intent(this, ImportExportActivity.class);
intent.putExtra("master_secret", masterSecret);
startActivity(intent);
}
private void handleMyIdentity() {
final Intent intent = new Intent(this, ViewLocalIdentityActivity.class);
intent.putExtra("master_secret", masterSecret);
startActivity(intent);
}
private void handleMarkAllRead() {
new AsyncTask<Void, Void, Void>() {
@Override
@ -212,47 +187,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
}.execute();
}
private void initializeNavigationDrawer() {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
int[] attributes = new int[] {R.attr.navigation_drawer_icons, R.attr.navigation_drawer_shadow};
String[] from = new String[]{"navigation_icon", "navigation_text" };
int[] to = new int[] {R.id.navigation_icon, R.id.navigation_text};
TypedArray iconArray = obtainStyledAttributes(attributes);
int iconArrayResource = iconArray.getResourceId(0, -1);
TypedArray icons = getResources().obtainTypedArray(iconArrayResource);
String[] text = getResources().getStringArray(R.array.navigation_drawer_text);
List<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
for(int i = 0; i < text.length; i++){
HashMap<String, String> item = new HashMap<String, String>();
item.put("navigation_icon", Integer.toString(icons.getResourceId(i, -1)));
item.put("navigation_text", text[i]);
items.add(item);
}
DrawerLayout drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
drawerToggle = new DrawerToggle(this, drawerLayout,
R.drawable.ic_drawer,
R.string.conversation_list__drawer_open,
R.string.conversation_list__drawer_close);
drawerLayout.setDrawerListener(drawerToggle);
ListView drawer = (ListView)findViewById(R.id.left_drawer);
SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.navigation_drawer_item, from, to);
drawerLayout.setDrawerShadow(iconArray.getDrawable(1), GravityCompat.START);
drawer.setAdapter(adapter);
drawer.setOnItemClickListener(this);
iconArray.recycle();
icons.recycle();
}
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
@ -284,8 +218,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
}
private void initializeResources() {
this.drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
this.drawerList = (ListView)findViewById(R.id.left_drawer);
this.masterSecret = getIntent().getParcelableExtra("master_secret");
this.fragment = (ConversationListFragment)this.getSupportFragmentManager()
@ -293,32 +225,4 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
this.fragment.setMasterSecret(masterSecret);
}
class DrawerToggle extends ActionBarDrawerToggle {
public DrawerToggle(Activity activity, DrawerLayout drawerLayout,
int drawerImageRes, int openDrawerContentDescRes,
int closeDrawerContentDescRes) {
super(activity, drawerLayout, drawerImageRes,
openDrawerContentDescRes, closeDrawerContentDescRes);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
fragment.resetQueryFilter();
invalidateOptionsMenu();
}
}
}

View File

@ -16,18 +16,15 @@
*/
package org.thoughtcrime.securesms;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -50,7 +47,6 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.loaders.ConversationListLoader;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
import org.thoughtcrime.securesms.util.Dialogs;
import org.whispersystems.textsecure.crypto.MasterSecret;
@ -155,12 +151,6 @@ public class ConversationListFragment extends SherlockListFragment
getLoaderManager().restartLoader(0, null, this);
}
public void resetQueryFilter() {
if (!TextUtils.isEmpty(this.queryFilter)) {
setQueryFilter("");
}
}
private void initializeSearch(SearchView searchView) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override

View File

@ -32,13 +32,11 @@ public class DynamicTheme {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("light")) {
if (activity instanceof ConversationListActivity) return R.style.TextSecure_LightTheme_NavigationDrawer;
else if (activity instanceof ConversationActivity) return R.style.TextSecure_LightTheme_ConversationActivity;
else return R.style.TextSecure_LightTheme;
if (activity instanceof ConversationActivity) return R.style.TextSecure_LightTheme_ConversationActivity;
else return R.style.TextSecure_LightTheme;
} else if (theme.equals("dark")) {
if (activity instanceof ConversationListActivity) return R.style.TextSecure_DarkTheme_NavigationDrawer;
else if (activity instanceof ConversationActivity) return R.style.TextSecure_DarkTheme_ConversationActivity;
else return R.style.TextSecure_DarkTheme;
if (activity instanceof ConversationActivity) return R.style.TextSecure_DarkTheme_ConversationActivity;
else return R.style.TextSecure_DarkTheme;
}
return R.style.TextSecure_LightTheme;