diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-01-06 18:13:46 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-01-06 18:13:46 +0100 |
commit | 109bc4104444a93b71b88c5e2297af03f778aed3 (patch) | |
tree | 03ea8abb4a2ee7474bc4f4da3c019c3a46463aec | |
parent | b2dcc657c933cfdd66bf5038f1308230e73d05a8 (diff) | |
download | open-keychain-109bc4104444a93b71b88c5e2297af03f778aed3.tar.gz open-keychain-109bc4104444a93b71b88c5e2297af03f778aed3.tar.bz2 open-keychain-109bc4104444a93b71b88c5e2297af03f778aed3.zip |
Fix bug on Android 4.2 with DialogFragments especially with FileDialogFragment
15 files changed, 85 insertions, 164 deletions
diff --git a/APG/AndroidManifest.xml b/APG/AndroidManifest.xml index 491de65a9..408e48364 100644 --- a/APG/AndroidManifest.xml +++ b/APG/AndroidManifest.xml @@ -47,7 +47,7 @@ <uses-sdk android:minSdkVersion="8" - android:targetSdkVersion="14" /> + android:targetSdkVersion="17" /> <uses-feature android:name="android.hardware.wifi" diff --git a/APG/project.properties b/APG/project.properties index 63019788e..2267fbaf8 100644 --- a/APG/project.properties +++ b/APG/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-15 +target=android-17 android.library.reference.1=android-libs/ActionBarSherlock diff --git a/APG/src/org/thialfihar/android/apg/ui/DecryptActivity.java b/APG/src/org/thialfihar/android/apg/ui/DecryptActivity.java index 3c4911420..4c669789b 100644 --- a/APG/src/org/thialfihar/android/apg/ui/DecryptActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/DecryptActivity.java @@ -20,6 +20,7 @@ package org.thialfihar.android.apg.ui; import org.spongycastle.openpgp.PGPPublicKeyRing; import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Id; +import org.thialfihar.android.apg.compatibility.Clipboard; import org.thialfihar.android.apg.helper.FileHelper; import org.thialfihar.android.apg.helper.OtherHelper; import org.thialfihar.android.apg.helper.PGPHelper; @@ -32,7 +33,6 @@ import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment; import org.thialfihar.android.apg.ui.dialog.FileDialogFragment; import org.thialfihar.android.apg.ui.dialog.LookupUnknownKeyDialogFragment; import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment; -import org.thialfihar.android.apg.util.Compatibility; import org.thialfihar.android.apg.R; import com.actionbarsherlock.app.SherlockFragmentActivity; @@ -264,7 +264,7 @@ public class DecryptActivity extends SherlockFragmentActivity { if (mSource.getCurrentView().getId() == R.id.sourceMessage && mMessage.getText().length() == 0) { - CharSequence clipboardText = Compatibility.getClipboardText(this); + CharSequence clipboardText = Clipboard.getClipboardText(this); String data = ""; if (clipboardText != null) { diff --git a/APG/src/org/thialfihar/android/apg/ui/EncryptActivity.java b/APG/src/org/thialfihar/android/apg/ui/EncryptActivity.java index 3014892a3..dab14de0d 100644 --- a/APG/src/org/thialfihar/android/apg/ui/EncryptActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/EncryptActivity.java @@ -23,6 +23,7 @@ import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKeyRing; import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Id; +import org.thialfihar.android.apg.compatibility.Clipboard; import org.thialfihar.android.apg.helper.FileHelper; import org.thialfihar.android.apg.helper.OtherHelper; import org.thialfihar.android.apg.helper.PGPHelper; @@ -36,7 +37,6 @@ import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment; import org.thialfihar.android.apg.ui.dialog.FileDialogFragment; import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment; import org.thialfihar.android.apg.util.Choice; -import org.thialfihar.android.apg.util.Compatibility; import org.thialfihar.android.apg.R; import com.actionbarsherlock.app.SherlockFragmentActivity; @@ -758,7 +758,7 @@ public class EncryptActivity extends SherlockFragmentActivity { case Id.target.clipboard: output = data.getString(ApgIntentService.RESULT_ENCRYPTED_STRING); Log.d(Constants.TAG, "output: " + output); - Compatibility.copyToClipboard(EncryptActivity.this, output); + Clipboard.copyToClipboard(EncryptActivity.this, output); Toast.makeText(EncryptActivity.this, R.string.encryptionToClipboardSuccessful, Toast.LENGTH_SHORT) .show(); diff --git a/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java b/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java index 2dc09d545..a4f547090 100644 --- a/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java @@ -20,6 +20,7 @@ package org.thialfihar.android.apg.ui; import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Id; import org.thialfihar.android.apg.R; +import org.thialfihar.android.apg.compatibility.DialogFragmentWorkaround; import org.thialfihar.android.apg.service.ApgIntentService; import org.thialfihar.android.apg.service.ApgIntentServiceHandler; import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment; @@ -159,9 +160,9 @@ public class KeyListActivity extends SherlockFragmentActivity { // TODO: reimplement! // menu.add(3, Id.menu.option.search, 0, R.string.menu_search) // .setIcon(R.drawable.ic_menu_search).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - menu.add(0, Id.menu.option.import_keys, 2, R.string.menu_importKeys).setShowAsAction( + menu.add(0, Id.menu.option.import_keys, 5, R.string.menu_importKeys).setShowAsAction( MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT); - menu.add(0, Id.menu.option.export_keys, 3, R.string.menu_exportKeys).setShowAsAction( + menu.add(0, Id.menu.option.export_keys, 6, R.string.menu_exportKeys).setShowAsAction( MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; @@ -207,6 +208,7 @@ public class KeyListActivity extends SherlockFragmentActivity { @Override public void handleMessage(Message message) { if (message.what == FileDialogFragment.MESSAGE_OKAY) { + Log.d(Constants.TAG, "FileDialogFragment.MESSAGE_OKAY"); Bundle data = message.getData(); mImportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME); @@ -217,13 +219,18 @@ public class KeyListActivity extends SherlockFragmentActivity { }; // Create a new Messenger for the communication back - Messenger messenger = new Messenger(returnHandler); + final Messenger messenger = new Messenger(returnHandler); - mFileDialog = FileDialogFragment.newInstance(messenger, - getString(R.string.title_importKeys), getString(R.string.specifyFileToImportFrom), - mImportFilename, null, Id.request.filename); + DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { + public void run() { + mFileDialog = FileDialogFragment.newInstance(messenger, + getString(R.string.title_importKeys), + getString(R.string.specifyFileToImportFrom), mImportFilename, null, + Id.request.filename); - mFileDialog.show(getSupportFragmentManager(), "fileDialog"); + mFileDialog.show(getSupportFragmentManager(), "fileDialog"); + } + }); } /** @@ -233,21 +240,6 @@ public class KeyListActivity extends SherlockFragmentActivity { * if -1 export all keys */ public void showExportKeysDialog(final long keyRingRowId) { - String title = null; - if (keyRingRowId != -1) { - // single key export - title = getString(R.string.title_exportKey); - } else { - title = getString(R.string.title_exportKeys); - } - - String message = null; - if (mKeyType == Id.type.public_key) { - message = getString(R.string.specifyFileToExportTo); - } else { - message = getString(R.string.specifyFileToExportSecretKeysTo); - } - // Message is received after file is selected Handler returnHandler = new Handler() { @Override @@ -262,12 +254,31 @@ public class KeyListActivity extends SherlockFragmentActivity { }; // Create a new Messenger for the communication back - Messenger messenger = new Messenger(returnHandler); + final Messenger messenger = new Messenger(returnHandler); + + DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { + public void run() { + String title = null; + if (keyRingRowId != -1) { + // single key export + title = getString(R.string.title_exportKey); + } else { + title = getString(R.string.title_exportKeys); + } - mFileDialog = FileDialogFragment.newInstance(messenger, title, message, mExportFilename, - null, Id.request.filename); + String message = null; + if (mKeyType == Id.type.public_key) { + message = getString(R.string.specifyFileToExportTo); + } else { + message = getString(R.string.specifyFileToExportSecretKeysTo); + } + + mFileDialog = FileDialogFragment.newInstance(messenger, title, message, + mExportFilename, null, Id.request.filename); - mFileDialog.show(getSupportFragmentManager(), "fileDialog"); + mFileDialog.show(getSupportFragmentManager(), "fileDialog"); + } + }); } /** diff --git a/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java b/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java index 556138049..6f07b7e8a 100644 --- a/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java @@ -42,14 +42,16 @@ public class KeyListPublicActivity extends KeyListActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - menu.add(1, Id.menu.option.key_server, 2, R.string.menu_keyServer) - .setIcon(R.drawable.ic_menu_search_list) - .setShowAsAction( - MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + super.onCreateOptionsMenu(menu); + menu.add(1, Id.menu.option.scanQRCode, 1, R.string.menu_scanQRCode) .setIcon(R.drawable.ic_menu_scan_qrcode) .setShowAsAction( MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + menu.add(1, Id.menu.option.key_server, 2, R.string.menu_keyServer) + .setIcon(R.drawable.ic_menu_search_list) + .setShowAsAction( + MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; } diff --git a/APG/src/org/thialfihar/android/apg/ui/SelectPublicKeyFragment.java b/APG/src/org/thialfihar/android/apg/ui/SelectPublicKeyFragment.java index 744c3fa81..a316fbdd3 100644 --- a/APG/src/org/thialfihar/android/apg/ui/SelectPublicKeyFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/SelectPublicKeyFragment.java @@ -22,6 +22,7 @@ import java.util.Vector; import org.thialfihar.android.apg.Id; import org.thialfihar.android.apg.R; +import org.thialfihar.android.apg.compatibility.ListFragmentWorkaround; import org.thialfihar.android.apg.provider.ApgDatabase; import org.thialfihar.android.apg.provider.ApgContract.KeyRings; import org.thialfihar.android.apg.provider.ApgContract.Keys; @@ -29,8 +30,6 @@ import org.thialfihar.android.apg.provider.ApgContract.UserIds; import org.thialfihar.android.apg.provider.ApgDatabase.Tables; import org.thialfihar.android.apg.ui.widget.SelectKeyCursorAdapter; -import com.actionbarsherlock.app.SherlockListFragment; - import android.database.Cursor; import android.database.DatabaseUtils; import android.net.Uri; @@ -38,10 +37,9 @@ import android.os.Bundle; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.app.LoaderManager; -import android.view.View; import android.widget.ListView; -public class SelectPublicKeyFragment extends SherlockListFragment implements +public class SelectPublicKeyFragment extends ListFragmentWorkaround implements LoaderManager.LoaderCallbacks<Cursor> { private SelectPublicKeyActivity mActivity; @@ -82,15 +80,6 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements } /** - * Workaround for Android 4.1. Items are not checked in layout. See - * http://code.google.com/p/android/issues/detail?id=35885 - */ - @Override - public void onListItemClick(ListView l, View v, int position, long id) { - l.setItemChecked(position, l.isItemChecked(position)); - } - - /** * Selects items based on master key ids in list view * * @param masterKeyIds diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java index 311066389..342cd41d0 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java @@ -33,7 +33,6 @@ import android.support.v4.app.FragmentActivity; import android.widget.Toast; public class DeleteFileDialogFragment extends DialogFragment { - private static final String ARG_DELETE_FILE = "delete_file"; /** @@ -66,6 +65,8 @@ public class DeleteFileDialogFragment extends DialogFragment { alert.setMessage(this.getString(R.string.fileDeleteConfirmation, deleteFile)); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java index bb5271ce7..97477ee17 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java @@ -36,15 +36,14 @@ import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; public class DeleteKeyDialogFragment extends DialogFragment { - - private Messenger mMessenger; - private static final String ARG_MESSENGER = "messenger"; private static final String ARG_DELETE_KEY_RING_ROW_ID = "delete_file"; private static final String ARG_KEY_TYPE = "key_type"; public static final int MESSAGE_OKAY = 1; + private Messenger mMessenger; + /** * Creates new instance of this delete file dialog fragment */ @@ -68,6 +67,7 @@ public class DeleteKeyDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final FragmentActivity activity = getActivity(); + mMessenger = getArguments().getParcelable(ARG_MESSENGER); final long deleteKeyRingRowId = getArguments().getLong(ARG_DELETE_KEY_RING_ROW_ID); final int keyType = getArguments().getInt(ARG_KEY_TYPE); @@ -92,6 +92,8 @@ public class DeleteKeyDialogFragment extends DialogFragment { : R.string.secretKeyDeletionConfirmation, userId)); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { if (keyType == Id.type.public_key) { ProviderHelper.deletePublicKeyRing(activity, deleteKeyRingRowId); @@ -105,6 +107,8 @@ public class DeleteKeyDialogFragment extends DialogFragment { } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/FileDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/FileDialogFragment.java index 7786d9228..513bb058e 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/FileDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/FileDialogFragment.java @@ -38,9 +38,6 @@ import android.widget.EditText; import android.widget.ImageButton; public class FileDialogFragment extends DialogFragment { - - private Messenger mMessenger; - private static final String ARG_MESSENGER = "messenger"; private static final String ARG_TITLE = "title"; private static final String ARG_MESSAGE = "message"; @@ -53,6 +50,8 @@ public class FileDialogFragment extends DialogFragment { public static final String MESSAGE_DATA_FILENAME = "filename"; public static final String MESSAGE_DATA_CHECKED = "checked"; + private Messenger mMessenger; + /** * Creates new instance of this file dialog fragment */ @@ -107,7 +106,8 @@ public class FileDialogFragment extends DialogFragment { mBrowse.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // only .asc or .gpg files - FileHelper.openFile(activity, mFilename.getText().toString(), "text/plain", requestCode); + FileHelper.openFile(activity, mFilename.getText().toString(), "text/plain", + requestCode); } }); @@ -127,6 +127,10 @@ public class FileDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int id) { + Log.d(Constants.TAG, "onclock"); + + dismiss(); + boolean checked = false; if (mCheckBox.isEnabled()) { checked = mCheckBox.isChecked(); @@ -138,12 +142,11 @@ public class FileDialogFragment extends DialogFragment { data.putBoolean(MESSAGE_DATA_CHECKED, checked); sendMessageToHandler(MESSAGE_OKAY, data); - - dismiss(); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/LookupUnknownKeyDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/LookupUnknownKeyDialogFragment.java index 9797abc2a..359c94ee9 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/LookupUnknownKeyDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/LookupUnknownKeyDialogFragment.java @@ -37,15 +37,14 @@ import org.thialfihar.android.apg.ui.KeyServerQueryActivity; import org.thialfihar.android.apg.util.Log; public class LookupUnknownKeyDialogFragment extends DialogFragment { - - private Messenger mMessenger; - private static final String ARG_MESSENGER = "messenger"; private static final String ARG_UNKNOWN_KEY_ID = "unknown_key_id"; public static final int MESSAGE_OKAY = 1; public static final int MESSAGE_CANCEL = 2; + private Messenger mMessenger; + /** * Creates new instance of this dialog fragment * @@ -82,6 +81,8 @@ public class LookupUnknownKeyDialogFragment extends DialogFragment { PGPHelper.getSmallFingerPrint(unknownKeyId))); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); @@ -94,6 +95,8 @@ public class LookupUnknownKeyDialogFragment extends DialogFragment { } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java index fb8f4b6d1..236386efe 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java @@ -56,14 +56,12 @@ import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; public class PassphraseDialogFragment extends DialogFragment implements OnEditorActionListener { - - private Messenger mMessenger; - private static final String ARG_MESSENGER = "messenger"; private static final String ARG_SECRET_KEY_ID = "secret_key_id"; public static final int MESSAGE_OKAY = 1; + private Messenger mMessenger; private EditText mPassphraseEditText; /** @@ -182,6 +180,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); @@ -217,6 +217,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/ProgressDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/ProgressDialogFragment.java index 2fb3b3256..2c007e8e3 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/ProgressDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/ProgressDialogFragment.java @@ -26,7 +26,6 @@ import android.support.v4.app.DialogFragment; import android.view.KeyEvent; public class ProgressDialogFragment extends DialogFragment { - private static final String ARG_MESSAGE_ID = "message_id"; private static final String ARG_STYLE = "style"; diff --git a/APG/src/org/thialfihar/android/apg/ui/dialog/SetPassphraseDialogFragment.java b/APG/src/org/thialfihar/android/apg/ui/dialog/SetPassphraseDialogFragment.java index b23101a0a..c1bbd886a 100644 --- a/APG/src/org/thialfihar/android/apg/ui/dialog/SetPassphraseDialogFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/dialog/SetPassphraseDialogFragment.java @@ -42,8 +42,6 @@ import android.widget.Toast; import android.widget.TextView.OnEditorActionListener; public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener { - private Messenger mMessenger; - private static final String ARG_MESSENGER = "messenger"; private static final String ARG_TITLE = "title"; @@ -51,6 +49,7 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi public static final String MESSAGE_NEW_PASSPHRASE = "new_passphrase"; + private Messenger mMessenger; private EditText mPassphraseEditText; private EditText mPassphraseAgainEditText; @@ -97,6 +96,8 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); @@ -129,6 +130,8 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + + @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } diff --git a/APG/src/org/thialfihar/android/apg/util/Compatibility.java b/APG/src/org/thialfihar/android/apg/util/Compatibility.java deleted file mode 100644 index e0e6b2202..000000000 --- a/APG/src/org/thialfihar/android/apg/util/Compatibility.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de> - * - * 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.util; - -import java.lang.reflect.Method; - -import android.content.Context; -import org.thialfihar.android.apg.util.Log; - -public class Compatibility { - - private static final String clipboardLabel = "APG"; - - /** - * Wrapper around ClipboardManager based on Android version using Reflection API - * - * @param context - * @param text - */ - public static void copyToClipboard(Context context, String text) { - Object clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE); - try { - if ("android.text.ClipboardManager".equals(clipboard.getClass().getName())) { - Method methodSetText = clipboard.getClass() - .getMethod("setText", CharSequence.class); - methodSetText.invoke(clipboard, text); - } else if ("android.content.ClipboardManager".equals(clipboard.getClass().getName())) { - Class<?> classClipData = Class.forName("android.content.ClipData"); - Method methodNewPlainText = classClipData.getMethod("newPlainText", - CharSequence.class, CharSequence.class); - Object clip = methodNewPlainText.invoke(null, clipboardLabel, text); - methodNewPlainText = clipboard.getClass() - .getMethod("setPrimaryClip", classClipData); - methodNewPlainText.invoke(clipboard, clip); - } - } catch (Exception e) { - Log.e("ProjectsException", "There was and error copying the text to the clipboard: " - + e.getMessage()); - } - } - - /** - * Wrapper around ClipboardManager based on Android version using Reflection API - * - * @param context - * @param text - */ - public static CharSequence getClipboardText(Context context) { - Object clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE); - try { - if ("android.text.ClipboardManager".equals(clipboard.getClass().getName())) { - // CharSequence text = clipboard.getText(); - Method methodGetText = clipboard.getClass().getMethod("getText"); - Object text = methodGetText.invoke(clipboard); - - return (CharSequence) text; - } else if ("android.content.ClipboardManager".equals(clipboard.getClass().getName())) { - // ClipData clipData = clipboard.getPrimaryClip(); - Method methodGetPrimaryClip = clipboard.getClass().getMethod("getPrimaryClip"); - Object clipData = methodGetPrimaryClip.invoke(clipboard); - - // ClipData.Item clipDataItem = clipData.getItemAt(0); - Method methodGetItemAt = clipData.getClass().getMethod("getItemAt", int.class); - Object clipDataItem = methodGetItemAt.invoke(clipData, 0); - - // CharSequence text = clipDataItem.coerceToText(context); - Method methodGetString = clipDataItem.getClass().getMethod("coerceToText", - Context.class); - Object text = methodGetString.invoke(clipDataItem, context); - - return (CharSequence) text; - } else { - return null; - } - } catch (Exception e) { - Log.e("ProjectsException", "There was and error getting the text from the clipboard: " - + e.getMessage()); - - return null; - } - } -} |