Example usage for android.content Intent ACTION_PROCESS_TEXT

List of usage examples for android.content Intent ACTION_PROCESS_TEXT

Introduction

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

Prototype

String ACTION_PROCESS_TEXT

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

Click Source Link

Document

Activity Action: Process a piece of text.

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;/*from w  w w  .ja v a  2s  . co 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:com.commonsware.android.processtext.MainActivity.java

@Override
public void onQuestion(Item question) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && Intent.ACTION_PROCESS_TEXT.equals(getIntent().getAction())
            && getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT) != null) {
        setResult(Activity.RESULT_OK, new Intent().putExtra(Intent.EXTRA_PROCESS_TEXT, question.link));
        finish();//from www  .  ja  v  a 2s. c om
    } else {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(question.link)));
    }
}

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();//  w  w w.  jav  a  2s.  c  o 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();
    }

}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

@Override
public void onResume() {
    super.onResume();
    invalidateOptionsMenu();/*from w  w  w .j ava 2s.  c  o m*/
    if (wasHideToolbar != isHideToolbar) {
        wasHideToolbar = isHideToolbar;

        List<KiwixWebView> newWebViews = new ArrayList<>();
        for (int i = 0; i < mWebViews.size(); i++) {
            KiwixWebView newView = getWebView(mWebViews.get(i).getUrl());
            newWebViews.add(i, newView);
        }
        mWebViews = newWebViews;
        selectTab(currentWebViewIndex);
    }
    if (refresh) {
        refresh = false;
        recreate();
    }
    if (menu != null) {
        refreshBookmarkSymbol(menu);
    }
    if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
        if (menu != null) {
            menu.getItem(4).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }
    } else {
        if (menu != null) {
            menu.getItem(4).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
    }

    if (settings.getBoolean(KiwixSettingsActivity.PREF_BOTTOM_TOOLBAR, false)) {
        pageBottomTabLayout.setVisibility(View.VISIBLE);
    } else {
        pageBottomTabLayout.setVisibility(View.GONE);
    }

    Intent intent = getIntent();
    if (intent.getAction() != null) {

        if (intent.getAction().equals(Intent.ACTION_PROCESS_TEXT)) {
            final String zimFile = ZimContentProvider.getZimFile();
            saveTabStates();
            Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class);
            i.putExtra("zimFile", zimFile);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                i.putExtra(Intent.EXTRA_PROCESS_TEXT, intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT));
            }
            intent.setAction("");
            startActivityForResult(i, REQUEST_FILE_SEARCH);
        } else if (intent.getAction().equals(KiwixSearchWidget.TEXT_CLICKED)) {
            intent.setAction("");
            goToSearch(false);
        } else if (intent.getAction().equals(KiwixSearchWidget.STAR_CLICKED)) {
            intent.setAction("");
            goToBookmarks();
        } else if (intent.getAction().equals(KiwixSearchWidget.MIC_CLICKED)) {
            intent.setAction("");
            goToSearch(true);
        }

    }
    updateWidgets(this);
}