diff options
author | vectorijk <jiangkai@gmail.com> | 2015-04-24 03:21:54 -0700 |
---|---|---|
committer | vectorijk <jiangkai@gmail.com> | 2015-04-24 03:22:15 -0700 |
commit | b323fc29c29ec2a7cba87ed19c7809b843a1fd60 (patch) | |
tree | 213f6d2583946c539e1d02c5585f2da6e8a11239 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | 3ee2c6fc6a2a5e18e333bb82f16d0efe365df2b8 (diff) | |
download | open-keychain-b323fc29c29ec2a7cba87ed19c7809b843a1fd60.tar.gz open-keychain-b323fc29c29ec2a7cba87ed19c7809b843a1fd60.tar.bz2 open-keychain-b323fc29c29ec2a7cba87ed19c7809b843a1fd60.zip |
Fix #1197 Switch to MaterialDrawer library
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java | 129 |
1 files changed, 85 insertions, 44 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java index 045d1e658..fa4f07d88 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java @@ -21,56 +21,48 @@ package org.sufficientlysecure.keychain.ui; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import android.widget.Toast; import com.mikepenz.community_material_typeface_library.CommunityMaterial; import com.mikepenz.google_material_typeface_library.GoogleMaterial; import com.mikepenz.iconics.typeface.FontAwesome; import com.mikepenz.materialdrawer.Drawer; -import com.mikepenz.materialdrawer.model.DividerDrawerItem; -import com.mikepenz.materialdrawer.model.SectionDrawerItem; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.remote.ui.AppsListFragment; -import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.FabContainer; - -import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer; +import org.sufficientlysecure.keychain.util.Preferences; public class MainActivity extends ActionBarActivity implements FabContainer { public Drawer.Result result; -// public Drawer.Result result; + private KeyListFragment mKeyListFragment ; + private AppsListFragment mAppsListFragment; + private EncryptDecryptOverviewFragment mEncryptDecryptOverviewFragment; + private Fragment lastUsedFragment; + @Override public void onCreate(Bundle savedInstanceState) { -// // don't open drawer on first run -// disableLearningPattern(); -// -//// addMultiPaneSupport(); -// -// // set the header image -// // create and set the header -// setDrawerHeaderImage(R.drawable.drawer_header); -// -// // create sections -// addSection(newSection(getString(R.string.nav_keys), R.drawable.ic_vpn_key_black_24dp, new KeyListFragment())); -// addSection(newSection(getString(R.string.nav_encrypt_decrypt), R.drawable.ic_lock_black_24dp, new EncryptDecryptOverviewFragment())); -// addSection(newSection(getString(R.string.title_api_registered_apps), R.drawable.ic_apps_black_24dp, new AppsListFragment())); -// -// // create bottom section -// addBottomSection(newSection(getString(R.string.menu_preferences), R.drawable.ic_settings_black_24dp, new Intent(this, SettingsActivity.class))); -// addBottomSection(newSection(getString(R.string.menu_help), R.drawable.ic_help_black_24dp, new Intent(this, HelpActivity.class))); super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); + //initialize FragmentLayout with KeyListFragment at first + Fragment mainFragment = new KeyListFragment(); + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction transaction = fm.beginTransaction(); + transaction.replace(R.id.main_fragment_container, mainFragment); + transaction.commit(); + final Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar); toolbar.setTitle(R.string.app_name); setSupportActionBar(toolbar); @@ -82,8 +74,10 @@ public class MainActivity extends ActionBarActivity implements FabContainer { .addDrawerItems( new PrimaryDrawerItem().withName(R.string.nav_keys).withIcon(CommunityMaterial.Icon.cmd_key).withIdentifier(1).withCheckable(false), new PrimaryDrawerItem().withName(R.string.nav_encrypt_decrypt).withIcon(FontAwesome.Icon.faw_lock).withIdentifier(2).withCheckable(false), - new PrimaryDrawerItem().withName(R.string.title_api_registered_apps).withIcon(CommunityMaterial.Icon.cmd_apps).withIdentifier(3).withCheckable(false), - new DividerDrawerItem(), + new PrimaryDrawerItem().withName(R.string.title_api_registered_apps).withIcon(CommunityMaterial.Icon.cmd_apps).withIdentifier(3).withCheckable(false) + ) + .addStickyDrawerItems( + // display and stick on bottom of drawer new PrimaryDrawerItem().withName(R.string.menu_preferences).withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(4).withCheckable(false), new PrimaryDrawerItem().withName(R.string.menu_help).withIcon(CommunityMaterial.Icon.cmd_help_circle).withIdentifier(5).withCheckable(false) ) @@ -94,10 +88,13 @@ public class MainActivity extends ActionBarActivity implements FabContainer { Intent intent = null; switch(drawerItem.getIdentifier()) { case 1: + onKeysSelected(); break; case 2: + onEnDecryptSelected(); break; case 3: + onAppsSelected(); break; case 4: intent = new Intent(MainActivity.this, SettingsActivity.class); @@ -110,7 +107,6 @@ public class MainActivity extends ActionBarActivity implements FabContainer { MainActivity.this.startActivity(intent); } } - Toast.makeText(MainActivity.this, Integer.toString(drawerItem.getIdentifier()), Toast.LENGTH_SHORT).show(); } }) .withSelectedItem(-1) @@ -135,15 +131,58 @@ public class MainActivity extends ActionBarActivity implements FabContainer { } } -// private void onPreferenceSelected() { -// Intent intent = new Intent(this, SettingsActivity.class); -// startActivity(intent); -// } -// -// private void onHelpSelected() { -// Intent intent = new Intent(this, HelpActivity.class); -// startActivity(intent); -// } + private void clearFragments() { + mKeyListFragment = null; + mAppsListFragment = null; + mEncryptDecryptOverviewFragment = null; + + getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); + } + + private void setFragment(Fragment fragment) { + setFragment(fragment, true); + } + + private void setFragment(Fragment fragment, boolean addToBackStack) { + this.lastUsedFragment = fragment; + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.main_fragment_container, fragment); + if (addToBackStack) { + ft.addToBackStack(null); + } + ft.commit(); + } + + private boolean onKeysSelected() { + clearFragments(); + + if (mKeyListFragment == null) { + mKeyListFragment = new KeyListFragment(); + } + + setFragment(mKeyListFragment, false); + return true; + } + + private boolean onEnDecryptSelected() { + clearFragments(); + if (mEncryptDecryptOverviewFragment == null) { + mEncryptDecryptOverviewFragment = new EncryptDecryptOverviewFragment(); + } + + setFragment(mEncryptDecryptOverviewFragment); + return true; + } + + private boolean onAppsSelected() { + clearFragments(); + if (mAppsListFragment == null) { + mAppsListFragment = new AppsListFragment(); + } + + setFragment(mAppsListFragment); + return true; + } @Override protected void onSaveInstanceState(Bundle outState) { @@ -164,18 +203,20 @@ public class MainActivity extends ActionBarActivity implements FabContainer { @Override public void fabMoveUp(int height) { -// Object fragment = getCurrentSection().getTargetFragment(); -// if (fragment instanceof FabContainer) { -// ((FabContainer) fragment).fabMoveUp(height); -// } + Object fragment = getSupportFragmentManager() + .findFragmentById(R.id.main_fragment_container); + if (fragment instanceof FabContainer) { + ((FabContainer) fragment).fabMoveUp(height); + } } @Override public void fabRestorePosition() { -// Object fragment = getCurrentSection().getTargetFragment(); -// if (fragment instanceof FabContainer) { -// ((FabContainer) fragment).fabRestorePosition(); -// } + Object fragment = getSupportFragmentManager() + .findFragmentById(R.id.main_fragment_container); + if (fragment instanceof FabContainer) { + ((FabContainer) fragment).fabRestorePosition(); + } } } |