diff options
author | vectorijk <jiangkai@gmail.com> | 2015-04-24 00:00:58 -0700 |
---|---|---|
committer | vectorijk <jiangkai@gmail.com> | 2015-04-24 00:00:58 -0700 |
commit | 3ee2c6fc6a2a5e18e333bb82f16d0efe365df2b8 (patch) | |
tree | b0fa56971ad91142576010b085ea4cf963ff2305 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | 702c28854bf0afe3d7b97e47716530dc751c9322 (diff) | |
download | open-keychain-3ee2c6fc6a2a5e18e333bb82f16d0efe365df2b8.tar.gz open-keychain-3ee2c6fc6a2a5e18e333bb82f16d0efe365df2b8.tar.bz2 open-keychain-3ee2c6fc6a2a5e18e333bb82f16d0efe365df2b8.zip |
Introduce and Switch to mikepenz/MaterialDrawer
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java | 143 |
1 files changed, 118 insertions, 25 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 5fa3edba4..045d1e658 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de> * Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com> + * Copyright (C) 2015 Kai Jiang <jiangkai@gmail.com> * * 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 @@ -20,6 +21,20 @@ package org.sufficientlysecure.keychain.ui; import android.content.Intent; import android.os.Bundle; +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; @@ -29,27 +44,78 @@ import org.sufficientlysecure.keychain.util.FabContainer; import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer; -public class MainActivity extends MaterialNavigationDrawer implements FabContainer { - - @Override - public void init(Bundle savedInstanceState) { - // don't open drawer on first run - disableLearningPattern(); +public class MainActivity extends ActionBarActivity implements FabContainer { -// addMultiPaneSupport(); + public Drawer.Result result; - // set the header image - // create and set the header - setDrawerHeaderImage(R.drawable.drawer_header); +// public Drawer.Result result; + @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); - // 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())); + final Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar); + toolbar.setTitle(R.string.app_name); + setSupportActionBar(toolbar); - // 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))); + result = new Drawer() + .withActivity(this) + .withHeader(R.layout.main_drawer_header) + .withToolbar(toolbar) + .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.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) + ) + .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { + if (drawerItem != null) { + Intent intent = null; + switch(drawerItem.getIdentifier()) { + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + intent = new Intent(MainActivity.this, SettingsActivity.class); + break; + case 5: + intent = new Intent(MainActivity.this, HelpActivity.class); + break; + } + if (intent != null) { + MainActivity.this.startActivity(intent); + } + } + Toast.makeText(MainActivity.this, Integer.toString(drawerItem.getIdentifier()), Toast.LENGTH_SHORT).show(); + } + }) + .withSelectedItem(-1) + .withSavedInstance(savedInstanceState) + .build(); // if this is the first time show first time activity Preferences prefs = Preferences.getPreferences(this); @@ -69,20 +135,47 @@ public class MainActivity extends MaterialNavigationDrawer implements FabContain } } +// private void onPreferenceSelected() { +// Intent intent = new Intent(this, SettingsActivity.class); +// startActivity(intent); +// } +// +// private void onHelpSelected() { +// Intent intent = new Intent(this, HelpActivity.class); +// startActivity(intent); +// } + @Override - public void fabMoveUp(int height) { - Object fragment = getCurrentSection().getTargetFragment(); - if (fragment instanceof FabContainer) { - ((FabContainer) fragment).fabMoveUp(height); + protected void onSaveInstanceState(Bundle outState) { + //add the values which need to be saved from the drawer to the bundle + outState = result.saveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + @Override + public void onBackPressed(){ + //handle the back press :D close the drawer first and if the drawer is closed close the activity + if (result != null && result.isDrawerOpen()) { + result.closeDrawer(); + } else { + super.onBackPressed(); } } @Override + public void fabMoveUp(int height) { +// Object fragment = getCurrentSection().getTargetFragment(); +// 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 = getCurrentSection().getTargetFragment(); +// if (fragment instanceof FabContainer) { +// ((FabContainer) fragment).fabRestorePosition(); +// } } } |