From 4d43950841b567d83e7879ed00702253fd9ba5b2 Mon Sep 17 00:00:00 2001 From: Kent Date: Fri, 20 Mar 2015 06:11:50 +0800 Subject: - Added footer so that the Floating Action Button won't block the last few items' content --- .../keychain/ui/KeyListFragment.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') 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 f8939f3d1..793fb4524 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -169,6 +169,22 @@ public class KeyListFragment extends LoaderFragment mStickyList.setDrawingListUnderStickyHeader(false); mStickyList.setFastScrollEnabled(true); + // Adds an empty footer view so that the Floating Action Button won't block content + // in last few rows. + View footer = new View(getActivity()); + + int spacing = (int) android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_DIP, 72, getResources().getDisplayMetrics() + ); + + android.widget.AbsListView.LayoutParams params = new android.widget.AbsListView.LayoutParams( + android.widget.AbsListView.LayoutParams.MATCH_PARENT, + spacing + ); + + footer.setLayoutParams(params); + mStickyList.addFooterView(footer, null, false); + /* * Multi-selection */ @@ -369,7 +385,7 @@ public class KeyListFragment extends LoaderFragment /** * Show dialog to delete key * - * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not + * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not */ public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) { // Can only work on singular secret keys @@ -909,5 +925,4 @@ public class KeyListFragment extends LoaderFragment } - } -- cgit v1.2.3 From 4e4b8efd6ea275d5fe2d07c188ab8a2581617ec6 Mon Sep 17 00:00:00 2001 From: Manoj Khanna Date: Fri, 20 Mar 2015 18:23:23 +0530 Subject: Reworked Notify class --- .../keychain/ui/CertifyKeyFragment.java | 8 +- .../keychain/ui/CreateKeyFinalFragment.java | 4 +- .../keychain/ui/DecryptFilesFragment.java | 2 +- .../keychain/ui/DecryptTextActivity.java | 4 +- .../keychain/ui/DecryptTextFragment.java | 2 +- .../keychain/ui/EditKeyFragment.java | 4 +- .../keychain/ui/EncryptFilesActivity.java | 12 +- .../keychain/ui/EncryptFilesFragment.java | 8 +- .../keychain/ui/EncryptTextActivity.java | 17 +- .../keychain/ui/ImportKeysActivity.java | 6 +- .../keychain/ui/KeyListFragment.java | 12 +- .../keychain/ui/QrCodeViewActivity.java | 4 +- .../keychain/ui/SafeSlingerActivity.java | 2 +- .../keychain/ui/ViewKeyActivity.java | 10 +- .../keychain/ui/ViewKeyAdvShareFragment.java | 10 +- .../keychain/ui/dialog/FileDialogFragment.java | 2 +- .../keychain/ui/util/Notify.java | 196 ++++++++------------- 17 files changed, 130 insertions(+), 173 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index a0f89b06a..b3738851c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -169,8 +169,8 @@ public class CertifyKeyFragment extends LoaderFragment @Override public void onClick(View v) { if (mSignMasterKeyId == Constants.key.none) { - Notify.showNotify(getActivity(), getString(R.string.select_key_to_certify), - Notify.Style.ERROR); + Notify.create(getActivity(), getString(R.string.select_key_to_certify), + Notify.Style.ERROR).show(); } else { initiateCertifying(); } @@ -360,8 +360,8 @@ public class CertifyKeyFragment extends LoaderFragment // Bail out if there is not at least one user id selected ArrayList certifyActions = mUserIdsAdapter.getSelectedCertifyActions(); if (certifyActions.isEmpty()) { - Notify.showNotify(getActivity(), "No identities selected!", - Notify.Style.ERROR); + Notify.create(getActivity(), "No identities selected!", + Notify.Style.ERROR).show(); return; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 75f49a426..cbe3eecd4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -277,8 +277,8 @@ public class CreateKeyFinalFragment extends Fragment { // TODO: upload operation needs a result! // TODO: then combine these results //if (result.getResult() == OperationResultParcel.RESULT_OK) { - //Notify.showNotify(getActivity(), R.string.key_send_success, - //Notify.Style.INFO); + //Notify.create(getActivity(), R.string.key_send_success, + //Notify.Style.OK).show(); Intent data = new Intent(); data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java index 71832daa5..a92fb596c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java @@ -139,7 +139,7 @@ public class DecryptFilesFragment extends DecryptFragment { private void decryptAction() { if (mInputUri == null) { - Notify.showNotify(getActivity(), R.string.no_file_selected, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show(); return; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java index 1e9e7bcb1..bc2ec014a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java @@ -161,7 +161,7 @@ public class DecryptTextActivity extends BaseActivity { if (sharedText != null) { loadFragment(savedInstanceState, sharedText); } else { - Notify.showNotify(this, R.string.error_invalid_data, Notify.Style.ERROR); + Notify.create(this, R.string.error_invalid_data, Notify.Style.ERROR).show(); } } else { Log.e(Constants.TAG, "ACTION_SEND received non-plaintext, this should not happen in this activity!"); @@ -175,7 +175,7 @@ public class DecryptTextActivity extends BaseActivity { if (extraText != null) { loadFragment(savedInstanceState, extraText); } else { - Notify.showNotify(this, R.string.error_invalid_data, Notify.Style.ERROR); + Notify.create(this, R.string.error_invalid_data, Notify.Style.ERROR).show(); } } else if (ACTION_DECRYPT_FROM_CLIPBOARD.equals(action)) { Log.d(Constants.TAG, "ACTION_DECRYPT_FROM_CLIPBOARD"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java index 30cf739fc..80a07214b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java @@ -132,7 +132,7 @@ public class DecryptTextFragment extends DecryptFragment { private void copyToClipboard(String text) { ClipboardReflection.copyToClipboard(getActivity(), text); - Notify.showNotify(getActivity(), R.string.text_copied_to_clipboard, Notify.Style.INFO); + Notify.create(getActivity(), R.string.text_copied_to_clipboard, Notify.Style.OK).show(); } @Override 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 d2c1ab74c..61a02720e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -577,11 +577,11 @@ public class EditKeyFragment extends LoaderFragment implements private void returnKeyringParcel() { if (mSaveKeyringParcel.mAddUserIds.size() == 0) { - Notify.showNotify(getActivity(), R.string.edit_key_error_add_identity, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.edit_key_error_add_identity, Notify.Style.ERROR).show(); return; } if (mSaveKeyringParcel.mAddSubKeys.size() == 0) { - Notify.showNotify(getActivity(), R.string.edit_key_error_add_subkey, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.edit_key_error_add_subkey, Notify.Style.ERROR).show(); return; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java index 0dd672c90..fe9b05226 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java @@ -303,7 +303,8 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi // file checks if (mInputUris.isEmpty()) { - Notify.showNotify(this, R.string.no_file_selected, Notify.Style.ERROR); + Notify.create(this, R.string.no_file_selected, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment)); return false; } else if (mInputUris.size() > 1 && !mShareAfterEncrypt) { // This should be impossible... @@ -317,11 +318,13 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi // symmetric encryption checks if (mPassphrase == null) { - Notify.showNotify(this, R.string.passphrases_do_not_match, Notify.Style.ERROR); + Notify.create(this, R.string.passphrases_do_not_match, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment)); return false; } if (mPassphrase.isEmpty()) { - Notify.showNotify(this, R.string.passphrase_must_not_be_empty, Notify.Style.ERROR); + Notify.create(this, R.string.passphrase_must_not_be_empty, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment)); return false; } @@ -333,7 +336,8 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi // Files must be encrypted, only text can be signed-only right now if (!gotEncryptionKeys) { - Notify.showNotify(this, R.string.select_encryption_key, Notify.Style.ERROR); + Notify.create(this, R.string.select_encryption_key, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment)); return false; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java index 9c9b44511..4ba76d8ea 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java @@ -115,9 +115,9 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt } if (mEncryptInterface.getInputUris().contains(inputUri)) { - Notify.showNotify(getActivity(), + Notify.create(getActivity(), getActivity().getString(R.string.error_file_added_already, FileHelper.getFilename(getActivity(), inputUri)), - Notify.Style.ERROR); + Notify.Style.ERROR).show(this); return; } @@ -153,7 +153,7 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt private void encryptClicked(boolean share) { if (mEncryptInterface.getInputUris().isEmpty()) { - Notify.showNotify(getActivity(), R.string.error_no_file_selected, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.error_no_file_selected, Notify.Style.ERROR).show(this); return; } if (share) { @@ -169,7 +169,7 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt mEncryptInterface.startEncrypt(true); } else { if (mEncryptInterface.getInputUris().size() > 1) { - Notify.showNotify(getActivity(), R.string.error_multi_not_supported, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.error_multi_not_supported, Notify.Style.ERROR).show(this); return; } showOutputFileDialog(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java index 847f745d7..c800153ae 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java @@ -198,8 +198,9 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv // Copy to clipboard copyToClipboard(result.getResultBytes()); result.createNotify(EncryptTextActivity.this).show(); - // Notify.showNotify(EncryptTextActivity.this, - // R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO); + // Notify.create(EncryptTextActivity.this, + // R.string.encrypt_sign_clipboard_successful, Notify.Style.OK) + // .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_text_fragment)); } } @@ -281,7 +282,8 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv protected boolean inputIsValid() { if (mMessage == null) { - Notify.showNotify(this, R.string.error_message, Notify.Style.ERROR); + Notify.create(this, R.string.error_message, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_text_fragment)); return false; } @@ -289,11 +291,13 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv // symmetric encryption checks if (mPassphrase == null) { - Notify.showNotify(this, R.string.passphrases_do_not_match, Notify.Style.ERROR); + Notify.create(this, R.string.passphrases_do_not_match, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_text_fragment)); return false; } if (mPassphrase.isEmpty()) { - Notify.showNotify(this, R.string.passphrase_must_not_be_empty, Notify.Style.ERROR); + Notify.create(this, R.string.passphrase_must_not_be_empty, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_text_fragment)); return false; } @@ -304,7 +308,8 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv && mEncryptionKeyIds.length > 0); if (!gotEncryptionKeys && mSigningKeyId == 0) { - Notify.showNotify(this, R.string.select_encryption_or_signature_key, Notify.Style.ERROR); + Notify.create(this, R.string.select_encryption_or_signature_key, Notify.Style.ERROR) + .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_text_fragment)); return false; } } 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 d51e2c7fc..d59936967 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -277,7 +277,7 @@ public class ImportKeysActivity extends BaseActivity { private boolean isFingerprintValid(String fingerprint) { if (fingerprint == null || fingerprint.length() < 40) { - Notify.showNotify(this, R.string.import_qr_code_too_short_fingerprint, Notify.Style.ERROR); + Notify.create(this, R.string.import_qr_code_too_short_fingerprint, Notify.Style.ERROR).show(); return false; } else { return true; @@ -372,7 +372,7 @@ public class ImportKeysActivity extends BaseActivity { startService(intent); } catch (IOException e) { Log.e(Constants.TAG, "Problem writing cache file", e); - Notify.showNotify(this, "Problem writing cache file!", Notify.Style.ERROR); + Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR).show(); } } else if (ls instanceof ImportKeysListFragment.CloudLoaderState) { ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls; @@ -412,7 +412,7 @@ public class ImportKeysActivity extends BaseActivity { // start service with intent startService(intent); } else { - Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR); + Notify.create(this, R.string.error_nothing_import, Notify.Style.ERROR).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 793fb4524..5f1189deb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -390,8 +390,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) { - Notify.showNotify(getActivity(), R.string.secret_cannot_multiple, - Notify.Style.ERROR); + Notify.create(getActivity(), R.string.secret_cannot_multiple, + Notify.Style.ERROR).show(); return; } @@ -484,21 +484,21 @@ public class KeyListFragment extends LoaderFragment case R.id.menu_key_list_debug_read: try { KeychainDatabase.debugBackup(getActivity(), true); - Notify.showNotify(getActivity(), "Restored debug_backup.db", Notify.Style.INFO); + Notify.create(getActivity(), "Restored debug_backup.db", Notify.Style.OK).show(); getActivity().getContentResolver().notifyChange(KeychainContract.KeyRings.CONTENT_URI, null); } catch (IOException e) { Log.e(Constants.TAG, "IO Error", e); - Notify.showNotify(getActivity(), "IO Error " + e.getMessage(), Notify.Style.ERROR); + Notify.create(getActivity(), "IO Error " + e.getMessage(), Notify.Style.ERROR).show(); } return true; case R.id.menu_key_list_debug_write: try { KeychainDatabase.debugBackup(getActivity(), false); - Notify.showNotify(getActivity(), "Backup to debug_backup.db completed", Notify.Style.INFO); + Notify.create(getActivity(), "Backup to debug_backup.db completed", Notify.Style.OK).show(); } catch (IOException e) { Log.e(Constants.TAG, "IO Error", e); - Notify.showNotify(getActivity(), "IO Error: " + e.getMessage(), Notify.Style.ERROR); + Notify.create(getActivity(), "IO Error: " + e.getMessage(), Notify.Style.ERROR).show(); } return true; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index d3c1d971a..43af07bbe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -80,7 +80,7 @@ public class QrCodeViewActivity extends BaseActivity { KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); if (blob == null) { Log.e(Constants.TAG, "key not found!"); - Notify.showNotify(this, R.string.error_key_not_found, Style.ERROR); + Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); ActivityCompat.finishAfterTransition(QrCodeViewActivity.this); } @@ -102,7 +102,7 @@ public class QrCodeViewActivity extends BaseActivity { }); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); - Notify.showNotify(this, R.string.error_key_not_found, Style.ERROR); + Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); ActivityCompat.finishAfterTransition(QrCodeViewActivity.this); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index d0cea5f05..863aef65f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -205,7 +205,7 @@ public class SafeSlingerActivity extends BaseActivity { activity.startService(intent); } catch (IOException e) { Log.e(Constants.TAG, "Problem writing cache file", e); - Notify.showNotify(activity, "Problem writing cache file!", Notify.Style.ERROR); + Notify.create(activity, "Problem writing cache file!", Notify.Style.ERROR).show(); } } else { // give everything else down to KeyListActivity! 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 45ad944c4..484956e6a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -338,7 +338,7 @@ public class ViewKeyActivity extends BaseActivity implements try { updateFromKeyserver(mDataUri, mProviderHelper); } catch (ProviderHelper.NotFoundException e) { - Notify.showNotify(this, R.string.error_key_not_found, Notify.Style.ERROR); + Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } return true; } @@ -449,7 +449,7 @@ public class ViewKeyActivity extends BaseActivity implements Constants.Path.APP_DIR_FILE, ((Long) data.get(KeychainContract.KeyRings.HAS_SECRET) != 0) ); } catch (ProviderHelper.NotFoundException e) { - Notify.showNotify(this, R.string.error_key_not_found, Notify.Style.ERROR); + Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); Log.e(Constants.TAG, "Key not found", e); } } @@ -486,14 +486,14 @@ public class ViewKeyActivity extends BaseActivity implements String fp = data.getStringExtra(ImportKeysProxyActivity.EXTRA_FINGERPRINT); if (fp == null) { - Notify.createNotify(this, "Error scanning fingerprint!", + Notify.create(this, "Error scanning fingerprint!", Notify.LENGTH_LONG, Notify.Style.ERROR).show(); return; } if (mFingerprint.equalsIgnoreCase(fp)) { certifyImmediate(); } else { - Notify.createNotify(this, "Fingerprints did not match!", + Notify.create(this, "Fingerprints did not match!", Notify.LENGTH_LONG, Notify.Style.ERROR).show(); } @@ -519,7 +519,7 @@ public class ViewKeyActivity extends BaseActivity implements private void encrypt(Uri dataUri, boolean text) { // If there is no encryption key, don't bother. if (!mHasEncrypt) { - Notify.showNotify(this, R.string.error_no_encrypt_subkey, Notify.Style.ERROR); + Notify.create(this, R.string.error_no_encrypt_subkey, Notify.Style.ERROR).show(); return; } try { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 29586ae9f..6bd3a9303 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -199,13 +199,13 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } else { message = getResources().getString(R.string.key_copied_to_clipboard); } - Notify.showNotify(getActivity(), message, Notify.Style.OK); + Notify.create(getActivity(), message, Notify.Style.OK).show(); } else { // Android will fail with android.os.TransactionTooLargeException if key is too big // see http://www.lonestarprod.com/?p=34 if (content.length() >= 86389) { - Notify.showNotify(getActivity(), R.string.key_too_big_for_sharing, - Notify.Style.ERROR); + Notify.create(getActivity(), R.string.key_too_big_for_sharing, + Notify.Style.ERROR).show(); return; } @@ -223,10 +223,10 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); - Notify.showNotify(getActivity(), R.string.error_key_processing, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.error_key_processing, Notify.Style.ERROR).show(); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); - Notify.showNotify(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR).show(); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java index 7ac85781f..63b6d26ac 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java @@ -190,7 +190,7 @@ public class FileDialogFragment extends DialogFragment { mFile = file; mFilename.setText(mFile.getName()); } else { - Notify.showNotify(getActivity(), R.string.no_file_selected, Notify.Style.ERROR); + Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show(); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java index 9736b5765..4224fb9a2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java @@ -18,10 +18,7 @@ package org.sufficientlysecure.keychain.ui.util; import android.app.Activity; -import android.content.res.Resources; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; import android.view.View; import android.view.ViewGroup; @@ -40,135 +37,49 @@ import org.sufficientlysecure.keychain.util.FabContainer; */ public class Notify { - public static enum Style {OK, WARN, INFO, ERROR} + public static enum Style {OK, WARN, ERROR} public static final int LENGTH_INDEFINITE = 0; public static final int LENGTH_LONG = 3500; - /** - * Shows a simple in-layout notification with the CharSequence given as parameter - * @param text Text to show - * @param style Notification styling - */ - public static void showNotify(final Activity activity, CharSequence text, Style style) { - - Snackbar bar = getSnackbar(activity) + public static Showable create(final Activity activity, String text, int duration, Style style, + final ActionListener actionListener, int actionResId) { + final Snackbar snackbar = Snackbar.with(activity) + .type(SnackbarType.MULTI_LINE) .text(text); - switch (style) { - case OK: - break; - case WARN: - bar.textColor(activity.getResources().getColor(R.color.android_orange_light)); - break; - case ERROR: - bar.textColor(activity.getResources().getColor(R.color.android_red_light)); - break; - } - - showSnackbar(activity, bar); - - } - - public static Showable createNotify (final Activity activity, int resId, int duration, Style style) { - final Snackbar bar = getSnackbar(activity) - .text(resId); - if (duration == LENGTH_INDEFINITE) { - bar.duration(SnackbarDuration.LENGTH_INDEFINITE); + snackbar.duration(SnackbarDuration.LENGTH_INDEFINITE); } else { - bar.duration(duration); + snackbar.duration(duration); } switch (style) { case OK: - bar.actionColor(activity.getResources().getColor(R.color.android_green_light)); + snackbar.actionColorResource(R.color.android_green_light); break; - case WARN: - bar.textColor(activity.getResources().getColor(R.color.android_orange_light)); - break; - case ERROR: - bar.textColor(activity.getResources().getColor(R.color.android_red_light)); - break; - } - - return new Showable () { - @Override - public void show() { - showSnackbar(activity, bar); - } - }; - } - - public static Showable createNotify(Activity activity, int resId, int duration, Style style, - final ActionListener listener, int resIdAction) { - return createNotify(activity, activity.getString(resId), duration, style, listener, resIdAction); - } - - public static Showable createNotify(Activity activity, String msg, int duration, Style style) { - return createNotify(activity, msg, duration, style, null, 0); - } - - public static Showable createNotify(final Activity activity, String msg, int duration, Style style, - final ActionListener listener, int resIdAction) { - - final Snackbar bar = getSnackbar(activity) - .text(msg); - - if (listener != null) { - bar.actionLabel(resIdAction); - bar.actionListener(new ActionClickListener() { - @Override - public void onActionClicked(Snackbar snackbar) { - listener.onAction(); - } - }); - } - - if (duration == LENGTH_INDEFINITE) { - bar.duration(SnackbarDuration.LENGTH_INDEFINITE); - } else { - bar.duration(duration); - } - switch (style) { - case OK: - bar.actionColor(activity.getResources().getColor(R.color.android_green_light)); - break; case WARN: - bar.textColor(activity.getResources().getColor(R.color.android_orange_light)); + snackbar.textColorResource(R.color.android_orange_light); break; + case ERROR: - bar.textColor(activity.getResources().getColor(R.color.android_red_light)); + snackbar.textColorResource(R.color.android_red_light); break; } - return new Showable () { - @Override - public void show() { - showSnackbar(activity, bar); - } - }; - - } - - /** - * Shows a simple in-layout notification with the resource text from given id - * @param resId ResourceId of notification text - * @param style Notification styling - * @throws Resources.NotFoundException - */ - public static void showNotify(Activity activity, int resId, Style style) throws Resources.NotFoundException { - showNotify(activity, activity.getResources().getText(resId), style); - } - - private static Snackbar getSnackbar(final Activity activity) { - Snackbar bar = Snackbar.with(activity) - .type(SnackbarType.MULTI_LINE) - .duration(SnackbarDuration.LENGTH_LONG); + if (actionListener != null) { + snackbar.actionLabel(actionResId) + .actionListener(new ActionClickListener() { + @Override + public void onActionClicked(Snackbar snackbar) { + actionListener.onAction(); + } + }); + } if (activity instanceof FabContainer) { - bar.eventListener(new EventListenerAdapter() { + snackbar.eventListener(new EventListenerAdapter() { @Override public void onShow(Snackbar snackbar) { ((FabContainer) activity).fabMoveUp(snackbar.getHeight()); @@ -180,37 +91,74 @@ public class Notify { } }); } - return bar; - } - private static void showSnackbar(Activity activity, Snackbar snackbar) { - if (activity instanceof FragmentActivity) { - FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager(); + return new Showable() { + @Override + public void show() { + SnackbarManager.show(snackbar, activity); + } - int count = fragmentManager.getBackStackEntryCount(); - Fragment fragment = fragmentManager.getFragments().get(count > 0 ? count - 1 : 0); + @Override + public void show(Fragment fragment) { + if (fragment != null) { + View view = fragment.getView(); + + if (view != null && view instanceof ViewGroup) { + SnackbarManager.show(snackbar, (ViewGroup) view); + return; + } + } - if (fragment != null) { - View view = fragment.getView(); + show(); + } - if (view != null) { - SnackbarManager.show(snackbar, (ViewGroup) view); + @Override + public void show(ViewGroup viewGroup) { + if (viewGroup != null) { + SnackbarManager.show(snackbar, viewGroup); return; } + + show(); } - } + }; + } + + public static Showable create(Activity activity, String text, int duration, Style style) { + return create(activity, text, duration, style, null, -1); + } - SnackbarManager.show(snackbar); + public static Showable create(Activity activity, String text, Style style) { + return create(activity, text, LENGTH_LONG, style); + } + + public static Showable create(Activity activity, int textResId, int duration, Style style, + ActionListener actionListener, int actionResId) { + return create(activity, activity.getString(textResId), duration, style, actionListener, actionResId); + } + + public static Showable create(Activity activity, int textResId, int duration, Style style) { + return create(activity, activity.getString(textResId), duration, style); + } + + public static Showable create(Activity activity, int textResId, Style style) { + return create(activity, activity.getString(textResId), style); } public interface Showable { + public void show(); + public void show(Fragment fragment); + + public void show(ViewGroup viewGroup); + } public interface ActionListener { + public void onAction(); } -} \ No newline at end of file +} -- cgit v1.2.3 From fa8d5657bec8fc8106635fd7a5d4ad17256fb93b Mon Sep 17 00:00:00 2001 From: Manoj Khanna Date: Fri, 20 Mar 2015 18:35:20 +0530 Subject: Fixed Snackbar behind keyboard on ImportKeysActivity --- .../sufficientlysecure/keychain/ui/ImportKeysActivity.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') 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 d59936967..9143609ad 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -26,6 +26,7 @@ import android.os.Messenger; import android.support.v4.app.Fragment; import android.view.View; import android.view.View.OnClickListener; +import android.view.ViewGroup; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -277,7 +278,8 @@ public class ImportKeysActivity extends BaseActivity { private boolean isFingerprintValid(String fingerprint) { if (fingerprint == null || fingerprint.length() < 40) { - Notify.create(this, R.string.import_qr_code_too_short_fingerprint, Notify.Style.ERROR).show(); + Notify.create(this, R.string.import_qr_code_too_short_fingerprint, Notify.Style.ERROR) + .show((ViewGroup) findViewById(R.id.import_snackbar)); return false; } else { return true; @@ -329,7 +331,8 @@ public class ImportKeysActivity extends BaseActivity { return; } - result.createNotify(ImportKeysActivity.this).show(); + result.createNotify(ImportKeysActivity.this) + .show((ViewGroup) findViewById(R.id.import_snackbar)); } } }; @@ -372,7 +375,8 @@ public class ImportKeysActivity extends BaseActivity { startService(intent); } catch (IOException e) { Log.e(Constants.TAG, "Problem writing cache file", e); - Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR).show(); + Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR) + .show((ViewGroup) findViewById(R.id.import_snackbar)); } } else if (ls instanceof ImportKeysListFragment.CloudLoaderState) { ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls; @@ -412,7 +416,8 @@ public class ImportKeysActivity extends BaseActivity { // start service with intent startService(intent); } else { - Notify.create(this, R.string.error_nothing_import, Notify.Style.ERROR).show(); + Notify.create(this, R.string.error_nothing_import, Notify.Style.ERROR) + .show((ViewGroup) findViewById(R.id.import_snackbar)); } } -- cgit v1.2.3 From 850a3747886064d648e7fe2436eff9531eb6011c Mon Sep 17 00:00:00 2001 From: Manoj Khanna Date: Fri, 20 Mar 2015 19:19:35 +0530 Subject: Added docs for Notify class --- .../java/org/sufficientlysecure/keychain/ui/util/Notify.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java index 4224fb9a2..3121e02ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java @@ -147,10 +147,20 @@ public class Notify { public interface Showable { + /** + * Shows the notification on the bottom of the Activity. + */ public void show(); + /** + * Shows the notification on the bottom of the Fragment. + */ public void show(Fragment fragment); + /** + * Shows the notification on the given ViewGroup. + * The viewGroup should be either a RelativeLayout or FrameLayout. + */ public void show(ViewGroup viewGroup); } -- cgit v1.2.3