mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-18 06:45:03 -05:00
Fix code style in /helper
This commit is contained in:
parent
540aa044e2
commit
f26ba217e5
@ -17,24 +17,23 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.helper;
|
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.app.Activity;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class ActionBarHelper {
|
public class ActionBarHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set actionbar without home button if called from another app
|
* Set actionbar without home button if called from another app
|
||||||
*
|
*
|
||||||
* @param activity
|
* @param activity
|
||||||
*/
|
*/
|
||||||
public static void setBackButton(ActionBarActivity activity) {
|
public static void setBackButton(ActionBarActivity activity) {
|
||||||
@ -54,7 +53,7 @@ public class ActionBarHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets custom view on ActionBar for Done/Cancel activities
|
* Sets custom view on ActionBar for Done/Cancel activities
|
||||||
*
|
*
|
||||||
* @param actionBar
|
* @param actionBar
|
||||||
* @param firstText
|
* @param firstText
|
||||||
* @param firstDrawableId
|
* @param firstDrawableId
|
||||||
@ -63,9 +62,9 @@ public class ActionBarHelper {
|
|||||||
* @param secondDrawableId
|
* @param secondDrawableId
|
||||||
* @param secondOnClickListener
|
* @param secondOnClickListener
|
||||||
*/
|
*/
|
||||||
public static void setTwoButtonView(ActionBar actionBar, int firstText, int firstDrawableId,
|
public static void setTwoButtonView(ActionBar actionBar,
|
||||||
OnClickListener firstOnClickListener, int secondText, int secondDrawableId,
|
int firstText, int firstDrawableId, OnClickListener firstOnClickListener,
|
||||||
OnClickListener secondOnClickListener) {
|
int secondText, int secondDrawableId, OnClickListener secondOnClickListener) {
|
||||||
|
|
||||||
// Inflate the custom action bar view
|
// Inflate the custom action bar view
|
||||||
final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext()
|
final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext()
|
||||||
@ -94,13 +93,13 @@ public class ActionBarHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets custom view on ActionBar for Done activities
|
* Sets custom view on ActionBar for Done activities
|
||||||
*
|
*
|
||||||
* @param actionBar
|
* @param actionBar
|
||||||
* @param firstText
|
* @param firstText
|
||||||
* @param firstOnClickListener
|
* @param firstOnClickListener
|
||||||
*/
|
*/
|
||||||
public static void setOneButtonView(ActionBar actionBar, int firstText, int firstDrawableId,
|
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.
|
// Inflate a "Done" custom action bar view to serve as the "Up" affordance.
|
||||||
final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext()
|
final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext()
|
||||||
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||||
|
@ -26,7 +26,6 @@ import android.os.Message;
|
|||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@ -41,11 +40,11 @@ public class ExportHelper {
|
|||||||
protected FileDialogFragment mFileDialog;
|
protected FileDialogFragment mFileDialog;
|
||||||
protected String mExportFilename;
|
protected String mExportFilename;
|
||||||
|
|
||||||
ActionBarActivity activity;
|
ActionBarActivity mActivity;
|
||||||
|
|
||||||
public ExportHelper(ActionBarActivity activity) {
|
public ExportHelper(ActionBarActivity activity) {
|
||||||
super();
|
super();
|
||||||
this.activity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteKey(Uri dataUri, final int keyType, Handler deleteHandler) {
|
public void deleteKey(Uri dataUri, final int keyType, Handler deleteHandler) {
|
||||||
@ -55,16 +54,16 @@ public class ExportHelper {
|
|||||||
Messenger messenger = new Messenger(deleteHandler);
|
Messenger messenger = new Messenger(deleteHandler);
|
||||||
|
|
||||||
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
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
|
* Show dialog where to export keys
|
||||||
*/
|
*/
|
||||||
public void showExportKeysDialog(final long[] rowIds, final int keyType,
|
public void showExportKeysDialog(final long[] rowIds, final int keyType,
|
||||||
final String exportFilename) {
|
final String exportFilename) {
|
||||||
mExportFilename = exportFilename;
|
mExportFilename = exportFilename;
|
||||||
|
|
||||||
// Message is received after file is selected
|
// Message is received after file is selected
|
||||||
@ -88,23 +87,23 @@ public class ExportHelper {
|
|||||||
String title = null;
|
String title = null;
|
||||||
if (rowIds == null) {
|
if (rowIds == null) {
|
||||||
// export all keys
|
// export all keys
|
||||||
title = activity.getString(R.string.title_export_keys);
|
title = mActivity.getString(R.string.title_export_keys);
|
||||||
} else {
|
} else {
|
||||||
// export only key specified at data uri
|
// 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;
|
String message = null;
|
||||||
if (keyType == Id.type.public_key) {
|
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 {
|
} 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,
|
mFileDialog = FileDialogFragment.newInstance(messenger, title, message,
|
||||||
exportFilename, null);
|
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");
|
Log.d(Constants.TAG, "exportKeys started");
|
||||||
|
|
||||||
// Send all information needed to service to export key in other thread
|
// 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);
|
intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING);
|
||||||
|
|
||||||
@ -135,12 +134,15 @@ public class ExportHelper {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after exporting is done in ApgService
|
// Message is received after exporting is done in ApgService
|
||||||
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(activity,
|
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(mActivity,
|
||||||
activity.getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL, true, new DialogInterface.OnCancelListener() {
|
mActivity.getString(R.string.progress_exporting),
|
||||||
@Override
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
public void onCancel(DialogInterface dialogInterface) {
|
true,
|
||||||
activity.stopService(intent);
|
new DialogInterface.OnCancelListener() {
|
||||||
}
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialogInterface) {
|
||||||
|
mActivity.stopService(intent);
|
||||||
|
}
|
||||||
}) {
|
}) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard ApgHandler first
|
// handle messages by standard ApgHandler first
|
||||||
@ -153,13 +155,13 @@ public class ExportHelper {
|
|||||||
int exported = returnData.getInt(KeychainIntentService.RESULT_EXPORT);
|
int exported = returnData.getInt(KeychainIntentService.RESULT_EXPORT);
|
||||||
String toastMessage;
|
String toastMessage;
|
||||||
if (exported == 1) {
|
if (exported == 1) {
|
||||||
toastMessage = activity.getString(R.string.key_exported);
|
toastMessage = mActivity.getString(R.string.key_exported);
|
||||||
} else if (exported > 0) {
|
} else if (exported > 0) {
|
||||||
toastMessage = activity.getString(R.string.keys_exported, exported);
|
toastMessage = mActivity.getString(R.string.keys_exported, exported);
|
||||||
} else {
|
} 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);
|
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
exportHandler.showProgressDialog(activity);
|
exportHandler.showProgressDialog(mActivity);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
activity.startService(intent);
|
mActivity.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,6 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.helper;
|
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.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -30,12 +26,15 @@ import android.net.Uri;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class FileHelper {
|
public class FileHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if external storage is mounted if file is located on external storage
|
* Checks if external storage is mounted if file is located on external storage
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @return true if storage is mounted
|
* @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
|
* Opens the preferred installed file manager on Android and shows a toast if no manager is
|
||||||
* installed.
|
* installed.
|
||||||
*
|
*
|
||||||
* @param activity
|
* @param activity
|
||||||
* @param filename
|
* @param filename default selected file, not supported by all file managers
|
||||||
* default selected file, not supported by all file managers
|
* @param mimeType can be text/plain for example
|
||||||
* @param mimeType
|
* @param requestCode requestCode used to identify the result coming back from file manager to
|
||||||
* can be text/plain for example
|
* onActivityResult() in your activity
|
||||||
* @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) {
|
public static void openFile(Activity activity, String filename, String mimeType, int requestCode) {
|
||||||
Intent intent = buildFileIntent(filename, mimeType);
|
Intent intent = buildFileIntent(filename, mimeType);
|
||||||
@ -97,14 +93,13 @@ public class FileHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a file path from a Uri.
|
* Get a file path from a Uri.
|
||||||
*
|
* <p/>
|
||||||
* from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
|
* from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
|
||||||
* afilechooser/utils/FileUtils.java
|
* afilechooser/utils/FileUtils.java
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @param uri
|
* @param uri
|
||||||
* @return
|
* @return
|
||||||
*
|
|
||||||
* @author paulburke
|
* @author paulburke
|
||||||
*/
|
*/
|
||||||
public static String getPath(Context context, Uri uri) {
|
public static String getPath(Context context, Uri uri) {
|
||||||
@ -115,21 +110,19 @@ public class FileHelper {
|
|||||||
+ uri.getPathSegments().toString());
|
+ uri.getPathSegments().toString());
|
||||||
|
|
||||||
if ("content".equalsIgnoreCase(uri.getScheme())) {
|
if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||||
String[] projection = { "_data" };
|
String[] projection = {"_data"};
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(uri, projection, null, null, null);
|
cursor = context.getContentResolver().query(uri, projection, null, null, null);
|
||||||
int column_index = cursor.getColumnIndexOrThrow("_data");
|
int columnIndex = cursor.getColumnIndexOrThrow("_data");
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
return cursor.getString(column_index);
|
return cursor.getString(columnIndex);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Eat it
|
// Eat it
|
||||||
}
|
}
|
||||||
}
|
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||||
|
|
||||||
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
|
||||||
return uri.getPath();
|
return uri.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,22 +17,21 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.helper;
|
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.DigestException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
public class OtherHelper {
|
public class OtherHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs bundle content to debug for inspecting the content
|
* Logs bundle content to debug for inspecting the content
|
||||||
*
|
*
|
||||||
* @param bundle
|
* @param bundle
|
||||||
* @param bundleName
|
* @param bundleName
|
||||||
*/
|
*/
|
||||||
@ -63,6 +62,7 @@ public class OtherHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given bytes to a unique RGB color using SHA1 algorithm
|
* Converts the given bytes to a unique RGB color using SHA1 algorithm
|
||||||
|
*
|
||||||
* @param bytes
|
* @param bytes
|
||||||
* @return an integer array containing 3 numeric color representations (Red, Green, Black)
|
* @return an integer array containing 3 numeric color representations (Red, Green, Black)
|
||||||
* @throws NoSuchAlgorithmException
|
* @throws NoSuchAlgorithmException
|
||||||
@ -75,8 +75,8 @@ public class OtherHelper {
|
|||||||
byte[] digest = md.digest();
|
byte[] digest = md.digest();
|
||||||
|
|
||||||
int[] result = {((int) digest[0] + 256) % 256,
|
int[] result = {((int) digest[0] + 256) % 256,
|
||||||
((int) digest[1] + 256) % 256,
|
((int) digest[1] + 256) % 256,
|
||||||
((int) digest[2] + 256) % 256};
|
((int) digest[2] + 256) % 256};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,14 +17,13 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.helper;
|
package org.sufficientlysecure.keychain.helper;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||||
import org.spongycastle.openpgp.PGPEncryptedData;
|
import org.spongycastle.openpgp.PGPEncryptedData;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,8 +37,8 @@ public class Preferences {
|
|||||||
return getPreferences(context, false);
|
return getPreferences(context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized Preferences getPreferences(Context context, boolean force_new) {
|
public static synchronized Preferences getPreferences(Context context, boolean forceNew) {
|
||||||
if (mPreferences == null || force_new) {
|
if (mPreferences == null || forceNew) {
|
||||||
mPreferences = new Preferences(context);
|
mPreferences = new Preferences(context);
|
||||||
}
|
}
|
||||||
return mPreferences;
|
return mPreferences;
|
||||||
|
Loading…
Reference in New Issue
Block a user