From 534cbec7c59446743d0f005b953913e35b5d7a9d Mon Sep 17 00:00:00 2001 From: Dominik Date: Mon, 10 Sep 2012 23:34:14 +0200 Subject: [PATCH] fixes, cleanup --- .../android/apg/ApgApplication.java | 11 + .../android/apg/deprecated/BaseActivity.java | 422 ++++++++++++++++++ .../android/apg/service/ApgService.java | 23 +- .../android/apg/ui/BaseActivity.java | 408 ----------------- .../android/apg/ui/EncryptActivity.java | 2 +- .../android/apg/ui/KeyListActivity.java | 4 + .../apg/ui/SelectPublicKeyListActivity.java | 3 +- .../apg/ui/SelectSecretKeyListActivity.java | 3 +- .../android/apg/ui/SignKeyActivity.java | 87 +--- 9 files changed, 467 insertions(+), 496 deletions(-) create mode 100644 org_apg/src/org/thialfihar/android/apg/deprecated/BaseActivity.java delete mode 100644 org_apg/src/org/thialfihar/android/apg/ui/BaseActivity.java diff --git a/org_apg/src/org/thialfihar/android/apg/ApgApplication.java b/org_apg/src/org/thialfihar/android/apg/ApgApplication.java index ba9c9f08d..23e685b9c 100644 --- a/org_apg/src/org/thialfihar/android/apg/ApgApplication.java +++ b/org_apg/src/org/thialfihar/android/apg/ApgApplication.java @@ -16,6 +16,7 @@ package org.thialfihar.android.apg; +import java.io.File; import java.security.Security; import org.spongycastle.jce.provider.BouncyCastleProvider; @@ -23,6 +24,7 @@ import org.thialfihar.android.apg.helper.PGPMain; import org.thialfihar.android.apg.service.PassphraseCacheService; import android.app.Application; +import android.os.Environment; public class ApgApplication extends Application { @@ -40,6 +42,15 @@ public class ApgApplication extends Application { // TODO: Do it better than this! // this initializes the database to be used in PGPMain PGPMain.initialize(this); + + // Create APG directory on sdcard if not existing + if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + File dir = new File(Constants.path.APP_DIR); + if (!dir.exists() && !dir.mkdirs()) { + // ignore this for now, it's not crucial + // that the directory doesn't exist at this point + } + } } } diff --git a/org_apg/src/org/thialfihar/android/apg/deprecated/BaseActivity.java b/org_apg/src/org/thialfihar/android/apg/deprecated/BaseActivity.java new file mode 100644 index 000000000..c2d6f96fa --- /dev/null +++ b/org_apg/src/org/thialfihar/android/apg/deprecated/BaseActivity.java @@ -0,0 +1,422 @@ +/* + * Copyright (C) 2010 Thialfihar + * + * 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.thialfihar.android.apg.deprecated; + +import java.io.File; + +import org.thialfihar.android.apg.R; +import org.thialfihar.android.apg.Constants; +import org.thialfihar.android.apg.Id; +import org.thialfihar.android.apg.helper.PGPMain; +import org.thialfihar.android.apg.helper.Preferences; +import org.thialfihar.android.apg.ui.MainActivity; +import org.thialfihar.android.apg.ui.SelectSecretKeyListActivity; +import org.thialfihar.android.apg.util.ProgressDialogUpdater; + +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.view.MenuItem; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.os.Environment; +import android.os.Handler; +import android.os.Message; + +public class BaseActivity extends SherlockFragmentActivity implements Runnable, + ProgressDialogUpdater, AskForPassphrase.PassPhraseCallbackInterface { + + private ProgressDialog mProgressDialog = null; + private PausableThread mRunningThread = null; + private Thread mDeletingThread = null; + + private long mSecretKeyId = 0; + private String mDeleteFile = null; + + protected Preferences mPreferences; + + // private Handler mHandler = new Handler() { + // @Override + // public void handleMessage(Message msg) { + // handlerCallback(msg); + // } + // }; + // + // @Override + // protected void onCreate(Bundle savedInstanceState) { + // super.onCreate(savedInstanceState); + // + // // not needed later: + // // mPreferences = Preferences.getPreferences(this); + // + // // PGPMain.initialize(this); + // + // // if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + // // File dir = new File(Constants.path.APP_DIR); + // // if (!dir.exists() && !dir.mkdirs()) { + // // // ignore this for now, it's not crucial + // // // that the directory doesn't exist at this point + // // } + // // } + // + // // startCacheService(this, mPreferences); + // } + // + // // public static void startCacheService(Activity activity, Preferences preferences) { + // // Intent intent = new Intent(activity, PassphraseCacheService.class); + // // intent.putExtra(PassphraseCacheService.EXTRA_TTL, preferences.getPassPhraseCacheTtl()); + // // activity.startService(intent); + // // } + // + // @Override + // public boolean onOptionsItemSelected(MenuItem item) { + // switch (item.getItemId()) { + // + // case android.R.id.home: + // // app icon in Action Bar clicked; go home + // Intent intent = new Intent(this, MainActivity.class); + // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + // startActivity(intent); + // return true; + // + // // TODO: needed?: + // // case Id.menu.option.search: + // // startSearch("", false, null, false); + // // return true; + // + // default: + // break; + // + // } + // return false; + // } + // + // @Override + // protected Dialog onCreateDialog(int id) { + // // in case it is a progress dialog + // mProgressDialog = new ProgressDialog(this); + // mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + // mProgressDialog.setCancelable(false); + // switch (id) { + // case Id.dialog.encrypting: { + // mProgressDialog.setMessage(this.getString(R.string.progress_initializing)); + // return mProgressDialog; + // } + // + // case Id.dialog.decrypting: { + // mProgressDialog.setMessage(this.getString(R.string.progress_initializing)); + // return mProgressDialog; + // } + // + // case Id.dialog.saving: { + // mProgressDialog.setMessage(this.getString(R.string.progress_saving)); + // return mProgressDialog; + // } + // + // case Id.dialog.importing: { + // mProgressDialog.setMessage(this.getString(R.string.progress_importing)); + // return mProgressDialog; + // } + // + // case Id.dialog.exporting: { + // mProgressDialog.setMessage(this.getString(R.string.progress_exporting)); + // return mProgressDialog; + // } + // + // case Id.dialog.deleting: { + // mProgressDialog.setMessage(this.getString(R.string.progress_initializing)); + // return mProgressDialog; + // } + // + // case Id.dialog.querying: { + // mProgressDialog.setMessage(this.getString(R.string.progress_querying)); + // mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); + // mProgressDialog.setCancelable(false); + // return mProgressDialog; + // } + // + // case Id.dialog.signing: { + // mProgressDialog.setMessage(this.getString(R.string.progress_signing)); + // mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); + // mProgressDialog.setCancelable(false); + // return mProgressDialog; + // } + // + // default: { + // break; + // } + // } + // mProgressDialog = null; + // + // switch (id) { + // + // case Id.dialog.pass_phrase: { + // return AskForPassphrase.createDialog(this, getSecretKeyId(), this); + // } + // + // case Id.dialog.pass_phrases_do_not_match: { + // AlertDialog.Builder alert = new AlertDialog.Builder(this); + // + // alert.setIcon(android.R.drawable.ic_dialog_alert); + // alert.setTitle(R.string.error); + // alert.setMessage(R.string.passPhrasesDoNotMatch); + // + // alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + // public void onClick(DialogInterface dialog, int id) { + // removeDialog(Id.dialog.pass_phrases_do_not_match); + // } + // }); + // alert.setCancelable(false); + // + // return alert.create(); + // } + // + // case Id.dialog.no_pass_phrase: { + // AlertDialog.Builder alert = new AlertDialog.Builder(this); + // + // alert.setIcon(android.R.drawable.ic_dialog_alert); + // alert.setTitle(R.string.error); + // alert.setMessage(R.string.passPhraseMustNotBeEmpty); + // + // alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + // public void onClick(DialogInterface dialog, int id) { + // removeDialog(Id.dialog.no_pass_phrase); + // } + // }); + // alert.setCancelable(false); + // + // return alert.create(); + // } + // + // // case Id.dialog.delete_file: { + // // AlertDialog.Builder alert = new AlertDialog.Builder(this); + // // + // // alert.setIcon(android.R.drawable.ic_dialog_alert); + // // alert.setTitle(R.string.warning); + // // alert.setMessage(this.getString(R.string.fileDeleteConfirmation, getDeleteFile())); + // // + // // alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + // // public void onClick(DialogInterface dialog, int id) { + // // removeDialog(Id.dialog.delete_file); + // // final File file = new File(getDeleteFile()); + // // showDialog(Id.dialog.deleting); + // // mDeletingThread = new Thread(new Runnable() { + // // public void run() { + // // Bundle data = new Bundle(); + // // data.putInt(Constants.extras.STATUS, Id.message.delete_done); + // // try { + // // Apg.deleteFileSecurely(BaseActivity.this, file, BaseActivity.this); + // // } catch (FileNotFoundException e) { + // // data.putString(Apg.EXTRA_ERROR, BaseActivity.this.getString( + // // R.string.error_fileNotFound, file)); + // // } catch (IOException e) { + // // data.putString(Apg.EXTRA_ERROR, BaseActivity.this.getString( + // // R.string.error_fileDeleteFailed, file)); + // // } + // // Message msg = new Message(); + // // msg.setData(data); + // // sendMessage(msg); + // // } + // // }); + // // mDeletingThread.start(); + // // } + // // }); + // // alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + // // public void onClick(DialogInterface dialog, int id) { + // // removeDialog(Id.dialog.delete_file); + // // } + // // }); + // // alert.setCancelable(true); + // // + // // return alert.create(); + // // } + // + // default: { + // break; + // } + // } + // + // return super.onCreateDialog(id); + // } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case Id.request.secret_keys: { + if (resultCode == RESULT_OK) { + Bundle bundle = data.getExtras(); + setSecretKeyId(bundle.getLong(SelectSecretKeyListActivity.EXTRA_KEY_ID)); + } else { + setSecretKeyId(Id.key.none); + } + break; + } + + default: { + break; + } + } + + super.onActivityResult(requestCode, resultCode, data); + } + + // public void setProgress(int resourceId, int progress, int max) { + // setProgress(getString(resourceId), progress, max); + // } + // + // public void setProgress(int progress, int max) { + // Message msg = new Message(); + // Bundle data = new Bundle(); + // data.putInt(Constants.extras.STATUS, Id.message.progress_update); + // data.putInt(Constants.extras.PROGRESS, progress); + // data.putInt(Constants.extras.PROGRESS_MAX, max); + // msg.setData(data); + // mHandler.sendMessage(msg); + // } + // + // public void setProgress(String message, int progress, int max) { + // Message msg = new Message(); + // Bundle data = new Bundle(); + // data.putInt(Constants.extras.STATUS, Id.message.progress_update); + // data.putString(Constants.extras.MESSAGE, message); + // data.putInt(Constants.extras.PROGRESS, progress); + // data.putInt(Constants.extras.PROGRESS_MAX, max); + // msg.setData(data); + // mHandler.sendMessage(msg); + // } + // + // public void handlerCallback(Message msg) { + // Bundle data = msg.getData(); + // if (data == null) { + // return; + // } + // + // int type = data.getInt(Constants.extras.STATUS); + // switch (type) { + // case Id.message.progress_update: { + // String message = data.getString(Constants.extras.MESSAGE); + // if (mProgressDialog != null) { + // if (message != null) { + // mProgressDialog.setMessage(message); + // } + // mProgressDialog.setMax(data.getInt(Constants.extras.PROGRESS_MAX)); + // mProgressDialog.setProgress(data.getInt(Constants.extras.PROGRESS)); + // } + // break; + // } + // + // // case Id.message.delete_done: { + // // mProgressDialog = null; + // // deleteDoneCallback(msg); + // // break; + // // } + // + // case Id.message.import_done: // intentionally no break + // case Id.message.export_done: // intentionally no break + // case Id.message.query_done: // intentionally no break + // case Id.message.done: { + // mProgressDialog = null; + // doneCallback(msg); + // break; + // } + // + // default: { + // break; + // } + // } + // } + // + // public void doneCallback(Message msg) { + // + // } + + // public void deleteDoneCallback(Message msg) { + // removeDialog(Id.dialog.deleting); + // mDeletingThread = null; + // + // Bundle data = msg.getData(); + // String error = data.getString(Apg.EXTRA_ERROR); + // String message; + // if (error != null) { + // message = getString(R.string.errorMessage, error); + // } else { + // message = getString(R.string.fileDeleteSuccessful); + // } + // + // Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + // } + + public void passPhraseCallback(long keyId, String passPhrase) { + // TODO: Not needed anymore, now implemented in AskForSecretKeyPass + PGPMain.setCachedPassPhrase(keyId, passPhrase); + } + + // public void sendMessage(Message msg) { + // mHandler.sendMessage(msg); + // } + + public PausableThread getRunningThread() { + return mRunningThread; + } + + public void startThread() { + mRunningThread = new PausableThread(this); + mRunningThread.start(); + } + + public void run() { + + } + + public void setSecretKeyId(long id) { + mSecretKeyId = id; + } + + public long getSecretKeyId() { + return mSecretKeyId; + } + + protected void setDeleteFile(String deleteFile) { + mDeleteFile = deleteFile; + } + + protected String getDeleteFile() { + return mDeleteFile; + } + + @Override + public void setProgress(String message, int current, int total) { + // TODO Auto-generated method stub + + } + + @Override + public void setProgress(int resourceId, int current, int total) { + // TODO Auto-generated method stub + + } + + @Override + public void setProgress(int current, int total) { + // TODO Auto-generated method stub + + } +} diff --git a/org_apg/src/org/thialfihar/android/apg/service/ApgService.java b/org_apg/src/org/thialfihar/android/apg/service/ApgService.java index 8a2022825..2121a500a 100644 --- a/org_apg/src/org/thialfihar/android/apg/service/ApgService.java +++ b/org_apg/src/org/thialfihar/android/apg/service/ApgService.java @@ -63,8 +63,6 @@ import android.os.Bundle; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; -import android.widget.CheckBox; -import android.widget.Spinner; import org.thialfihar.android.apg.util.Log; @@ -777,7 +775,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater { String keyServer = data.getString(QUERY_KEY_SERVER); String queryString = data.getString(QUERY_KEY_STRING); - long queryId = data.getLong(QUERY_KEY_ID); + long keyId = data.getLong(QUERY_KEY_ID); /* Operation */ @@ -789,7 +787,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater { resultData.putParcelableArrayList(RESULT_QUERY_KEY_SEARCH_RESULT, searchResult); } else if (queryType == Id.keyserver.get) { - String keyData = server.get(queryId); + String keyData = server.get(keyId); resultData.putString(RESULT_QUERY_KEY_KEY_DATA, keyData); } @@ -806,8 +804,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater { /* Input */ - long masterKeyId = data.getInt(SIGN_KEY_MASTER_KEY_ID); - long pubKeyId = data.getInt(SIGN_KEY_PUB_KEY_ID); + long masterKeyId = data.getLong(SIGN_KEY_MASTER_KEY_ID); + long pubKeyId = data.getLong(SIGN_KEY_PUB_KEY_ID); /* Operation */ @@ -836,19 +834,6 @@ public class ApgService extends IntentService implements ProgressDialogUpdater { pubring.getPublicKey(pubKeyId), sGen.generate()); pubring = PGPPublicKeyRing.insertPublicKey(pubring, signedKey); - // check if we need to send the key to the server or not - // CheckBox sendKey = (CheckBox) findViewById(R.id.sendKey); - // if (sendKey.isChecked()) { - // Spinner keyServer = (Spinner) findViewById(R.id.keyServer); - // HkpKeyServer server = new HkpKeyServer((String) keyServer.getSelectedItem()); - // - // /* - // * upload the newly signed key to the key server - // */ - // - // PGPMain.uploadKeyRingToServer(server, pubring); - // } - // store the signed key in our local cache int retval = PGPMain.storeKeyRingInCache(pubring); if (retval != Id.return_value.ok && retval != Id.return_value.updated) { diff --git a/org_apg/src/org/thialfihar/android/apg/ui/BaseActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/BaseActivity.java deleted file mode 100644 index fa508399d..000000000 --- a/org_apg/src/org/thialfihar/android/apg/ui/BaseActivity.java +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright (C) 2010 Thialfihar - * - * 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.thialfihar.android.apg.ui; - -import java.io.File; - -import org.thialfihar.android.apg.R; -import org.thialfihar.android.apg.Constants; -import org.thialfihar.android.apg.Id; -import org.thialfihar.android.apg.deprecated.AskForPassphrase; -import org.thialfihar.android.apg.deprecated.PausableThread; -import org.thialfihar.android.apg.helper.PGPMain; -import org.thialfihar.android.apg.helper.Preferences; -import org.thialfihar.android.apg.util.ProgressDialogUpdater; - -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.SherlockFragmentActivity; -import com.actionbarsherlock.view.MenuItem; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.os.Environment; -import android.os.Handler; -import android.os.Message; - -public class BaseActivity extends SherlockFragmentActivity implements Runnable, - ProgressDialogUpdater, AskForPassphrase.PassPhraseCallbackInterface { - - private ProgressDialog mProgressDialog = null; - private PausableThread mRunningThread = null; - private Thread mDeletingThread = null; - - private long mSecretKeyId = 0; - private String mDeleteFile = null; - - protected Preferences mPreferences; - - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - handlerCallback(msg); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - final ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayHomeAsUpEnabled(true); - - // not needed later: - mPreferences = Preferences.getPreferences(this); - - // PGPMain.initialize(this); - - if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - File dir = new File(Constants.path.APP_DIR); - if (!dir.exists() && !dir.mkdirs()) { - // ignore this for now, it's not crucial - // that the directory doesn't exist at this point - } - } - - // startCacheService(this, mPreferences); - } - - // public static void startCacheService(Activity activity, Preferences preferences) { - // Intent intent = new Intent(activity, PassphraseCacheService.class); - // intent.putExtra(PassphraseCacheService.EXTRA_TTL, preferences.getPassPhraseCacheTtl()); - // activity.startService(intent); - // } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case android.R.id.home: - // app icon in Action Bar clicked; go home - Intent intent = new Intent(this, MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - return true; - - // TODO: needed?: - case Id.menu.option.search: - startSearch("", false, null, false); - return true; - - default: - break; - - } - return false; - } - - @Override - protected Dialog onCreateDialog(int id) { - // in case it is a progress dialog - mProgressDialog = new ProgressDialog(this); - mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - mProgressDialog.setCancelable(false); - switch (id) { - case Id.dialog.encrypting: { - mProgressDialog.setMessage(this.getString(R.string.progress_initializing)); - return mProgressDialog; - } - - case Id.dialog.decrypting: { - mProgressDialog.setMessage(this.getString(R.string.progress_initializing)); - return mProgressDialog; - } - - case Id.dialog.saving: { - mProgressDialog.setMessage(this.getString(R.string.progress_saving)); - return mProgressDialog; - } - - case Id.dialog.importing: { - mProgressDialog.setMessage(this.getString(R.string.progress_importing)); - return mProgressDialog; - } - - case Id.dialog.exporting: { - mProgressDialog.setMessage(this.getString(R.string.progress_exporting)); - return mProgressDialog; - } - - case Id.dialog.deleting: { - mProgressDialog.setMessage(this.getString(R.string.progress_initializing)); - return mProgressDialog; - } - - case Id.dialog.querying: { - mProgressDialog.setMessage(this.getString(R.string.progress_querying)); - mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); - mProgressDialog.setCancelable(false); - return mProgressDialog; - } - - case Id.dialog.signing: { - mProgressDialog.setMessage(this.getString(R.string.progress_signing)); - mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); - mProgressDialog.setCancelable(false); - return mProgressDialog; - } - - default: { - break; - } - } - mProgressDialog = null; - - switch (id) { - - case Id.dialog.pass_phrase: { - return AskForPassphrase.createDialog(this, getSecretKeyId(), this); - } - - case Id.dialog.pass_phrases_do_not_match: { - AlertDialog.Builder alert = new AlertDialog.Builder(this); - - alert.setIcon(android.R.drawable.ic_dialog_alert); - alert.setTitle(R.string.error); - alert.setMessage(R.string.passPhrasesDoNotMatch); - - alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - removeDialog(Id.dialog.pass_phrases_do_not_match); - } - }); - alert.setCancelable(false); - - return alert.create(); - } - - case Id.dialog.no_pass_phrase: { - AlertDialog.Builder alert = new AlertDialog.Builder(this); - - alert.setIcon(android.R.drawable.ic_dialog_alert); - alert.setTitle(R.string.error); - alert.setMessage(R.string.passPhraseMustNotBeEmpty); - - alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - removeDialog(Id.dialog.no_pass_phrase); - } - }); - alert.setCancelable(false); - - return alert.create(); - } - - // case Id.dialog.delete_file: { - // AlertDialog.Builder alert = new AlertDialog.Builder(this); - // - // alert.setIcon(android.R.drawable.ic_dialog_alert); - // alert.setTitle(R.string.warning); - // alert.setMessage(this.getString(R.string.fileDeleteConfirmation, getDeleteFile())); - // - // alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - // public void onClick(DialogInterface dialog, int id) { - // removeDialog(Id.dialog.delete_file); - // final File file = new File(getDeleteFile()); - // showDialog(Id.dialog.deleting); - // mDeletingThread = new Thread(new Runnable() { - // public void run() { - // Bundle data = new Bundle(); - // data.putInt(Constants.extras.STATUS, Id.message.delete_done); - // try { - // Apg.deleteFileSecurely(BaseActivity.this, file, BaseActivity.this); - // } catch (FileNotFoundException e) { - // data.putString(Apg.EXTRA_ERROR, BaseActivity.this.getString( - // R.string.error_fileNotFound, file)); - // } catch (IOException e) { - // data.putString(Apg.EXTRA_ERROR, BaseActivity.this.getString( - // R.string.error_fileDeleteFailed, file)); - // } - // Message msg = new Message(); - // msg.setData(data); - // sendMessage(msg); - // } - // }); - // mDeletingThread.start(); - // } - // }); - // alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - // public void onClick(DialogInterface dialog, int id) { - // removeDialog(Id.dialog.delete_file); - // } - // }); - // alert.setCancelable(true); - // - // return alert.create(); - // } - - default: { - break; - } - } - - return super.onCreateDialog(id); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case Id.request.secret_keys: { - if (resultCode == RESULT_OK) { - Bundle bundle = data.getExtras(); - setSecretKeyId(bundle.getLong(SelectSecretKeyListActivity.EXTRA_KEY_ID)); - } else { - setSecretKeyId(Id.key.none); - } - break; - } - - default: { - break; - } - } - - super.onActivityResult(requestCode, resultCode, data); - } - - public void setProgress(int resourceId, int progress, int max) { - setProgress(getString(resourceId), progress, max); - } - - public void setProgress(int progress, int max) { - Message msg = new Message(); - Bundle data = new Bundle(); - data.putInt(Constants.extras.STATUS, Id.message.progress_update); - data.putInt(Constants.extras.PROGRESS, progress); - data.putInt(Constants.extras.PROGRESS_MAX, max); - msg.setData(data); - mHandler.sendMessage(msg); - } - - public void setProgress(String message, int progress, int max) { - Message msg = new Message(); - Bundle data = new Bundle(); - data.putInt(Constants.extras.STATUS, Id.message.progress_update); - data.putString(Constants.extras.MESSAGE, message); - data.putInt(Constants.extras.PROGRESS, progress); - data.putInt(Constants.extras.PROGRESS_MAX, max); - msg.setData(data); - mHandler.sendMessage(msg); - } - - public void handlerCallback(Message msg) { - Bundle data = msg.getData(); - if (data == null) { - return; - } - - int type = data.getInt(Constants.extras.STATUS); - switch (type) { - case Id.message.progress_update: { - String message = data.getString(Constants.extras.MESSAGE); - if (mProgressDialog != null) { - if (message != null) { - mProgressDialog.setMessage(message); - } - mProgressDialog.setMax(data.getInt(Constants.extras.PROGRESS_MAX)); - mProgressDialog.setProgress(data.getInt(Constants.extras.PROGRESS)); - } - break; - } - - // case Id.message.delete_done: { - // mProgressDialog = null; - // deleteDoneCallback(msg); - // break; - // } - - case Id.message.import_done: // intentionally no break - case Id.message.export_done: // intentionally no break - case Id.message.query_done: // intentionally no break - case Id.message.done: { - mProgressDialog = null; - doneCallback(msg); - break; - } - - default: { - break; - } - } - } - - public void doneCallback(Message msg) { - - } - - // public void deleteDoneCallback(Message msg) { - // removeDialog(Id.dialog.deleting); - // mDeletingThread = null; - // - // Bundle data = msg.getData(); - // String error = data.getString(Apg.EXTRA_ERROR); - // String message; - // if (error != null) { - // message = getString(R.string.errorMessage, error); - // } else { - // message = getString(R.string.fileDeleteSuccessful); - // } - // - // Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); - // } - - public void passPhraseCallback(long keyId, String passPhrase) { - // TODO: Not needed anymore, now implemented in AskForSecretKeyPass - PGPMain.setCachedPassPhrase(keyId, passPhrase); - } - - public void sendMessage(Message msg) { - mHandler.sendMessage(msg); - } - - public PausableThread getRunningThread() { - return mRunningThread; - } - - public void startThread() { - mRunningThread = new PausableThread(this); - mRunningThread.start(); - } - - public void run() { - - } - - public void setSecretKeyId(long id) { - mSecretKeyId = id; - } - - public long getSecretKeyId() { - return mSecretKeyId; - } - - protected void setDeleteFile(String deleteFile) { - mDeleteFile = deleteFile; - } - - protected String getDeleteFile() { - return mDeleteFile; - } -} diff --git a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java index f09d1950a..7316fc770 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java @@ -703,7 +703,7 @@ public class EncryptActivity extends SherlockFragmentActivity { // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); - + try { PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance( messenger, mSecretKeyId); diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java index fedccca82..d0438fbe6 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java @@ -163,6 +163,10 @@ public class KeyListActivity extends SherlockFragmentActivity { showExportKeysDialog(false); return true; } + + case Id.menu.option.search: + startSearch("", false, null, false); + return true; default: { return super.onOptionsItemSelected(item); diff --git a/org_apg/src/org/thialfihar/android/apg/ui/SelectPublicKeyListActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/SelectPublicKeyListActivity.java index 545db98f9..500526567 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/SelectPublicKeyListActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/SelectPublicKeyListActivity.java @@ -24,6 +24,7 @@ import org.thialfihar.android.apg.Id; import org.thialfihar.android.apg.ui.widget.SelectPublicKeyListAdapter; import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; @@ -36,7 +37,7 @@ import android.widget.Button; import android.widget.ListView; import android.widget.TextView; -public class SelectPublicKeyListActivity extends BaseActivity { +public class SelectPublicKeyListActivity extends SherlockFragmentActivity { // Not used in sourcode, but listed in AndroidManifest! public static final String ACTION_SELECT_PUBLIC_KEYS = Constants.INTENT_PREFIX diff --git a/org_apg/src/org/thialfihar/android/apg/ui/SelectSecretKeyListActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/SelectSecretKeyListActivity.java index b36278a74..722e52216 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/SelectSecretKeyListActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/SelectSecretKeyListActivity.java @@ -22,6 +22,7 @@ import org.thialfihar.android.apg.Id; import org.thialfihar.android.apg.ui.widget.SelectSecretKeyListAdapter; import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import android.app.SearchManager; @@ -35,7 +36,7 @@ import android.widget.Button; import android.widget.ListView; import android.widget.TextView; -public class SelectSecretKeyListActivity extends BaseActivity { +public class SelectSecretKeyListActivity extends SherlockFragmentActivity { // Not used in sourcode, but listed in AndroidManifest! public static final String ACTION_SELECT_SECRET_KEY = Constants.INTENT_PREFIX diff --git a/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java index 3ae2d6e50..4c8c12bef 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java @@ -16,22 +16,10 @@ package org.thialfihar.android.apg.ui; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.SignatureException; import java.util.Iterator; -import org.spongycastle.jce.provider.BouncyCastleProvider; -import org.spongycastle.openpgp.PGPException; -import org.spongycastle.openpgp.PGPPrivateKey; -import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPPublicKeyRing; -import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSignature; -import org.spongycastle.openpgp.PGPSignatureGenerator; -import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator; -import org.spongycastle.openpgp.PGPSignatureSubpacketVector; -import org.spongycastle.openpgp.PGPUtil; import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Id; import org.thialfihar.android.apg.R; @@ -40,10 +28,9 @@ import org.thialfihar.android.apg.helper.Preferences; import org.thialfihar.android.apg.service.ApgService; import org.thialfihar.android.apg.service.ApgServiceHandler; import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment; -import org.thialfihar.android.apg.util.HkpKeyServer; +import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; -import com.actionbarsherlock.view.MenuItem; import android.app.ProgressDialog; import android.content.Intent; @@ -75,23 +62,8 @@ public class SignKeyActivity extends SherlockFragmentActivity { // TODO: remove when using new intentservice: public static final String EXTRA_ERROR = "error"; - private long pubKeyId = 0; - private long masterKeyId = 0; - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case android.R.id.home: - startActivity(new Intent(this, PublicKeyListActivity.class)); - return true; - - default: - break; - - } - return false; - } + private long mPubKeyId = 0; + private long mMasterKeyId = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -100,6 +72,11 @@ public class SignKeyActivity extends SherlockFragmentActivity { // check we havent already signed it setContentView(R.layout.sign_key_layout); + final ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setDisplayHomeAsUpEnabled(false); + actionBar.setHomeButtonEnabled(false); + final Spinner keyServer = (Spinner) findViewById(R.id.keyServer); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, Preferences.getPreferences(this) @@ -132,14 +109,14 @@ public class SignKeyActivity extends SherlockFragmentActivity { @Override public void onClick(View v) { - if (pubKeyId != 0) { + if (mPubKeyId != 0) { initiateSigning(); } } }); - pubKeyId = getIntent().getLongExtra(EXTRA_KEY_ID, 0); - if (pubKeyId == 0) { + mPubKeyId = getIntent().getLongExtra(EXTRA_KEY_ID, 0); + if (mPubKeyId == 0) { finish(); // nothing to do if we dont know what key to sign } else { // kick off the SecretKey selection activity so the user chooses which key to sign with @@ -179,16 +156,16 @@ public class SignKeyActivity extends SherlockFragmentActivity { * handles the UI bits of the signing process on the UI thread */ private void initiateSigning() { - PGPPublicKeyRing pubring = PGPMain.getPublicKeyRing(pubKeyId); + PGPPublicKeyRing pubring = PGPMain.getPublicKeyRing(mPubKeyId); if (pubring != null) { // if we have already signed this key, dont bother doing it again boolean alreadySigned = false; @SuppressWarnings("unchecked") - Iterator itr = pubring.getPublicKey(pubKeyId).getSignatures(); + Iterator itr = pubring.getPublicKey(mPubKeyId).getSignatures(); while (itr.hasNext()) { PGPSignature sig = itr.next(); - if (sig.getKeyID() == masterKeyId) { + if (sig.getKeyID() == mMasterKeyId) { alreadySigned = true; break; } @@ -198,9 +175,9 @@ public class SignKeyActivity extends SherlockFragmentActivity { /* * get the user's passphrase for this key (if required) */ - String passphrase = PGPMain.getCachedPassPhrase(masterKeyId); + String passphrase = PGPMain.getCachedPassPhrase(mMasterKeyId); if (passphrase == null) { - showPassphraseDialog(masterKeyId); + showPassphraseDialog(mMasterKeyId); return; // bail out; need to wait until the user has entered the passphrase // before trying again } else { @@ -246,18 +223,14 @@ public class SignKeyActivity extends SherlockFragmentActivity { // fill values for this action Bundle data = new Bundle(); - int keyRingId = getIntent().getIntExtra(EXTRA_KEY_ID, -1); - data.putInt(ApgService.UPLOAD_KEY_KEYRING_ID, keyRingId); - - Spinner keyServer = (Spinner) findViewById(R.id.keyServer); - String server = (String) keyServer.getSelectedItem(); - data.putString(ApgService.UPLOAD_KEY_SERVER, server); + data.putLong(ApgService.SIGN_KEY_MASTER_KEY_ID, mMasterKeyId); + data.putLong(ApgService.SIGN_KEY_PUB_KEY_ID, mPubKeyId); intent.putExtra(ApgService.EXTRA_DATA, data); // Message is received after signing is done in ApgService ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_signing, - ProgressDialog.STYLE_HORIZONTAL) { + ProgressDialog.STYLE_SPINNER) { public void handleMessage(Message message) { // handle messages by standard ApgHandler first super.handleMessage(message); @@ -301,7 +274,7 @@ public class SignKeyActivity extends SherlockFragmentActivity { // fill values for this action Bundle data = new Bundle(); - data.putLong(ApgService.UPLOAD_KEY_KEYRING_ID, pubKeyId); + data.putLong(ApgService.UPLOAD_KEY_KEYRING_ID, mPubKeyId); Spinner keyServer = (Spinner) findViewById(R.id.keyServer); String server = (String) keyServer.getSelectedItem(); @@ -433,7 +406,7 @@ public class SignKeyActivity extends SherlockFragmentActivity { switch (requestCode) { case Id.request.secret_keys: { if (resultCode == RESULT_OK) { - masterKeyId = data.getLongExtra(EXTRA_KEY_ID, 0); + mMasterKeyId = data.getLongExtra(EXTRA_KEY_ID, 0); // re-enable the sign button so the user can initiate the sign process Button sign = (Button) findViewById(R.id.sign); @@ -448,22 +421,4 @@ public class SignKeyActivity extends SherlockFragmentActivity { } } } - // - // @Override - // public void doneCallback(Message msg) { - // super.doneCallback(msg); - // - // removeDialog(Id.dialog.signing); - // - // Bundle data = msg.getData(); - // String error = data.getString(EXTRA_ERROR); - // if (error != null) { - // Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT) - // .show(); - // return; - // } - // - // Toast.makeText(this, R.string.keySignSuccess, Toast.LENGTH_SHORT).show(); - // finish(); - // } }