Fix code style in /helper

This commit is contained in:
uberspot 2014-03-13 19:59:27 +02:00
parent 540aa044e2
commit f26ba217e5
5 changed files with 64 additions and 71 deletions

View File

@ -17,18 +17,17 @@
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 {
@ -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()

View File

@ -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,9 +54,9 @@ 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");
}
/**
@ -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,11 +134,14 @@ 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() {
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(mActivity,
mActivity.getString(R.string.progress_exporting),
ProgressDialog.STYLE_HORIZONTAL,
true,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
activity.stopService(intent);
mActivity.stopService(intent);
}
}) {
public void handleMessage(Message message) {
@ -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);
}
}

View File

@ -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,6 +26,9 @@ 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 {
@ -54,12 +53,9 @@ public class FileHelper {
* 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
* @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) {
@ -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();
}

View File

@ -17,17 +17,16 @@
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 {
/**
@ -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

View File

@ -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;