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;
    }
  }
 @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);
     }
   }
 }
Beispiel #3
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);
    }
  }
  @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());
    }
  }
  public void copyURLButtonClicked(View v) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

    if (v.getId() == R.id.copyurlbutton) {
      ClipData clip = null;
      if (((EditText) bar.findViewById(R.id.browser_searchbar)) != null)
        clip =
            ClipData.newPlainText(
                "", ((EditText) bar.findViewById(R.id.browser_searchbar)).getText());

      if (clip != null) clipboard.setPrimaryClip(clip);
    }

    if (v.getId() == R.id.pastebutton) {
      if (clipboard.hasPrimaryClip())
        if (((EditText) bar.findViewById(R.id.browser_searchbar)) != null)
          ((EditText) bar.findViewById(R.id.browser_searchbar))
              .setText(clipboard.getText().toString());
    }

    SetupLayouts.popup.dismiss();
    if (((EditText) bar.findViewById(R.id.browser_searchbar)) != null)
      ((EditText) bar.findViewById(R.id.browser_searchbar)).setFocusableInTouchMode(true);
  }
 private boolean canPaste() {
   ClipboardManager clipMgr =
       (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
   return clipMgr.hasPrimaryClip();
 }
  @Override
  public boolean OnPrepareOptionsMenu(Menu menu) throws Throwable {
    super.OnPrepareOptionsMenu(menu);

    // The paste menu item is enabled if there is data on the clipboard.
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

    MenuItem mPasteItem = menu.findItem(R.id.menu_paste);

    // If the clipboard contains an item, enables the Paste option on the menu.
    if (clipboard.hasPrimaryClip()) {
      mPasteItem.setEnabled(true);
    } else {
      // If the clipboard is empty, disables the menu's Paste option.
      mPasteItem.setEnabled(false);
    }

    // Gets the number of notes currently being displayed.
    final boolean haveItems = getListAdapter().getCount() > 0;

    // If there are any notes in the list (which implies that one of
    // them is selected), then we need to generate the actions that
    // can be performed on the current selection.  This will be a combination
    // of our own specific actions along with any extensions that can be
    // found.
    if (haveItems) {

      // This is the selected item.
      Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId());

      // Creates an array of Intents with one element. This will be used to send an Intent
      // based on the selected menu item.
      Intent[] specifics = new Intent[1];

      // Sets the Intent in the array to be an EDIT action on the URI of the selected note.
      specifics[0] = new Intent(Intent.ACTION_EDIT, uri);

      // Creates an array of menu items with one element. This will contain the EDIT option.
      MenuItem[] items = new MenuItem[1];

      // Creates an Intent with no specific action, using the URI of the selected note.
      Intent intent = new Intent(null, uri);

      /* Adds the category ALTERNATIVE to the Intent, with the note ID URI as its
       * data. This prepares the Intent as a place to group alternative options in the
       * menu.
       */
      intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

      /*
       * Add alternatives to the menu
       */
      menu.addIntentOptions(
          Menu.CATEGORY_ALTERNATIVE, // Add the Intents as options in the alternatives group.
          Menu.NONE, // A unique item ID is not required.
          Menu.NONE, // The alternatives don't need to be in order.
          null, // The caller's name is not excluded from the group.
          specifics, // These specific options must appear first.
          intent, // These Intent objects map to the options in specifics.
          Menu.NONE, // No flags are required.
          items // The menu items generated from the specifics-to-
          // Intents mapping
          );
      // If the Edit menu item exists, adds shortcuts for it.
      if (items[0] != null) {

        // Sets the Edit menu item shortcut to numeric "1", letter "e"
        items[0].setShortcut('1', 'e');
      }
    } else {
      // If the list is empty, removes any existing alternative actions from the menu
      menu.removeGroup(Menu.CATEGORY_ALTERNATIVE);
    }

    // Displays the menu
    return true;
  }