Support for Android 6 ACTION_PROCESS_TEXT
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user