@Override refactoring, some explicit casting added

This commit is contained in:
Oliver Runge 2011-09-17 23:44:06 +02:00
parent 50036a4642
commit 3ec27e07ae
24 changed files with 27 additions and 101 deletions

View File

@ -372,10 +372,10 @@ public class Apg {
new SecureRandom(), new BouncyCastleProvider().getName());
ringGen.addSubKey(keyPair);
PGPSecretKeyRing secKeyRing = ringGen.generateSecretKeyRing();
Iterator it = secKeyRing.getSecretKeys();
Iterator<PGPSecretKey> it = secKeyRing.getSecretKeys();
// first one is the master key
it.next();
secretKey = (PGPSecretKey) it.next();
secretKey = it.next();
}
return secretKey;
@ -1048,7 +1048,7 @@ public class Apg {
} else if (i != 0 && i % 2 == 0) {
fingerPrint += " ";
}
String chunk = Integer.toHexString((((int)fp[i]) + 256) % 256).toUpperCase();
String chunk = Integer.toHexString((fp[i] + 256) % 256).toUpperCase();
while (chunk.length() < 2) {
chunk = "0" + chunk;
}
@ -1597,7 +1597,7 @@ public class Apg {
// TODO: currently we always only look at the first known key
// find the secret key
PGPSecretKey secretKey = null;
Iterator it = enc.getEncryptedDataObjects();
Iterator<?> it = enc.getEncryptedDataObjects();
boolean gotAsymmetricEncryption = false;
while (it.hasNext()) {
Object obj = it.next();
@ -1640,7 +1640,7 @@ public class Apg {
throw new GeneralException(context.getString(R.string.error_invalidData));
}
Iterator it = enc.getEncryptedDataObjects();
Iterator<?> it = enc.getEncryptedDataObjects();
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof PGPPBEEncryptedData) {
@ -1688,7 +1688,7 @@ public class Apg {
// there might be more...
if (assumeSymmetric) {
PGPPBEEncryptedData pbe = null;
Iterator it = enc.getEncryptedDataObjects();
Iterator<?> it = enc.getEncryptedDataObjects();
// find secret key
while (it.hasNext()) {
Object obj = it.next();
@ -1710,7 +1710,7 @@ public class Apg {
progress.setProgress(R.string.progress_findingKey, currentProgress, 100);
PGPPublicKeyEncryptedData pbe = null;
PGPSecretKey secretKey = null;
Iterator it = enc.getEncryptedDataObjects();
Iterator<?> it = enc.getEncryptedDataObjects();
// find secret key
while (it.hasNext()) {
Object obj = it.next();
@ -1842,7 +1842,7 @@ public class Apg {
if (signature != null) {
progress.setProgress(R.string.progress_verifyingSignature, 90, 100);
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
PGPSignature messageSignature = (PGPSignature) signatureList.get(signatureIndex);
PGPSignature messageSignature = signatureList.get(signatureIndex);
if (signature.verify(messageSignature)) {
returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, true);
} else {
@ -2195,13 +2195,13 @@ public class Apg {
random.nextBytes(bytes);
String result = "";
for (int i = 0; i < length; ++i) {
int v = ((int)bytes[i] + 256) % 64;
int v = (bytes[i] + 256) % 64;
if (v < 10) {
result += (char)((int)'0' + v);
result += (char)('0' + v);
} else if (v < 36) {
result += (char)((int)'A' + v - 10);
result += (char)('A' + v - 10);
} else if (v < 62) {
result += (char)((int)'a' + v - 36);
result += (char)('a' + v - 36);
} else if (v == 62) {
result += '_';
} else if (v == 63) {

View File

@ -20,8 +20,6 @@ import org.bouncycastle2.jce.provider.BouncyCastleProvider;
import org.bouncycastle2.openpgp.PGPException;
import org.bouncycastle2.openpgp.PGPPrivateKey;
import org.bouncycastle2.openpgp.PGPSecretKey;
import org.thialfihar.android.apg.Apg.GeneralException;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -56,7 +54,6 @@ public class AskForSecretKeyPassPhrase {
alert.setTitle(R.string.title_keyNotFound);
alert.setMessage(context.getString(R.string.keyNotFound, secretKeyId));
alert.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
activity.removeDialog(Id.dialog.pass_phrase);
}

View File

@ -253,7 +253,6 @@ public class BaseActivity extends Activity
final File file = new File(getDeleteFile());
showDialog(Id.dialog.deleting);
mDeletingThread = new Thread(new Runnable() {
@Override
public void run() {
Bundle data = new Bundle();
data.putInt(Constants.extras.status, Id.message.delete_done);

View File

@ -10,12 +10,14 @@ public class CachedPassPhrase {
this.passPhrase = passPhrase;
}
@Override
public int hashCode() {
int hc1 = (int)(this.timestamp & 0xffffffff);
int hc2 = (this.passPhrase == null ? 0 : this.passPhrase.hashCode());
return (hc1 + hc2) * hc2 + hc1;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof CachedPassPhrase)) {
return false;
@ -39,6 +41,7 @@ public class CachedPassPhrase {
return true;
}
@Override
public String toString() {
return "(" + timestamp + ", *******)";
}

View File

@ -108,7 +108,6 @@ public class DecryptActivity extends BaseActivity {
mSourcePrevious.setClickable(true);
mSourcePrevious.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSource.setInAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
R.anim.push_right_in));
@ -121,7 +120,6 @@ public class DecryptActivity extends BaseActivity {
mSourceNext.setClickable(true);
OnClickListener nextSourceClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
mSource.setInAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
R.anim.push_left_in));
@ -154,7 +152,6 @@ public class DecryptActivity extends BaseActivity {
mFilename = (EditText) findViewById(R.id.filename);
mBrowse = (ImageButton) findViewById(R.id.btn_browse);
mBrowse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFile();
}
@ -282,7 +279,6 @@ public class DecryptActivity extends BaseActivity {
mSignatureLayout.setVisibility(View.GONE);
mSignatureLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mSignatureKeyId == 0) {
return;
@ -298,14 +294,12 @@ public class DecryptActivity extends BaseActivity {
});
mDecryptButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
decryptClicked();
}
});
mReplyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
replyClicked();
}
@ -704,14 +698,12 @@ public class DecryptActivity extends BaseActivity {
getString(R.string.specifyFileToDecryptTo),
mOutputFilename,
new FileDialog.OnClickListener() {
@Override
public void onOkClick(String filename, boolean checked) {
removeDialog(Id.dialog.output_filename);
mOutputFilename = filename;
decryptStart();
}
@Override
public void onCancelClick() {
removeDialog(Id.dialog.output_filename);
}

View File

@ -93,7 +93,6 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
mChangePassPhrase = (Button) findViewById(R.id.btn_change_pass_phrase);
mChangePassPhrase.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(Id.dialog.new_pass_phrase);
}
@ -209,7 +208,6 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
}
}
@Override
public void onClick(View v) {
if (v == mSaveButton) {
// TODO: some warning

View File

@ -119,7 +119,6 @@ public class EncryptActivity extends BaseActivity {
mSourcePrevious.setClickable(true);
mSourcePrevious.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSource.setInAnimation(AnimationUtils.loadAnimation(EncryptActivity.this,
R.anim.push_right_in));
@ -132,7 +131,6 @@ public class EncryptActivity extends BaseActivity {
mSourceNext.setClickable(true);
OnClickListener nextSourceClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
mSource.setInAnimation(AnimationUtils.loadAnimation(EncryptActivity.this,
R.anim.push_left_in));
@ -154,7 +152,6 @@ public class EncryptActivity extends BaseActivity {
mModePrevious.setClickable(true);
mModePrevious.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mMode.setInAnimation(AnimationUtils.loadAnimation(EncryptActivity.this,
R.anim.push_right_in));
@ -166,7 +163,6 @@ public class EncryptActivity extends BaseActivity {
});
OnClickListener nextModeClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
mMode.setInAnimation(AnimationUtils.loadAnimation(EncryptActivity.this,
R.anim.push_left_in));
@ -202,7 +198,6 @@ public class EncryptActivity extends BaseActivity {
mFilename = (EditText) findViewById(R.id.filename);
mBrowse = (ImageButton) findViewById(R.id.btn_browse);
mBrowse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFile();
}
@ -234,35 +229,30 @@ public class EncryptActivity extends BaseActivity {
mAsciiArmour = (CheckBox) findViewById(R.id.asciiArmour);
mAsciiArmour.setChecked(mPreferences.getDefaultAsciiArmour());
mAsciiArmour.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
guessOutputFilename();
}
});
mEncryptToClipboardButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
encryptToClipboardClicked();
}
});
mEncryptButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
encryptClicked();
}
});
mSelectKeysButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
selectPublicKeys();
}
});
mSign.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CheckBox checkBox = (CheckBox) v;
if (checkBox.isChecked()) {
@ -949,14 +939,12 @@ public class EncryptActivity extends BaseActivity {
getString(R.string.specifyFileToEncryptTo),
mOutputFilename,
new FileDialog.OnClickListener() {
@Override
public void onOkClick(String filename, boolean checked) {
removeDialog(Id.dialog.output_filename);
mOutputFilename = filename;
encryptStart();
}
@Override
public void onCancelClick() {
removeDialog(Id.dialog.output_filename);
}

View File

@ -58,14 +58,13 @@ public class FileDialog {
alert.setTitle(title);
alert.setMessage(message);
View view = (View) inflater.inflate(R.layout.file_dialog, null);
View view = inflater.inflate(R.layout.file_dialog, null);
mActivity = activity;
mFilename = (EditText) view.findViewById(R.id.input);
mFilename.setText(defaultFile);
mBrowse = (ImageButton) view.findViewById(R.id.btn_browse);
mBrowse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFile();
}

View File

@ -94,7 +94,6 @@ public class GeneralActivity extends BaseActivity {
mList.setAdapter(mAdapter);
mList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
clicked(mAdapter.getItem(arg2).getId());
}
@ -102,8 +101,6 @@ public class GeneralActivity extends BaseActivity {
mCancelButton = (Button) findViewById(R.id.btn_cancel);
mCancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
GeneralActivity.this.finish();
}

View File

@ -86,12 +86,11 @@ public class KeyListActivity extends BaseActivity {
mList = (ExpandableListView) findViewById(R.id.list);
registerForContextMenu(mList);
mFilterLayout = (View) findViewById(R.id.layout_filter);
mFilterLayout = findViewById(R.id.layout_filter);
mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
mClearFilterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
handleIntent(new Intent());
}
@ -232,8 +231,6 @@ public class KeyListActivity extends BaseActivity {
getString(R.string.specifyFileToImportFrom),
mImportFilename,
new FileDialog.OnClickListener() {
@Override
public void onOkClick(String filename, boolean checked) {
removeDialog(Id.dialog.import_keys);
mDeleteAfterImport = checked;
@ -241,7 +238,6 @@ public class KeyListActivity extends BaseActivity {
importKeys();
}
@Override
public void onCancelClick() {
removeDialog(Id.dialog.import_keys);
}
@ -270,14 +266,12 @@ public class KeyListActivity extends BaseActivity {
R.string.specifyFileToExportSecretKeysTo),
mExportFilename,
new FileDialog.OnClickListener() {
@Override
public void onOkClick(String filename, boolean checked) {
removeDialog(thisDialogId);
mExportFilename = filename;
exportKeys();
}
@Override
public void onCancelClick() {
removeDialog(thisDialogId);
}
@ -646,12 +640,10 @@ public class KeyListActivity extends BaseActivity {
return children;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}

View File

@ -70,7 +70,6 @@ public class KeyServerPreferenceActivity extends BaseActivity
Button okButton = (Button) findViewById(R.id.btn_ok);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
okClicked();
}
@ -78,7 +77,6 @@ public class KeyServerPreferenceActivity extends BaseActivity
Button cancelButton = (Button) findViewById(R.id.btn_cancel);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cancelClicked();
}

View File

@ -71,14 +71,12 @@ public class KeyServerQueryActivity extends BaseActivity {
}
mList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long keyId) {
get(keyId);
}
});
mSearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String query = mQuery.getText().toString();
search(query);
@ -112,6 +110,7 @@ public class KeyServerQueryActivity extends BaseActivity {
startThread();
}
@Override
protected Dialog onCreateDialog(int id) {
ProgressDialog progress = (ProgressDialog) super.onCreateDialog(id);
progress.setMessage(this.getString(R.string.progress_queryingServer,
@ -211,22 +210,18 @@ public class KeyServerQueryActivity extends BaseActivity {
return true;
}
@Override
public int getCount() {
return mKeys.size();
}
@Override
public Object getItem(int position) {
return mKeys.get(position);
}
@Override
public long getItemId(int position) {
return mKeys.get(position).keyId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
KeyInfo keyInfo = mKeys.get(position);

View File

@ -153,7 +153,6 @@ public class MailListActivity extends ListActivity {
setListAdapter(new MailboxAdapter());
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
Intent intent = new Intent(MailListActivity.this, DecryptActivity.class);
intent.setAction(Apg.Intent.DECRYPT);
@ -179,22 +178,18 @@ public class MailListActivity extends ListActivity {
return true;
}
@Override
public int getCount() {
return mMessages.size();
}
@Override
public Object getItem(int position) {
return mMessages.get(position);
}
@Override
public long getItemId(int position) {
return mMessages.get(position).id;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = mInflater.inflate(R.layout.mailbox_message_item, null);

View File

@ -67,7 +67,6 @@ public class MainActivity extends BaseActivity {
mAccounts = (ListView) findViewById(R.id.accounts);
encryptMessageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EncryptActivity.class);
intent.setAction(Apg.Intent.ENCRYPT);
@ -76,7 +75,6 @@ public class MainActivity extends BaseActivity {
});
decryptMessageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, DecryptActivity.class);
intent.setAction(Apg.Intent.DECRYPT);
@ -85,7 +83,6 @@ public class MainActivity extends BaseActivity {
});
encryptFileButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EncryptActivity.class);
intent.setAction(Apg.Intent.ENCRYPT_FILE);
@ -94,7 +91,6 @@ public class MainActivity extends BaseActivity {
});
decryptFileButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, DecryptActivity.class);
intent.setAction(Apg.Intent.DECRYPT_FILE);
@ -113,7 +109,6 @@ public class MainActivity extends BaseActivity {
mListAdapter = new AccountListAdapter(this, mAccountCursor);
mAccounts.setAdapter(mListAdapter);
mAccounts.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
String accountName = (String) mAccounts.getItemAtPosition(index);
startActivity(new Intent(MainActivity.this, MailListActivity.class)
@ -142,7 +137,7 @@ public class MainActivity extends BaseActivity {
LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = (View) inflater.inflate(R.layout.add_account_dialog, null);
View view = inflater.inflate(R.layout.add_account_dialog, null);
final EditText input = (EditText) view.findViewById(R.id.input);
alert.setView(view);

View File

@ -106,7 +106,6 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
}
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
mSelectedItem = groupPosition;

View File

@ -48,7 +48,6 @@ public class SelectPublicKeyListActivity extends BaseActivity {
Button okButton = (Button) findViewById(R.id.btn_ok);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
okClicked();
}
@ -56,18 +55,16 @@ public class SelectPublicKeyListActivity extends BaseActivity {
Button cancelButton = (Button) findViewById(R.id.btn_cancel);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cancelClicked();
}
});
mFilterLayout = (View) findViewById(R.id.layout_filter);
mFilterLayout = findViewById(R.id.layout_filter);
mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
mClearFilterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
handleIntent(new Intent());
}

View File

@ -143,24 +143,20 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
return true;
}
@Override
public int getCount() {
return mCursor.getCount();
}
@Override
public Object getItem(int position) {
mCursor.moveToPosition(position);
return mCursor.getString(2); // USER_ID
}
@Override
public long getItemId(int position) {
mCursor.moveToPosition(position);
return mCursor.getLong(1); // MASTER_KEY_ID
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
mCursor.moveToPosition(position);

View File

@ -48,7 +48,6 @@ public class SelectSecretKeyListActivity extends BaseActivity {
mList = (ListView) findViewById(R.id.list);
mList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent data = new Intent();
data.putExtra(Apg.EXTRA_KEY_ID, id);
@ -58,12 +57,11 @@ public class SelectSecretKeyListActivity extends BaseActivity {
}
});
mFilterLayout = (View) findViewById(R.id.layout_filter);
mFilterLayout = findViewById(R.id.layout_filter);
mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
mClearFilterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
handleIntent(new Intent());
}

