diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-11-04 20:24:11 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-11-04 20:24:11 +0100 |
commit | 3ca8af060b2f6452df794a8770714d1f02b36734 (patch) | |
tree | 438d92f9107bd76e10c5f72f41c4d7bc12e44ced /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | a4518c43c2fdff3852668242978a8b9739447d0b (diff) | |
parent | 31a45759ccfbca76f89e6e51bf94c4a3af3a874f (diff) | |
download | open-keychain-3ca8af060b2f6452df794a8770714d1f02b36734.tar.gz open-keychain-3ca8af060b2f6452df794a8770714d1f02b36734.tar.bz2 open-keychain-3ca8af060b2f6452df794a8770714d1f02b36734.zip |
Merge branch 'master' of github.com:open-keychain/open-keychain
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
4 files changed, 154 insertions, 23 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java index 0afb942b5..50dbc9a8b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java @@ -60,6 +60,9 @@ public class EncryptTextActivity extends EncryptActivity { extras = new Bundle(); } + String textData = extras.getString(EXTRA_TEXT); + boolean returnProcessText = false; + // When sending to OpenKeychain Encrypt via share menu if (Intent.ACTION_SEND.equals(action) && type != null) { Log.logDebugBundle(extras, "extras"); @@ -95,12 +98,33 @@ public class EncryptTextActivity extends EncryptActivity { } // handle like normal text encryption, override action and extras to later // executeServiceMethod ACTION_ENCRYPT_TEXT in main actions - extras.putString(EXTRA_TEXT, sharedText); + textData = sharedText; } } - String textData = extras.getString(EXTRA_TEXT); + // Android 6, PROCESS_TEXT Intent + if (Intent.ACTION_PROCESS_TEXT.equals(action) && type != null) { + + String sharedText = null; + if (extras.containsKey(Intent.EXTRA_PROCESS_TEXT)) { + sharedText = extras.getString(Intent.EXTRA_PROCESS_TEXT); + returnProcessText = true; + } else if (extras.containsKey(Intent.EXTRA_PROCESS_TEXT_READONLY)) { + sharedText = extras.getString(Intent.EXTRA_PROCESS_TEXT_READONLY); + } + + if (sharedText != null) { + if (sharedText.length() > Constants.TEXT_LENGTH_LIMIT) { + sharedText = sharedText.substring(0, Constants.TEXT_LENGTH_LIMIT); + Notify.create(this, R.string.snack_shared_text_too_long, Style.WARN).show(); + } + // handle like normal text encryption, override action and extras to later + // executeServiceMethod ACTION_ENCRYPT_TEXT in main actions + textData = sharedText; + } + } + if (textData == null) { textData = ""; } @@ -108,7 +132,7 @@ public class EncryptTextActivity extends EncryptActivity { if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - EncryptTextFragment encryptFragment = EncryptTextFragment.newInstance(textData); + EncryptTextFragment encryptFragment = EncryptTextFragment.newInstance(textData, returnProcessText); transaction.replace(R.id.encrypt_text_container, encryptFragment); transaction.commit(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java index 4ce241c02..10d88253d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java @@ -56,8 +56,10 @@ public class EncryptTextFragment public static final String ARG_TEXT = "text"; public static final String ARG_USE_COMPRESSION = "use_compression"; + public static final String ARG_RETURN_PROCESS_TEXT = "return_process_text"; private boolean mShareAfterEncrypt; + private boolean mReturnProcessTextAfterEncrypt; private boolean mUseCompression; private boolean mHiddenRecipients = false; @@ -66,11 +68,12 @@ public class EncryptTextFragment /** * Creates new instance of this fragment */ - public static EncryptTextFragment newInstance(String text) { + public static EncryptTextFragment newInstance(String text, boolean returnProcessTextAfterEncrypt) { EncryptTextFragment frag = new EncryptTextFragment(); Bundle args = new Bundle(); args.putString(ARG_TEXT, text); + args.putBoolean(ARG_RETURN_PROCESS_TEXT, returnProcessTextAfterEncrypt); frag.setArguments(args); return frag; @@ -128,6 +131,7 @@ public class EncryptTextFragment super.onCreate(savedInstanceState); if (savedInstanceState == null) { mMessage = getArguments().getString(ARG_TEXT); + mReturnProcessTextAfterEncrypt = getArguments().getBoolean(ARG_RETURN_PROCESS_TEXT, false); } Preferences prefs = Preferences.getPreferences(getActivity()); @@ -151,6 +155,12 @@ public class EncryptTextFragment inflater.inflate(R.menu.encrypt_text_fragment, menu); menu.findItem(R.id.check_enable_compression).setChecked(mUseCompression); + + if (mReturnProcessTextAfterEncrypt) { + menu.findItem(R.id.encrypt_paste).setVisible(true); + menu.findItem(R.id.encrypt_copy).setVisible(false); + menu.findItem(R.id.encrypt_share).setVisible(false); + } } @Override @@ -177,6 +187,11 @@ public class EncryptTextFragment cryptoOperation(new CryptoInputParcel(new Date())); break; } + case R.id.encrypt_paste: { + hideKeyboard(); + cryptoOperation(new CryptoInputParcel(new Date())); + break; + } default: { return super.onOptionsItemSelected(item); } @@ -328,6 +343,11 @@ public class EncryptTextFragment // Share encrypted message/file startActivity(Intent.createChooser(createSendIntent(result.getResultBytes()), getString(R.string.title_share_message))); + } else if (mReturnProcessTextAfterEncrypt) { + Intent resultIntent = new Intent(); + resultIntent.putExtra(Intent.EXTRA_PROCESS_TEXT, new String(result.getResultBytes())); + getActivity().setResult(Activity.RESULT_OK, resultIntent); + getActivity().finish(); } else { // Copy to clipboard copyToClipboard(result); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java index 6172c8c8e..bf024cb5b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java @@ -1,23 +1,31 @@ /* * Copyright (C) 2015 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 + * 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. * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.sufficientlysecure.keychain.ui; +import android.Manifest; +import android.app.Activity; +import android.content.Intent; +import android.content.pm.PackageManager; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.FragmentActivity; +import android.support.v4.content.ContextCompat; import android.view.KeyEvent; import com.journeyapps.barcodescanner.CaptureManager; @@ -29,6 +37,8 @@ public class QrCodeCaptureActivity extends FragmentActivity { private CaptureManager capture; private CompoundBarcodeView barcodeScannerView; + public static final int MY_PERMISSIONS_REQUEST_CAMERA = 42; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -38,33 +48,87 @@ public class QrCodeCaptureActivity extends FragmentActivity { barcodeScannerView = (CompoundBarcodeView) findViewById(R.id.zxing_barcode_scanner); barcodeScannerView.setStatusText(getString(R.string.import_qr_code_text)); + if (savedInstanceState != null) { + init(barcodeScannerView, getIntent(), savedInstanceState); + } + + // check Android 6 permission + if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) + == PackageManager.PERMISSION_GRANTED) { + init(barcodeScannerView, getIntent(), null); + } else { + +// // Should we show an explanation? +// if (ActivityCompat.shouldShowRequestPermissionRationale(this, +// Manifest.permission.CAMERA)) { +// +// // Show an explanation to the user *asynchronously* -- don't block +// // this thread waiting for the user's response! After the user +// // sees the explanation, try again to request the permission. +// +// } else { + + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.CAMERA}, + MY_PERMISSIONS_REQUEST_CAMERA); + +// } + } + } + + private void init(CompoundBarcodeView barcodeScannerView, Intent intent, Bundle savedInstanceState) { capture = new CaptureManager(this, barcodeScannerView); - capture.initializeFromIntent(getIntent(), savedInstanceState); + capture.initializeFromIntent(intent, savedInstanceState); capture.decode(); } @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], + @NonNull int[] grantResults) { + switch (requestCode) { + case MY_PERMISSIONS_REQUEST_CAMERA: { + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // permission was granted + init(barcodeScannerView, getIntent(), null); + } else { + setResult(Activity.RESULT_CANCELED); + finish(); + } + } + } + } + + @Override protected void onResume() { super.onResume(); - capture.onResume(); + if (capture != null) { + capture.onResume(); + } } @Override protected void onPause() { super.onPause(); - capture.onPause(); + if (capture != null) { + capture.onPause(); + } } @Override protected void onDestroy() { super.onDestroy(); - capture.onDestroy(); + if (capture != null) { + capture.onDestroy(); + } } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - capture.onSaveInstanceState(outState); + if (capture != null) { + capture.onSaveInstanceState(outState); + } } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index cbc7b88bf..0184527b7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -38,6 +38,7 @@ import android.os.Handler; import android.provider.ContactsContract; import android.support.design.widget.AppBarLayout; import android.support.design.widget.CollapsingToolbarLayout; +import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.ActivityCompat; import android.support.v4.app.FragmentManager; @@ -869,7 +870,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements mActionEncryptFile.setVisibility(View.INVISIBLE); mActionEncryptText.setVisibility(View.INVISIBLE); mActionNfc.setVisibility(View.INVISIBLE); - mFab.setVisibility(View.GONE); + hideFab(); mQrCodeLayout.setVisibility(View.GONE); } else if (mIsExpired) { if (mIsSecret) { @@ -885,7 +886,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements mActionEncryptFile.setVisibility(View.INVISIBLE); mActionEncryptText.setVisibility(View.INVISIBLE); mActionNfc.setVisibility(View.INVISIBLE); - mFab.setVisibility(View.GONE); + hideFab(); mQrCodeLayout.setVisibility(View.GONE); } else if (mIsSecret) { mStatusText.setText(R.string.view_key_my_key); @@ -927,7 +928,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements } else { mActionNfc.setVisibility(View.GONE); } - mFab.setVisibility(View.VISIBLE); + showFab(); // noinspection deprecation (no getDrawable with theme at current minApi level 15!) mFab.setImageDrawable(getResources().getDrawable(R.drawable.ic_repeat_white_24dp)); } else { @@ -944,7 +945,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements color = getResources().getColor(R.color.key_flag_green); photoTask.execute(mMasterKeyId); - mFab.setVisibility(View.GONE); + hideFab(); } else { mStatusText.setText(R.string.view_key_unverified); mStatusImage.setVisibility(View.VISIBLE); @@ -952,7 +953,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements State.UNVERIFIED, R.color.icons, true); color = getResources().getColor(R.color.key_flag_orange); - mFab.setVisibility(View.VISIBLE); + showFab(); } } @@ -982,6 +983,28 @@ public class ViewKeyActivity extends BaseNfcActivity implements } } + /** + * Helper to show Fab, from http://stackoverflow.com/a/31047038 + */ + private void showFab() { + CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams(); + p.setBehavior(new FloatingActionButton.Behavior()); + p.setAnchorId(R.id.app_bar_layout); + mFab.setLayoutParams(p); + mFab.setVisibility(View.VISIBLE); + } + + /** + * Helper to hide Fab, from http://stackoverflow.com/a/31047038 + */ + private void hideFab() { + CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams(); + p.setBehavior(null); //should disable default animations + p.setAnchorId(View.NO_ID); //should let you set visibility + mFab.setLayoutParams(p); + mFab.setVisibility(View.GONE); + } + @Override public void onLoaderReset(Loader<Cursor> loader) { |