Example usage for android.content Intent EXTRA_PROCESS_TEXT_READONLY

List of usage examples for android.content Intent EXTRA_PROCESS_TEXT_READONLY

Introduction

In this page you can find the example usage for android.content Intent EXTRA_PROCESS_TEXT_READONLY.

Prototype

String EXTRA_PROCESS_TEXT_READONLY

To view the source code for android.content Intent EXTRA_PROCESS_TEXT_READONLY.

Click Source Link

Document

The name of the boolean extra used to define if the processed text will be used as read-only.

Usage

From source file:com.commonsware.android.processtext.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
        String search = null;//w  w w.jav  a2s .  c  o m

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (Intent.ACTION_PROCESS_TEXT.equals(getIntent().getAction())) {
                search = getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT);

                if (search == null) {
                    search = getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT_READONLY);
                }
            }
        }

        getSupportFragmentManager().beginTransaction()
                .add(android.R.id.content, QuestionsFragment.newInstance(search)).commit();
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptTextActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setFullScreenDialogClose(Activity.RESULT_OK, false);

    Intent intent = getIntent();/*from   w w  w.java  2  s .  co m*/
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    String type = intent.getType();

    if (extras == null) {
        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");

        // When sending to OpenKeychain Encrypt via share menu
        if (!MimeUtil.isSameMimeType("text/plain", type)) {
            Toast.makeText(this, R.string.toast_wrong_mimetype, Toast.LENGTH_LONG).show();
            finish();
            return;
        }

        String sharedText;
        if (extras.containsKey(Intent.EXTRA_TEXT)) {
            sharedText = extras.getString(Intent.EXTRA_TEXT);
        } else if (extras.containsKey(Intent.EXTRA_STREAM)) {
            try {
                sharedText = FileHelper.readTextFromUri(this, extras.<Uri>getParcelable(Intent.EXTRA_STREAM),
                        null);
            } catch (IOException e) {
                Toast.makeText(this, R.string.error_preparing_data, Toast.LENGTH_LONG).show();
                finish();
                return;
            }
        } else {
            Toast.makeText(this, R.string.toast_no_text, Toast.LENGTH_LONG).show();
            finish();
            return;
        }

        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;
        }

    }

    // 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 = "";
    }

    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        EncryptTextFragment encryptFragment = EncryptTextFragment.newInstance(textData, returnProcessText);
        transaction.replace(R.id.encrypt_text_container, encryptFragment);
        transaction.commit();
    }

}