From 5adcb7885cf9629b1ef60b26e76a4c9a8b1f7845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 8 Jul 2014 03:34:27 +0200 Subject: Work on subkeys adapter --- .../ui/dialog/EditSubkeyDialogFragment.java | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java new file mode 100644 index 000000000..9fef88a78 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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.dialog; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.support.v4.app.DialogFragment; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; + +public class EditSubkeyDialogFragment extends DialogFragment { + private static final String ARG_MESSENGER = "messenger"; + + public static final int MESSAGE_CHANGE_EXPIRY = 1; + public static final int MESSAGE_REVOKE = 2; + + private Messenger mMessenger; + + /** + * Creates new instance of this dialog fragment + */ + public static EditSubkeyDialogFragment newInstance(Messenger messenger) { + EditSubkeyDialogFragment frag = new EditSubkeyDialogFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_MESSENGER, messenger); + + frag.setArguments(args); + + return frag; + } + + /** + * Creates dialog + */ + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + mMessenger = getArguments().getParcelable(ARG_MESSENGER); + + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(getActivity()); + CharSequence[] array = getResources().getStringArray(R.array.edit_key_edit_subkey); + + builder.setTitle(R.string.edit_key_edit_subkey_title); + builder.setItems(array, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case 0: + sendMessageToHandler(MESSAGE_CHANGE_EXPIRY, null); + break; + case 1: + sendMessageToHandler(MESSAGE_REVOKE, null); + break; + default: + break; + } + } + }); + builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dismiss(); + } + }); + + return builder.show(); + } + + /** + * Send message back to handler which is initialized in a activity + * + * @param what Message integer you want to send + */ + private void sendMessageToHandler(Integer what, Bundle data) { + Message msg = Message.obtain(); + msg.what = what; + if (data != null) { + msg.setData(data); + } + + try { + mMessenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } + } +} -- cgit v1.2.3 From cf40517eaca2c852a0a0022b93c46e7a41766d80 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 12:27:19 +0200 Subject: Implemented Notification, no fallback yet --- .../keychain/ui/dialog/PassphraseDialogFragment.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 59e4d8dee..5bbbf20a7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -189,7 +189,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // Early breakout if we are dealing with a symmetric key if (secretRing == null) { - PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, passphrase); + PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, + passphrase, "Password"); // also return passphrase back to activity Bundle data = new Bundle(); data.putString(MESSAGE_DATA_PASSPHRASE, passphrase); @@ -228,10 +229,18 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // cache the new passphrase Log.d(Constants.TAG, "Everything okay! Caching entered passphrase"); - PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase); + + try { + PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase, + secretRing.getPrimaryUserId()); + } catch(PgpGeneralException e) { + Log.e(Constants.TAG, e.getMessage()); + } + if (unlockedSecretKey.getKeyId() != masterKeyId) { PassphraseCacheService.addCachedPassphrase( - activity, unlockedSecretKey.getKeyId(), passphrase); + activity, unlockedSecretKey.getKeyId(), passphrase, + unlockedSecretKey.getPrimaryUserId()); } // also return passphrase back to activity -- cgit v1.2.3 From 079194abe5b48c2b6a5cf943b45a67b956937435 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 18:12:03 +0200 Subject: Fixed issues discussed in #713 --- .../keychain/ui/dialog/PassphraseDialogFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 5bbbf20a7..4d0b73d30 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -190,7 +190,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // Early breakout if we are dealing with a symmetric key if (secretRing == null) { PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, - passphrase, "Password"); + passphrase, getString(R.string.passp_cache_notif_pwd)); // also return passphrase back to activity Bundle data = new Bundle(); data.putString(MESSAGE_DATA_PASSPHRASE, passphrase); @@ -234,7 +234,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase, secretRing.getPrimaryUserId()); } catch(PgpGeneralException e) { - Log.e(Constants.TAG, e.getMessage()); + Log.e(Constants.TAG, "adding of a passhrase failed", e); } if (unlockedSecretKey.getKeyId() != masterKeyId) { -- cgit v1.2.3 From 45dfb3974908d953ff656fb69696f69c0af017c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 12 Jul 2014 20:39:23 +0200 Subject: more work on edit key --- .../ui/dialog/ChangeExpiryDialogFragment.java | 187 +++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ChangeExpiryDialogFragment.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ChangeExpiryDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ChangeExpiryDialogFragment.java new file mode 100644 index 000000000..d5354a9f6 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ChangeExpiryDialogFragment.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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.dialog; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.support.v4.app.DialogFragment; +import android.text.format.DateUtils; +import android.widget.DatePicker; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +public class ChangeExpiryDialogFragment extends DialogFragment { + private static final String ARG_MESSENGER = "messenger"; + private static final String ARG_CREATION_DATE = "creation_date"; + private static final String ARG_EXPIRY_DATE = "expiry_date"; + + public static final int MESSAGE_NEW_EXPIRY_DATE = 1; + public static final String MESSAGE_DATA_EXPIRY_DATE = "expiry_date"; + + private Messenger mMessenger; + private Calendar mCreationCal; + private Calendar mExpiryCal; + + private int mDatePickerResultCount = 0; + private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = + new DatePickerDialog.OnDateSetListener() { + public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + // Note: Ignore results after the first one - android sends multiples. + if (mDatePickerResultCount++ == 0) { + Calendar selectedCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + selectedCal.set(year, monthOfYear, dayOfMonth); + if (mExpiryCal != null) { + long numDays = (selectedCal.getTimeInMillis() / 86400000) + - (mExpiryCal.getTimeInMillis() / 86400000); + if (numDays > 0) { + Bundle data = new Bundle(); + data.putSerializable(MESSAGE_DATA_EXPIRY_DATE, selectedCal.getTime()); + sendMessageToHandler(MESSAGE_NEW_EXPIRY_DATE, data); + } + } else { + Bundle data = new Bundle(); + data.putSerializable(MESSAGE_DATA_EXPIRY_DATE, selectedCal.getTime()); + sendMessageToHandler(MESSAGE_NEW_EXPIRY_DATE, data); + } + } + } + }; + + public class ExpiryDatePickerDialog extends DatePickerDialog { + + public ExpiryDatePickerDialog(Context context, OnDateSetListener callBack, + int year, int monthOfYear, int dayOfMonth) { + super(context, callBack, year, monthOfYear, dayOfMonth); + } + + // set permanent title + public void setTitle(CharSequence title) { + super.setTitle(getContext().getString(R.string.expiry_date_dialog_title)); + } + } + + /** + * Creates new instance of this dialog fragment + */ + public static ChangeExpiryDialogFragment newInstance(Messenger messenger, + Date creationDate, Date expiryDate) { + ChangeExpiryDialogFragment frag = new ChangeExpiryDialogFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_MESSENGER, messenger); + args.putSerializable(ARG_CREATION_DATE, creationDate); + args.putSerializable(ARG_EXPIRY_DATE, expiryDate); + + frag.setArguments(args); + + return frag; + } + + /** + * Creates dialog + */ + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + mMessenger = getArguments().getParcelable(ARG_MESSENGER); + Date creationDate = (Date) getArguments().getSerializable(ARG_CREATION_DATE); + Date expiryDate = (Date) getArguments().getSerializable(ARG_EXPIRY_DATE); + + mCreationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + mCreationCal.setTime(creationDate); + mExpiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + mExpiryCal.setTime(expiryDate); + + /* + * Using custom DatePickerDialog which overrides the setTitle because + * the DatePickerDialog title is buggy (unix warparound bug). + * See: https://code.google.com/p/android/issues/detail?id=49066 + */ + DatePickerDialog dialog = new ExpiryDatePickerDialog(getActivity(), + mExpiryDateSetListener, mExpiryCal.get(Calendar.YEAR), mExpiryCal.get(Calendar.MONTH), + mExpiryCal.get(Calendar.DAY_OF_MONTH)); + mDatePickerResultCount = 0; + dialog.setCancelable(true); + dialog.setButton(Dialog.BUTTON_NEGATIVE, + getActivity().getString(R.string.btn_no_date), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // Note: Ignore results after the first one - android sends multiples. + if (mDatePickerResultCount++ == 0) { + // none expiry dates corresponds to a null message + Bundle data = new Bundle(); + data.putSerializable(MESSAGE_DATA_EXPIRY_DATE, null); + sendMessageToHandler(MESSAGE_NEW_EXPIRY_DATE, data); + } + } + } + ); + + // setCalendarViewShown() is supported from API 11 onwards. + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + // Hide calendarView in tablets because of the unix warparound bug. + dialog.getDatePicker().setCalendarViewShown(false); + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + // will crash with IllegalArgumentException if we set a min date + // that is not before expiry + if (mCreationCal != null && mCreationCal.before(mExpiryCal)) { + dialog.getDatePicker().setMinDate(mCreationCal.getTime().getTime() + + DateUtils.DAY_IN_MILLIS); + } else { + // When created date isn't available + dialog.getDatePicker().setMinDate(mExpiryCal.getTime().getTime() + + DateUtils.DAY_IN_MILLIS); + } + } + + return dialog; + } + + /** + * Send message back to handler which is initialized in a activity + * + * @param what Message integer you want to send + */ + private void sendMessageToHandler(Integer what, Bundle data) { + Message msg = Message.obtain(); + msg.what = what; + if (data != null) { + msg.setData(data); + } + + try { + mMessenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } + } +} -- cgit v1.2.3 From d3c54d5f129ca24cbfa08208fc5c79c626897d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 16 Jul 2014 00:22:45 +0200 Subject: Fallback if no primary user id exists --- .../keychain/ui/dialog/PassphraseDialogFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 4d0b73d30..d723f88af 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -152,7 +152,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // above can't be statically verified to have been set in all cases because // the catch clause doesn't return. try { - userId = secretRing.getPrimaryUserId(); + userId = secretRing.getPrimaryUserIdWithFallback(); } catch (PgpGeneralException e) { userId = null; } @@ -232,7 +232,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor try { PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase, - secretRing.getPrimaryUserId()); + secretRing.getPrimaryUserIdWithFallback()); } catch(PgpGeneralException e) { Log.e(Constants.TAG, "adding of a passhrase failed", e); } @@ -240,7 +240,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor if (unlockedSecretKey.getKeyId() != masterKeyId) { PassphraseCacheService.addCachedPassphrase( activity, unlockedSecretKey.getKeyId(), passphrase, - unlockedSecretKey.getPrimaryUserId()); + unlockedSecretKey.getPrimaryUserIdWithFallback()); } // also return passphrase back to activity -- cgit v1.2.3 From 57d9c7a013cefa6641bff7167486f7fe12247265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sun, 27 Jul 2014 20:42:39 +0200 Subject: Open keyboard on passphrase dialog, this should now work on all Android versions... hopefully --- .../ui/dialog/PassphraseDialogFragment.java | 73 +++++++++++++++------- .../ui/dialog/SetPassphraseDialogFragment.java | 46 ++++++++++++-- 2 files changed, 92 insertions(+), 27 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index d723f88af..7981b717e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -33,8 +33,10 @@ import android.support.v4.app.FragmentActivity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.WindowManager.LayoutParams; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @@ -62,7 +64,6 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor private Messenger mMessenger; private EditText mPassphraseEditText; - private boolean mCanKB; /** * Shows passphrase dialog to cache a new passphrase the user enters for using it later for @@ -105,7 +106,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor if (!new ProviderHelper(context).getWrappedSecretKeyRing(secretKeyId).hasPassphrase()) { throw new PgpGeneralException("No passphrase! No passphrase dialog needed!"); } - } catch(ProviderHelper.NotFoundException e) { + } catch (ProviderHelper.NotFoundException e) { throw new PgpGeneralException("Error: Key not found!", e); } } @@ -165,7 +166,6 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor } }); alert.setCancelable(false); - mCanKB = false; return alert.create(); } @@ -190,7 +190,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // Early breakout if we are dealing with a symmetric key if (secretRing == null) { PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, - passphrase, getString(R.string.passp_cache_notif_pwd)); + passphrase, getString(R.string.passp_cache_notif_pwd)); // also return passphrase back to activity Bundle data = new Bundle(); data.putString(MESSAGE_DATA_PASSPHRASE, passphrase); @@ -200,7 +200,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor WrappedSecretKey unlockedSecretKey = null; - for(WrappedSecretKey clickSecretKey : secretRing.secretKeyIterator()) { + for (WrappedSecretKey clickSecretKey : secretRing.secretKeyIterator()) { try { boolean unlocked = clickSecretKey.unlock(passphrase); if (unlocked) { @@ -232,9 +232,9 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor try { PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase, - secretRing.getPrimaryUserIdWithFallback()); - } catch(PgpGeneralException e) { - Log.e(Constants.TAG, "adding of a passhrase failed", e); + secretRing.getPrimaryUserIdWithFallback()); + } catch (PgpGeneralException e) { + Log.e(Constants.TAG, "adding of a passphrase failed", e); } if (unlockedSecretKey.getKeyId() != masterKeyId) { @@ -258,20 +258,30 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor } }); - mCanKB = true; - return alert.show(); - } + // Hack to open keyboard. + // This is the only method that I found to work across all Android versions + // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/ + // Notes: * onCreateView can't be used because we want to add buttons to the dialog + // * opening in onActivityCreated does not work on Android 4.4 + mPassphraseEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + mPassphraseEditText.post(new Runnable() { + @Override + public void run() { + InputMethodManager imm = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT); + } + }); + } + }); + mPassphraseEditText.requestFocus(); - @Override - public void onActivityCreated(Bundle arg0) { - super.onActivityCreated(arg0); - if (mCanKB) { - // request focus and open soft keyboard - mPassphraseEditText.requestFocus(); - getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); - - mPassphraseEditText.setOnEditorActionListener(this); - } + mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE); + mPassphraseEditText.setOnEditorActionListener(this); + + return alert.show(); } @Override @@ -282,6 +292,27 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor sendMessageToHandler(MESSAGE_CANCEL); } + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + Log.d(Constants.TAG, "onDismiss"); + + // hide keyboard on dismiss + hideKeyboard(); + } + + private void hideKeyboard() { + InputMethodManager inputManager = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + + //check if no view has focus: + View v = getActivity().getCurrentFocus(); + if (v == null) + return; + + inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); + } + /** * Associate the "done" button on the soft keyboard with the okay button in the view */ diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java index 93da48b75..1386ed098 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.dialog; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.os.Message; @@ -32,6 +33,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager.LayoutParams; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -164,18 +166,50 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi } }); + // Hack to open keyboard. + // This is the only method that I found to work across all Android versions + // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/ + // Notes: * onCreateView can't be used because we want to add buttons to the dialog + // * opening in onActivityCreated does not work on Android 4.4 + mPassphraseEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + mPassphraseEditText.post(new Runnable() { + @Override + public void run() { + InputMethodManager imm = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT); + } + }); + } + }); + mPassphraseEditText.requestFocus(); + + mPassphraseAgainEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE); + mPassphraseAgainEditText.setOnEditorActionListener(this); + return alert.show(); } @Override - public void onActivityCreated(Bundle arg0) { - super.onActivityCreated(arg0); + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); - // request focus and open soft keyboard - mPassphraseEditText.requestFocus(); - getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + // hide keyboard on dismiss + hideKeyboard(); + } - mPassphraseAgainEditText.setOnEditorActionListener(this); + private void hideKeyboard() { + InputMethodManager inputManager = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + + //check if no view has focus: + View v = getActivity().getCurrentFocus(); + if (v == null) + return; + + inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); } /** -- cgit v1.2.3 From 5974dccbeaf672db76cb3be7ee639f2bd6638a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sun, 27 Jul 2014 21:40:43 +0200 Subject: Redesigned QR Code view --- .../ui/dialog/ShareQrCodeDialogFragment.java | 111 --------------------- 1 file changed, 111 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') 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 deleted file mode 100644 index 24608784b..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2012-2014 Dominik Schürmann - * - * 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.dialog; - -import android.app.Activity; -import android.app.Dialog; -import android.net.Uri; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.view.LayoutInflater; -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.QrCodeUtils; - -public class ShareQrCodeDialogFragment extends DialogFragment { - private static final String ARG_KEY_URI = "uri"; - - private ImageView mImage; - private TextView mText; - - private static final int QR_CODE_SIZE = 1000; - - /** - * Creates new instance of this dialog fragment - */ - public static ShareQrCodeDialogFragment newInstance(Uri dataUri) { - ShareQrCodeDialogFragment frag = new ShareQrCodeDialogFragment(); - Bundle args = new Bundle(); - args.putParcelable(ARG_KEY_URI, dataUri); - - frag.setArguments(args); - - return frag; - } - - /** - * Creates dialog - */ - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - final Activity activity = getActivity(); - - Uri dataUri = getArguments().getParcelable(ARG_KEY_URI); - - CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(getActivity()); - alert.setTitle(R.string.share_qr_code_dialog_title); - - LayoutInflater inflater = activity.getLayoutInflater(); - View view = inflater.inflate(R.layout.share_qr_code_dialog, null); - alert.setView(view); - - mImage = (ImageView) view.findViewById(R.id.share_qr_code_dialog_image); - mText = (TextView) view.findViewById(R.id.share_qr_code_dialog_text); - - ProviderHelper providerHelper = new ProviderHelper(getActivity()); - String content; - try { - alert.setPositiveButton(R.string.btn_okay, null); - - byte[] blob = (byte[]) providerHelper.getGenericData( - KeyRings.buildUnifiedKeyRingUri(dataUri), - 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(); - return null; - } - - String fingerprint = PgpKeyHelper.convertFingerprintToHex(blob); - mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + fingerprint); - content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint; - 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(); - return null; - } - - return alert.show(); - } - - private void setQrCode(String data) { - mImage.setImageBitmap(QrCodeUtils.getQRCodeBitmap(data, QR_CODE_SIZE)); - } - -} -- cgit v1.2.3 From fcc535a57381009b173bbe455e67e6825be6b684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 30 Jul 2014 15:29:01 +0200 Subject: Create key: repeat passphrase --- .../keychain/ui/dialog/PassphraseDialogFragment.java | 5 ----- 1 file changed, 5 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 7981b717e..0a7fd6aee 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -121,11 +121,6 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor return frag; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - /** * Creates dialog */ -- cgit v1.2.3 From b156a057e8c5b715f515725ab051087a86ecd547 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 31 Jul 2014 17:08:33 +0200 Subject: rename Wrapped*Key* to Canonicalized*Key* --- .../keychain/ui/dialog/PassphraseDialogFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 0a7fd6aee..cce8c9d9f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -46,8 +46,8 @@ import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; -import org.sufficientlysecure.keychain.pgp.WrappedSecretKey; -import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.PassphraseCacheService; @@ -103,7 +103,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // check if secret key has a passphrase if (!(secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none)) { try { - if (!new ProviderHelper(context).getWrappedSecretKeyRing(secretKeyId).hasPassphrase()) { + if (!new ProviderHelper(context).getCanonicalizedSecretKeyRing(secretKeyId).hasPassphrase()) { throw new PgpGeneralException("No passphrase! No passphrase dialog needed!"); } } catch (ProviderHelper.NotFoundException e) { @@ -134,7 +134,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor alert.setTitle(R.string.title_authentication); - final WrappedSecretKeyRing secretRing; + final CanonicalizedSecretKeyRing secretRing; String userId; if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) { @@ -143,7 +143,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor } else { try { ProviderHelper helper = new ProviderHelper(activity); - secretRing = helper.getWrappedSecretKeyRing(secretKeyId); + secretRing = helper.getCanonicalizedSecretKeyRing(secretKeyId); // yes the inner try/catch block is necessary, otherwise the final variable // above can't be statically verified to have been set in all cases because // the catch clause doesn't return. @@ -193,9 +193,9 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor return; } - WrappedSecretKey unlockedSecretKey = null; + CanonicalizedSecretKey unlockedSecretKey = null; - for (WrappedSecretKey clickSecretKey : secretRing.secretKeyIterator()) { + for (CanonicalizedSecretKey clickSecretKey : secretRing.secretKeyIterator()) { try { boolean unlocked = clickSecretKey.unlock(passphrase); if (unlocked) { -- cgit v1.2.3 From 33172d598da62ab1d529facf22660b4e1700c2fa Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 31 Jul 2014 17:09:20 +0200 Subject: couple of logging fixes --- .../sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index cce8c9d9f..ef2659cf8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -33,8 +33,6 @@ import android.support.v4.app.FragmentActivity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager.LayoutParams; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.Button; -- cgit v1.2.3