@Override
 protected void onResume() {
   super.onResume();
   final int entryCount = getSupportFragmentManager().getBackStackEntryCount();
   final ClipboardManager clipboardManager =
       (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
   if (entryCount == 0
       && clipboardManager.hasPrimaryClip()
       && clipboardManager.getPrimaryClip().getItemCount() > 0) {
     final ClipData primaryClip = clipboardManager.getPrimaryClip();
     final ClipData.Item item = primaryClip.getItemAt(0);
     final String text = item.coerceToText(this).toString();
     if (text.trim().length() > 0) {
       final Snackbar snackbar =
           Snackbar.with(this)
               .text(getString(R.string.paste_from_clipboard_prompt))
               .actionLabel(getString(R.string.paste_clipboard_action))
               .actionColorResource(R.color.sharelock_orange)
               .actionListener(
                   new ActionClickListener() {
                     @Override
                     public void onActionClicked(Snackbar snackbar) {
                       bus.postSticky(new ClipboardSecretEvent(text));
                       clipboardManager.setPrimaryClip(ClipData.newPlainText("", ""));
                     }
                   })
               .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE);
       SnackbarManager.show(snackbar);
     }
   }
 }
Esempio n. 2
0
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  /*
   * Cancel clipboard content
   */
  public void cancelClipBoardContent() {

    if (android.os.Build.VERSION.SDK_INT < 11) {
      android.text.ClipboardManager clipboard =
          (android.text.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
      if (clipboard != null) {
        clipboard.setText("");
      }
    } else {
      android.content.ClipboardManager clipboard =
          (android.content.ClipboardManager)
              getContext().getSystemService(Context.CLIPBOARD_SERVICE);
      if (clipboard != null
          && clipboard.getPrimaryClip() != null
          && clipboard.getPrimaryClip().getItemCount() > 0) {
        android.content.ClipData clip = android.content.ClipData.newPlainText("", "");
        clipboard.setPrimaryClip(clip);
      }
    }
  }
  private Address getAddressFromPrimaryClip() {
    if (!clipboardManager.hasPrimaryClip()) return null;

    final ClipData clip = clipboardManager.getPrimaryClip();
    final ClipDescription clipDescription = clip.getDescription();

    if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
      final CharSequence clipText = clip.getItemAt(0).getText();
      if (clipText == null) return null;

      try {
        return new Address(Constants.NETWORK_PARAMETERS, clipText.toString().trim());
      } catch (final AddressFormatException x) {
        return null;
      }
    } else if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
      final Uri clipUri = clip.getItemAt(0).getUri();
      if (clipUri == null) return null;
      try {
        return new BitcoinURI(clipUri.toString()).getAddress();
      } catch (final BitcoinURIParseException x) {
        return null;
      }
    } else {
      return null;
    }
  }
 /**
  * 获取剪贴板的意图
  *
  * @param context 上下文
  * @return 剪贴板的意图
  */
 public static Intent getIntent(Context context) {
   ClipboardManager clipboard =
       (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
   ClipData clip = clipboard.getPrimaryClip();
   if (clip != null && clip.getItemCount() > 0) {
     return clip.getItemAt(0).getIntent();
   }
   return null;
 }
Esempio n. 5
0
 /**
  * 粘贴【剪切板】功能
  *
  * @return 返回剪贴板的内容
  */
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 public String paste() {
   // 粘贴部分【本案例不需要粘贴】
   ClipboardManager myClipboard;
   myClipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
   // 需要做的下一件事就是通过调用ClipData类的数据方法的相应类型来实例化ClipData对象。如果文本数据在newPlainText方法被调用。必须将数据设置为剪贴板管理器对象的剪辑。
   ClipData clipData = myClipboard.getPrimaryClip();
   ClipData.Item item = clipData.getItemAt(0);
   return item.getText().toString();
 }
Esempio n. 6
0
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 public static String getImageUrl(final Context context) {
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return null;
   final ClipboardManager cm =
       (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
   final ClipData primaryClip = cm.getPrimaryClip();
   if (primaryClip.getItemCount() > 0) {
     final ClipData.Item item = primaryClip.getItemAt(0);
     final CharSequence styledText = item.coerceToStyledText(context);
     if (styledText instanceof Spanned) {
       final Spanned spanned = (Spanned) styledText;
       final ImageSpan[] imageSpans = spanned.getSpans(0, spanned.length(), ImageSpan.class);
       if (imageSpans.length == 1) return imageSpans[0].getSource();
     }
   }
   return null;
 }
Esempio n. 7
0
  void pasteIntent() {
    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (cm.hasPrimaryClip() == false) {
      Toast.makeText(this, "Clipboard Empty", 0).show();
      return;
    }
    if (cm.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT) == false) {
      Toast.makeText(this, "Clip is not intent", 0).show();
      return;
    }

    ClipData clip = cm.getPrimaryClip();
    ClipData.Item item = clip.getItemAt(0);
    Intent intent = item.getIntent();
    if (intent != null) {
      startActivity(intent);
    }
  }
Esempio n. 8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //        setContentView(R.layout.activity_test_hook_binder);
    try {
      BinderHookHelper.hookClipboardService();
    } catch (Exception e) {
      e.printStackTrace();
    }

    EditText editText = new EditText(this);
    setContentView(editText);

    ClipboardManager manager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (manager.hasPrimaryClip()) {
      ClipData data = manager.getPrimaryClip();
      ClipData.Item item = data.getItemAt(0);
      editText.setText(item.getText().toString());
    }
  }
Esempio n. 9
0
 private void readClipboard() {
   ClipboardManager cm =
       (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
   ClipData cmContent = cm.getPrimaryClip();
   if (cmContent == null) {
     return;
   }
   ClipData.Item item = cmContent.getItemAt(0);
   if (item != null) {
     String url = item.coerceToText(this).toString();
     boolean a =
         !TextUtils.isEmpty(url) && !url.equals(SettingUtility.getLastFoundWeiboAccountLink());
     boolean b = Utility.isWeiboAccountIdLink(url) || Utility.isWeiboAccountDomainLink(url);
     if (a && b) {
       OpenWeiboAccountLinkDialog dialog = new OpenWeiboAccountLinkDialog(url);
       dialog.show(getSupportFragmentManager(), "");
       SettingUtility.setLastFoundWeiboAccountLink(url);
     }
   }
 }
 public void PasteFromClipboard() {
   ClipData cdata = mClipBoard.getPrimaryClip();
   ClipData.Item item = cdata.getItemAt(0);
   this.setText(item.getText().toString());
 }
Esempio n. 11
0
 public static boolean hasText(Context context) {
   ClipboardManager clipboard = getManager(context);
   ClipData clip = clipboard.getPrimaryClip();
   return clip != null && clip.getItemCount() > 0;
 }
Esempio n. 12
0
 public static CharSequence getText(Context context) {
   ClipboardManager clipboard = getManager(context);
   ClipData clip = clipboard.getPrimaryClip();
   return hasText(context) ? clip.getItemAt(0).coerceToText(context) : null;
 }
Esempio n. 13
0
 private ClipData getPrimaryClip() {
   ClipboardManager clipboard =
       (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
   return clipboard.getPrimaryClip();
 }