mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-17 22:35:05 -05:00
make loading of drawer items a bit more dynamic
This commit is contained in:
parent
cea62b1857
commit
e01c99a193
@ -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};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user