From 8279f84eb88a80e197514f2ab94e0e91416a19e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 15 Oct 2015 19:10:06 +0200 Subject: Add restore to backup fragment, cleanup, renamings --- .../keychain/ui/BackupRestoreFragment.java | 66 ++++++-- .../keychain/ui/EncryptDecryptFragment.java | 178 ++++++++++++++++++++ .../ui/EncryptDecryptOverviewFragment.java | 179 --------------------- .../keychain/ui/MainActivity.java | 4 +- .../main/res/layout/backup_restore_fragment.xml | 93 +++++++++++ .../src/main/res/layout/drawer_backup_fragment.xml | 71 -------- .../main/res/layout/encrypt_decrypt_fragment.xml | 127 +++++++++++++++ .../layout/encrypt_decrypt_overview_fragment.xml | 127 --------------- OpenKeychain/src/main/res/values/strings.xml | 1 + 9 files changed, 453 insertions(+), 393 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptFragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java create mode 100644 OpenKeychain/src/main/res/layout/backup_restore_fragment.xml delete mode 100644 OpenKeychain/src/main/res/layout/drawer_backup_fragment.xml create mode 100644 OpenKeychain/src/main/res/layout/encrypt_decrypt_fragment.xml delete mode 100644 OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupRestoreFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupRestoreFragment.java index 5336f909c..25601d655 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupRestoreFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/BackupRestoreFragment.java @@ -17,13 +17,13 @@ package org.sufficientlysecure.keychain.ui; - import java.util.ArrayList; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.database.Cursor; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; @@ -36,6 +36,8 @@ import android.view.ViewGroup; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.util.FileHelper; public class BackupRestoreFragment extends Fragment { @@ -44,14 +46,16 @@ public class BackupRestoreFragment extends Fragment { // This index for remembering the number of master key. private int mIndex; - static final int REQUEST_REPEAT_PASSPHRASE = 1; + private static final int REQUEST_REPEAT_PASSPHRASE = 0x00007002; + private static final int REQUEST_CODE_INPUT = 0x00007003; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.drawer_backup_fragment, container, false); + View view = inflater.inflate(R.layout.backup_restore_fragment, container, false); View backupAll = view.findViewById(R.id.backup_all); View backupPublicKeys = view.findViewById(R.id.backup_public_keys); + final View restore = view.findViewById(R.id.restore); backupAll.setOnClickListener(new View.OnClickListener() { @Override @@ -67,6 +71,13 @@ public class BackupRestoreFragment extends Fragment { } }); + restore.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + restore(); + } + }); + return view; } @@ -81,12 +92,12 @@ public class BackupRestoreFragment extends Fragment { return; } - new AsyncTask>() { + new AsyncTask>() { @Override protected ArrayList doInBackground(ContentResolver... resolver) { ArrayList askPassphraseIds = new ArrayList<>(); Cursor cursor = resolver[0].query( - KeyRings.buildUnifiedKeyRingsUri(), new String[] { + KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.MASTER_KEY_ID, KeyRings.HAS_SECRET, }, KeyRings.HAS_SECRET + " != 0", null, null); @@ -136,7 +147,6 @@ public class BackupRestoreFragment extends Fragment { } }.execute(activity.getContentResolver()); - } private void startPassphraseActivity() { @@ -153,25 +163,53 @@ public class BackupRestoreFragment extends Fragment { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == REQUEST_REPEAT_PASSPHRASE) { - if (resultCode != Activity.RESULT_OK) { - return; + switch (requestCode) { + case REQUEST_REPEAT_PASSPHRASE: { + if (resultCode != Activity.RESULT_OK) { + return; + } + if (mIndex < mIdsForRepeatAskPassphrase.size()) { + startPassphraseActivity(); + return; + } + + startBackup(true); + + break; } - if (mIndex < mIdsForRepeatAskPassphrase.size()) { - startPassphraseActivity(); - return; + + case REQUEST_CODE_INPUT: { + if (resultCode != Activity.RESULT_OK || data == null) { + return; + } + + Uri uri = data.getData(); + if (uri == null) { + Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show(); + return; + } + + Intent intent = new Intent(getActivity(), DecryptActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.setData(uri); + startActivity(intent); + break; } - startBackup(true); + default: { + super.onActivityResult(requestCode, resultCode, data); + } } } private void startBackup(boolean exportSecret) { - Intent intent = new Intent(getActivity(), BackupActivity.class); intent.putExtra(BackupActivity.EXTRA_SECRET, exportSecret); startActivity(intent); + } + private void restore() { + FileHelper.openDocument(this, null, "*/*", false, REQUEST_CODE_INPUT); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptFragment.java new file mode 100644 index 000000000..89ea6165b --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptFragment.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2014-2015 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * 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 java.util.regex.Matcher; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; +import org.sufficientlysecure.keychain.pgp.PgpHelper; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; +import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker; +import org.sufficientlysecure.keychain.util.FileHelper; + +public class EncryptDecryptFragment extends Fragment { + + View mClipboardIcon; + + private static final int REQUEST_CODE_INPUT = 0x00007003; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + } + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.encrypt_decrypt_fragment, container, false); + + View mEncryptFile = view.findViewById(R.id.encrypt_files); + View mEncryptText = view.findViewById(R.id.encrypt_text); + View mDecryptFile = view.findViewById(R.id.decrypt_files); + View mDecryptFromClipboard = view.findViewById(R.id.decrypt_from_clipboard); + mClipboardIcon = view.findViewById(R.id.clipboard_icon); + + mEncryptFile.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent encrypt = new Intent(getActivity(), EncryptFilesActivity.class); + startActivity(encrypt); + } + }); + + mEncryptText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent encrypt = new Intent(getActivity(), EncryptTextActivity.class); + startActivity(encrypt); + } + }); + + mDecryptFile.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FileHelper.openDocument(EncryptDecryptFragment.this, null, "*/*", false, REQUEST_CODE_INPUT); + } + }); + + mDecryptFromClipboard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + decryptFromClipboard(); + } + }); + + return view; + } + + private void decryptFromClipboard() { + + Activity activity = getActivity(); + if (activity == null) { + return; + } + + final CharSequence clipboardText = ClipboardReflection.getClipboardText(activity); + if (clipboardText == null || TextUtils.isEmpty(clipboardText)) { + Notify.create(activity, R.string.error_clipboard_empty, Style.ERROR).show(); + return; + } + + Intent clipboardDecrypt = new Intent(getActivity(), DecryptActivity.class); + clipboardDecrypt.setAction(DecryptActivity.ACTION_DECRYPT_FROM_CLIPBOARD); + startActivityForResult(clipboardDecrypt, 0); + } + + @Override + public void onResume() { + super.onResume(); + + // get text from clipboard + final CharSequence clipboardText = ClipboardReflection.getClipboardText(getActivity()); + + // if it's null, nothing to do here /o/ + if (clipboardText == null) { + return; + } + + new AsyncTask() { + @Override + protected Boolean doInBackground(String... clipboardText) { + + // see if it looks like a pgp thing + Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(clipboardText[0]); + boolean animate = matcher.matches(); + + // see if it looks like another pgp thing + if (!animate) { + matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(clipboardText[0]); + animate = matcher.matches(); + } + return animate; + } + + @Override + protected void onPostExecute(Boolean animate) { + super.onPostExecute(animate); + + // if so, animate the clipboard icon just a bit~ + if (animate) { + SubtleAttentionSeeker.tada(mClipboardIcon, 1.5f).start(); + } + } + }.execute(clipboardText.toString()); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode != REQUEST_CODE_INPUT) { + return; + } + + if (resultCode == Activity.RESULT_OK && data != null) { + Uri uri = data.getData(); + if (uri == null) { + Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show(); + return; + } + + Intent intent = new Intent(getActivity(), DecryptActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.setData(uri); + startActivity(intent); + + } + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java deleted file mode 100644 index 84660ca7a..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (C) 2014-2015 Dominik Schürmann - * Copyright (C) 2014 Vincent Breitmoser - * - * 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 java.util.regex.Matcher; - -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; -import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.ui.util.Notify.Style; -import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker; -import org.sufficientlysecure.keychain.util.FileHelper; - -public class EncryptDecryptOverviewFragment extends Fragment { - - View mClipboardIcon; - - private static final int REQUEST_CODE_INPUT = 0x00007003; - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - } - - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.encrypt_decrypt_overview_fragment, container, false); - - View mEncryptFile = view.findViewById(R.id.encrypt_files); - View mEncryptText = view.findViewById(R.id.encrypt_text); - View mDecryptFile = view.findViewById(R.id.decrypt_files); - View mDecryptFromClipboard = view.findViewById(R.id.decrypt_from_clipboard); - mClipboardIcon = view.findViewById(R.id.clipboard_icon); - - mEncryptFile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent encrypt = new Intent(getActivity(), EncryptFilesActivity.class); - startActivity(encrypt); - } - }); - - mEncryptText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent encrypt = new Intent(getActivity(), EncryptTextActivity.class); - startActivity(encrypt); - } - }); - - mDecryptFile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FileHelper.openDocument(EncryptDecryptOverviewFragment.this, null, "*/*", false, REQUEST_CODE_INPUT); - } - }); - - mDecryptFromClipboard.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - decryptFromClipboard(); - } - }); - - return view; - } - - private void decryptFromClipboard() { - - Activity activity = getActivity(); - if (activity == null) { - return; - } - - final CharSequence clipboardText = ClipboardReflection.getClipboardText(activity); - if (clipboardText == null || TextUtils.isEmpty(clipboardText)) { - Notify.create(activity, R.string.error_clipboard_empty, Style.ERROR).show(); - return; - } - - Intent clipboardDecrypt = new Intent(getActivity(), DecryptActivity.class); - clipboardDecrypt.setAction(DecryptActivity.ACTION_DECRYPT_FROM_CLIPBOARD); - startActivityForResult(clipboardDecrypt, 0); - } - - @Override - public void onResume() { - super.onResume(); - - // get text from clipboard - final CharSequence clipboardText = ClipboardReflection.getClipboardText(getActivity()); - - // if it's null, nothing to do here /o/ - if (clipboardText == null) { - return; - } - - new AsyncTask() { - @Override - protected Boolean doInBackground(String... clipboardText) { - - // see if it looks like a pgp thing - Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(clipboardText[0]); - boolean animate = matcher.matches(); - - // see if it looks like another pgp thing - if (!animate) { - matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(clipboardText[0]); - animate = matcher.matches(); - } - return animate; - } - - @Override - protected void onPostExecute(Boolean animate) { - super.onPostExecute(animate); - - // if so, animate the clipboard icon just a bit~ - if (animate) { - SubtleAttentionSeeker.tada(mClipboardIcon, 1.5f).start(); - } - } - }.execute(clipboardText.toString()); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode != REQUEST_CODE_INPUT) { - return; - } - - if (resultCode == Activity.RESULT_OK && data != null) { - Uri uri = data.getData(); - if (uri == null) { - Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show(); - return; - } - - Intent intent = new Intent(getActivity(), DecryptActivity.class); - intent.setAction(Intent.ACTION_VIEW); - intent.setData(uri); - startActivity(intent); - - } - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java index 51bc99ea3..7e9b4953c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java @@ -190,7 +190,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac private void onEnDecryptSelected() { mToolbar.setTitle(R.string.nav_encrypt_decrypt); mDrawer.setSelectionByIdentifier(ID_ENCRYPT_DECRYPT, false); - Fragment frag = new EncryptDecryptOverviewFragment(); + Fragment frag = new EncryptDecryptFragment(); setFragment(frag, true); } @@ -259,7 +259,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac if (frag instanceof KeyListFragment) { mToolbar.setTitle(R.string.app_name); mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_KEYS), false); - } else if (frag instanceof EncryptDecryptOverviewFragment) { + } else if (frag instanceof EncryptDecryptFragment) { mToolbar.setTitle(R.string.nav_encrypt_decrypt); mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_ENCRYPT_DECRYPT), false); } else if (frag instanceof AppsListFragment) { diff --git a/OpenKeychain/src/main/res/layout/backup_restore_fragment.xml b/OpenKeychain/src/main/res/layout/backup_restore_fragment.xml new file mode 100644 index 000000000..ce97b7fd4 --- /dev/null +++ b/OpenKeychain/src/main/res/layout/backup_restore_fragment.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/drawer_backup_fragment.xml b/OpenKeychain/src/main/res/layout/drawer_backup_fragment.xml deleted file mode 100644 index 96fba954b..000000000 --- a/OpenKeychain/src/main/res/layout/drawer_backup_fragment.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/encrypt_decrypt_fragment.xml b/OpenKeychain/src/main/res/layout/encrypt_decrypt_fragment.xml new file mode 100644 index 000000000..7bd919abc --- /dev/null +++ b/OpenKeychain/src/main/res/layout/encrypt_decrypt_fragment.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml b/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml deleted file mode 100644 index 7bd919abc..000000000 --- a/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 8dd1f1b50..f1154645d 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1434,6 +1434,7 @@ "All keys + your own keys" "All keys" "Backup" + "Restore" "Certifier" -- cgit v1.2.3