From d044daeedd9ae42e72ce3d3b2ed191778b173943 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 7 Jul 2014 17:32:16 +0200 Subject: get rid of AppMsg library --- .../keychain/ui/EditKeyActivityOld.java | 744 --------------------- 1 file changed, 744 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityOld.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityOld.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityOld.java deleted file mode 100644 index 51457cd45..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityOld.java +++ /dev/null @@ -1,744 +0,0 @@ -/* - * Copyright (C) 2012-2014 Dominik Schürmann - * Copyright (C) 2010-2014 Thialfihar - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui; - -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.Messenger; -import android.support.v4.app.ActivityCompat; -import android.support.v7.app.ActionBarActivity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.LinearLayout; -import android.widget.Toast; - -import com.devspark.appmsg.AppMsg; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.ActionBarHelper; -import org.sufficientlysecure.keychain.helper.ExportHelper; -import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedSecretKey; -import org.sufficientlysecure.keychain.pgp.WrappedSecretKey; -import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; -import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; -import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; -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.SectionView; -import org.sufficientlysecure.keychain.ui.widget.UserIdEditor; -import org.sufficientlysecure.keychain.util.Log; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Vector; - -public class EditKeyActivityOld extends ActionBarActivity implements EditorListener { - - // Actions for internal use only: - public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY"; - public static final String ACTION_EDIT_KEY = Constants.INTENT_PREFIX + "EDIT_KEY"; - - // possible extra keys - public static final String EXTRA_USER_IDS = "user_ids"; - public static final String EXTRA_NO_PASSPHRASE = "no_passphrase"; - public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generate_default_keys"; - - // EDIT - private Uri mDataUri; - - private SectionView mUserIdsView; - private SectionView mKeysView; - - private String mCurrentPassphrase = null; - private String mNewPassphrase = null; - private String mSavedNewPassphrase = null; - private boolean mIsPassphraseSet; - private boolean mNeedsSaving; - private boolean mIsBrandNewKeyring = false; - - private Button mChangePassphrase; - - private CheckBox mNoPassphrase; - - Vector mUserIds; - Vector mKeys; - Vector mKeysUsages; - boolean mMasterCanSign = true; - - ExportHelper mExportHelper; - - public boolean needsSaving() { - mNeedsSaving = (mUserIdsView == null) ? false : mUserIdsView.needsSaving(); - mNeedsSaving |= (mKeysView == null) ? false : mKeysView.needsSaving(); - mNeedsSaving |= hasPassphraseChanged(); - mNeedsSaving |= mIsBrandNewKeyring; - return mNeedsSaving; - } - - - public void somethingChanged() { - ActivityCompat.invalidateOptionsMenu(this); - } - - public void onDeleted(Editor e, boolean wasNewItem) { - somethingChanged(); - } - - public void onEdited() { - somethingChanged(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mExportHelper = new ExportHelper(this); - - // Inflate a "Done"/"Cancel" custom action bar view - ActionBarHelper.setTwoButtonView(getSupportActionBar(), - R.string.btn_save, R.drawable.ic_action_save, - new View.OnClickListener() { - @Override - public void onClick(View v) { - // Save - saveClicked(); - } - }, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel, - new View.OnClickListener() { - @Override - public void onClick(View v) { - // Cancel - cancelClicked(); - } - } - ); - - mUserIds = new Vector(); - mKeys = new Vector(); - mKeysUsages = new Vector(); - - // Catch Intents opened from other apps - Intent intent = getIntent(); - String action = intent.getAction(); - if (ACTION_CREATE_KEY.equals(action)) { - handleActionCreateKey(intent); - } else if (ACTION_EDIT_KEY.equals(action)) { - handleActionEditKey(intent); - } - } - - /** - * Handle intent action to create new key - * - * @param intent - */ - private void handleActionCreateKey(Intent intent) { - Bundle extras = intent.getExtras(); - - mCurrentPassphrase = ""; - mIsBrandNewKeyring = true; - - if (extras != null) { - // if userId is given, prefill the fields - if (extras.containsKey(EXTRA_USER_IDS)) { - Log.d(Constants.TAG, "UserIds are given!"); - mUserIds.add(extras.getString(EXTRA_USER_IDS)); - } - - // if no passphrase is given - if (extras.containsKey(EXTRA_NO_PASSPHRASE)) { - boolean noPassphrase = extras.getBoolean(EXTRA_NO_PASSPHRASE); - if (noPassphrase) { - // check "no passphrase" checkbox and remove button - mNoPassphrase.setChecked(true); - mChangePassphrase.setVisibility(View.GONE); - } - } - - // generate key - if (extras.containsKey(EXTRA_GENERATE_DEFAULT_KEYS)) { - /* - boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS); - if (generateDefaultKeys) { - - // fill values for this action - Bundle data = new Bundle(); - data.putString(KeychainIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE, - mCurrentPassphrase); - - serviceIntent.putExtra(KeychainIntentService.EXTRA_DATA, data); - - // Message is received after generating is done in KeychainIntentService - KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler( - this, getResources().getQuantityString(R.plurals.progress_generating, 1), - ProgressDialog.STYLE_HORIZONTAL, true, - - new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - // Stop key generation on cancel - stopService(serviceIntent); - EditKeyActivity.this.setResult(Activity.RESULT_CANCELED); - EditKeyActivity.this.finish(); - } - }) { - - @Override - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); - - if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - // get new key from data bundle returned from service - Bundle data = message.getDataAsStringList(); - - ArrayList newKeys = - PgpConversionHelper.BytesToPGPSecretKeyList(data - .getByteArray(KeychainIntentService.RESULT_NEW_KEY)); - - ArrayList keyUsageFlags = data.getIntegerArrayList( - KeychainIntentService.RESULT_KEY_USAGES); - - if (newKeys.size() == keyUsageFlags.size()) { - for (int i = 0; i < newKeys.size(); ++i) { - mKeys.add(newKeys.get(i)); - mKeysUsages.add(keyUsageFlags.get(i)); - } - } - - buildLayout(true); - } - } - }; - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - serviceIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - - saveHandler.showProgressDialog(this); - - // start service with intent - startService(serviceIntent); - } - */ - } - } else { - buildLayout(false); - } - } - - /** - * Handle intent action to edit existing key - * - * @param intent - */ - private void handleActionEditKey(Intent intent) { - mDataUri = intent.getData(); - if (mDataUri == null) { - Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); - finish(); - } else { - Log.d(Constants.TAG, "uri: " + mDataUri); - - try { - Uri secretUri = KeyRings.buildUnifiedKeyRingUri(mDataUri); - WrappedSecretKeyRing keyRing = new ProviderHelper(this).getWrappedSecretKeyRing(secretUri); - - mMasterCanSign = keyRing.getSubKey().canCertify(); - for (WrappedSecretKey key : keyRing.secretKeyIterator()) { - // Turn into uncached instance - mKeys.add(key.getUncached()); - mKeysUsages.add(key.getKeyUsage()); // get usage when view is created - } - - boolean isSet = false; - for (String userId : keyRing.getSubKey().getUserIds()) { - Log.d(Constants.TAG, "Added userId " + userId); - if (!isSet) { - isSet = true; - String[] parts = KeyRing.splitUserId(userId); - if (parts[0] != null) { - setTitle(parts[0]); - } - } - mUserIds.add(userId); - } - - buildLayout(false); - - mCurrentPassphrase = ""; - mIsPassphraseSet = keyRing.hasPassphrase(); - if (!mIsPassphraseSet) { - // check "no passphrase" checkbox and remove button - mNoPassphrase.setChecked(true); - mChangePassphrase.setVisibility(View.GONE); - } - - } catch (ProviderHelper.NotFoundException e) { - Log.e(Constants.TAG, "Keyring not found: " + e.getMessage(), e); - Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_SHORT).show(); - finish(); - } - - } - } - - /** - * Shows the dialog to set a new passphrase - */ - private void showSetPassphraseDialog() { - // Message is received after passphrase is cached - Handler returnHandler = new Handler() { - @Override - public void handleMessage(Message message) { - if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { - Bundle data = message.getData(); - - // set new returned passphrase! - mNewPassphrase = data - .getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE); - - updatePassphraseButtonText(); - somethingChanged(); - } - } - }; - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(returnHandler); - - // set title based on isPassphraseSet() - int title; - if (isPassphraseSet()) { - title = R.string.title_change_passphrase; - } else { - title = R.string.title_set_passphrase; - } - - SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance( - messenger, null, title); - - setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog"); - } - - /** - * Build layout based on mUserId, mKeys and mKeysUsages Vectors. It creates Views for every user - * id and key. - * - * @param newKeys - */ - private void buildLayout(boolean newKeys) { - setContentView(R.layout.edit_key_activity); - - // find views - mChangePassphrase = (Button) findViewById(R.id.edit_key_btn_change_passphrase); - mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase); - // Build layout based on given userIds and keys - - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - LinearLayout container = (LinearLayout) findViewById(R.id.edit_key_container); - if (mIsPassphraseSet) { - mChangePassphrase.setText(getString(R.string.btn_change_passphrase)); - } - mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false); - mUserIdsView.setType(SectionView.TYPE_USER_ID); - mUserIdsView.setCanBeEdited(mMasterCanSign); - mUserIdsView.setUserIds(mUserIds); - mUserIdsView.setEditorListener(this); - container.addView(mUserIdsView); - mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false); - mKeysView.setType(SectionView.TYPE_KEY); - mKeysView.setCanBeEdited(mMasterCanSign); - mKeysView.setKeys(mKeys, mKeysUsages, newKeys); - mKeysView.setEditorListener(this); - container.addView(mKeysView); - - updatePassphraseButtonText(); - - mChangePassphrase.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - showSetPassphraseDialog(); - } - }); - - // disable passphrase when no passphrase checkbox is checked! - mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - // remove passphrase - mSavedNewPassphrase = mNewPassphrase; - mNewPassphrase = ""; - mChangePassphrase.setVisibility(View.GONE); - } else { - mNewPassphrase = mSavedNewPassphrase; - mChangePassphrase.setVisibility(View.VISIBLE); - } - somethingChanged(); - } - }); - } - - private long getMasterKeyId() { - if (mKeysView.getEditors().getChildCount() == 0) { - return 0; - } - return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyId(); - } - - public boolean isPassphraseSet() { - if (mNoPassphrase.isChecked()) { - return true; - } else if ((mIsPassphraseSet) - || (mNewPassphrase != null && !mNewPassphrase.equals(""))) { - return true; - } else { - return false; - } - } - - public boolean hasPassphraseChanged() { - if (mNoPassphrase != null) { - if (mNoPassphrase.isChecked()) { - return mIsPassphraseSet; - } else { - return (mNewPassphrase != null && !mNewPassphrase.equals("")); - } - } else { - return false; - } - } - - private void saveClicked() { - final long masterKeyId = getMasterKeyId(); - if (needsSaving()) { //make sure, as some versions don't support invalidateOptionsMenu - try { - if (!isPassphraseSet()) { - throw new PgpGeneralException(this.getString(R.string.set_a_passphrase)); - } - - String passphrase; - if (mIsPassphraseSet) { - passphrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId); - } else { - passphrase = ""; - } - if (passphrase == null) { - PassphraseDialogFragment.show(this, masterKeyId, - new Handler() { - @Override - public void handleMessage(Message message) { - if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { - mCurrentPassphrase = PassphraseCacheService.getCachedPassphrase( - EditKeyActivityOld.this, masterKeyId); - checkEmptyIDsWanted(); - } - } - }); - } else { - mCurrentPassphrase = passphrase; - checkEmptyIDsWanted(); - } - } catch (PgpGeneralException e) { - AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), - AppMsg.STYLE_ALERT).show(); - } - } else { - AppMsg.makeText(this, R.string.error_change_something_first, AppMsg.STYLE_ALERT).show(); - } - } - - private void checkEmptyIDsWanted() { - try { - ArrayList userIDs = getUserIds(mUserIdsView); - List newIDs = mUserIdsView.getNewIDFlags(); - ArrayList originalIDs = mUserIdsView.getOriginalIDs(); - int curID = 0; - for (String userID : userIDs) { - if (userID.equals("") && (!userID.equals(originalIDs.get(curID)) || newIDs.get(curID))) { - CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder( - EditKeyActivityOld.this); - - alert.setIcon(R.drawable.ic_dialog_alert_holo_light); - alert.setTitle(R.string.warning); - alert.setMessage(EditKeyActivityOld.this.getString(R.string.ask_empty_id_ok)); - - alert.setPositiveButton(EditKeyActivityOld.this.getString(android.R.string.yes), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - finallySaveClicked(); - } - } - ); - alert.setNegativeButton(this.getString(android.R.string.no), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - } - ); - alert.setCancelable(false); - alert.show(); - return; - } - curID++; - } - } catch (PgpGeneralException e) { - Log.e(Constants.TAG, getString(R.string.error_message, e.getMessage())); - AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), AppMsg.STYLE_ALERT).show(); - } - finallySaveClicked(); - } - - private boolean[] toPrimitiveArray(final List booleanList) { - final boolean[] primitives = new boolean[booleanList.size()]; - int index = 0; - for (Boolean object : booleanList) { - primitives[index++] = object; - } - return primitives; - } - - private void finallySaveClicked() { - /* - try { - // Send all information needed to service to edit key in other thread - Intent intent = new Intent(this, KeychainIntentService.class); - - intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); - - OldSaveKeyringParcel saveParams = new OldSaveKeyringParcel(); - saveParams.userIds = getUserIds(mUserIdsView); - saveParams.originalIDs = mUserIdsView.getOriginalIDs(); - saveParams.deletedIDs = mUserIdsView.getDeletedIDs(); - saveParams.newIDs = toPrimitiveArray(mUserIdsView.getNewIDFlags()); - saveParams.primaryIDChanged = mUserIdsView.primaryChanged(); - saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray()); - saveParams.deletedKeys = mKeysView.getDeletedKeys(); - saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView); - saveParams.keysUsages = getKeysUsages(mKeysView); - saveParams.newPassphrase = mNewPassphrase; - saveParams.oldPassphrase = mCurrentPassphrase; - saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray()); - saveParams.keys = getKeys(mKeysView); - saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID(); - - // fill values for this action - Bundle data = new Bundle(); - data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign); - data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, saveParams); - - intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - - // Message is received after saving is done in KeychainIntentService - KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, - getString(R.string.progress_saving), ProgressDialog.STYLE_HORIZONTAL) { - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); - - if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - Intent data = new Intent(); - - // return uri pointing to new created key - Uri uri = KeyRings.buildGenericKeyRingUri(getMasterKeyId()); - data.setData(uri); - - setResult(RESULT_OK, data); - finish(); - } - } - }; - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - - saveHandler.showProgressDialog(this); - - // start service with intent - startService(intent); - } catch (PgpGeneralException e) { - Log.e(Constants.TAG, getString(R.string.error_message, e.getMessage())); - AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), - AppMsg.STYLE_ALERT).show(); - } - */ - } - - private void cancelClicked() { - if (needsSaving()) { //ask if we want to save - CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder( - EditKeyActivityOld.this); - - alert.setIcon(R.drawable.ic_dialog_alert_holo_light); - alert.setTitle(R.string.warning); - alert.setMessage(EditKeyActivityOld.this.getString(R.string.ask_save_changed_key)); - - alert.setPositiveButton(EditKeyActivityOld.this.getString(android.R.string.yes), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - saveClicked(); - } - }); - alert.setNegativeButton(this.getString(android.R.string.no), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - setResult(RESULT_CANCELED); - finish(); - } - }); - alert.setCancelable(false); - alert.show(); - } else { - setResult(RESULT_CANCELED); - finish(); - } - } - - /** - * Returns user ids from the SectionView - * - * @param userIdsView - * @return - */ - private ArrayList getUserIds(SectionView userIdsView) throws PgpGeneralException { - ArrayList userIds = new ArrayList(); - - ViewGroup userIdEditors = userIdsView.getEditors(); - - boolean gotMainUserId = false; - for (int i = 0; i < userIdEditors.getChildCount(); ++i) { - UserIdEditor editor = (UserIdEditor) userIdEditors.getChildAt(i); - String userId; - userId = editor.getValue(); - - if (editor.isMainUserId()) { - userIds.add(0, userId); - gotMainUserId = true; - } else { - userIds.add(userId); - } - } - - if (userIds.size() == 0) { - throw new PgpGeneralException(getString(R.string.error_key_needs_a_user_id)); - } - - if (!gotMainUserId) { - throw new PgpGeneralException(getString(R.string.error_main_user_id_must_not_be_empty)); - } - - return userIds; - } - - /** - * Returns keys from the SectionView - * - * @param keysView - * @return - */ - private ArrayList getKeys(SectionView keysView) throws PgpGeneralException { - ArrayList keys = new ArrayList(); - - ViewGroup keyEditors = keysView.getEditors(); - - if (keyEditors.getChildCount() == 0) { - throw new PgpGeneralException(getString(R.string.error_key_needs_master_key)); - } - - for (int i = 0; i < keyEditors.getChildCount(); ++i) { - KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i); - keys.add(editor.getValue()); - } - - return keys; - } - - /** - * Returns usage selections of keys from the SectionView - * - * @param keysView - * @return - */ - private ArrayList getKeysUsages(SectionView keysView) throws PgpGeneralException { - ArrayList keysUsages = new ArrayList(); - - ViewGroup keyEditors = keysView.getEditors(); - - if (keyEditors.getChildCount() == 0) { - throw new PgpGeneralException(getString(R.string.error_key_needs_master_key)); - } - - for (int i = 0; i < keyEditors.getChildCount(); ++i) { - KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i); - keysUsages.add(editor.getUsage()); - } - - return keysUsages; - } - - private ArrayList getKeysExpiryDates(SectionView keysView) throws PgpGeneralException { - ArrayList keysExpiryDates = new ArrayList(); - - ViewGroup keyEditors = keysView.getEditors(); - - if (keyEditors.getChildCount() == 0) { - throw new PgpGeneralException(getString(R.string.error_key_needs_master_key)); - } - - for (int i = 0; i < keyEditors.getChildCount(); ++i) { - KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i); - keysExpiryDates.add(editor.getExpiryDate()); - } - - return keysExpiryDates; - } - - private void updatePassphraseButtonText() { - mChangePassphrase.setText(isPassphraseSet() ? getString(R.string.btn_change_passphrase) - : getString(R.string.btn_set_passphrase)); - } - -} -- cgit v1.2.3 From 2c62aa90c0560c975d34b39df4379b5e1fcd6884 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 7 Jul 2014 17:34:41 +0200 Subject: use SuperToast instead of AppMsg in code, part 1 --- .../service/KeychainIntentServiceHandler.java | 7 +++-- .../keychain/ui/CertifyKeyActivity.java | 18 +++++++------ .../keychain/ui/DecryptFileFragment.java | 10 ++----- .../keychain/ui/DecryptMessageFragment.java | 9 +++---- .../keychain/ui/EncryptFileFragment.java | 27 +++++++++---------- .../keychain/ui/EncryptMessageFragment.java | 17 +++++------- .../keychain/ui/KeyListActivity.java | 16 +++++------ .../keychain/ui/KeyListFragment.java | 15 +++++------ .../keychain/ui/ViewKeyActivity.java | 31 +++++++--------------- .../keychain/ui/ViewKeyMainFragment.java | 7 +++-- .../keychain/ui/ViewKeyShareFragment.java | 15 +++++------ .../ui/dialog/ShareQrCodeDialogFragment.java | 7 +++-- .../sufficientlysecure/keychain/util/Notify.java | 2 +- 13 files changed, 75 insertions(+), 106 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java index 755827482..0cdbe708e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java @@ -25,12 +25,11 @@ import android.os.Message; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; public class KeychainIntentServiceHandler extends Handler { @@ -102,9 +101,9 @@ public class KeychainIntentServiceHandler extends Handler { // show error from service if (data.containsKey(DATA_ERROR)) { - AppMsg.makeText(mActivity, + Notify.showNotify(mActivity, mActivity.getString(R.string.error_message, data.getString(DATA_ERROR)), - AppMsg.STYLE_ALERT).show(); + Notify.Style.ERROR); } break; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java index 7ac229b91..301b4ad40 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java @@ -41,8 +41,6 @@ import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; @@ -52,10 +50,12 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; +import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.util.ArrayList; @@ -246,8 +246,8 @@ public class CertifyKeyActivity extends ActionBarActivity implements // Bail out if there is not at least one user id selected ArrayList userIds = mUserIdsAdapter.getSelectedUserIds(); if (userIds.isEmpty()) { - AppMsg.makeText(CertifyKeyActivity.this, "No User IDs to sign selected!", - AppMsg.STYLE_ALERT).show(); + Notify.showNotify(CertifyKeyActivity.this, "No Notify.Style IDs to sign selected!", + Notify.Style.ERROR); return; } @@ -274,8 +274,8 @@ public class CertifyKeyActivity extends ActionBarActivity implements if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - AppMsg.makeText(CertifyKeyActivity.this, R.string.key_certify_success, - AppMsg.STYLE_INFO).show(); + Notify.showNotify(CertifyKeyActivity.this, R.string.key_certify_success, + Notify.Style.INFO); // check if we need to send the key to the server or not if (mUploadKeyCheckbox.isChecked()) { @@ -327,8 +327,10 @@ public class CertifyKeyActivity extends ActionBarActivity implements super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - AppMsg.makeText(CertifyKeyActivity.this, R.string.key_send_success, - AppMsg.STYLE_INFO).show(); + Intent intent = new Intent(); + intent.putExtra(OperationResultParcel.EXTRA_RESULT, message.getData()); + Notify.showNotify(CertifyKeyActivity.this, R.string.key_send_success, + Notify.Style.INFO); setResult(RESULT_OK); finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java index c12b5b7be..56dfdbd95 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java @@ -34,8 +34,6 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageButton; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.FileHelper; @@ -129,7 +127,6 @@ public class DecryptFileFragment extends DecryptFragment { } if (mInputFilename.equals("")) { - //AppMsg.makeText(getActivity(), R.string.no_file_selected, AppMsg.STYLE_ALERT).show(); Notify.showNotify(getActivity(), R.string.no_file_selected, Notify.Style.ERROR); return; } @@ -137,11 +134,8 @@ public class DecryptFileFragment extends DecryptFragment { if (mInputUri == null && mInputFilename.startsWith("file")) { File file = new File(mInputFilename); if (!file.exists() || !file.isFile()) { - AppMsg.makeText( - getActivity(), - getString(R.string.error_message, - getString(R.string.error_file_not_found)), AppMsg.STYLE_ALERT) - .show(); + Notify.showNotify(getActivity(), getString(R.string.error_message, + getString(R.string.error_file_not_found)), Notify.Style.ERROR); return; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java index 46462f924..cf7a0b4b8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java @@ -28,8 +28,6 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.EditText; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; @@ -38,6 +36,7 @@ import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.util.regex.Matcher; @@ -107,12 +106,10 @@ public class DecryptMessageFragment extends DecryptFragment { mCiphertext = matcher.group(1); decryptStart(null); } else { - AppMsg.makeText(getActivity(), R.string.error_invalid_data, AppMsg.STYLE_ALERT) - .show(); + Notify.showNotify(getActivity(), R.string.error_invalid_data, Notify.Style.ERROR); } } else { - AppMsg.makeText(getActivity(), R.string.error_invalid_data, AppMsg.STYLE_ALERT) - .show(); + Notify.showNotify(getActivity(), R.string.error_invalid_data, Notify.Style.ERROR); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java index f5d89d186..6ff8d421b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java @@ -37,8 +37,6 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.Spinner; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.FileHelper; @@ -51,6 +49,7 @@ import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.util.Choice; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.io.File; @@ -218,18 +217,18 @@ public class EncryptFileFragment extends Fragment { } if (mInputFilename.equals("")) { - AppMsg.makeText(getActivity(), R.string.no_file_selected, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.no_file_selected, Notify.Style.ERROR); return; } if (mInputUri == null && !mInputFilename.startsWith("content")) { File file = new File(mInputFilename); if (!file.exists() || !file.isFile()) { - AppMsg.makeText( + Notify.showNotify( getActivity(), getString(R.string.error_message, - getString(R.string.error_file_not_found)), AppMsg.STYLE_ALERT) - .show(); + getString(R.string.error_file_not_found)), Notify.Style.ERROR + ); return; } } @@ -240,13 +239,13 @@ public class EncryptFileFragment extends Fragment { boolean gotPassphrase = (mEncryptInterface.getPassphrase() != null && mEncryptInterface.getPassphrase().length() != 0); if (!gotPassphrase) { - AppMsg.makeText(getActivity(), R.string.passphrase_must_not_be_empty, AppMsg.STYLE_ALERT) - .show(); + Notify.showNotify(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR) + ; return; } if (!mEncryptInterface.getPassphrase().equals(mEncryptInterface.getPassphraseAgain())) { - AppMsg.makeText(getActivity(), R.string.passphrases_do_not_match, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR); return; } } else { @@ -256,13 +255,13 @@ public class EncryptFileFragment extends Fragment { && mEncryptInterface.getEncryptionKeys().length > 0); if (!gotEncryptionKeys) { - AppMsg.makeText(getActivity(), R.string.select_encryption_key, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.select_encryption_key, Notify.Style.ERROR); return; } if (!gotEncryptionKeys && mEncryptInterface.getSignatureKey() == 0) { - AppMsg.makeText(getActivity(), R.string.select_encryption_or_signature_key, - AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.select_encryption_or_signature_key, + Notify.Style.ERROR); return; } @@ -345,8 +344,8 @@ public class EncryptFileFragment extends Fragment { super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - AppMsg.makeText(getActivity(), R.string.encrypt_sign_successful, - AppMsg.STYLE_INFO).show(); + Notify.showNotify(getActivity(), R.string.encrypt_sign_successful, + Notify.Style.INFO); if (mDeleteAfter.isChecked()) { // Create and show dialog to delete original file diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java index 8a6103b16..e1760b4ed 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java @@ -30,8 +30,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; @@ -41,6 +39,7 @@ import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; public class EncryptMessageFragment extends Fragment { public static final String ARG_TEXT = "text"; @@ -126,13 +125,12 @@ public class EncryptMessageFragment extends Fragment { boolean gotPassphrase = (mEncryptInterface.getPassphrase() != null && mEncryptInterface.getPassphrase().length() != 0); if (!gotPassphrase) { - AppMsg.makeText(getActivity(), R.string.passphrase_must_not_be_empty, AppMsg.STYLE_ALERT) - .show(); + Notify.showNotify(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR); return; } if (!mEncryptInterface.getPassphrase().equals(mEncryptInterface.getPassphraseAgain())) { - AppMsg.makeText(getActivity(), R.string.passphrases_do_not_match, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR); return; } @@ -143,8 +141,8 @@ public class EncryptMessageFragment extends Fragment { && mEncryptInterface.getEncryptionKeys().length > 0); if (!gotEncryptionKeys && mEncryptInterface.getSignatureKey() == 0) { - AppMsg.makeText(getActivity(), R.string.select_encryption_or_signature_key, - AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.select_encryption_or_signature_key, + Notify.Style.ERROR); return; } @@ -226,9 +224,8 @@ public class EncryptMessageFragment extends Fragment { if (toClipboard) { ClipboardReflection.copyToClipboard(getActivity(), output); - AppMsg.makeText(getActivity(), - R.string.encrypt_sign_clipboard_successful, AppMsg.STYLE_INFO) - .show(); + Notify.showNotify(getActivity(), + R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO); } else { Intent sendIntent = new Intent(Intent.ACTION_SEND); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 849576284..c219fb98c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -25,15 +25,11 @@ import android.os.Messenger; import android.view.Menu; import android.view.MenuItem; -import com.devspark.appmsg.AppMsg; - import org.spongycastle.bcpg.sig.KeyFlags; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants.choice.algorithm; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ExportHelper; -import org.sufficientlysecure.keychain.helper.OtherHelper; -import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.service.KeychainIntentService; @@ -41,9 +37,9 @@ import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.io.IOException; -import java.util.ArrayList; public class KeyListActivity extends DrawerActivity { @@ -96,21 +92,21 @@ public class KeyListActivity extends DrawerActivity { case R.id.menu_key_list_debug_read: try { KeychainDatabase.debugRead(this); - AppMsg.makeText(this, "Restored from backup", AppMsg.STYLE_CONFIRM).show(); + Notify.showNotify(this, "Restored Notify.Style backup", Notify.Style.INFO); getContentResolver().notifyChange(KeychainContract.KeyRings.CONTENT_URI, null); } catch(IOException e) { Log.e(Constants.TAG, "IO Error", e); - AppMsg.makeText(this, "IO Error: " + e.getMessage(), AppMsg.STYLE_ALERT).show(); + Notify.showNotify(this, "IO Notify.Style: " + e.getMessage(), Notify.Style.ERROR); } return true; case R.id.menu_key_list_debug_write: try { KeychainDatabase.debugWrite(this); - AppMsg.makeText(this, "Backup successful", AppMsg.STYLE_CONFIRM).show(); + Notify.showNotify(this, "Backup Notify.Style", Notify.Style.INFO); } catch(IOException e) { Log.e(Constants.TAG, "IO Error", e); - AppMsg.makeText(this, "IO Error: " + e.getMessage(), AppMsg.STYLE_ALERT).show(); + Notify.showNotify(this, "IO Notify.Style: " + e.getMessage(), Notify.Style.ERROR); } return true; @@ -171,4 +167,4 @@ public class KeyListActivity extends DrawerActivity { startService(intent); } -} \ No newline at end of file +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 9d0a80406..c8f6b7b1e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -52,8 +52,6 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Button; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ExportHelper; @@ -62,6 +60,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.util.Highlighter; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.util.Date; import java.util.HashMap; @@ -104,10 +103,10 @@ public class KeyListFragment extends LoaderFragment @Override public void onClick(View v) { - Intent intent = new Intent(getActivity(), EditKeyActivityOld.class); - intent.setAction(EditKeyActivityOld.ACTION_CREATE_KEY); - intent.putExtra(EditKeyActivityOld.EXTRA_GENERATE_DEFAULT_KEYS, true); - intent.putExtra(EditKeyActivityOld.EXTRA_USER_IDS, ""); // show user id view + Intent intent = new Intent(getActivity(), EditKeyActivity.class); + intent.setAction(EditKeyActivity.ACTION_CREATE_KEY); + intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true); + intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view startActivityForResult(intent, 0); } }); @@ -339,8 +338,8 @@ public class KeyListFragment extends LoaderFragment public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) { // Can only work on singular secret keys if(hasSecret && masterKeyIds.length > 1) { - AppMsg.makeText(getActivity(), R.string.secret_cannot_multiple, - AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.secret_cannot_multiple, + Notify.Style.ERROR); return; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index a9cd0976b..b8b2542ce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -44,8 +44,6 @@ import android.view.MenuItem; import android.view.View; import android.view.Window; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ContactHelper; @@ -54,11 +52,13 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; +import org.sufficientlysecure.keychain.util.Notify; import java.util.Date; import java.util.HashMap; @@ -295,7 +295,7 @@ public class ViewKeyActivity extends ActionBarActivity implements } } } catch (ProviderHelper.NotFoundException e) { - AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(this, R.string.error_key_not_found, Notify.Style.ERROR); Log.e(Constants.TAG, "Key not found", e); } return super.onOptionsItemSelected(item); @@ -352,22 +352,11 @@ public class ViewKeyActivity extends ActionBarActivity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case REQUEST_CODE_LOOKUP_KEY: { - if (resultCode == Activity.RESULT_OK) { - ImportResult result = data.getParcelableExtra(ImportKeysActivity.EXTRA_RESULT); - if (result != null) { - result.displayNotify(this); - } - } - break; - } - - default: { - super.onActivityResult(requestCode, resultCode, data); - - break; - } + if (data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { + OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + result.createNotify(this).show(); + } else { + super.onActivityResult(requestCode, resultCode, data); } } @@ -455,8 +444,8 @@ public class ViewKeyActivity extends ActionBarActivity implements public void handleMessage(Message msg) { switch (msg.what) { case NFC_SENT: - AppMsg.makeText(ViewKeyActivity.this, R.string.nfc_successful, - AppMsg.STYLE_INFO).show(); + Notify.showNotify( + ViewKeyActivity.this, R.string.nfc_successful, Notify.Style.INFO); break; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index f0636cf2c..2a0f518d8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -29,8 +29,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ListView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; @@ -40,6 +38,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.util.Date; @@ -225,7 +224,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements private void encrypt(Uri dataUri) { // If there is no encryption key, don't bother. if (!mHasEncrypt) { - AppMsg.makeText(getActivity(), R.string.error_no_encrypt_subkey, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.error_no_encrypt_subkey, Notify.Style.ERROR); return; } try { @@ -246,7 +245,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements private void certify(Uri dataUri) { Intent signIntent = new Intent(getActivity(), CertifyKeyActivity.class); signIntent.setData(dataUri); - startActivity(signIntent); + startActivityForResult(signIntent, 0); } private void editKey(Uri dataUri) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java index 52b573f47..c2339c25f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java @@ -33,8 +33,6 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; @@ -47,6 +45,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import org.sufficientlysecure.keychain.util.QrCodeUtils; import java.io.IOException; @@ -171,13 +170,13 @@ public class ViewKeyShareFragment extends LoaderFragment implements } else { message = getResources().getString(R.string.key_copied_to_clipboard); } - AppMsg.makeText(getActivity(), message, AppMsg.STYLE_INFO).show(); + Notify.showNotify(getActivity(), message, Notify.Style.OK); } else { // Android will fail with android.os.TransactionTooLargeException if key is too big // see http://www.lonestarprod.com/?p=34 if (content.length() >= 86389) { - AppMsg.makeText(getActivity(), R.string.key_too_big_for_sharing, - AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.key_too_big_for_sharing, + Notify.Style.ERROR); return; } @@ -195,13 +194,13 @@ public class ViewKeyShareFragment extends LoaderFragment implements } } catch (PgpGeneralException e) { Log.e(Constants.TAG, "error processing key!", e); - AppMsg.makeText(getActivity(), R.string.error_key_processing, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.error_key_processing, Notify.Style.ERROR); } catch (IOException e) { Log.e(Constants.TAG, "error processing key!", e); - AppMsg.makeText(getActivity(), R.string.error_key_processing, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.error_key_processing, Notify.Style.ERROR); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); - AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java index 24608784b..eb779f401 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java @@ -27,14 +27,13 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import org.sufficientlysecure.keychain.util.QrCodeUtils; public class ShareQrCodeDialogFragment extends DialogFragment { @@ -87,7 +86,7 @@ public class ShareQrCodeDialogFragment extends DialogFragment { KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); if (blob == null) { Log.e(Constants.TAG, "key not found!"); - AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR); return null; } @@ -97,7 +96,7 @@ public class ShareQrCodeDialogFragment extends DialogFragment { setQrCode(content); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); - AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR); return null; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Notify.java index 67f81fb24..22e3f5d66 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Notify.java @@ -29,7 +29,7 @@ import com.github.johnpersano.supertoasts.SuperToast; */ public class Notify { - public static enum Style {OK, WARN, ERROR} + public static enum Style {OK, WARN, INFO, ERROR} /** * Shows a simple in-layout notification with the CharSequence given as parameter -- cgit v1.2.3 From d8f278229352a58dbdcf49bb65538249f8c4ccc0 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 7 Jul 2014 17:35:23 +0200 Subject: use SuperToast instead of AppMsg in code, part 2 --- .../keychain/service/OperationResultParcel.java | 60 ++++++++++++++++++++++ .../keychain/service/OperationResults.java | 7 +-- 2 files changed, 64 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index 6bf6b655d..1df2a38f1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -1,10 +1,20 @@ package org.sufficientlysecure.keychain.service; +import android.app.Activity; +import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -21,6 +31,9 @@ import java.util.ArrayList; * */ public class OperationResultParcel implements Parcelable { + + public static final String EXTRA_RESULT = "operation_result"; + /** Holds the overall result, the number specifying varying degrees of success. The first bit * is 0 on overall success, 1 on overall failure. All other bits may be used for more specific * conditions. */ @@ -104,6 +117,43 @@ public class OperationResultParcel implements Parcelable { } + public SuperCardToast createNotify(final Activity activity) { + + int resultType = getResult(); + + String str; + int duration, color; + + // Not an overall failure + if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) { + + if (getLog().containsWarnings()) { + duration = 0; + color = Style.ORANGE; + } else { + duration = SuperToast.Duration.LONG; + color = Style.GREEN; + } + + str = activity.getString(R.string.import_error); + + } else { + duration = 0; + color = Style.RED; + str = activity.getString(R.string.import_error); + } + + SuperCardToast toast = new SuperCardToast(activity, + SuperToast.Type.STANDARD, Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(duration); + toast.setIndeterminate(duration == 0); + toast.setSwipeToDismiss(true); + + return toast; + + } + /** This is an enum of all possible log events. * * Element names should generally be prefixed with MSG_XX_ where XX is an @@ -123,6 +173,8 @@ public class OperationResultParcel implements Parcelable { */ public static enum LogType { + INTERNAL_ERROR (R.string.internal_error), + // import public MSG_IP(R.string.msg_ip), MSG_IP_APPLY_BATCH (R.string.msg_ip_apply_batch), @@ -313,6 +365,14 @@ public class OperationResultParcel implements Parcelable { add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); } + public LogEntryParcel getResultId() { + LogEntryParcel entry = get(size()-1); + if (entry.mLevel != LogLevel.OK && entry.mLevel != LogLevel.ERROR) { + return new LogEntryParcel(LogLevel.ERROR, LogType.INTERNAL_ERROR, 0); + } + return entry; + } + public boolean containsWarnings() { for(LogEntryParcel entry : new IterableIterator(iterator())) { if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java index fd3d4ed00..39c11a855 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java @@ -80,7 +80,7 @@ public abstract class OperationResults { } }; - public void displayNotify(final Activity activity) { + public SuperCardToast createNotify(final Activity activity) { int resultType = getResult(); @@ -88,7 +88,7 @@ public abstract class OperationResults { int duration, color; // Not an overall failure - if ((resultType & ImportResult.RESULT_ERROR) == 0) { + if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) { String withWarnings; // Any warnings? @@ -157,7 +157,8 @@ public abstract class OperationResults { } )); } - toast.show(); + + return toast; } -- cgit v1.2.3 From a8782272b3db20ba6e88acab1d035d4699aa7166 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 27 Jul 2014 00:46:38 +0200 Subject: some more work on supertoast and result parcel stuff --- .../keychain/pgp/PgpImportExport.java | 22 ++++++------ .../remote/ui/AccountSettingsFragment.java | 11 +++--- .../keychain/service/KeychainIntentService.java | 3 +- .../keychain/service/OperationResultParcel.java | 8 ----- .../keychain/service/OperationResults.java | 42 ++++++++++++++++------ .../keychain/ui/EditKeyActivity.java | 2 +- .../keychain/ui/EditKeyFragment.java | 14 ++++++-- .../keychain/ui/ImportKeysActivity.java | 8 ++--- .../keychain/ui/KeyListFragment.java | 7 ++-- .../keychain/ui/ViewKeyActivity.java | 2 -- 10 files changed, 66 insertions(+), 53 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 6fc55cfb8..9d334d9bd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; +import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -123,14 +123,14 @@ public class PgpImportExport { } /** Imports keys from given data. If keyIds is given only those are imported */ - public ImportResult importKeyRings(List entries) { + public ImportKeyResult importKeyRings(List entries) { updateProgress(R.string.progress_importing, 0, 100); // If there aren't even any keys, do nothing here. if (entries == null || entries.size() == 0) { - return new ImportResult( - ImportResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0); + return new ImportKeyResult( + ImportKeyResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0); } int newKeys = 0, oldKeys = 0, badKeys = 0; @@ -185,26 +185,26 @@ public class PgpImportExport { int resultType = 0; // special return case: no new keys at all if (badKeys == 0 && newKeys == 0 && oldKeys == 0) { - resultType = ImportResult.RESULT_FAIL_NOTHING; + resultType = ImportKeyResult.RESULT_FAIL_NOTHING; } else { if (newKeys > 0) { - resultType |= ImportResult.RESULT_OK_NEWKEYS; + resultType |= ImportKeyResult.RESULT_OK_NEWKEYS; } if (oldKeys > 0) { - resultType |= ImportResult.RESULT_OK_UPDATED; + resultType |= ImportKeyResult.RESULT_OK_UPDATED; } if (badKeys > 0) { - resultType |= ImportResult.RESULT_WITH_ERRORS; + resultType |= ImportKeyResult.RESULT_WITH_ERRORS; if (newKeys == 0 && oldKeys == 0) { - resultType |= ImportResult.RESULT_ERROR; + resultType |= ImportKeyResult.RESULT_ERROR; } } if (log.containsWarnings()) { - resultType |= ImportResult.RESULT_WITH_WARNINGS; + resultType |= ImportKeyResult.RESULT_WITH_WARNINGS; } } - return new ImportResult(resultType, log, newKeys, oldKeys, badKeys); + return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java index 0b1d521ad..86460c45d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java @@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.AccountSettings; -import org.sufficientlysecure.keychain.ui.EditKeyActivityOld; +import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment; import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; import org.sufficientlysecure.keychain.util.AlgorithmNames; @@ -163,12 +163,9 @@ public class AccountSettingsFragment extends Fragment implements } private void createKey() { - Intent intent = new Intent(getActivity(), EditKeyActivityOld.class); - intent.setAction(EditKeyActivityOld.ACTION_CREATE_KEY); - intent.putExtra(EditKeyActivityOld.EXTRA_GENERATE_DEFAULT_KEYS, true); - // set default user id to account name - intent.putExtra(EditKeyActivityOld.EXTRA_USER_IDS, mAccSettings.getAccountName()); - startActivityForResult(intent, REQUEST_CODE_CREATE_KEY); + Intent intent = new Intent(getActivity(), CreateKeyActivity.class); + // startActivityForResult(intent, REQUEST_CODE_CREATE_KEY); + startActivity(intent); } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 9a4cef2f1..f6a269e24 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -53,6 +53,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -390,7 +391,7 @@ public class KeychainIntentService extends IntentService List entries = data.getParcelableArrayList(IMPORT_KEY_LIST); PgpImportExport pgpImportExport = new PgpImportExport(this, this); - OperationResults.ImportResult result = pgpImportExport.importKeyRings(entries); + ImportKeyResult result = pgpImportExport.importKeyRings(entries); Bundle resultData = new Bundle(); resultData.putParcelable(RESULT, result); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index d80c508c3..2c6c29f8d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -391,14 +391,6 @@ public class OperationResultParcel implements Parcelable { mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); } - public LogEntryParcel getResultId() { - LogEntryParcel entry = get(size()-1); - if (entry.mLevel != LogLevel.OK && entry.mLevel != LogLevel.ERROR) { - return new LogEntryParcel(LogLevel.ERROR, LogType.INTERNAL_ERROR, 0); - } - return entry; - } - public boolean containsWarnings() { for(LogEntryParcel entry : new IterableIterator(mParcels.iterator())) { if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java index 39c11a855..fcb6c027d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java @@ -12,12 +12,13 @@ import com.github.johnpersano.supertoasts.util.OnClickWrapper; import com.github.johnpersano.supertoasts.util.Style; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayFragment; public abstract class OperationResults { - public static class ImportResult extends OperationResultParcel { + public static class ImportKeyResult extends OperationResultParcel { public final int mNewKeys, mUpdatedKeys, mBadKeys; @@ -47,15 +48,15 @@ public abstract class OperationResults { return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; } - public ImportResult(Parcel source) { + public ImportKeyResult(Parcel source) { super(source); mNewKeys = source.readInt(); mUpdatedKeys = source.readInt(); mBadKeys = source.readInt(); } - public ImportResult(int result, OperationLog log, - int newKeys, int updatedKeys, int badKeys) { + public ImportKeyResult(int result, OperationLog log, + int newKeys, int updatedKeys, int badKeys) { super(result, log); mNewKeys = newKeys; mUpdatedKeys = updatedKeys; @@ -70,13 +71,13 @@ public abstract class OperationResults { dest.writeInt(mBadKeys); } - public static Creator CREATOR = new Creator() { - public ImportResult createFromParcel(final Parcel source) { - return new ImportResult(source); + public static Creator CREATOR = new Creator() { + public ImportKeyResult createFromParcel(final Parcel source) { + return new ImportKeyResult(source); } - public ImportResult[] newArray(final int size) { - return new ImportResult[size]; + public ImportKeyResult[] newArray(final int size) { + return new ImportKeyResult[size]; } }; @@ -92,7 +93,7 @@ public abstract class OperationResults { String withWarnings; // Any warnings? - if ((resultType & ImportResult.RESULT_WITH_WARNINGS) > 0) { + if ((resultType & ImportKeyResult.RESULT_WITH_WARNINGS) > 0) { duration = 0; color = Style.ORANGE; withWarnings = activity.getResources().getString(R.string.import_with_warnings); @@ -151,7 +152,7 @@ public abstract class OperationResults { public void onClick(View view, Parcelable token) { Intent intent = new Intent( activity, LogDisplayActivity.class); - intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportResult.this); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this); activity.startActivity(intent); } } @@ -164,6 +165,25 @@ public abstract class OperationResults { } + public static class EditKeyResult extends OperationResultParcel { + + public EditKeyResult(Parcel source) { + super(source); + } + + public static Creator CREATOR = new Creator() { + public EditKeyResult createFromParcel(final Parcel source) { + return new EditKeyResult(source); + } + + public EditKeyResult[] newArray(final int size) { + return new EditKeyResult[size]; + } + }; + + } + + public static class SaveKeyringResult extends OperationResultParcel { public SaveKeyringResult(int result, OperationLog log) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index d80425c3c..6ddaec17f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -33,7 +33,7 @@ public class EditKeyActivity extends ActionBarActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.edit_key_activity_new); + setContentView(R.layout.edit_key_activity); Uri dataUri = getIntent().getData(); if (dataUri == null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index b41871a39..8fc4cffb8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,6 +48,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.OperationResults; +import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; @@ -480,12 +481,19 @@ public class EditKeyFragment extends LoaderFragment implements return; } - // if good -> finish, return result to showkey and display there! + // if bad -> display here! + if (!result.success()) { + result.createNotify(getActivity()).show(); + return; + } -// result.displayNotify(ImportKeysActivity.this); + // if good -> finish, return result to showkey and display there! + Intent intent = new Intent(); + intent.putExtra(ImportKeyResult.EXTRA_RESULT, result); + getActivity().setResult(EditKeyActivity.RESULT_OK, intent); + getActivity().finish(); -// getActivity().finish(); } } }; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 3ff3b56bf..5ab4d69f1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -45,7 +45,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; +import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.util.Log; @@ -427,7 +427,7 @@ public class ImportKeysActivity extends ActionBarActivity { if (returnData == null) { return; } - final ImportResult result = + final ImportKeyResult result = returnData.getParcelable(KeychainIntentService.RESULT); if (result == null) { return; @@ -435,7 +435,7 @@ public class ImportKeysActivity extends ActionBarActivity { if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())) { Intent intent = new Intent(); - intent.putExtra(EXTRA_RESULT, result); + intent.putExtra(ImportKeyResult.EXTRA_RESULT, result); ImportKeysActivity.this.setResult(RESULT_OK, intent); ImportKeysActivity.this.finish(); return; @@ -451,7 +451,7 @@ public class ImportKeysActivity extends ActionBarActivity { return; } - result.displayNotify(ImportKeysActivity.this); + result.createNotify(ImportKeysActivity.this).show(); } } }; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index c8f6b7b1e..5e2e4cb43 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -103,11 +103,8 @@ public class KeyListFragment extends LoaderFragment @Override public void onClick(View v) { - Intent intent = new Intent(getActivity(), EditKeyActivity.class); - intent.setAction(EditKeyActivity.ACTION_CREATE_KEY); - intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true); - intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view - startActivityForResult(intent, 0); + Intent intent = new Intent(getActivity(), CreateKeyActivity.class); + startActivity(intent); } }); mButtonEmptyImport = (Button) view.findViewById(R.id.key_list_empty_button_import); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index b8b2542ce..256526dd9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -19,7 +19,6 @@ package org.sufficientlysecure.keychain.ui; import android.annotation.TargetApi; -import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.net.Uri; @@ -53,7 +52,6 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer; import org.sufficientlysecure.keychain.util.Log; -- cgit v1.2.3 From f4ee71e3ef0dcacf691def97a94880b277a99496 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 27 Jul 2014 01:22:10 +0200 Subject: introduce EditKeyResult with transient UncachedKeyRing (half-baked!) --- .../keychain/pgp/PgpKeyOperation.java | 27 ++++++++---- .../keychain/service/KeychainIntentService.java | 50 ++++++++++++---------- .../keychain/service/OperationResultParcel.java | 31 ++++++++++++-- .../keychain/service/OperationResults.java | 14 +++++- .../keychain/ui/EditKeyFragment.java | 10 ++--- .../keychain/ui/ViewKeyActivity.java | 2 +- .../keychain/ui/ViewKeyMainFragment.java | 4 +- 7 files changed, 93 insertions(+), 45 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 69244ca14..c498bad0b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -47,9 +47,11 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; +import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd; import org.sufficientlysecure.keychain.util.IterableIterator; @@ -163,8 +165,10 @@ public class PgpKeyOperation { } } - public UncachedKeyRing createSecretKeyRing(SaveKeyringParcel saveParcel, OperationLog log, - int indent) { + public EditKeyResult createSecretKeyRing(SaveKeyringParcel saveParcel) { + + OperationLog log = new OperationLog(); + int indent = 0; try { @@ -213,7 +217,7 @@ public class PgpKeyOperation { PGPSecretKeyRing sKR = new PGPSecretKeyRing( masterSecretKey.getEncoded(), new JcaKeyFingerprintCalculator()); - return internal(sKR, masterSecretKey, add.mFlags, saveParcel, "", log, indent); + return internal(sKR, masterSecretKey, add.mFlags, saveParcel, "", log); } catch (PGPException e) { log.add(LogLevel.ERROR, LogType.MSG_CR_ERROR_INTERNAL_PGP, indent); @@ -237,8 +241,11 @@ public class PgpKeyOperation { * are changed by adding new certificates, which implicitly override older certificates. * */ - public UncachedKeyRing modifySecretKeyRing(WrappedSecretKeyRing wsKR, SaveKeyringParcel saveParcel, - String passphrase, OperationLog log, int indent) { + public EditKeyResult modifySecretKeyRing(WrappedSecretKeyRing wsKR, SaveKeyringParcel saveParcel, + String passphrase) { + + OperationLog log = new OperationLog(); + int indent = 0; /* * 1. Unlock private key @@ -277,14 +284,16 @@ public class PgpKeyOperation { // since this is the master key, this contains at least CERTIFY_OTHER int masterKeyFlags = readKeyFlags(masterSecretKey.getPublicKey()) | KeyFlags.CERTIFY_OTHER; - return internal(sKR, masterSecretKey, masterKeyFlags, saveParcel, passphrase, log, indent); + return internal(sKR, masterSecretKey, masterKeyFlags, saveParcel, passphrase, log); } - private UncachedKeyRing internal(PGPSecretKeyRing sKR, PGPSecretKey masterSecretKey, + private EditKeyResult internal(PGPSecretKeyRing sKR, PGPSecretKey masterSecretKey, int masterKeyFlags, SaveKeyringParcel saveParcel, String passphrase, - OperationLog log, int indent) { + OperationLog log) { + + int indent = 1; updateProgress(R.string.progress_certifying_master_key, 20, 100); @@ -613,7 +622,7 @@ public class PgpKeyOperation { } log.add(LogLevel.OK, LogType.MSG_MF_SUCCESS, indent); - return new UncachedKeyRing(sKR); + return new EditKeyResult(OperationResultParcel.RESULT_OK, log, new UncachedKeyRing(sKR)); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index f6a269e24..0e38a1c47 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -24,6 +24,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Message; import android.os.Messenger; +import android.os.Parcelable; import android.os.RemoteException; import org.sufficientlysecure.keychain.Constants; @@ -53,6 +54,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; @@ -333,38 +335,36 @@ public class KeychainIntentService extends IntentService /* Operation */ ProviderHelper providerHelper = new ProviderHelper(this); PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 10, 50, 100)); - try { - OperationLog log = new OperationLog(); - UncachedKeyRing ring; - if (saveParcel.mMasterKeyId != null) { - String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE); - WrappedSecretKeyRing secRing = - providerHelper.getWrappedSecretKeyRing(saveParcel.mMasterKeyId); - - ring = keyOperations.modifySecretKeyRing(secRing, saveParcel, - passphrase, log, 0); - } else { - ring = keyOperations.createSecretKeyRing(saveParcel, log, 0); - } + EditKeyResult result; - providerHelper.saveSecretKeyRing(ring, new ProgressScaler(this, 10, 95, 100)); + if (saveParcel.mMasterKeyId != null) { + String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE); + WrappedSecretKeyRing secRing = + providerHelper.getWrappedSecretKeyRing(saveParcel.mMasterKeyId); - // cache new passphrase - if (saveParcel.mNewPassphrase != null) { - PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(), - saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserIdWithFallback()); - } - } catch (ProviderHelper.NotFoundException e) { - sendErrorToHandler(e); + result = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase); + } else { + result = keyOperations.createSecretKeyRing(saveParcel); + } + + UncachedKeyRing ring = result.getRing(); + + providerHelper.saveSecretKeyRing(ring, new ProgressScaler(this, 10, 95, 100)); + + // cache new passphrase + if (saveParcel.mNewPassphrase != null) { + PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(), + saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserIdWithFallback()); } setProgress(R.string.progress_done, 100, 100); /* Output */ - sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY); + sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result); } catch (Exception e) { sendErrorToHandler(e); } + } else if (ACTION_DELETE_FILE_SECURELY.equals(action)) { try { /* Input */ @@ -624,6 +624,12 @@ public class KeychainIntentService extends IntentService } } + private void sendMessageToHandler(Integer arg1, OperationResultParcel data) { + Bundle bundle = new Bundle(); + bundle.putParcelable(OperationResultParcel.EXTRA_RESULT, data); + sendMessageToHandler(arg1, null, bundle); + } + private void sendMessageToHandler(Integer arg1, Bundle data) { sendMessageToHandler(arg1, null, data); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index 2c6c29f8d..99cafd3f9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -144,20 +144,45 @@ public class OperationResultParcel implements Parcelable { color = Style.GREEN; } - str = activity.getString(R.string.import_error); + str = "operation succeeded!"; + // str = activity.getString(R.string.import_error); } else { + duration = 0; color = Style.RED; - str = activity.getString(R.string.import_error); + + str = "operation failed"; + // str = activity.getString(R.string.import_error); + } + boolean button = getLog() != null && !getLog().isEmpty(); SuperCardToast toast = new SuperCardToast(activity, - SuperToast.Type.STANDARD, Style.getStyle(color, SuperToast.Animations.POPUP)); + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); toast.setText(str); toast.setDuration(duration); toast.setIndeterminate(duration == 0); toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResultParcel.this); + activity.startActivity(intent); + } + } + )); + } return toast; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java index fcb6c027d..6fb0db0e5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java @@ -143,7 +143,7 @@ public abstract class OperationResults { // If we have a log and it's non-empty, show a View Log button if (button) { toast.setButtonIcon(R.drawable.ic_action_view_as_list, - activity.getResources().getString(R.string.import_view_log)); + activity.getResources().getString(R.string.view_log)); toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); toast.setTextColor(activity.getResources().getColor(R.color.black)); toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", @@ -167,6 +167,18 @@ public abstract class OperationResults { public static class EditKeyResult extends OperationResultParcel { + private transient UncachedKeyRing mRing; + + public EditKeyResult(int result, OperationLog log, + UncachedKeyRing ring) { + super(result, log); + mRing = ring; + } + + public UncachedKeyRing getRing() { + return mRing; + } + public EditKeyResult(Parcel source) { super(source); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 8fc4cffb8..5ff864547 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,6 +48,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.OperationResults; +import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -467,21 +468,18 @@ public class EditKeyFragment extends LoaderFragment implements super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - getActivity().finish(); - // TODO below // get returned data bundle Bundle returnData = message.getData(); if (returnData == null) { return; } - final OperationResults.SaveKeyringResult result = - returnData.getParcelable(KeychainIntentService.RESULT); + final OperationResults.EditKeyResult result = + returnData.getParcelable(EditKeyResult.EXTRA_RESULT); if (result == null) { return; } - // if bad -> display here! if (!result.success()) { result.createNotify(getActivity()).show(); @@ -490,7 +488,7 @@ public class EditKeyFragment extends LoaderFragment implements // if good -> finish, return result to showkey and display there! Intent intent = new Intent(); - intent.putExtra(ImportKeyResult.EXTRA_RESULT, result); + intent.putExtra(EditKeyResult.EXTRA_RESULT, result); getActivity().setResult(EditKeyActivity.RESULT_OK, intent); getActivity().finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 256526dd9..f92977dbe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -350,7 +350,7 @@ public class ViewKeyActivity extends ActionBarActivity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { + if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); result.createNotify(this).show(); } else { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index 2a0f518d8..ade618840 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -251,9 +251,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements private void editKey(Uri dataUri) { Intent editIntent = new Intent(getActivity(), EditKeyActivity.class); editIntent.setData(KeychainContract.KeyRingData.buildSecretKeyRingUri(dataUri)); -// editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY); -// startActivityForResult(editIntent, 0); - startActivity(editIntent); + startActivityForResult(editIntent, 0); } } -- cgit v1.2.3 From da131220aac727865b9e33e8d34743939e8acbf0 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 28 Jul 2014 17:04:25 +0200 Subject: watch out for nullpointers from get(Un|)HashedSubpackets fixes #721 --- .../keychain/pgp/PgpKeyOperation.java | 5 +++-- .../keychain/pgp/UncachedKeyRing.java | 3 ++- .../keychain/pgp/WrappedSignature.java | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 69244ca14..6bce07824 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -413,7 +413,8 @@ public class PgpKeyOperation { } // if this is~ the/a primary user id - if (currentCert.hasSubpackets() && currentCert.getHashedSubPackets().isPrimaryUserID()) { + if (currentCert.getHashedSubPackets() != null + && currentCert.getHashedSubPackets().isPrimaryUserID()) { // if it's the one we want, just leave it as is if (userId.equals(saveParcel.mChangePrimaryUserId)) { ok = true; @@ -740,7 +741,7 @@ public class PgpKeyOperation { int flags = 0; //noinspection unchecked for(PGPSignature sig : new IterableIterator(key.getSignatures())) { - if (!sig.hasSubpackets()) { + if (sig.getHashedSubPackets() == null) { continue; } flags |= sig.getHashedSubPackets().getKeyFlags(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index 8838075cd..de8c683ff 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -513,7 +513,8 @@ public class UncachedKeyRing { } // if this certificate says it allows signing for the key - if (zert.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) { + if (zert.getHashedSubPackets() != null && + zert.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) { int flags = ((KeyFlags) zert.getHashedSubPackets() .getSubpacket(SignatureSubpacketTags.KEY_FLAGS)).getFlags(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java index df19930c4..28e4c51d6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java @@ -63,13 +63,17 @@ public class WrappedSignature { } try { PGPSignatureList list; - list = mSig.getHashedSubPackets().getEmbeddedSignatures(); - for(int i = 0; i < list.size(); i++) { - sigs.add(new WrappedSignature(list.get(i))); + if (mSig.getHashedSubPackets() != null) { + list = mSig.getHashedSubPackets().getEmbeddedSignatures(); + for (int i = 0; i < list.size(); i++) { + sigs.add(new WrappedSignature(list.get(i))); + } } - list = mSig.getUnhashedSubPackets().getEmbeddedSignatures(); - for(int i = 0; i < list.size(); i++) { - sigs.add(new WrappedSignature(list.get(i))); + if (mSig.getUnhashedSubPackets() != null) { + list = mSig.getUnhashedSubPackets().getEmbeddedSignatures(); + for (int i = 0; i < list.size(); i++) { + sigs.add(new WrappedSignature(list.get(i))); + } } } catch (PGPException e) { // no matter @@ -97,6 +101,9 @@ public class WrappedSignature { if(!isRevocation()) { throw new PgpGeneralException("Not a revocation signature."); } + if (mSig.getHashedSubPackets() == null) { + return null; + } SignatureSubpacket p = mSig.getHashedSubPackets().getSubpacket( SignatureSubpacketTags.REVOCATION_REASON); // For some reason, this is missing in SignatureSubpacketInputStream:146 @@ -205,7 +212,7 @@ public class WrappedSignature { } public boolean isLocal() { - if (!mSig.hasSubpackets() + if (mSig.getHashedSubPackets() == null || !mSig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.EXPORTABLE)) { return false; } -- cgit v1.2.3 From 4457b4a24c4078723c94f949235e040de0328c63 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 29 Jul 2014 14:00:36 +0200 Subject: fix a couple remaining AppMsgs --- .../org/sufficientlysecure/keychain/ui/CreateKeyActivity.java | 9 +++------ .../java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index 3cf89f6a4..57390ec4d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.os.Message; import android.os.Messenger; @@ -31,13 +30,10 @@ import android.util.Patterns; import android.view.View; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; -import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; -import com.devspark.appmsg.AppMsg; - import org.spongycastle.bcpg.sig.KeyFlags; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -45,6 +41,7 @@ import org.sufficientlysecure.keychain.helper.ContactHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; +import org.sufficientlysecure.keychain.util.Notify; import java.util.regex.Matcher; @@ -206,8 +203,8 @@ public class CreateKeyActivity extends ActionBarActivity { super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - AppMsg.makeText(CreateKeyActivity.this, R.string.key_send_success, - AppMsg.STYLE_INFO).show(); + Notify.showNotify(CreateKeyActivity.this, R.string.key_send_success, + Notify.Style.INFO); CreateKeyActivity.this.setResult(RESULT_OK); CreateKeyActivity.this.finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java index f4d395ae6..99400056f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java @@ -23,8 +23,6 @@ import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.ImageView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ActionBarHelper; @@ -32,6 +30,8 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; +import org.sufficientlysecure.keychain.util.Notify.Style; import org.sufficientlysecure.keychain.util.QrCodeUtils; public class QrCodeActivity extends ActionBarActivity { @@ -81,7 +81,7 @@ public class QrCodeActivity extends ActionBarActivity { KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); if (blob == null) { Log.e(Constants.TAG, "key not found!"); - AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(this, R.string.error_key_not_found, Style.ERROR); finish(); } @@ -90,7 +90,7 @@ public class QrCodeActivity extends ActionBarActivity { mFingerprintQrCode.setImageBitmap(QrCodeUtils.getQRCodeBitmap(qrCodeContent, QR_CODE_SIZE)); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); - AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show(); + Notify.showNotify(this, R.string.error_key_not_found, Style.ERROR); finish(); } } -- cgit v1.2.3