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 24e8ff4c7..91e50637e 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,24 +17,23 @@ 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) { @@ -54,7 +53,7 @@ public class ActionBarHelper { /** * Sets custom view on ActionBar for Done/Cancel activities - * + * * @param actionBar * @param firstText * @param firstDrawableId @@ -63,9 +62,9 @@ public class ActionBarHelper { * @param secondDrawableId * @param secondOnClickListener */ - public static void setTwoButtonView(ActionBar actionBar, int firstText, int firstDrawableId, - OnClickListener firstOnClickListener, int secondText, int secondDrawableId, - OnClickListener secondOnClickListener) { + public static void setTwoButtonView(ActionBar actionBar, + int firstText, int firstDrawableId, OnClickListener firstOnClickListener, + int secondText, int secondDrawableId, OnClickListener secondOnClickListener) { // Inflate the custom action bar view final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext() @@ -94,13 +93,13 @@ public class ActionBarHelper { /** * Sets custom view on ActionBar for Done activities - * + * * @param actionBar * @param firstText * @param firstOnClickListener */ public static void setOneButtonView(ActionBar actionBar, int firstText, int firstDrawableId, - OnClickListener firstOnClickListener) { + 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); 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 245c5fda1..557d75dbf 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 @@ -26,7 +26,6 @@ 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; @@ -41,11 +40,11 @@ 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) { @@ -55,16 +54,16 @@ public class ExportHelper { Messenger messenger = new Messenger(deleteHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, - new long[] { keyRingRowId }, keyType); + new long[]{keyRingRowId}, keyType); - deleteKeyDialog.show(activity.getSupportFragmentManager(), "deleteKeyDialog"); + deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog"); } /** * Show dialog where to export keys */ public void showExportKeysDialog(final long[] rowIds, final int keyType, - final String exportFilename) { + final String exportFilename) { mExportFilename = exportFilename; // Message is received after file is selected @@ -88,23 +87,23 @@ public class ExportHelper { String title = null; if (rowIds == 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); + message = mActivity.getString(R.string.specify_file_to_export_to); } else { - message = activity.getString(R.string.specify_file_to_export_secret_keys_to); + message = mActivity.getString(R.string.specify_file_to_export_secret_keys_to); } mFileDialog = FileDialogFragment.newInstance(messenger, title, message, exportFilename, null); - mFileDialog.show(activity.getSupportFragmentManager(), "fileDialog"); + mFileDialog.show(mActivity.getSupportFragmentManager(), "fileDialog"); } }); } @@ -116,7 +115,7 @@ public class ExportHelper { Log.d(Constants.TAG, "exportKeys started"); // Send all information needed to service to export key in other thread - final Intent intent = new Intent(activity, KeychainIntentService.class); + final Intent intent = new Intent(mActivity, KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING); @@ -135,12 +134,15 @@ public class ExportHelper { intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after exporting is done in ApgService - KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(activity, - activity.getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL, true, new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialogInterface) { - activity.stopService(intent); - } + 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 @@ -153,13 +155,13 @@ 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(); } } @@ -170,10 +172,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. - * + *

* 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 292b5bf3d..eb46a52e5 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,22 +17,21 @@ package org.sufficientlysecure.keychain.helper; +import android.os.Bundle; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.util.Log; + import java.security.DigestException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Iterator; import java.util.Set; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.util.Log; - -import android.os.Bundle; - public class OtherHelper { /** * Logs bundle content to debug for inspecting the content - * + * * @param bundle * @param bundleName */ @@ -63,6 +62,7 @@ public class OtherHelper { /** * Converts the given bytes to a unique RGB color using SHA1 algorithm + * * @param bytes * @return an integer array containing 3 numeric color representations (Red, Green, Black) * @throws NoSuchAlgorithmException @@ -75,8 +75,8 @@ public class OtherHelper { byte[] digest = md.digest(); int[] result = {((int) digest[0] + 256) % 256, - ((int) digest[1] + 256) % 256, - ((int) digest[2] + 256) % 256}; + ((int) digest[1] + 256) % 256, + ((int) digest[2] + 256) % 256}; return result; } 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 f18a290b3..82e181664 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;