From 4f8ddad9d37f77d5a119623ccaf042f41b65ebbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 19 Aug 2014 16:40:57 +0200 Subject: ConsolidateDialogActivity --- .../keychain/ui/ConsolidateDialogActivity.java | 102 ++++++++++++++++++ .../keychain/ui/OpenDialogActivity.java | 117 --------------------- 2 files changed, 102 insertions(+), 117 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OpenDialogActivity.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java new file mode 100644 index 000000000..e4a80ff48 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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 . + */ + +package org.sufficientlysecure.keychain.ui; + +import android.app.Dialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import android.util.Log; +import android.view.ContextThemeWrapper; +import android.view.KeyEvent; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; + +/** + * We can not directly create a dialog on the application context. + * This activity encapsulates a DialogFragment to emulate a dialog. + */ +public class ConsolidateDialogActivity extends FragmentActivity { + + MyDialogFragment mDialogFragment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // this activity itself has no content view (see manifest) + + mDialogFragment = new MyDialogFragment(); + // give all extras through to the fragment + mDialogFragment.setArguments(getIntent().getExtras()); + + mDialogFragment.show(getSupportFragmentManager(), "dialog"); + } + + public static class MyDialogFragment extends DialogFragment { + + /** + * Creates dialog + */ + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay + ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), + R.style.Theme_AppCompat_Light); + ProgressDialog dialog = new ProgressDialog(context); + dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + dialog.setCancelable(false); + dialog.setCanceledOnTouchOutside(false); + + // Disable the back button + DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() { + @Override + public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK) { + return true; + } + return false; + } + + }; + dialog.setOnKeyListener(keyListener); + + return dialog; + } + + @Override + public void onCancel(DialogInterface dialog) { + super.onCancel(dialog); + + dismiss(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + Log.d(Constants.TAG, "onDismiss"); + + getActivity().finish(); + } + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OpenDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OpenDialogActivity.java deleted file mode 100644 index cdb09bbd0..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OpenDialogActivity.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * 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 . - */ - -package org.sufficientlysecure.keychain.ui; - -import android.app.Dialog; -import android.app.DialogFragment; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; -import android.support.v4.app.FragmentActivity; -import android.util.Log; -import android.view.ContextThemeWrapper; - -import org.sufficientlysecure.keychain.Constants; - -/** - * We can not directly create a dialog on the context provided inside the content provider. - * This activity encapsulates a DialogFragment to emulate a dialog. - */ -public class OpenDialogActivity extends FragmentActivity { - - public static final String EXTRA_MESSENGER = "messenger"; - public static final String EXTRA_FILENAME = "filename"; - - public static final int MSG_CANCEL = 1; - public static final int MSG_DECRYPT_OPEN = 2; - public static final int MSG_GET_ENCRYPTED = 3; - - MyDialogFragment mDialogFragment; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // this activity itself has no content view (see manifest) - - mDialogFragment = new MyDialogFragment(); - // give all extras through to the fragment - mDialogFragment.setArguments(getIntent().getExtras()); - - mDialogFragment.show(getFragmentManager(), "dialog"); - } - - public static class MyDialogFragment extends DialogFragment { - - private Messenger mMessenger; - - /** - * Creates dialog - */ - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - mMessenger = getArguments().getParcelable(EXTRA_MESSENGER); - String filename = getArguments().getString(EXTRA_FILENAME); - - // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay - ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), - android.R.style.Theme_DeviceDefault_Light_Dialog); - ProgressDialog.Builder progress = new ProgressDialog.Builder(context); - return progress.show(); - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - - dismiss(); - sendMessageToHandler(MSG_CANCEL); - } - - @Override - public void onDismiss(DialogInterface dialog) { - super.onDismiss(dialog); - Log.d(Constants.TAG, "onDismiss"); - - getActivity().finish(); - } - - /** - * Send message back to handler which is initialized in a activity - * - * @param what Message integer you want to send - */ - private void sendMessageToHandler(Integer what) { - Message msg = Message.obtain(); - msg.what = what; - - try { - mMessenger.send(msg); - } catch (RemoteException e) { - Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); - } catch (NullPointerException e) { - Log.w(Constants.TAG, "Messenger is null!", e); - } - } - - } - -} -- cgit v1.2.3