Cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -17,13 +17,8 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@@ -33,14 +28,20 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.*;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
import com.devspark.appmsg.AppMsg;
|
import com.devspark.appmsg.AppMsg;
|
||||||
|
|
||||||
@@ -63,20 +64,17 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
|||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.Editor;
|
import org.sufficientlysecure.keychain.ui.widget.Editor;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
|
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.SectionView;
|
import org.sufficientlysecure.keychain.ui.widget.SectionView;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
|
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import java.util.ArrayList;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import java.util.GregorianCalendar;
|
||||||
import android.view.LayoutInflater;
|
import java.util.List;
|
||||||
import android.view.Menu;
|
import java.util.Vector;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
public class EditKeyActivity extends ActionBarActivity implements EditorListener {
|
public class EditKeyActivity extends ActionBarActivity implements EditorListener {
|
||||||
|
|
||||||
@@ -89,10 +87,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
public static final String EXTRA_NO_PASSPHRASE = "no_passphrase";
|
public static final String EXTRA_NO_PASSPHRASE = "no_passphrase";
|
||||||
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generate_default_keys";
|
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generate_default_keys";
|
||||||
|
|
||||||
// results when saving key
|
|
||||||
public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id";
|
|
||||||
public static final String RESULT_EXTRA_USER_ID = "user_id";
|
|
||||||
|
|
||||||
// EDIT
|
// EDIT
|
||||||
private Uri mDataUri;
|
private Uri mDataUri;
|
||||||
|
|
||||||
@@ -119,8 +113,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
|
|
||||||
ExportHelper mExportHelper;
|
ExportHelper mExportHelper;
|
||||||
|
|
||||||
public boolean needsSaving()
|
public boolean needsSaving() {
|
||||||
{
|
|
||||||
mNeedsSaving = (mUserIdsView == null) ? false : mUserIdsView.needsSaving();
|
mNeedsSaving = (mUserIdsView == null) ? false : mUserIdsView.needsSaving();
|
||||||
mNeedsSaving |= (mKeysView == null) ? false : mKeysView.needsSaving();
|
mNeedsSaving |= (mKeysView == null) ? false : mKeysView.needsSaving();
|
||||||
mNeedsSaving |= hasPassphraseChanged();
|
mNeedsSaving |= hasPassphraseChanged();
|
||||||
@@ -129,19 +122,16 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void somethingChanged()
|
public void somethingChanged() {
|
||||||
{
|
|
||||||
ActivityCompat.invalidateOptionsMenu(this);
|
ActivityCompat.invalidateOptionsMenu(this);
|
||||||
//Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show();
|
//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) {
|
||||||
{
|
|
||||||
somethingChanged();
|
somethingChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEdited()
|
public void onEdited() {
|
||||||
{
|
|
||||||
somethingChanged();
|
somethingChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,41 +327,42 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
cancelClicked(); //TODO: why isn't this triggered on my tablet - one of many ui problems I've had with this device. A code compatibility issue or a Samsung fail?
|
cancelClicked(); //TODO: why isn't this triggered on my tablet - one of many ui problems I've had with this device. A code compatibility issue or a Samsung fail?
|
||||||
return true;
|
|
||||||
case R.id.menu_key_edit_cancel:
|
|
||||||
cancelClicked();
|
|
||||||
return true;
|
|
||||||
case R.id.menu_key_edit_export_file:
|
|
||||||
if (needsSaving()) {
|
|
||||||
Toast.makeText(this, R.string.error_save_first, Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
|
||||||
long[] ids = new long[]{masterKeyId};
|
|
||||||
mExportHelper.showExportKeysDialog(ids, Id.type.secret_key, Constants.Path.APP_DIR_FILE_SEC,
|
|
||||||
null);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
case R.id.menu_key_edit_cancel:
|
||||||
return true;
|
cancelClicked();
|
||||||
case R.id.menu_key_edit_delete:
|
return true;
|
||||||
long rowId= ProviderHelper.getRowId(this,mDataUri);
|
case R.id.menu_key_edit_export_file:
|
||||||
Uri convertUri = KeychainContract.KeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
if (needsSaving()) {
|
||||||
// Message is received after key is deleted
|
Toast.makeText(this, R.string.error_save_first, Toast.LENGTH_LONG).show();
|
||||||
Handler returnHandler = new Handler() {
|
} else {
|
||||||
@Override
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||||
public void handleMessage(Message message) {
|
long[] ids = new long[]{masterKeyId};
|
||||||
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
|
mExportHelper.showExportKeysDialog(ids, Id.type.secret_key, Constants.Path.APP_DIR_FILE_SEC,
|
||||||
setResult(RESULT_CANCELED);
|
null);
|
||||||
finish();
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.menu_key_edit_delete:
|
||||||
|
long rowId = ProviderHelper.getRowId(this, mDataUri);
|
||||||
|
Uri convertUri = KeychainContract.KeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||||
|
// Message is received after key is deleted
|
||||||
|
Handler returnHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}};
|
};
|
||||||
mExportHelper.deleteKey(convertUri, returnHandler);
|
mExportHelper.deleteKey(convertUri, returnHandler);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_key_edit_save:
|
case R.id.menu_key_edit_save:
|
||||||
saveClicked();
|
saveClicked();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -458,6 +449,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
/**
|
/**
|
||||||
* Build layout based on mUserId, mKeys and mKeysUsages Vectors. It creates Views for every user
|
* Build layout based on mUserId, mKeys and mKeysUsages Vectors. It creates Views for every user
|
||||||
* id and key.
|
* id and key.
|
||||||
|
*
|
||||||
* @param newKeys
|
* @param newKeys
|
||||||
*/
|
*/
|
||||||
private void buildLayout(boolean newKeys) {
|
private void buildLayout(boolean newKeys) {
|
||||||
@@ -471,7 +463,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
LinearLayout container = (LinearLayout) findViewById(R.id.edit_key_container);
|
LinearLayout container = (LinearLayout) findViewById(R.id.edit_key_container);
|
||||||
if(mIsPassPhraseSet){
|
if (mIsPassPhraseSet) {
|
||||||
mChangePassphrase.setText(getString(R.string.btn_change_passphrase));
|
mChangePassphrase.setText(getString(R.string.btn_change_passphrase));
|
||||||
}
|
}
|
||||||
mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
|
mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
|
||||||
@@ -532,15 +524,14 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPassphraseChanged()
|
public boolean hasPassphraseChanged() {
|
||||||
{
|
|
||||||
if (mNoPassphrase != null) {
|
if (mNoPassphrase != null) {
|
||||||
if (mNoPassphrase.isChecked()) {
|
if (mNoPassphrase.isChecked()) {
|
||||||
return mIsPassPhraseSet;
|
return mIsPassPhraseSet;
|
||||||
} else {
|
} else {
|
||||||
return (mNewPassPhrase != null && !mNewPassPhrase.equals(""));
|
return (mNewPassPhrase != null && !mNewPassPhrase.equals(""));
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -622,21 +613,11 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
Intent data = new Intent();
|
Intent data = new Intent();
|
||||||
|
|
||||||
// TODO: remove, now using uri!
|
|
||||||
data.putExtra(RESULT_EXTRA_MASTER_KEY_ID, getMasterKeyId());
|
|
||||||
|
|
||||||
// return uri pointing to new created key
|
// return uri pointing to new created key
|
||||||
Uri uri = KeychainContract.KeyRings.buildPublicKeyRingsByKeyIdUri(
|
Uri uri = KeychainContract.KeyRings.buildPublicKeyRingsByKeyIdUri(
|
||||||
String.valueOf(getMasterKeyId()));
|
String.valueOf(getMasterKeyId()));
|
||||||
data.setData(uri);
|
data.setData(uri);
|
||||||
|
|
||||||
ArrayList<String> userIds = null;
|
|
||||||
try {
|
|
||||||
userIds = getUserIds(mUserIdsView);
|
|
||||||
} catch (PgpGeneralException e) {
|
|
||||||
Log.e(Constants.TAG, "exception while getting user ids", e);
|
|
||||||
}
|
|
||||||
data.putExtra(RESULT_EXTRA_USER_ID, userIds.get(0));
|
|
||||||
setResult(RESULT_OK, data);
|
setResult(RESULT_OK, data);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
|||||||
mKeyUserId.setVisibility(View.VISIBLE);
|
mKeyUserId.setVisibility(View.VISIBLE);
|
||||||
mKeyUserIdRest.setVisibility(View.VISIBLE);
|
mKeyUserIdRest.setVisibility(View.VISIBLE);
|
||||||
mKeyMasterKeyIdHex.setVisibility(View.VISIBLE);
|
mKeyMasterKeyIdHex.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setError(String error) {
|
public void setError(String error) {
|
||||||
@@ -134,7 +133,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
//We don't care about the Loader id
|
|
||||||
return new CursorLoader(getActivity(), mReceivedUri, PROJECTION, null, null, null);
|
return new CursorLoader(getActivity(), mReceivedUri, PROJECTION, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +177,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select Secret Key Activity delivers the intent which was sent by it using interface to Select
|
|
||||||
// Secret Key Fragment.Intent contains the passed Uri
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
@@ -192,7 +188,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
|||||||
getActivity().getSupportLoaderManager().restartLoader(0, null, this);
|
getActivity().getSupportLoaderManager().restartLoader(0, null, this);
|
||||||
|
|
||||||
mKeyUserId.setError(null);
|
mKeyUserId.setError(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user