action bar and a small fix

This commit is contained in:
Ashley Hughes 2014-02-06 22:16:41 +00:00
parent d4d6de1bc5
commit aee4ec6d1f
4 changed files with 44 additions and 30 deletions

View File

@ -55,6 +55,7 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.ActivityCompat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -97,6 +98,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
private String mSavedNewPassPhrase = null; private String mSavedNewPassPhrase = null;
private boolean mIsPassPhraseSet; private boolean mIsPassPhraseSet;
private boolean mNeedsSaving; private boolean mNeedsSaving;
private MenuItem mSaveButton;
private BootstrapButton mChangePassPhrase; private BootstrapButton mChangePassPhrase;
@ -109,12 +111,19 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
ExportHelper mExportHelper; ExportHelper mExportHelper;
public void somethingChanged() public boolean needsSaving()
{ {
mNeedsSaving = mUserIdsView.needsSaving(); mNeedsSaving = mUserIdsView.needsSaving();
mNeedsSaving |= mKeysView.needsSaving(); mNeedsSaving |= mKeysView.needsSaving();
mNeedsSaving |= hasPassphraseChanged(); mNeedsSaving |= hasPassphraseChanged();
Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show(); return mNeedsSaving;
}
public void somethingChanged()
{
ActivityCompat.invalidateOptionsMenu(this);
//Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show();
} }
public void onDeleted(Editor e, boolean wasNewItem) public void onDeleted(Editor e, boolean wasNewItem)
@ -133,6 +142,10 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
mExportHelper = new ExportHelper(this); mExportHelper = new ExportHelper(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(android.R.color.transparent);
getSupportActionBar().setHomeButtonEnabled(true);
mUserIds = new Vector<String>(); mUserIds = new Vector<String>();
mKeys = new Vector<PGPSecretKey>(); mKeys = new Vector<PGPSecretKey>();
mKeysUsages = new Vector<Integer>(); mKeysUsages = new Vector<Integer>();
@ -153,20 +166,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
* @param intent * @param intent
*/ */
private void handleActionCreateKey(Intent intent) { private void handleActionCreateKey(Intent intent) {
// Inflate a "Done"/"Cancel" custom action bar
ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save,
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveClicked();
}
}, R.string.btn_do_not_save, new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelClicked();
}
});
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
mCurrentPassPhrase = ""; mCurrentPassPhrase = "";
@ -255,15 +254,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
* @param intent * @param intent
*/ */
private void handleActionEditKey(Intent intent) { private void handleActionEditKey(Intent intent) {
// Inflate a "Done"/"Cancel" custom action bar
ActionBarHelper.setDoneView(getSupportActionBar(), R.string.btn_save,
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveClicked();
}
});
mDataUri = intent.getData(); mDataUri = intent.getData();
if (mDataUri == null) { if (mDataUri == null) {
Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
@ -325,12 +315,17 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.key_edit, menu); getMenuInflater().inflate(R.menu.key_edit, menu);
mSaveButton = (MenuItem) menu.findItem(R.id.menu_key_edit_save);
mSaveButton.setEnabled(needsSaving());
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home:
cancelClicked();
return true;
case R.id.menu_key_edit_cancel: case R.id.menu_key_edit_cancel:
cancelClicked(); cancelClicked();
return true; return true;
@ -353,6 +348,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
mExportHelper.deleteKey(mDataUri, Id.type.secret_key, returnHandler); mExportHelper.deleteKey(mDataUri, Id.type.secret_key, returnHandler);
return true; return true;
} }
case R.id.menu_key_edit_save:
saveClicked();
return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -373,8 +371,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show();
} }
if (masterKey != null) { if (masterKey != null) {
boolean isSet = false;
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) { for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
Log.d(Constants.TAG, "Added userId " + userId); Log.d(Constants.TAG, "Added userId " + userId);
if (!isSet) {
isSet = true;
String[] parts = PgpKeyHelper.splitUserId(userId);
if (parts[0] != null)
setTitle(parts[0]);
}
mUserIds.add(userId); mUserIds.add(userId);
} }
} }
@ -465,7 +470,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
} }
}); });
// disable passphrase when no passphrase checkobox is checked! // disable passphrase when no passphrase checkbox is checked!
mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() { mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override

View File

@ -133,6 +133,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public void onDeleted(Editor editor, boolean wasNewItem) { public void onDeleted(Editor editor, boolean wasNewItem) {
oldItemDeleted |= !wasNewItem; oldItemDeleted |= !wasNewItem;
this.updateEditorsVisible(); this.updateEditorsVisible();
if (mEditorListener != null) {
mEditorListener.onEdited();
}
} }
@Override @Override

View File

@ -137,12 +137,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
mOriginalName = result[0]; mOriginalName = result[0];
} }
if (result[1] != null) { if (result[1] != null) {
mComment.setText(result[1]); mEmail.setText(result[1]);
mOriginalComment = result[1]; mOriginalEmail = result[1];
} }
if (result[2] != null) { if (result[2] != null) {
mEmail.setText(result[2]); mComment.setText(result[2]);
mOriginalEmail = result[2]; mOriginalComment = result[2];
} }
mOriginallyMainUserID = isMainID; mOriginallyMainUserID = isMainID;

View File

@ -2,6 +2,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_key_edit_save"
android:icon="@drawable/ic_action_done"
app:showAsAction="always"
android:title="@string/btn_save">
</item>
<item <item
android:id="@+id/menu_key_edit_export_file" android:id="@+id/menu_key_edit_export_file"
app:showAsAction="never" app:showAsAction="never"