From e01c99a193528df717d5cf5bd9fe20c649297375 Mon Sep 17 00:00:00 2001 From: uberspot Date: Mon, 17 Mar 2014 00:27:52 +0200 Subject: make loading of drawer items a bit more dynamic --- .../org/sufficientlysecure/keychain/Constants.java | 14 +++++++++++ .../keychain/ui/DrawerActivity.java | 27 +++++++++++----------- .../keychain/ui/KeyListActivity.java | 6 +---- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java index 011cd9663..ff4abe56a 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java @@ -19,6 +19,11 @@ package org.sufficientlysecure.keychain; import android.os.Environment; import org.spongycastle.jce.provider.BouncyCastleProvider; +import org.sufficientlysecure.keychain.service.remote.RegisteredAppsListActivity; +import org.sufficientlysecure.keychain.ui.DecryptActivity; +import org.sufficientlysecure.keychain.ui.EncryptActivity; +import org.sufficientlysecure.keychain.ui.ImportKeysActivity; +import org.sufficientlysecure.keychain.ui.KeyListActivity; public final class Constants { @@ -63,4 +68,13 @@ public final class Constants { public static final String KEY_SERVERS = "pool.sks-keyservers.net, subkeys.pgp.net, pgp.mit.edu"; } + public static final class DrawerItems { + public static final Class KEY_LIST = KeyListActivity.class; + public static final Class ENCRYPT = EncryptActivity.class; + public static final Class DECRYPT = DecryptActivity.class; + public static final Class IMPORT_KEYS = ImportKeysActivity.class; + public static final Class REGISTERED_APPS_LIST = RegisteredAppsListActivity.class; + public static final Class[] ARRAY = new Class[]{KEY_LIST, ENCRYPT, DECRYPT, + IMPORT_KEYS, REGISTERED_APPS_LIST}; + } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DrawerActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DrawerActivity.java index 985f6c309..f01e67449 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DrawerActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DrawerActivity.java @@ -30,9 +30,8 @@ import android.support.v7.app.ActionBarActivity; import android.view.*; import android.widget.*; import com.beardedhen.androidbootstrap.FontAwesomeText; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.ActionBarHelper; -import org.sufficientlysecure.keychain.service.remote.RegisteredAppsListActivity; public class DrawerActivity extends ActionBarActivity { private DrawerLayout mDrawerLayout; @@ -43,9 +42,6 @@ public class DrawerActivity extends ActionBarActivity { private CharSequence mTitle; private boolean mIsDrawerLocked = false; - private static Class[] mItemsClass = new Class[]{KeyListActivity.class, - EncryptActivity.class, DecryptActivity.class, ImportKeysActivity.class, - RegisteredAppsListActivity.class}; private Class mSelectedItem; private static final int MENU_ID_PREFERENCE = 222; @@ -102,7 +98,7 @@ public class DrawerActivity extends ActionBarActivity { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); - callIntentForSelectedItem(); + callIntentForDrawerItem(mSelectedItem); } public void onDrawerOpened(View drawerView) { @@ -112,11 +108,10 @@ public class DrawerActivity extends ActionBarActivity { supportInvalidateOptionsMenu(); } }; + if ( !mIsDrawerLocked ) { mDrawerLayout.setDrawerListener(mDrawerToggle); - } - - if ( mIsDrawerLocked ) { + } else { // If the drawer is locked open make it un-focusable // so that it doesn't consume all the Back button presses mDrawerLayout.setFocusableInTouchMode(false); @@ -126,16 +121,20 @@ public class DrawerActivity extends ActionBarActivity { // } } - private void callIntentForSelectedItem() { + /** + * Uses startActivity to call the Intent of the given class + * @param drawerItem the class of the drawer item you want to load. Based on Constants.DrawerItems.* + */ + public void callIntentForDrawerItem(Class drawerItem) { // creates call to onPrepareOptionsMenu() supportInvalidateOptionsMenu(); // call intent activity if selected - if (mSelectedItem != null) { + if (drawerItem != null) { finish(); overridePendingTransition(0, 0); - Intent intent = new Intent(this, mSelectedItem); + Intent intent = new Intent(this, drawerItem); startActivity(intent); // disable animation of activity start @@ -214,7 +213,7 @@ public class DrawerActivity extends ActionBarActivity { // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); // set selected class - mSelectedItem = mItemsClass[position]; + mSelectedItem = Constants.DrawerItems.ARRAY[position]; // setTitle(mDrawerTitles[position]); // If drawer isn't locked just close the drawer and @@ -223,7 +222,7 @@ public class DrawerActivity extends ActionBarActivity { mDrawerLayout.closeDrawer(mDrawerList); // else move to the selected item yourself } else { - callIntentForSelectedItem(); + callIntentForDrawerItem(mSelectedItem); } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 57709350e..06df6f12d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -53,11 +53,7 @@ public class KeyListActivity extends DrawerActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_key_list_import: - - overridePendingTransition(0, 0); - Intent intentImport = new Intent(this, ImportKeysActivity.class); - startActivityForResult(intentImport, 0); - overridePendingTransition(0, 0); + callIntentForDrawerItem(Constants.DrawerItems.IMPORT_KEYS); return true; case R.id.menu_key_list_export: -- cgit v1.2.3