Java Code Examples for android.content.ClipboardManager#hasText()

The following examples show how to use android.content.ClipboardManager#hasText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ws_Main3Activity.java    From styT with Apache License 2.0 6 votes vote down vote up
private String getClipboardText() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    String text = "";
    try {
        if (clipboard != null && clipboard.hasText()) {
            CharSequence tmpText = clipboard.getText();
            clipboard.setText(tmpText);
            if (tmpText != null && tmpText.length() > 0) {
                text = tmpText.toString().trim();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        text = "";
    }
    return text;
}
 
Example 2
Source File: x5_MainActivity.java    From stynico with MIT License 6 votes vote down vote up
private String getClipboardText()
{
       ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
       String text = "";
       try
	{
           if (clipboard != null && clipboard.hasText())
		{
               CharSequence tmpText = clipboard.getText();
               clipboard.setText(tmpText);
               if (tmpText != null && tmpText.length() > 0)
			{
                   text = tmpText.toString().trim();
               }
           }
       }
	catch (Exception e)
	{
           e.printStackTrace();
           text = "";
       }
       return text;
   }
 
Example 3
Source File: PopupActivity.java    From ankihelper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if(isFromAndroidQClipboard) {
        if (!Settings.getInstance(MyApplication.getContext()).getMoniteClipboardQ()) {
            return;
        }
        ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        if (cb.hasPrimaryClip()) {
            if (cb.hasText()) {
                String text = cb.getText().toString();
                mTextToProcess = text;
            }
        }
        populateWordSelectBox();
        bigBangLayout.post( new Runnable() {
            @Override
            public void run() {
                setTargetWord();
                if(Utils.containsTranslationField(currentOutputPlan)){
                    asyncTranslate(mTextToProcess);
                }
            }
        });
    }
}
 
Example 4
Source File: CBWatcherService.java    From ankihelper with GNU General Public License v3.0 6 votes vote down vote up
private void performClipboardCheck() {
    Log.d("clip", "clip_changed");
    if (!Settings.getInstance(MyApplication.getContext()).getMoniteClipboardQ()) {
        return;
    }
    ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (cb.hasPrimaryClip()) {
        if (cb.hasText()) {
            String text = cb.getText().toString();
            if (/*isEnglish(text)*/true) {
                long[] vibList = new long[1];
                vibList[0] = 10L;
                Intent intent = new Intent(getApplicationContext(), PopupActivity.class);
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("text/plain");
                //intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                intent.putExtra(Intent.EXTRA_TEXT, text);
                startActivity(intent);
            }
        }
    }
}
 
Example 5
Source File: ClipboardUtils.java    From AdBlockedWebView-Android with MIT License 5 votes vote down vote up
public static boolean hasText(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        return clipData != null
                && description != null
                && (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
    } else {
        //noinspection deprecation
        return cm.hasText();
    }
}