mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
Fix #1197 Switch to MaterialDrawer library
This commit is contained in:
parent
3ee2c6fc6a
commit
b323fc29c2
@ -21,56 +21,48 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
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.app.ActionBarActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
|
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
|
||||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||||
import com.mikepenz.iconics.typeface.FontAwesome;
|
import com.mikepenz.iconics.typeface.FontAwesome;
|
||||||
import com.mikepenz.materialdrawer.Drawer;
|
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.PrimaryDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
|
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
|
||||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||||
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
|
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity implements FabContainer {
|
public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||||
|
|
||||||
public Drawer.Result result;
|
public Drawer.Result result;
|
||||||
|
|
||||||
// public Drawer.Result result;
|
private KeyListFragment mKeyListFragment ;
|
||||||
|
private AppsListFragment mAppsListFragment;
|
||||||
|
private EncryptDecryptOverviewFragment mEncryptDecryptOverviewFragment;
|
||||||
|
private Fragment lastUsedFragment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
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);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main_activity);
|
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);
|
final Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
|
||||||
toolbar.setTitle(R.string.app_name);
|
toolbar.setTitle(R.string.app_name);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@ -82,8 +74,10 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
|||||||
.addDrawerItems(
|
.addDrawerItems(
|
||||||
new PrimaryDrawerItem().withName(R.string.nav_keys).withIcon(CommunityMaterial.Icon.cmd_key).withIdentifier(1).withCheckable(false),
|
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.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 PrimaryDrawerItem().withName(R.string.title_api_registered_apps).withIcon(CommunityMaterial.Icon.cmd_apps).withIdentifier(3).withCheckable(false)
|
||||||
new DividerDrawerItem(),
|
)
|
||||||
|
.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_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)
|
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;
|
Intent intent = null;
|
||||||
switch(drawerItem.getIdentifier()) {
|
switch(drawerItem.getIdentifier()) {
|
||||||
case 1:
|
case 1:
|
||||||
|
onKeysSelected();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
onEnDecryptSelected();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
onAppsSelected();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
intent = new Intent(MainActivity.this, SettingsActivity.class);
|
intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||||
@ -110,7 +107,6 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
|||||||
MainActivity.this.startActivity(intent);
|
MainActivity.this.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Toast.makeText(MainActivity.this, Integer.toString(drawerItem.getIdentifier()), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.withSelectedItem(-1)
|
.withSelectedItem(-1)
|
||||||
@ -135,15 +131,58 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void onPreferenceSelected() {
|
private void clearFragments() {
|
||||||
// Intent intent = new Intent(this, SettingsActivity.class);
|
mKeyListFragment = null;
|
||||||
// startActivity(intent);
|
mAppsListFragment = null;
|
||||||
// }
|
mEncryptDecryptOverviewFragment = null;
|
||||||
//
|
|
||||||
// private void onHelpSelected() {
|
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
// Intent intent = new Intent(this, HelpActivity.class);
|
}
|
||||||
// startActivity(intent);
|
|
||||||
// }
|
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
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
@ -164,18 +203,20 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fabMoveUp(int height) {
|
public void fabMoveUp(int height) {
|
||||||
// Object fragment = getCurrentSection().getTargetFragment();
|
Object fragment = getSupportFragmentManager()
|
||||||
// if (fragment instanceof FabContainer) {
|
.findFragmentById(R.id.main_fragment_container);
|
||||||
// ((FabContainer) fragment).fabMoveUp(height);
|
if (fragment instanceof FabContainer) {
|
||||||
// }
|
((FabContainer) fragment).fabMoveUp(height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fabRestorePosition() {
|
public void fabRestorePosition() {
|
||||||
// Object fragment = getCurrentSection().getTargetFragment();
|
Object fragment = getSupportFragmentManager()
|
||||||
// if (fragment instanceof FabContainer) {
|
.findFragmentById(R.id.main_fragment_container);
|
||||||
// ((FabContainer) fragment).fabRestorePosition();
|
if (fragment instanceof FabContainer) {
|
||||||
// }
|
((FabContainer) fragment).fabRestorePosition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,13 @@
|
|||||||
android:id="@+id/activity_main_toolbar"
|
android:id="@+id/activity_main_toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:elevation="4dp"
|
||||||
android:background="?attr/colorPrimary"/>
|
android:background="?attr/colorPrimary"/>
|
||||||
|
|
||||||
<fragment android:name="org.sufficientlysecure.keychain.ui.KeyListFragment"
|
<FrameLayout
|
||||||
android:id="@+id/keys_fragment"
|
android:id="@+id/main_fragment_container"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="match_parent"/>
|
android:layout_width="match_parent"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user