View File

@ -102,24 +102,20 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
return true;
}
@Override
public int getCount() {
return mCursor.getCount();
}
@Override
public Object getItem(int position) {
mCursor.moveToPosition(position);
return mCursor.getString(2); // USER_ID
}
@Override
public long getItemId(int position) {
mCursor.moveToPosition(position);
return mCursor.getLong(1); // MASTER_KEY_ID
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
mCursor.moveToPosition(position);

View File

@ -105,7 +105,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
setExpiryDate(null);
mExpiryDateButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
GregorianCalendar date = mExpiryDate;
if (date == null) {
@ -201,7 +200,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
return mKey;
}
@Override
public void onClick(View v) {
final ViewGroup parent = (ViewGroup)getParent();
if (v == mDeleteButton) {
@ -212,7 +210,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
}
}
@Override
public void setEditorListener(EditorListener listener) {
mEditorListener = listener;
}

View File

@ -62,7 +62,6 @@ public class KeyServerEditor extends LinearLayout implements Editor, OnClickList
return mServer.getText().toString().trim();
}
@Override
public void onClick(View v) {
final ViewGroup parent = (ViewGroup)getParent();
if (v == mDeleteButton) {
@ -73,7 +72,6 @@ public class KeyServerEditor extends LinearLayout implements Editor, OnClickList
}
}
@Override
public void setEditorListener(EditorListener listener) {
mEditorListener = listener;
}

View File

@ -212,7 +212,6 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
dialog.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int id) {
di.dismiss();
try {
@ -229,7 +228,6 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
dialog.setCancelable(true);
dialog.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int id) {
di.dismiss();
}

View File

@ -154,7 +154,6 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
return userId;
}
@Override
public void onClick(View v) {
final ViewGroup parent = (ViewGroup)getParent();
if (v == mDeleteButton) {
@ -187,7 +186,6 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
return mIsMainUserId.isChecked();
}
@Override
public void setEditorListener(EditorListener listener) {
mEditorListener = listener;
}

View File

@ -38,6 +38,7 @@ public class Choice {
return mName;
}
@Override
public String toString() {
return mName;
}