Support for Android 6 ACTION_PROCESS_TEXT

This commit is contained in:
Dominik Schürmann
2015-11-02 19:15:00 +01:00
parent 00c972b6a8
commit 8f070e2450
15 changed files with 130 additions and 10 deletions

View File

@@ -210,6 +210,12 @@
<data android:mimeType="text/*" />
<data android:mimeType="message/*" />
</intent-filter>
<!-- Android 6 Floating Action Mode -->
<intent-filter >
<action android:name="android.intent.action.PROCESS_TEXT"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".ui.DisplayTextActivity"

View File

@@ -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();
}

View File

@@ -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);

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 986 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -2,6 +2,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/encrypt_paste"
android:title="@string/btn_paste_encrypted_signed"
android:icon="@drawable/ic_action_encrypt_paste_24dp"
android:orderInCategory="1"
android:visible="false"
app:showAsAction="ifRoom" />
<item
android:id="@+id/encrypt_copy"
android:title="@string/btn_copy_encrypted_signed"

View File

@@ -88,6 +88,7 @@
<string name="btn_match_phrases">"Phrases match"</string>
<string name="btn_share_encrypted_signed">"Encrypt/sign and share text"</string>
<string name="btn_copy_encrypted_signed">"Encrypt/sign and copy text"</string>
<string name="btn_paste_encrypted_signed">"Encrypt/sign and paste text"</string>
<string name="btn_view_cert_key">"View certification key"</string>
<string name="btn_create_key">"Create key"</string>
<string name="btn_add_files">"Add file(s)"</string>