aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper
diff options
context:
space:
mode:
authorAshley Hughes <spirit.returned@gmail.com>2014-03-29 13:21:39 +0000
committerAshley Hughes <spirit.returned@gmail.com>2014-03-29 13:21:39 +0000
commite1d07214dfe12f893aa4052e08dbc3025f5cb67d (patch)
treeef945347e987806f4f448e32671c039345985356 /OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper
parent7a2d880c4db21ab62cb152f10d1938a36319acb3 (diff)
parent68668fd444b973502b91b7cbe0cf7dbdd8a8b5c4 (diff)
downloadopen-keychain-e1d07214dfe12f893aa4052e08dbc3025f5cb67d.tar.gz
open-keychain-e1d07214dfe12f893aa4052e08dbc3025f5cb67d.tar.bz2
open-keychain-e1d07214dfe12f893aa4052e08dbc3025f5cb67d.zip
merge master
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java62
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java41
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java102
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java37
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java19
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java55
6 files changed, 185 insertions, 131 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java
index b55075e6c..a26df556d 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java
@@ -17,28 +17,26 @@
package org.sufficientlysecure.keychain.helper;
-import org.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.util.Log;
-
import android.app.Activity;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.view.View.OnClickListener;
+import android.view.ViewGroup;
import android.widget.TextView;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.util.Log;
public class ActionBarHelper {
/**
* Set actionbar without home button if called from another app
- *
+ *
* @param activity
*/
public static void setBackButton(ActionBarActivity activity) {
- // set actionbar without home button if called from another app
final ActionBar actionBar = activity.getSupportActionBar();
Log.d(Constants.TAG, "calling package (only set when using startActivityForResult)="
+ activity.getCallingPackage());
@@ -54,30 +52,35 @@ public class ActionBarHelper {
/**
* Sets custom view on ActionBar for Done/Cancel activities
- *
+ *
* @param actionBar
- * @param doneText
- * @param doneOnClickListener
- * @param cancelText
- * @param cancelOnClickListener
+ * @param firstText
+ * @param firstDrawableId
+ * @param firstOnClickListener
+ * @param secondText
+ * @param secondDrawableId
+ * @param secondOnClickListener
*/
- public static void setDoneCancelView(ActionBar actionBar, int doneText,
- OnClickListener doneOnClickListener, int cancelText,
- OnClickListener cancelOnClickListener) {
+ public static void setTwoButtonView(ActionBar actionBar,
+ int firstText, int firstDrawableId, OnClickListener firstOnClickListener,
+ int secondText, int secondDrawableId, OnClickListener secondOnClickListener) {
- // Inflate a "Done"/"Cancel" custom action bar view
+ // Inflate the custom action bar view
final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext()
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_cancel, null);
- ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text)).setText(doneText);
+ TextView firstTextView = ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text));
+ firstTextView.setText(firstText);
+ firstTextView.setCompoundDrawablesWithIntrinsicBounds(firstDrawableId, 0, 0, 0);
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
- doneOnClickListener);
- ((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text))
- .setText(cancelText);
+ firstOnClickListener);
+ TextView secondTextView = ((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text));
+ secondTextView.setText(secondText);
+ secondTextView.setCompoundDrawablesWithIntrinsicBounds(secondDrawableId, 0, 0, 0);
customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(
- cancelOnClickListener);
+ secondOnClickListener);
// Show the custom action bar view and hide the normal Home icon and title.
actionBar.setDisplayShowTitleEnabled(false);
@@ -89,22 +92,24 @@ public class ActionBarHelper {
/**
* Sets custom view on ActionBar for Done activities
- *
+ *
* @param actionBar
- * @param doneText
- * @param doneOnClickListener
+ * @param firstText
+ * @param firstOnClickListener
*/
- public static void setDoneView(ActionBar actionBar, int doneText,
- OnClickListener doneOnClickListener) {
+ public static void setOneButtonView(ActionBar actionBar, int firstText, int firstDrawableId,
+ OnClickListener firstOnClickListener) {
// Inflate a "Done" custom action bar view to serve as the "Up" affordance.
final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext()
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater
.inflate(R.layout.actionbar_custom_view_done, null);
- ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text)).setText(doneText);
+ TextView firstTextView = ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text));
+ firstTextView.setText(firstText);
+ firstTextView.setCompoundDrawablesWithIntrinsicBounds(firstDrawableId, 0, 0, 0);
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
- doneOnClickListener);
+ firstOnClickListener);
// Show the custom action bar view and hide the normal Home icon and title.
actionBar.setDisplayShowTitleEnabled(false);
@@ -112,5 +117,4 @@ public class ActionBarHelper {
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(customActionBarView);
}
-
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java
new file mode 100644
index 000000000..f8ed21816
--- /dev/null
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.sufficientlysecure.keychain.helper;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.Context;
+import android.util.Patterns;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ContactHelper {
+
+ public static final List<String> getMailAccounts(Context context) {
+ final Account[] accounts = AccountManager.get(context).getAccounts();
+ final Set<String> emailSet = new HashSet<String>();
+ for (Account account : accounts) {
+ if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
+ emailSet.add(account.name);
+ }
+ }
+ return new ArrayList<String>(emailSet);
+ }
+}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java
index 21676a2a7..cc240a67b 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java
@@ -16,10 +16,21 @@
package org.sufficientlysecure.keychain.helper;
+import android.app.ProgressDialog;
+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.v7.app.ActionBarActivity;
+import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
+import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
@@ -27,44 +38,38 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
-import android.app.ProgressDialog;
-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.v7.app.ActionBarActivity;
-import android.widget.Toast;
+import java.lang.reflect.Array;
+import java.security.Provider;
+import java.util.ArrayList;
public class ExportHelper {
protected FileDialogFragment mFileDialog;
protected String mExportFilename;
- ActionBarActivity activity;
+ ActionBarActivity mActivity;
public ExportHelper(ActionBarActivity activity) {
super();
- this.activity = activity;
+ this.mActivity = activity;
}
- public void deleteKey(Uri dataUri, final int keyType, Handler deleteHandler) {
+ public void deleteKey(Uri dataUri, Handler deleteHandler) {
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(deleteHandler);
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
- new long[] { keyRingRowId }, keyType);
+ new long[]{keyRingRowId});
- deleteKeyDialog.show(activity.getSupportFragmentManager(), "deleteKeyDialog");
+ deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
}
/**
* Show dialog where to export keys
*/
- public void showExportKeysDialog(final Uri dataUri, final int keyType,
- final String exportFilename) {
+ public void showExportKeysDialog(final long[] masterKeyIds, final int keyType,
+ final String exportFilename, final String checkboxString) {
mExportFilename = exportFilename;
// Message is received after file is selected
@@ -73,9 +78,14 @@ public class ExportHelper {
public void handleMessage(Message message) {
if (message.what == FileDialogFragment.MESSAGE_OKAY) {
Bundle data = message.getData();
+ int type = keyType;
mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
- exportKeys(dataUri, keyType);
+ if( data.getBoolean(FileDialogFragment.MESSAGE_DATA_CHECKED) ) {
+ type = Id.type.public_secret_key;
+ }
+
+ exportKeys(masterKeyIds, type);
}
}
};
@@ -86,25 +96,20 @@ public class ExportHelper {
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
public void run() {
String title = null;
- if (dataUri == null) {
+ if (masterKeyIds == null) {
// export all keys
- title = activity.getString(R.string.title_export_keys);
+ title = mActivity.getString(R.string.title_export_keys);
} else {
// export only key specified at data uri
- title = activity.getString(R.string.title_export_key);
+ title = mActivity.getString(R.string.title_export_key);
}
- String message = null;
- if (keyType == Id.type.public_key) {
- message = activity.getString(R.string.specify_file_to_export_to);
- } else {
- message = activity.getString(R.string.specify_file_to_export_secret_keys_to);
- }
+ String message = mActivity.getString(R.string.specify_file_to_export_to);
mFileDialog = FileDialogFragment.newInstance(messenger, title, message,
- exportFilename, null);
+ exportFilename, checkboxString);
- mFileDialog.show(activity.getSupportFragmentManager(), "fileDialog");
+ mFileDialog.show(mActivity.getSupportFragmentManager(), "fileDialog");
}
});
}
@@ -112,11 +117,11 @@ public class ExportHelper {
/**
* Export keys
*/
- public void exportKeys(Uri dataUri, int keyType) {
+ public void exportKeys(long[] masterKeyIds, int keyType) {
Log.d(Constants.TAG, "exportKeys started");
// Send all information needed to service to export key in other thread
- Intent intent = new Intent(activity, KeychainIntentService.class);
+ final Intent intent = new Intent(mActivity, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING);
@@ -126,22 +131,27 @@ public class ExportHelper {
data.putString(KeychainIntentService.EXPORT_FILENAME, mExportFilename);
data.putInt(KeychainIntentService.EXPORT_KEY_TYPE, keyType);
- if (dataUri == null) {
+ if (masterKeyIds == null) {
data.putBoolean(KeychainIntentService.EXPORT_ALL, true);
} else {
- // TODO: put data uri into service???
- long keyRingMasterKeyId = ProviderHelper.getMasterKeyId(activity, dataUri);
-
- data.putLong(KeychainIntentService.EXPORT_KEY_RING_MASTER_KEY_ID, keyRingMasterKeyId);
+ data.putLongArray(KeychainIntentService.EXPORT_KEY_RING_MASTER_KEY_ID, masterKeyIds);
}
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
- // Message is received after exporting is done in ApgService
- KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(activity,
- R.string.progress_exporting, ProgressDialog.STYLE_HORIZONTAL) {
+ // Message is received after exporting is done in KeychainIntentService
+ KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(mActivity,
+ mActivity.getString(R.string.progress_exporting),
+ ProgressDialog.STYLE_HORIZONTAL,
+ true,
+ new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialogInterface) {
+ mActivity.stopService(intent);
+ }
+ }) {
public void handleMessage(Message message) {
- // handle messages by standard ApgHandler first
+ // handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
@@ -151,16 +161,16 @@ public class ExportHelper {
int exported = returnData.getInt(KeychainIntentService.RESULT_EXPORT);
String toastMessage;
if (exported == 1) {
- toastMessage = activity.getString(R.string.key_exported);
+ toastMessage = mActivity.getString(R.string.key_exported);
} else if (exported > 0) {
- toastMessage = activity.getString(R.string.keys_exported, exported);
+ toastMessage = mActivity.getString(R.string.keys_exported, exported);
} else {
- toastMessage = activity.getString(R.string.no_keys_exported);
+ toastMessage = mActivity.getString(R.string.no_keys_exported);
}
- Toast.makeText(activity, toastMessage, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mActivity, toastMessage, Toast.LENGTH_SHORT).show();
}
- };
+ }
};
// Create a new Messenger for the communication back
@@ -168,10 +178,10 @@ public class ExportHelper {
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
- exportHandler.showProgressDialog(activity);
+ exportHandler.showProgressDialog(mActivity);
// start service with intent
- activity.startService(intent);
+ mActivity.startService(intent);
}
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java
index ec56fe912..d24aeca52 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java
@@ -17,10 +17,6 @@
package org.sufficientlysecure.keychain.helper;
-import org.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.util.Log;
-
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -30,12 +26,15 @@ import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.widget.Toast;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.util.Log;
public class FileHelper {
/**
* Checks if external storage is mounted if file is located on external storage
- *
+ *
* @param file
* @return true if storage is mounted
*/
@@ -52,15 +51,12 @@ public class FileHelper {
/**
* Opens the preferred installed file manager on Android and shows a toast if no manager is
* installed.
- *
+ *
* @param activity
- * @param filename
- * default selected file, not supported by all file managers
- * @param mimeType
- * can be text/plain for example
- * @param requestCode
- * requestCode used to identify the result coming back from file manager to
- * onActivityResult() in your activity
+ * @param filename default selected file, not supported by all file managers
+ * @param mimeType can be text/plain for example
+ * @param requestCode requestCode used to identify the result coming back from file manager to
+ * onActivityResult() in your activity
*/
public static void openFile(Activity activity, String filename, String mimeType, int requestCode) {
Intent intent = buildFileIntent(filename, mimeType);
@@ -97,14 +93,13 @@ public class FileHelper {
/**
* Get a file path from a Uri.
- *
+ * <p/>
* from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
* afilechooser/utils/FileUtils.java
- *
+ *
* @param context
* @param uri
* @return
- *
* @author paulburke
*/
public static String getPath(Context context, Uri uri) {
@@ -115,21 +110,19 @@ public class FileHelper {
+ uri.getPathSegments().toString());
if ("content".equalsIgnoreCase(uri.getScheme())) {
- String[] projection = { "_data" };
+ String[] projection = {"_data"};
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection, null, null, null);
- int column_index = cursor.getColumnIndexOrThrow("_data");
+ int columnIndex = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
- return cursor.getString(column_index);
+ return cursor.getString(columnIndex);
}
} catch (Exception e) {
// Eat it
}
- }
-
- else if ("file".equalsIgnoreCase(uri.getScheme())) {
+ } else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java
index 639ab17b8..b31a889f0 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java
@@ -17,21 +17,22 @@
package org.sufficientlysecure.keychain.helper;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Iterator;
-import java.util.Set;
+import android.os.Bundle;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
+import android.text.style.StrikethroughSpan;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.util.Log;
-import android.os.Bundle;
+import java.util.Iterator;
+import java.util.Set;
public class OtherHelper {
/**
* Logs bundle content to debug for inspecting the content
- *
+ *
* @param bundle
* @param bundleName
*/
@@ -60,4 +61,10 @@ public class OtherHelper {
}
}
+ public static SpannableStringBuilder strikeOutText(CharSequence text) {
+ SpannableStringBuilder sb = new SpannableStringBuilder(text);
+ sb.setSpan(new StrikethroughSpan(), 0, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ return sb;
+ }
+
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java
index 493f25707..515201b92 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java
@@ -17,14 +17,13 @@
package org.sufficientlysecure.keychain.helper;
+import android.content.Context;
+import android.content.SharedPreferences;
import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
-import android.content.Context;
-import android.content.SharedPreferences;
-
import java.util.Vector;
/**
@@ -38,8 +37,8 @@ public class Preferences {
return getPreferences(context, false);
}
- public static synchronized Preferences getPreferences(Context context, boolean force_new) {
- if (mPreferences == null || force_new) {
+ public static synchronized Preferences getPreferences(Context context, boolean forceNew) {
+ if (mPreferences == null || forceNew) {
mPreferences = new Preferences(context);
}
return mPreferences;
@@ -50,17 +49,17 @@ public class Preferences {
}
public String getLanguage() {
- return mSharedPreferences.getString(Constants.pref.LANGUAGE, "");
+ return mSharedPreferences.getString(Constants.Pref.LANGUAGE, "");
}
public void setLanguage(String value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putString(Constants.pref.LANGUAGE, value);
+ editor.putString(Constants.Pref.LANGUAGE, value);
editor.commit();
}
public long getPassPhraseCacheTtl() {
- int ttl = mSharedPreferences.getInt(Constants.pref.PASS_PHRASE_CACHE_TTL, 180);
+ int ttl = mSharedPreferences.getInt(Constants.Pref.PASS_PHRASE_CACHE_TTL, 180);
// fix the value if it was set to "never" in previous versions, which currently is not
// supported
if (ttl == 0) {
@@ -71,81 +70,81 @@ public class Preferences {
public void setPassPhraseCacheTtl(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putInt(Constants.pref.PASS_PHRASE_CACHE_TTL, value);
+ editor.putInt(Constants.Pref.PASS_PHRASE_CACHE_TTL, value);
editor.commit();
}
public int getDefaultEncryptionAlgorithm() {
- return mSharedPreferences.getInt(Constants.pref.DEFAULT_ENCRYPTION_ALGORITHM,
+ return mSharedPreferences.getInt(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM,
PGPEncryptedData.AES_256);
}
public void setDefaultEncryptionAlgorithm(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putInt(Constants.pref.DEFAULT_ENCRYPTION_ALGORITHM, value);
+ editor.putInt(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM, value);
editor.commit();
}
public int getDefaultHashAlgorithm() {
- return mSharedPreferences.getInt(Constants.pref.DEFAULT_HASH_ALGORITHM,
+ return mSharedPreferences.getInt(Constants.Pref.DEFAULT_HASH_ALGORITHM,
HashAlgorithmTags.SHA512);
}
public void setDefaultHashAlgorithm(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putInt(Constants.pref.DEFAULT_HASH_ALGORITHM, value);
+ editor.putInt(Constants.Pref.DEFAULT_HASH_ALGORITHM, value);
editor.commit();
}
public int getDefaultMessageCompression() {
- return mSharedPreferences.getInt(Constants.pref.DEFAULT_MESSAGE_COMPRESSION,
+ return mSharedPreferences.getInt(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION,
Id.choice.compression.zlib);
}
public void setDefaultMessageCompression(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putInt(Constants.pref.DEFAULT_MESSAGE_COMPRESSION, value);
+ editor.putInt(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION, value);
editor.commit();
}
public int getDefaultFileCompression() {
- return mSharedPreferences.getInt(Constants.pref.DEFAULT_FILE_COMPRESSION,
+ return mSharedPreferences.getInt(Constants.Pref.DEFAULT_FILE_COMPRESSION,
Id.choice.compression.none);
}
public void setDefaultFileCompression(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putInt(Constants.pref.DEFAULT_FILE_COMPRESSION, value);
+ editor.putInt(Constants.Pref.DEFAULT_FILE_COMPRESSION, value);
editor.commit();
}
public boolean getDefaultAsciiArmour() {
- return mSharedPreferences.getBoolean(Constants.pref.DEFAULT_ASCII_ARMOUR, false);
+ return mSharedPreferences.getBoolean(Constants.Pref.DEFAULT_ASCII_ARMOUR, false);
}
public void setDefaultAsciiArmour(boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putBoolean(Constants.pref.DEFAULT_ASCII_ARMOUR, value);
+ editor.putBoolean(Constants.Pref.DEFAULT_ASCII_ARMOUR, value);
editor.commit();
}
public boolean getForceV3Signatures() {
- return mSharedPreferences.getBoolean(Constants.pref.FORCE_V3_SIGNATURES, false);
+ return mSharedPreferences.getBoolean(Constants.Pref.FORCE_V3_SIGNATURES, false);
}
public void setForceV3Signatures(boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
- editor.putBoolean(Constants.pref.FORCE_V3_SIGNATURES, value);
+ editor.putBoolean(Constants.Pref.FORCE_V3_SIGNATURES, value);
editor.commit();
}
public String[] getKeyServers() {
- String rawData = mSharedPreferences.getString(Constants.pref.KEY_SERVERS,
- Constants.defaults.KEY_SERVERS);
+ String rawData = mSharedPreferences.getString(Constants.Pref.KEY_SERVERS,
+ Constants.Defaults.KEY_SERVERS);
Vector<String> servers = new Vector<String>();
String chunks[] = rawData.split(",");
- for (int i = 0; i < chunks.length; ++i) {
- String tmp = chunks[i].trim();
+ for (String c : chunks) {
+ String tmp = c.trim();
if (tmp.length() > 0) {
servers.add(tmp);
}
@@ -156,8 +155,8 @@ public class Preferences {
public void setKeyServers(String[] value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
String rawData = "";
- for (int i = 0; i < value.length; ++i) {
- String tmp = value[i].trim();
+ for (String v : value) {
+ String tmp = v.trim();
if (tmp.length() == 0) {
continue;
}
@@ -166,7 +165,7 @@ public class Preferences {
}
rawData += tmp;
}
- editor.putString(Constants.pref.KEY_SERVERS, rawData);
+ editor.putString(Constants.Pref.KEY_SERVERS, rawData);
editor.commit();
}
}