mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-12 03:55:09 -05:00
more code style changes in /ui and /util
This commit is contained in:
parent
4353ea37e2
commit
2ff6949c95
@ -848,7 +848,7 @@ public class EncryptActivity extends DrawerActivity {
|
|||||||
new Choice(Id.choice.compression.zlib, "ZLIB ("
|
new Choice(Id.choice.compression.zlib, "ZLIB ("
|
||||||
+ getString(R.string.compression_fast) + ")"),
|
+ getString(R.string.compression_fast) + ")"),
|
||||||
new Choice(Id.choice.compression.bzip2, "BZIP2 ("
|
new Choice(Id.choice.compression.bzip2, "BZIP2 ("
|
||||||
+ getString(R.string.compression_very_slow) + ")"),};
|
+ getString(R.string.compression_very_slow) + ")"), };
|
||||||
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(this,
|
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(this,
|
||||||
android.R.layout.simple_spinner_item, choices);
|
android.R.layout.simple_spinner_item, choices);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
@ -167,7 +167,8 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
|
|||||||
query = "0x" + fingerprint;
|
query = "0x" + fingerprint;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or 'fingerprint' extra!");
|
Log.e(Constants.TAG,
|
||||||
|
"IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or 'fingerprint' extra!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +399,8 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
|
|||||||
AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO)
|
AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO)
|
||||||
.show();
|
.show();
|
||||||
if (bad > 0) {
|
if (bad > 0) {
|
||||||
BadImportKeyDialogFragment badImportKeyDialogFragment = BadImportKeyDialogFragment.newInstance(bad);
|
BadImportKeyDialogFragment badImportKeyDialogFragment =
|
||||||
|
BadImportKeyDialogFragment.newInstance(bad);
|
||||||
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
|
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,8 @@ public class ImportKeysServerFragment extends Fragment {
|
|||||||
search(query, keyServer);
|
search(query, keyServer);
|
||||||
|
|
||||||
// close keyboard after pressing search
|
// close keyboard after pressing search
|
||||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm =
|
||||||
|
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -108,7 +109,6 @@ public class ImportKeysServerFragment extends Fragment {
|
|||||||
search(query, keyServer);
|
search(query, keyServer);
|
||||||
|
|
||||||
// Don't return true to let the keyboard close itself after pressing search
|
// Don't return true to let the keyboard close itself after pressing search
|
||||||
// http://stackoverflow.com/questions/2342620/how-to-hide-keyboard-after-typing-in-edittext-in-android
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -141,7 +141,7 @@ public class SelectSecretKeyFragment extends ListFragment implements
|
|||||||
+ Keys.IS_REVOKED + " = '0' AND valid_keys." + Keys.CAN_SIGN
|
+ Keys.IS_REVOKED + " = '0' AND valid_keys." + Keys.CAN_SIGN
|
||||||
+ " = '1' AND valid_keys." + Keys.CREATION + " <= '" + now + "' AND "
|
+ " = '1' AND valid_keys." + Keys.CREATION + " <= '" + now + "' AND "
|
||||||
+ "(valid_keys." + Keys.EXPIRY + " IS NULL OR valid_keys." + Keys.EXPIRY
|
+ "(valid_keys." + Keys.EXPIRY + " IS NULL OR valid_keys." + Keys.EXPIRY
|
||||||
+ " >= '" + now + "')) AS " + SelectKeyCursorAdapter.PROJECTION_ROW_VALID,};
|
+ " >= '" + now + "')) AS " + SelectKeyCursorAdapter.PROJECTION_ROW_VALID, };
|
||||||
|
|
||||||
String orderBy = UserIds.USER_ID + " ASC";
|
String orderBy = UserIds.USER_ID + " ASC";
|
||||||
|
|
||||||
|
@ -27,20 +27,20 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
*/
|
*/
|
||||||
public class AsyncTaskResultWrapper<T> {
|
public class AsyncTaskResultWrapper<T> {
|
||||||
|
|
||||||
private final T result;
|
private final T mResult;
|
||||||
private final Exception error;
|
private final Exception mError;
|
||||||
|
|
||||||
public AsyncTaskResultWrapper(T result, Exception error) {
|
public AsyncTaskResultWrapper(T result, Exception error) {
|
||||||
this.result = result;
|
this.mResult = result;
|
||||||
this.error = error;
|
this.mError = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getResult() {
|
public T getResult() {
|
||||||
return result;
|
return mResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Exception getError() {
|
public Exception getError() {
|
||||||
return error;
|
return mError;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,15 +40,15 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
protected LayoutInflater mInflater;
|
protected LayoutInflater mInflater;
|
||||||
protected Activity mActivity;
|
protected Activity mActivity;
|
||||||
|
|
||||||
protected List<ImportKeysListEntry> data;
|
protected List<ImportKeysListEntry> mData;
|
||||||
|
|
||||||
static class ViewHolder {
|
static class ViewHolder {
|
||||||
private TextView mainUserId;
|
private TextView mMainUserId;
|
||||||
private TextView mainUserIdRest;
|
private TextView mMainUserIdRest;
|
||||||
private TextView keyId;
|
private TextView mKeyId;
|
||||||
private TextView fingerprint;
|
private TextView mFingerprint;
|
||||||
private TextView algorithm;
|
private TextView mAlgorithm;
|
||||||
private TextView status;
|
private TextView mStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
public void setData(List<ImportKeysListEntry> data) {
|
public void setData(List<ImportKeysListEntry> data) {
|
||||||
clear();
|
clear();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
this.data = data;
|
this.mData = data;
|
||||||
|
|
||||||
// add data to extended ArrayAdapter
|
// add data to extended ArrayAdapter
|
||||||
if (Build.VERSION.SDK_INT >= 11) {
|
if (Build.VERSION.SDK_INT >= 11) {
|
||||||
@ -76,15 +76,16 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ImportKeysListEntry> getData() {
|
public List<ImportKeysListEntry> getData() {
|
||||||
return data;
|
return mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<ImportKeysListEntry> getSelectedData() {
|
public ArrayList<ImportKeysListEntry> getSelectedData() {
|
||||||
ArrayList<ImportKeysListEntry> selectedData = new ArrayList<ImportKeysListEntry>();
|
ArrayList<ImportKeysListEntry> selectedData = new ArrayList<ImportKeysListEntry>();
|
||||||
for (ImportKeysListEntry entry : data) {
|
for (ImportKeysListEntry entry : mData) {
|
||||||
if (entry.isSelected())
|
if (entry.isSelected()) {
|
||||||
selectedData.add(entry);
|
selectedData.add(entry);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return selectedData;
|
return selectedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,17 +95,17 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
ImportKeysListEntry entry = data.get(position);
|
ImportKeysListEntry entry = mData.get(position);
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
holder = new ViewHolder();
|
holder = new ViewHolder();
|
||||||
convertView = mInflater.inflate(R.layout.import_keys_list_entry, null);
|
convertView = mInflater.inflate(R.layout.import_keys_list_entry, null);
|
||||||
holder.mainUserId = (TextView) convertView.findViewById(R.id.mainUserId);
|
holder.mMainUserId = (TextView) convertView.findViewById(R.id.mainUserId);
|
||||||
holder.mainUserIdRest = (TextView) convertView.findViewById(R.id.mainUserIdRest);
|
holder.mMainUserIdRest = (TextView) convertView.findViewById(R.id.mainUserIdRest);
|
||||||
holder.keyId = (TextView) convertView.findViewById(R.id.keyId);
|
holder.mKeyId = (TextView) convertView.findViewById(R.id.keyId);
|
||||||
holder.fingerprint = (TextView) convertView.findViewById(R.id.fingerprint);
|
holder.mFingerprint = (TextView) convertView.findViewById(R.id.fingerprint);
|
||||||
holder.algorithm = (TextView) convertView.findViewById(R.id.algorithm);
|
holder.mAlgorithm = (TextView) convertView.findViewById(R.id.algorithm);
|
||||||
holder.status = (TextView) convertView.findViewById(R.id.status);
|
holder.mStatus = (TextView) convertView.findViewById(R.id.status);
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
@ -118,36 +119,36 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
// show red user id if it is a secret key
|
// show red user id if it is a secret key
|
||||||
if (entry.secretKey) {
|
if (entry.secretKey) {
|
||||||
userIdSplit[0] = mActivity.getString(R.string.secret_key) + " " + userIdSplit[0];
|
userIdSplit[0] = mActivity.getString(R.string.secret_key) + " " + userIdSplit[0];
|
||||||
holder.mainUserId.setTextColor(Color.RED);
|
holder.mMainUserId.setTextColor(Color.RED);
|
||||||
}
|
}
|
||||||
holder.mainUserId.setText(userIdSplit[0]);
|
holder.mMainUserId.setText(userIdSplit[0]);
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserId.setText(R.string.user_id_no_name);
|
holder.mMainUserId.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// email
|
// email
|
||||||
if (userIdSplit[1] != null) {
|
if (userIdSplit[1] != null) {
|
||||||
holder.mainUserIdRest.setText(userIdSplit[1]);
|
holder.mMainUserIdRest.setText(userIdSplit[1]);
|
||||||
holder.mainUserIdRest.setVisibility(View.VISIBLE);
|
holder.mMainUserIdRest.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserIdRest.setVisibility(View.GONE);
|
holder.mMainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.keyId.setText(entry.hexKeyId);
|
holder.mKeyId.setText(entry.hexKeyId);
|
||||||
|
|
||||||
if (entry.fingerPrint != null) {
|
if (entry.fingerPrint != null) {
|
||||||
holder.fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint);
|
holder.mFingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint);
|
||||||
holder.fingerprint.setVisibility(View.VISIBLE);
|
holder.mFingerprint.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.fingerprint.setVisibility(View.GONE);
|
holder.mFingerprint.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
|
holder.mAlgorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
|
||||||
|
|
||||||
if (entry.revoked) {
|
if (entry.revoked) {
|
||||||
holder.status.setText(R.string.revoked);
|
holder.mStatus.setText(R.string.revoked);
|
||||||
} else {
|
} else {
|
||||||
holder.status.setVisibility(View.GONE);
|
holder.mStatus.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearLayout ll = (LinearLayout) convertView.findViewById(R.id.list);
|
LinearLayout ll = (LinearLayout) convertView.findViewById(R.id.list);
|
||||||
|
@ -45,9 +45,9 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
public String algorithm;
|
public String algorithm;
|
||||||
public boolean secretKey;
|
public boolean secretKey;
|
||||||
|
|
||||||
private boolean selected;
|
private boolean mSelected;
|
||||||
|
|
||||||
private byte[] bytes = new byte[]{};
|
private byte[] mBytes = new byte[]{};
|
||||||
|
|
||||||
public ImportKeysListEntry(ImportKeysListEntry b) {
|
public ImportKeysListEntry(ImportKeysListEntry b) {
|
||||||
this.userIds = b.userIds;
|
this.userIds = b.userIds;
|
||||||
@ -59,8 +59,8 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
this.bitStrength = b.bitStrength;
|
this.bitStrength = b.bitStrength;
|
||||||
this.algorithm = b.algorithm;
|
this.algorithm = b.algorithm;
|
||||||
this.secretKey = b.secretKey;
|
this.secretKey = b.secretKey;
|
||||||
this.selected = b.selected;
|
this.mSelected = b.mSelected;
|
||||||
this.bytes = b.bytes;
|
this.mBytes = b.mBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
@ -78,9 +78,9 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
dest.writeInt(bitStrength);
|
dest.writeInt(bitStrength);
|
||||||
dest.writeString(algorithm);
|
dest.writeString(algorithm);
|
||||||
dest.writeByte((byte) (secretKey ? 1 : 0));
|
dest.writeByte((byte) (secretKey ? 1 : 0));
|
||||||
dest.writeByte((byte) (selected ? 1 : 0));
|
dest.writeByte((byte) (mSelected ? 1 : 0));
|
||||||
dest.writeInt(bytes.length);
|
dest.writeInt(mBytes.length);
|
||||||
dest.writeByteArray(bytes);
|
dest.writeByteArray(mBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
||||||
@ -96,9 +96,9 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
vr.bitStrength = source.readInt();
|
vr.bitStrength = source.readInt();
|
||||||
vr.algorithm = source.readString();
|
vr.algorithm = source.readString();
|
||||||
vr.secretKey = source.readByte() == 1;
|
vr.secretKey = source.readByte() == 1;
|
||||||
vr.selected = source.readByte() == 1;
|
vr.mSelected = source.readByte() == 1;
|
||||||
vr.bytes = new byte[source.readInt()];
|
vr.mBytes = new byte[source.readInt()];
|
||||||
source.readByteArray(vr.bytes);
|
source.readByteArray(vr.mBytes);
|
||||||
|
|
||||||
return vr;
|
return vr;
|
||||||
}
|
}
|
||||||
@ -113,11 +113,11 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
return bytes;
|
return mBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBytes(byte[] bytes) {
|
public void setBytes(byte[] bytes) {
|
||||||
this.bytes = bytes;
|
this.mBytes = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,16 +127,16 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
// keys from keyserver are always public keys
|
// keys from keyserver are always public keys
|
||||||
secretKey = false;
|
secretKey = false;
|
||||||
// do not select by default
|
// do not select by default
|
||||||
selected = false;
|
mSelected = false;
|
||||||
userIds = new ArrayList<String>();
|
userIds = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelected() {
|
public boolean isSelected() {
|
||||||
return selected;
|
return mSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelected(boolean selected) {
|
public void setSelected(boolean selected) {
|
||||||
this.selected = selected;
|
this.mSelected = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,13 +146,13 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
public ImportKeysListEntry(PGPKeyRing pgpKeyRing) {
|
public ImportKeysListEntry(PGPKeyRing pgpKeyRing) {
|
||||||
// save actual key object into entry, used to import it later
|
// save actual key object into entry, used to import it later
|
||||||
try {
|
try {
|
||||||
this.bytes = pgpKeyRing.getEncoded();
|
this.mBytes = pgpKeyRing.getEncoded();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "IOException on pgpKeyRing.getEncoded()", e);
|
Log.e(Constants.TAG, "IOException on pgpKeyRing.getEncoded()", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// selected is default
|
// selected is default
|
||||||
this.selected = true;
|
this.mSelected = true;
|
||||||
|
|
||||||
if (pgpKeyRing instanceof PGPSecretKeyRing) {
|
if (pgpKeyRing instanceof PGPSecretKeyRing) {
|
||||||
secretKey = true;
|
secretKey = true;
|
||||||
|
@ -31,21 +31,22 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
public class ImportKeysListLoader
|
||||||
|
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
|
|
||||||
public static class FileHasNoContent extends Exception {
|
public static class FileHasNoContent extends Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NonPgpPart extends Exception {
|
public static class NonPgpPart extends Exception {
|
||||||
private int count;
|
private int mCount;
|
||||||
|
|
||||||
public NonPgpPart(int count) {
|
public NonPgpPart(int count) {
|
||||||
this.count = count;
|
this.mCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return count;
|
return mCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +54,8 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
|
|||||||
|
|
||||||
InputData mInputData;
|
InputData mInputData;
|
||||||
|
|
||||||
ArrayList<ImportKeysListEntry> data = new ArrayList<ImportKeysListEntry>();
|
ArrayList<ImportKeysListEntry> mData = new ArrayList<ImportKeysListEntry>();
|
||||||
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> entryListWrapper;
|
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> mEntryListWrapper;
|
||||||
|
|
||||||
public ImportKeysListLoader(Context context, InputData inputData) {
|
public ImportKeysListLoader(Context context, InputData inputData) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -65,16 +66,16 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
|
|||||||
@Override
|
@Override
|
||||||
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
|
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
|
||||||
|
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(data, null);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, null);
|
||||||
|
|
||||||
if (mInputData == null) {
|
if (mInputData == null) {
|
||||||
Log.e(Constants.TAG, "Input data is null!");
|
Log.e(Constants.TAG, "Input data is null!");
|
||||||
return entryListWrapper;
|
return mEntryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateListOfKeyrings(mInputData);
|
generateListOfKeyrings(mInputData);
|
||||||
|
|
||||||
return entryListWrapper;
|
return mEntryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -142,25 +143,25 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(Constants.TAG, "Exception on parsing key file!", e);
|
Log.e(Constants.TAG, "Exception on parsing key file!", e);
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(data, e);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
|
||||||
nonPgpCounter = 0;
|
nonPgpCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
Log.e(Constants.TAG, "File has no content!", new FileHasNoContent());
|
Log.e(Constants.TAG, "File has no content!", new FileHasNoContent());
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
||||||
(data, new FileHasNoContent());
|
(mData, new FileHasNoContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonPgpCounter > 0) {
|
if (nonPgpCounter > 0) {
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
||||||
(data, new NonPgpPart(nonPgpCounter));
|
(mData, new NonPgpPart(nonPgpCounter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToData(PGPKeyRing keyring) {
|
private void addToData(PGPKeyRing keyring) {
|
||||||
ImportKeysListEntry item = new ImportKeysListEntry(keyring);
|
ImportKeysListEntry item = new ImportKeysListEntry(keyring);
|
||||||
data.add(item);
|
mData.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,15 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ImportKeysListServerLoader extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
public class ImportKeysListServerLoader
|
||||||
|
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
|
||||||
String mServerQuery;
|
String mServerQuery;
|
||||||
String mKeyServer;
|
String mKeyServer;
|
||||||
|
|
||||||
private ArrayList<ImportKeysListEntry> entryList = new ArrayList<ImportKeysListEntry>();
|
private ArrayList<ImportKeysListEntry> mEntryList = new ArrayList<ImportKeysListEntry>();
|
||||||
private AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> entryListWrapper;
|
private AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> mEntryListWrapper;
|
||||||
|
|
||||||
public ImportKeysListServerLoader(Context context, String serverQuery, String keyServer) {
|
public ImportKeysListServerLoader(Context context, String serverQuery, String keyServer) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -45,16 +46,16 @@ public class ImportKeysListServerLoader extends AsyncTaskLoader<AsyncTaskResultW
|
|||||||
@Override
|
@Override
|
||||||
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
|
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
|
||||||
|
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, null);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null);
|
||||||
|
|
||||||
if (mServerQuery == null) {
|
if (mServerQuery == null) {
|
||||||
Log.e(Constants.TAG, "mServerQuery is null!");
|
Log.e(Constants.TAG, "mServerQuery is null!");
|
||||||
return entryListWrapper;
|
return mEntryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
queryServer(mServerQuery, mKeyServer);
|
queryServer(mServerQuery, mKeyServer);
|
||||||
|
|
||||||
return entryListWrapper;
|
return mEntryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,17 +90,17 @@ public class ImportKeysListServerLoader extends AsyncTaskLoader<AsyncTaskResultW
|
|||||||
ArrayList<ImportKeysListEntry> searchResult = server.search(query);
|
ArrayList<ImportKeysListEntry> searchResult = server.search(query);
|
||||||
|
|
||||||
// add result to data
|
// add result to data
|
||||||
entryList.addAll(searchResult);
|
mEntryList.addAll(searchResult);
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, null);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null);
|
||||||
} catch (KeyServer.InsufficientQuery e) {
|
} catch (KeyServer.InsufficientQuery e) {
|
||||||
Log.e(Constants.TAG, "InsufficientQuery", e);
|
Log.e(Constants.TAG, "InsufficientQuery", e);
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, e);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||||
} catch (KeyServer.QueryException e) {
|
} catch (KeyServer.QueryException e) {
|
||||||
Log.e(Constants.TAG, "QueryException", e);
|
Log.e(Constants.TAG, "QueryException", e);
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, e);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||||
} catch (KeyServer.TooManyResponses e) {
|
} catch (KeyServer.TooManyResponses e) {
|
||||||
Log.e(Constants.TAG, "TooManyResponses", e);
|
Log.e(Constants.TAG, "TooManyResponses", e);
|
||||||
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, e);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ public class SelectKeyCursorAdapter extends HighlightQueryCursorAdapter {
|
|||||||
private int mIndexProjectionValid;
|
private int mIndexProjectionValid;
|
||||||
private int mIndexProjectionAvailable;
|
private int mIndexProjectionAvailable;
|
||||||
|
|
||||||
public final static String PROJECTION_ROW_AVAILABLE = "available";
|
public static final String PROJECTION_ROW_AVAILABLE = "available";
|
||||||
public final static String PROJECTION_ROW_VALID = "valid";
|
public static final String PROJECTION_ROW_VALID = "valid";
|
||||||
|
|
||||||
public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView,
|
public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView,
|
||||||
int keyType) {
|
int keyType) {
|
||||||
|
@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.adapter;
|
package org.sufficientlysecure.keychain.ui.adapter;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -19,12 +36,12 @@ public class TabsAdapter extends FragmentStatePagerAdapter implements ActionBar.
|
|||||||
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
|
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
|
||||||
|
|
||||||
static final class TabInfo {
|
static final class TabInfo {
|
||||||
private final Class<?> clss;
|
private final Class<?> mClss;
|
||||||
private final Bundle args;
|
private final Bundle mArgs;
|
||||||
|
|
||||||
TabInfo(Class<?> _class, Bundle _args) {
|
TabInfo(Class<?> mClss, Bundle mArgs) {
|
||||||
clss = _class;
|
this.mClss = mClss;
|
||||||
args = _args;
|
this.mArgs = mArgs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +71,7 @@ public class TabsAdapter extends FragmentStatePagerAdapter implements ActionBar.
|
|||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
TabInfo info = mTabs.get(position);
|
TabInfo info = mTabs.get(position);
|
||||||
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
|
return Fragment.instantiate(mContext, info.mClss.getName(), info.mArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||||
import org.spongycastle.openpgp.PGPEncryptedData;
|
import org.spongycastle.openpgp.PGPEncryptedData;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@SuppressLint("UseSparseArrays")
|
@SuppressLint("UseSparseArrays")
|
||||||
public class AlgorithmNames {
|
public class AlgorithmNames {
|
||||||
|
@ -18,7 +18,6 @@ package org.sufficientlysecure.keychain.util;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
import com.google.zxing.integration.android.IntentIntegrator;
|
import com.google.zxing.integration.android.IntentIntegrator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,20 +27,19 @@ import com.google.zxing.integration.android.IntentIntegrator;
|
|||||||
*/
|
*/
|
||||||
public final class IntentIntegratorSupportV4 extends IntentIntegrator {
|
public final class IntentIntegratorSupportV4 extends IntentIntegrator {
|
||||||
|
|
||||||
private final Fragment fragment;
|
private final Fragment mFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fragment
|
* @param fragment Fragment to handle activity response.
|
||||||
* Fragment to handle activity response.
|
|
||||||
*/
|
*/
|
||||||
public IntentIntegratorSupportV4(Fragment fragment) {
|
public IntentIntegratorSupportV4(Fragment fragment) {
|
||||||
super(fragment.getActivity());
|
super(fragment.getActivity());
|
||||||
this.fragment = fragment;
|
this.mFragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startActivityForResult(Intent intent, int code) {
|
protected void startActivityForResult(Intent intent, int code) {
|
||||||
fragment.startActivityForResult(intent, code);
|
mFragment.startActivityForResult(intent, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class KeyServer {
|
public abstract class KeyServer {
|
||||||
static public class QueryException extends Exception {
|
public static class QueryException extends Exception {
|
||||||
private static final long serialVersionUID = 2703768928624654512L;
|
private static final long serialVersionUID = 2703768928624654512L;
|
||||||
|
|
||||||
public QueryException(String message) {
|
public QueryException(String message) {
|
||||||
@ -31,15 +31,15 @@ public abstract class KeyServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class TooManyResponses extends Exception {
|
public static class TooManyResponses extends Exception {
|
||||||
private static final long serialVersionUID = 2703768928624654513L;
|
private static final long serialVersionUID = 2703768928624654513L;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class InsufficientQuery extends Exception {
|
public static class InsufficientQuery extends Exception {
|
||||||
private static final long serialVersionUID = 2703768928624654514L;
|
private static final long serialVersionUID = 2703768928624654514L;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class AddKeyException extends Exception {
|
public static class AddKeyException extends Exception {
|
||||||
private static final long serialVersionUID = -507574859137295530L;
|
private static final long serialVersionUID = -507574859137295530L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
public interface KeychainServiceListener {
|
public interface KeychainServiceListener {
|
||||||
|
@ -21,7 +21,6 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps Android Logging to enable or disable debug output using Constants
|
* Wraps Android Logging to enable or disable debug output using Constants
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class Log {
|
public final class Log {
|
||||||
|
|
||||||
|
@ -14,48 +14,36 @@ import android.os.Build;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.DataInputStream;
|
import java.security.*;
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.Provider;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.security.SecureRandomSpi;
|
|
||||||
import java.security.Security;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixes for the output of the default PRNG having low entropy.
|
* Fixes for the output of the default PRNG having low entropy.
|
||||||
*
|
* <p/>
|
||||||
* The fixes need to be applied via {@link #apply()} before any use of Java Cryptography
|
* The fixes need to be applied via {@link #apply()} before any use of Java Cryptography
|
||||||
* Architecture primitives. A good place to invoke them is in the application's {@code onCreate}.
|
* Architecture primitives. A good place to invoke them is in the application's {@code onCreate}.
|
||||||
*
|
* <p/>
|
||||||
* copied from http://android-developers.blogspot.de/2013/08/some-securerandom-thoughts.html
|
* copied from http://android-developers.blogspot.de/2013/08/some-securerandom-thoughts.html
|
||||||
*
|
* <p/>
|
||||||
*
|
* <p/>
|
||||||
* More information on these Android bugs:
|
* More information on these Android bugs:
|
||||||
* http://blog.k3170makan.com/2013/08/more-details-on-android-jca-prng-flaw.html
|
* http://blog.k3170makan.com/2013/08/more-details-on-android-jca-prng-flaw.html
|
||||||
* Paper: "Randomly failed! Weaknesses in Java Pseudo Random Number Generators (PRNGs)"
|
* Paper: "Randomly failed! Weaknesses in Java Pseudo Random Number Generators (PRNGs)"
|
||||||
*
|
* <p/>
|
||||||
*
|
* <p/>
|
||||||
* Sep 15, 2013:
|
* Sep 15, 2013:
|
||||||
* On some devices /dev/urandom is non-writable!
|
* On some devices /dev/urandom is non-writable!
|
||||||
* No need to seed /dev/urandom. urandom should have enough seeds from the OS and kernel.
|
* No need to seed /dev/urandom. urandom should have enough seeds from the OS and kernel.
|
||||||
* Only OpenSSL seeds are broken. See http://emboss.github.io/blog/2013/08/21/openssl-prng-is-not-really-fork-safe
|
* Only OpenSSL seeds are broken. See http://emboss.github.io/blog/2013/08/21/openssl-prng-is-not-really-fork-safe
|
||||||
*
|
* <p/>
|
||||||
* see also:
|
* see also:
|
||||||
* https://github.com/k9mail/k-9/commit/dda8f64276d4d29c43f86237cd77819c28f22f21
|
* https://github.com/k9mail/k-9/commit/dda8f64276d4d29c43f86237cd77819c28f22f21
|
||||||
* In addition to a couple of custom ROMs linking /dev/urandom to a non-writable
|
* In addition to a couple of custom ROMs linking /dev/urandom to a non-writable
|
||||||
* random version, now Samsung's SELinux policy also prevents apps from opening
|
* random version, now Samsung's SELinux policy also prevents apps from opening
|
||||||
* /dev/urandom for writing. Since we shouldn't need to write to /dev/urandom anyway
|
* /dev/urandom for writing. Since we shouldn't need to write to /dev/urandom anyway
|
||||||
* we now simply don't.
|
* we now simply don't.
|
||||||
*
|
* <p/>
|
||||||
*
|
* <p/>
|
||||||
* Sep 17, 2013:
|
* Sep 17, 2013:
|
||||||
* Updated from official blogpost:
|
* Updated from official blogpost:
|
||||||
* Update: the original code sample below crashed on a small fraction of Android
|
* Update: the original code sample below crashed on a small fraction of Android
|
||||||
@ -68,8 +56,11 @@ public final class PRNGFixes {
|
|||||||
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
|
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
|
||||||
getBuildFingerprintAndDeviceSerial();
|
getBuildFingerprintAndDeviceSerial();
|
||||||
|
|
||||||
/** Hidden constructor to prevent instantiation. */
|
/**
|
||||||
private PRNGFixes() {}
|
* Hidden constructor to prevent instantiation.
|
||||||
|
*/
|
||||||
|
private PRNGFixes() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies all fixes.
|
* Applies all fixes.
|
||||||
|
@ -17,11 +17,7 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.RejectedExecutionHandler;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@ -32,18 +28,21 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
public class PausableThreadPoolExecutor extends ThreadPoolExecutor {
|
public class PausableThreadPoolExecutor extends ThreadPoolExecutor {
|
||||||
|
|
||||||
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
|
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
|
||||||
TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
|
TimeUnit unit, BlockingQueue<Runnable> workQueue,
|
||||||
|
RejectedExecutionHandler handler) {
|
||||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
|
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
|
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
|
||||||
TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory,
|
TimeUnit unit, BlockingQueue<Runnable> workQueue,
|
||||||
|
ThreadFactory threadFactory,
|
||||||
RejectedExecutionHandler handler) {
|
RejectedExecutionHandler handler) {
|
||||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
|
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
|
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
|
||||||
TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
|
TimeUnit unit, BlockingQueue<Runnable> workQueue,
|
||||||
|
ThreadFactory threadFactory) {
|
||||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
|
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,39 +51,40 @@ public class PausableThreadPoolExecutor extends ThreadPoolExecutor {
|
|||||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
|
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPaused;
|
private boolean mIsPaused;
|
||||||
private ReentrantLock pauseLock = new ReentrantLock();
|
private ReentrantLock mPauseLock = new ReentrantLock();
|
||||||
private Condition unpaused = pauseLock.newCondition();
|
private Condition mUnPaused = mPauseLock.newCondition();
|
||||||
|
|
||||||
protected void beforeExecute(Thread t, Runnable r) {
|
protected void beforeExecute(Thread t, Runnable r) {
|
||||||
super.beforeExecute(t, r);
|
super.beforeExecute(t, r);
|
||||||
pauseLock.lock();
|
mPauseLock.lock();
|
||||||
try {
|
try {
|
||||||
while (isPaused)
|
while (mIsPaused) {
|
||||||
unpaused.await();
|
mUnPaused.await();
|
||||||
|
}
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
t.interrupt();
|
t.interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
pauseLock.unlock();
|
mPauseLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
pauseLock.lock();
|
mPauseLock.lock();
|
||||||
try {
|
try {
|
||||||
isPaused = true;
|
mIsPaused = true;
|
||||||
} finally {
|
} finally {
|
||||||
pauseLock.unlock();
|
mPauseLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
pauseLock.lock();
|
mPauseLock.lock();
|
||||||
try {
|
try {
|
||||||
isPaused = false;
|
mIsPaused = false;
|
||||||
unpaused.signalAll();
|
mUnPaused.signalAll();
|
||||||
} finally {
|
} finally {
|
||||||
pauseLock.unlock();
|
mPauseLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,22 +18,20 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.EncodeHintType;
|
import com.google.zxing.EncodeHintType;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
public class QrCodeUtils {
|
public class QrCodeUtils {
|
||||||
public final static QRCodeWriter QR_CODE_WRITER = new QRCodeWriter();
|
public static final QRCodeWriter QR_CODE_WRITER = new QRCodeWriter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate Bitmap with QR Code based on input.
|
* Generate Bitmap with QR Code based on input.
|
||||||
|
Loading…
Reference in New Issue
Block a user