inline-edit: move action mode menu handling int activity
This commit is contained in:
parent
69220cb4c0
commit
aca0cd340b
|
@ -18,19 +18,26 @@
|
|||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.SimpleOnPageChangeListener;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.view.ActionMode;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
|
@ -47,7 +54,7 @@ import org.sufficientlysecure.keychain.util.ContactHelper;
|
|||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class ViewKeyAdvActivity extends BaseActivity implements
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
LoaderCallbacks<Cursor>, OnPageChangeListener {
|
||||
|
||||
ProviderHelper mProviderHelper;
|
||||
|
||||
|
@ -64,6 +71,11 @@ public class ViewKeyAdvActivity extends BaseActivity implements
|
|||
private PagerSlidingTabStrip mSlidingTabLayout;
|
||||
|
||||
private static final int LOADER_ID_UNIFIED = 0;
|
||||
private ActionMode mActionMode;
|
||||
private boolean mHasSecret;
|
||||
private PagerTabStripAdapter mTabAdapter;
|
||||
private boolean mActionIconShown;
|
||||
private boolean[] mTabsWithActionMode;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -109,33 +121,44 @@ public class ViewKeyAdvActivity extends BaseActivity implements
|
|||
}
|
||||
|
||||
private void initTabs(Uri dataUri, boolean hasSecret) {
|
||||
PagerTabStripAdapter adapter = new PagerTabStripAdapter(this);
|
||||
mViewPager.setAdapter(adapter);
|
||||
|
||||
mHasSecret = hasSecret;
|
||||
|
||||
mTabAdapter = new PagerTabStripAdapter(this);
|
||||
mViewPager.setAdapter(mTabAdapter);
|
||||
|
||||
// keep track which of these are action mode enabled!
|
||||
mTabsWithActionMode = new boolean[4];
|
||||
|
||||
Bundle shareBundle = new Bundle();
|
||||
shareBundle.putParcelable(ViewKeyAdvShareFragment.ARG_DATA_URI, dataUri);
|
||||
adapter.addTab(ViewKeyAdvShareFragment.class,
|
||||
mTabAdapter.addTab(ViewKeyAdvShareFragment.class,
|
||||
shareBundle, getString(R.string.key_view_tab_share));
|
||||
mTabsWithActionMode[0] = false;
|
||||
|
||||
Bundle userIdsBundle = new Bundle();
|
||||
userIdsBundle.putParcelable(ViewKeyAdvUserIdsFragment.ARG_DATA_URI, dataUri);
|
||||
userIdsBundle.putBoolean(ViewKeyAdvUserIdsFragment.ARG_HAS_SECRET, hasSecret);
|
||||
adapter.addTab(ViewKeyAdvUserIdsFragment.class,
|
||||
mTabAdapter.addTab(ViewKeyAdvUserIdsFragment.class,
|
||||
userIdsBundle, getString(R.string.section_user_ids));
|
||||
mTabsWithActionMode[1] = true;
|
||||
|
||||
Bundle keysBundle = new Bundle();
|
||||
keysBundle.putParcelable(ViewKeyAdvSubkeysFragment.ARG_DATA_URI, dataUri);
|
||||
keysBundle.putBoolean(ViewKeyAdvSubkeysFragment.ARG_HAS_SECRET, hasSecret);
|
||||
adapter.addTab(ViewKeyAdvSubkeysFragment.class,
|
||||
mTabAdapter.addTab(ViewKeyAdvSubkeysFragment.class,
|
||||
keysBundle, getString(R.string.key_view_tab_keys));
|
||||
mTabsWithActionMode[2] = true;
|
||||
|
||||
Bundle certsBundle = new Bundle();
|
||||
certsBundle.putParcelable(ViewKeyAdvCertsFragment.ARG_DATA_URI, dataUri);
|
||||
adapter.addTab(ViewKeyAdvCertsFragment.class,
|
||||
mTabAdapter.addTab(ViewKeyAdvCertsFragment.class,
|
||||
certsBundle, getString(R.string.key_view_tab_certs));
|
||||
mTabsWithActionMode[3] = false;
|
||||
|
||||
// update layout after operations
|
||||
mSlidingTabLayout.setViewPager(mViewPager);
|
||||
mSlidingTabLayout.setOnPageChangeListener(this);
|
||||
|
||||
// switch to tab selected by extra
|
||||
Intent intent = getIntent();
|
||||
|
@ -245,22 +268,83 @@ public class ViewKeyAdvActivity extends BaseActivity implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onActionModeStarted(final ActionMode mode) {
|
||||
super.onActionModeStarted(mode);
|
||||
// Leave whatever action mode we are in when we change the page
|
||||
mSlidingTabLayout.setOnPageChangeListener(new SimpleOnPageChangeListener() {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
if (!mHasSecret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// always add the item, switch its visibility depending on fragment
|
||||
getMenuInflater().inflate(R.menu.action_mode_edit, menu);
|
||||
final MenuItem vActionModeItem = menu.findItem(R.id.menu_action_mode_edit);
|
||||
|
||||
boolean isCurrentActionFragment = mTabsWithActionMode[mViewPager.getCurrentItem()];
|
||||
|
||||
// if the state is as it should be, never mind
|
||||
if (isCurrentActionFragment == mActionIconShown) {
|
||||
return isCurrentActionFragment;
|
||||
}
|
||||
|
||||
// show or hide accordingly
|
||||
mActionIconShown = isCurrentActionFragment;
|
||||
vActionModeItem.setEnabled(isCurrentActionFragment);
|
||||
animateMenuItem(vActionModeItem, isCurrentActionFragment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void animateMenuItem(final MenuItem vEditSubkeys, final boolean animateShow) {
|
||||
|
||||
View actionView = LayoutInflater.from(this).inflate(R.layout.edit_icon, null);
|
||||
vEditSubkeys.setActionView(actionView);
|
||||
actionView.setTranslationX(animateShow ? 150 : 0);
|
||||
|
||||
ViewPropertyAnimator animator = actionView.animate();
|
||||
animator.translationX(animateShow ? 0 : 150);
|
||||
animator.setDuration(300);
|
||||
animator.setInterpolator(new OvershootInterpolator(1.5f));
|
||||
animator.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
super.onPageSelected(position);
|
||||
mode.finish();
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (!animateShow) {
|
||||
vEditSubkeys.setVisible(false);
|
||||
}
|
||||
vEditSubkeys.setActionView(null);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionModeStarted(final ActionMode mode) {
|
||||
super.onActionModeStarted(mode);
|
||||
mActionMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionModeFinished(ActionMode mode) {
|
||||
super.onActionModeFinished(mode);
|
||||
mSlidingTabLayout.setOnPageChangeListener(null);
|
||||
mActionMode = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
mActionMode = null;
|
||||
}
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -28,7 +29,6 @@ import android.support.v4.app.LoaderManager;
|
|||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.view.ActionMode;
|
||||
import android.view.ActionMode.Callback;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -123,6 +123,8 @@ public class ViewKeyAdvSubkeysFragment extends LoaderFragment implements
|
|||
}
|
||||
});
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -138,8 +140,6 @@ public class ViewKeyAdvSubkeysFragment extends LoaderFragment implements
|
|||
}
|
||||
mHasSecret = getArguments().getBoolean(ARG_HAS_SECRET);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
loadData(dataUri);
|
||||
}
|
||||
|
||||
|
@ -184,9 +184,23 @@ public class ViewKeyAdvSubkeysFragment extends LoaderFragment implements
|
|||
mSubkeysAdapter.swapCursor(null);
|
||||
}
|
||||
|
||||
private void enterEditMode() {
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_action_mode_edit:
|
||||
enterEditMode();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void enterEditMode() {
|
||||
FragmentActivity activity = getActivity();
|
||||
activity.startActionMode(new Callback() {
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
activity.startActionMode(new ActionMode.Callback() {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
|
||||
|
@ -229,25 +243,6 @@ public class ViewKeyAdvSubkeysFragment extends LoaderFragment implements
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.edit_subkeys, menu);
|
||||
final MenuItem vEditSubkeys = menu.findItem(R.id.menu_edit_subkeys);
|
||||
vEditSubkeys.setVisible(mHasSecret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_edit_subkeys:
|
||||
enterEditMode();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void addSubkey() {
|
||||
boolean willBeMasterKey;
|
||||
if (mSubkeysAdapter != null) {
|
||||
|
|
|
@ -30,10 +30,8 @@ import android.support.v4.app.LoaderManager;
|
|||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.view.ActionMode;
|
||||
import android.view.ActionMode.Callback;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -109,6 +107,8 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
|
|||
}
|
||||
});
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -218,8 +218,6 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
|
|||
}
|
||||
boolean hasSecret = getArguments().getBoolean(ARG_HAS_SECRET);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
loadData(dataUri, hasSecret);
|
||||
}
|
||||
|
||||
|
@ -278,16 +276,22 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.edit_user_id, menu);
|
||||
MenuItem vEditUserIds = menu.findItem(R.id.menu_edit_user_ids);
|
||||
vEditUserIds.setVisible(mHasSecret);
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_action_mode_edit:
|
||||
enterEditMode();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void enterEditMode() {
|
||||
public void enterEditMode() {
|
||||
FragmentActivity activity = getActivity();
|
||||
activity.startActionMode(new Callback() {
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
activity.startActionMode(new ActionMode.Callback() {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
|
||||
|
@ -330,14 +334,4 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_edit_user_ids:
|
||||
enterEditMode();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
9
OpenKeychain/src/main/res/layout/edit_icon.xml
Normal file
9
OpenKeychain/src/main/res/layout/edit_icon.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:padding="0dp"
|
||||
android:src="@drawable/ic_mode_edit_white_24dp"
|
||||
style="@style/Widget.AppCompat.ActionButton" />
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_edit_user_ids"
|
||||
android:id="@+id/menu_action_mode_edit"
|
||||
android:icon="@drawable/ic_mode_edit_white_24dp"
|
||||
android:title="@string/key_view_action_edit_ids"
|
||||
android:title="@string/key_view_action_edit"
|
||||
app:showAsAction="always"
|
||||
/>
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_edit_subkeys"
|
||||
android:icon="@drawable/ic_mode_edit_white_24dp"
|
||||
android:title="@string/key_view_action_edit_subkeys"
|
||||
app:showAsAction="always"
|
||||
/>
|
||||
|
||||
</menu>
|
|
@ -666,8 +666,7 @@
|
|||
<string name="key_list_fab_import">"Import from File"</string>
|
||||
|
||||
<!-- Key view -->
|
||||
<string name="key_view_action_edit_ids">"Edit Identities"</string>
|
||||
<string name="key_view_action_edit_subkeys">"Edit Subkeys"</string>
|
||||
<string name="key_view_action_edit">"Edit"</string>
|
||||
<string name="key_view_action_encrypt">"Encrypt text"</string>
|
||||
<string name="key_view_action_encrypt_files">"files"</string>
|
||||
<string name="key_view_action_certify">"Confirm key"</string>
|
||||
|
|
Loading…
Reference in a new issue