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

The following examples show how to use android.content.ClipboardManager#hasText() . These examples are extracted from open source projects. 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 Project: styT   File: ws_Main3Activity.java    License: 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 Project: stynico   File: x5_MainActivity.java    License: 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
@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
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
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();
    }
}