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,18 +17,17 @@
|
|||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
@ -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()
|
||||||
|
@ -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,9 +54,9 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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,11 +134,14 @@ 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),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
true,
|
||||||
|
new DialogInterface.OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialogInterface) {
|
public void onCancel(DialogInterface dialogInterface) {
|
||||||
activity.stopService(intent);
|
mActivity.stopService(intent);
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
@ -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,6 +26,9 @@ 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 {
|
||||||
|
|
||||||
@ -54,12 +53,9 @@ public class FileHelper {
|
|||||||
* 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
|
|
||||||
* @param requestCode
|
|
||||||
* requestCode used to identify the result coming back from file manager to
|
|
||||||
* onActivityResult() in your activity
|
* 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) {
|
||||||
@ -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,17 +17,16 @@
|
|||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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
|
||||||
|
@ -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