android.content.ClipboardManager Java Examples

The following examples show how to use android.content.ClipboardManager. 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: ClipboardModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactMethod
public void getString(Promise promise) {
  try {
    ClipboardManager clipboard = getClipboardService();
    ClipData clipData = clipboard.getPrimaryClip();
    if (clipData == null) {
      promise.resolve("");
    } else if (clipData.getItemCount() >= 1) {
      ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
      promise.resolve("" + firstItem.getText());
    } else {
      promise.resolve("");
    }
  } catch (Exception e) {
    promise.reject(e);
  }
}
 
Example #2
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 #3
Source File: ChatSelectTouchListener.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_copy:
            ClipboardManager clipboard = (ClipboardManager) mRecyclerView.getContext()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setPrimaryClip(
                    ClipData.newPlainText("IRC Messages", getSelectedText()));
            clearSelection();
            mode.finish();
            return true;
        case R.id.action_share:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_TEXT, getSelectedText());
            intent.setType("text/plain");
            mRecyclerView.getContext().startActivity(Intent.createChooser(intent,
                    mRecyclerView.getContext().getString(R.string.message_share_title)));
            clearSelection();
            mode.finish();
            return true;
        default:
            return false;
    }
}
 
Example #4
Source File: ClipboardManagerUtil.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
public static CharSequence getText() {
    android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
    if (APILevel.require(11)) {
        ClipboardManager cm = (ClipboardManager) clipboardManager;
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        if (clipData != null
                && description != null
                && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
            return clipData.getItemAt(0).getText();
        else
            return null;
    } else {
        return clipboardManager.getText();
    }
}
 
Example #5
Source File: gifa.java    From stynico with MIT License 6 votes vote down vote up
public void cclick()
   {
EditText et=(EditText) findViewById(R.id.mainEditText1);
String os =et.getText().toString();
char[] a = os.toCharArray();
StringBuffer b = new StringBuffer("");
String mo ="敏ۣۖ";
for (int i=0;i < a.length;i++)
{
    b.append(mo.replace('敏', a[i])) ;
    ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    manager.setText(b);
}

TextView t=(TextView) findViewById(R.id.mainTextView1);
t.setText(b);
   }
 
Example #6
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 #7
Source File: MainActivity.java    From FileTransfer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard != null && clipboard.hasPrimaryClip() && clipboard.getPrimaryClip() != null) {
        ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
        if (item != null && item.getText() != null && item.getText().length() > 0 && !item.getText().equals(mAlreadyWrited)) {
            File file = new File(Constants.DIR, "clipboard_" + String.valueOf(System.currentTimeMillis()) + ".txt");
            try {
                FileUtils.writeByteArrayToFile(file, item.getText().toString().getBytes(), false);
                Toast.makeText(this, "已把剪切板中内容写入到该文件中", Toast.LENGTH_SHORT).show();
                RxBus.get().post(Constants.RxBusEventType.LOAD_BOOK_LIST, 0);
                mAlreadyWrited = item.getText().toString();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(this, "文件写入失败", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
 
Example #8
Source File: AweMeHook.java    From xposed-aweme with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {

    if (!mUserConfigManager.isCopyVideoDesc()) {
        return false;
    }

    try {
        // 把信息复制到粘贴板上
        ClipboardManager cm = (ClipboardManager)
                getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setPrimaryClip(ClipData.newPlainText(null, ((TextView) v).getText()));
        ToastUtil.show("内容已复制到粘贴板!");
    } catch (Throwable tr) {
        Alog.e("出异常了", tr);
        ToastUtil.show("内容复制到粘贴板出错了!");
    }
    return true;
}
 
Example #9
Source File: CustomTabToolbar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (v == mCloseButton) {
        return showAccessibilityToast(v, getResources().getString(R.string.close_tab));
    } else if (v == mCustomActionButton) {
        return showAccessibilityToast(v, mCustomActionButton.getContentDescription());
    } else if (v == mTitleUrlContainer) {
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("url", mUrlBar.getText());
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #10
Source File: DonateActivity.java    From dtube-mobile-unofficial with Apache License 2.0 6 votes vote down vote up
public void copyAddress(View v){
    String address = null;
    switch (v.getId()){
        case R.id.copybtc:
            address = "148kJvCVMmHfEPKxerz6Y4jdc94765c5VK";
            break;
        case R.id.copyeth:
            address = "0x944e6bc2c86144B89EaF7612782a5F570F5967a2";
            break;
        case R.id.copyltc:
            address = "LPxnm3UQ7VpL9stRCgECZgxkXuvb2jw1ik";
            break;
    }


    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("address", address);
    clipboard.setPrimaryClip(clip);

    Toast.makeText(this,R.string.copied,Toast.LENGTH_LONG).show();
}
 
Example #11
Source File: ClipboardTest.java    From hash-checker with Apache License 2.0 6 votes vote down vote up
@Test
public void validateClipboardTest() {
    InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
        Activity activity = activityTestRule.getActivity();

        String text = "Test text";
        new Clipboard(
                activity,
                text
        ).copy();

        ClipboardManager clipboardManager = (ClipboardManager) activity.getSystemService(
                Context.CLIPBOARD_SERVICE
        );

        assertEquals(
                clipboardManager.getPrimaryClip().getItemAt(0).coerceToText(
                        activity
                ),
                text
        );
    });

}
 
Example #12
Source File: gifa.java    From stynico with MIT License 6 votes vote down vote up
public void click()
   {
EditText et=(EditText) findViewById(R.id.mainEditText1);
String os =et.getText().toString();
char[] a = os.toCharArray();
StringBuffer b = new StringBuffer("");
String mo ="ζั͡爱 ั͡✾";
for (int i=0;i < a.length;i++)
{
    b.append(mo.replace('爱', a[i])) ;
    ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    manager.setText(b);
}
TextView t=(TextView) findViewById(R.id.mainTextView1);
t.setText(b);
   }
 
Example #13
Source File: ViewBuilder.java    From QNotified with GNU General Public License v3.0 6 votes vote down vote up
public static LinearLayout newDialogClickableItemClickToCopy(final Context ctx, String title, String value, ViewGroup vg, boolean attach) {
    return newDialogClickableItem(ctx, title, value, new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Context c = v.getContext();
            String msg = ((TextView) v).getText().toString();
            if (msg.length() > 0) {
                ClipboardManager cm = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
                if (cm != null) {
                    cm.setText(msg);
                    Utils.showToastShort(c, "已复制文本");
                }
            }
            return true;
        }
    }, vg, attach);
}
 
Example #14
Source File: ManChapterItemOnClickListener.java    From Man-Man with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(final View v) {
    PopupMenu pm = new PopupMenu(mContext, v);
    pm.inflate(R.menu.chapter_item_popup);
    pm.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.share_link_popup_menu_item:
                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    sendIntent.setType("text/plain");
                    sendIntent.putExtra(Intent.EXTRA_TITLE, current.getName());
                    sendIntent.putExtra(Intent.EXTRA_TEXT, current.getUrl());
                    mContext.startActivity(Intent.createChooser(sendIntent, mContext.getString(R.string.share_link)));
                    return true;
                case R.id.copy_link_popup_menu_item:
                    ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                    Toast.makeText(mContext.getApplicationContext(), mContext.getString(R.string.copied) + " " + current.getUrl(), Toast.LENGTH_SHORT).show();
                    clipboard.setPrimaryClip(ClipData.newPlainText(current.getName(), current.getUrl()));
                    return true;
            }
            return false;
        }
    });
    pm.show();
}
 
Example #15
Source File: TransferTicketDetailActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private void onUserTransaction(String hash)
{
    hideDialog();
    dialog = new AWalletAlertDialog(this);
    dialog.setTitle(R.string.transaction_succeeded);
    dialog.setMessage(hash);
    dialog.setButtonText(R.string.copy);
    dialog.setButtonListener(v -> {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("transaction hash",
                EthereumNetworkBase.getEtherscanURLbyNetwork(token.tokenInfo.chainId) + "tx/" + hash);
        clipboard.setPrimaryClip(clip);
        dialog.dismiss();
        sendBroadcast(new Intent(PRUNE_ACTIVITY));
    });
    dialog.setOnDismissListener(v -> {
        dialog.dismiss();
        sendBroadcast(new Intent(PRUNE_ACTIVITY));
        new HomeRouter().open(this, true);
        finish();
    });
    dialog.show();
}
 
Example #16
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 #17
Source File: gifa.java    From stynico with MIT License 6 votes vote down vote up
public void c_styTool()
   {
EditText et=(EditText) findViewById(R.id.mainEditText1);
String os =et.getText().toString();
char[] a = os.toCharArray();
StringBuffer b = new StringBuffer("");
String mo =getResources().getString(R.string.android_gifa); 
for (int i=0;i < a.length;i++)
{
    b.append(mo.replace('n', a[i])) ;
    ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    manager.setText(b);
}
TextView t=(TextView) findViewById(R.id.mainTextView1);
t.setText(b);
   }
 
Example #18
Source File: BaseAccessibilityService.java    From SmsCode with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 模拟输入
 *
 * @param nodeInfo nodeInfo
 * @param text text
 */
public void inputText(AccessibilityNodeInfo nodeInfo, CharSequence text) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bundle args = new Bundle();
        args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
        nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    } else {
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        if (cm == null)
            return;
        ClipData clipData = ClipData.newPlainText("label", text);
        cm.setPrimaryClip(clipData);
        nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
        nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE);
    }
}
 
Example #19
Source File: Util.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
private static void showDetailsDialog(Context context, String title, List<String> headers, final List<String> details) {
    ListView listView = new ListView(context);
    listView.setAdapter(new DetailsAdapter(context, headers, details));
    listView.setDivider(null);
    listView.setScrollbarFadingEnabled(false);

    // Let the user long-click on a row to copy its value to the clipboard
    final Context contextRef = context;
    listView.setOnItemLongClickListener((parent, view, pos, id) -> {
        TextView nameView = view.findViewById(R.id.detail_name);
        TextView detailsView = view.findViewById(R.id.detail_value);
        if (nameView == null || detailsView == null) {
            return false;
        }

        CharSequence name = nameView.getText();
        CharSequence value = detailsView.getText();

        ClipboardManager clipboard = (ClipboardManager) contextRef.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(name, value);
        clipboard.setPrimaryClip(clip);

        toast(contextRef, "Copied " + name + " to clipboard");

        return true;
    });

    new AlertDialog.Builder(context)
            // .setIcon(android.R.drawable.ic_dialog_info)
            .setTitle(title)
            .setView(listView)
            .setPositiveButton(R.string.common_close, (dialog, i) -> dialog.dismiss())
            .show();
}
 
Example #20
Source File: InfoRecyclerViewAdapter.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    String color = (String) view.getTag();
    if (color != null) {
        ClipboardManager clipboard = (ClipboardManager) view.getContext()
                .getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("label", color);
        clipboard.setPrimaryClip(clip);

        Toast.makeText(view.getContext(),
                R.string.copied_to_clipboard,
                Toast.LENGTH_SHORT).show();
    }
}
 
Example #21
Source File: MainActivity.java    From db-viewpager-image with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initDataSource();
    mWidget = (DbVPager) findViewById(R.id.db_vpager);
    tv_showText = (TextView) findViewById(R.id.tv_showText);
    btn_website = (TextView) findViewById(R.id.btn_website);
    btn_website.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            if (TextUtils.isEmpty(btn_website.getText())) {
                return false;
            }
            ClipboardManager manager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData data = ClipData.newPlainText("Lable", btn_website.getText());
            manager.setPrimaryClip(data);
            Toast.makeText(MainActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    mWidget.setBarPosition(DbVPager.BarPositon.BOTTOM);
    mWidget.setSource(dataSource);
    tv_showText.setText("当前分类:" + dataSource.get(0).groupName);
    mWidget.addTabChangeListenr(new DbVPager.DbCallbackListener() {
        @Override
        public void callback(int index, String text) {
            tv_showText.setText("当前分类:" + text);
        }
    });
    mWidget.show();
}
 
Example #22
Source File: CopyTextActivity.java    From Quran-For-My-Android with Apache License 2.0 5 votes vote down vote up
private void copyAllToClipBoard() {
	ClipData clip = ClipData.newPlainText("text", editText.getText());
	ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
	clipboard.setPrimaryClip(clip);

	Toast.makeText(getApplicationContext(), "Full Text Copied To Clipboard",
			Toast.LENGTH_SHORT).show();
}
 
Example #23
Source File: MainActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private String getTextFromClipboard() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard != null) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0 && clip.getItemAt(0).getText() != null) {
            return clip.getItemAt(0).getText().toString();
        }
    }
    return null;
}
 
Example #24
Source File: KILL.java    From stynico with MIT License 5 votes vote down vote up
@Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id)
      {
          TextView tv_appName = (TextView) view.findViewById(R.id.tv_app_name);
          TextView tv_processName = (TextView) view.findViewById(R.id.tv_app_process_name);

          String appName = tv_appName.getText().toString();
          String processName = tv_processName.getText().toString();

          Toast.makeText(KILL.this, "已复制" + "应用+进程", Toast.LENGTH_SHORT).show();
	ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
	manager.setText("应用: " + appName + "\n进程: " + processName);
}
 
Example #25
Source File: RxClipboardTool.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
/**
 * 获取剪贴板的文本
 *
 * @return 剪贴板的文本
 */
public static CharSequence getText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).coerceToText(context);
    }
    return null;
}
 
Example #26
Source File: SubmitConfirmationCodeFragment.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (!mHasResumed) {
        // Don't check for codes before we've even had the chance to send one.
        mHasResumed = true;
        return;
    }

    ClipData clip = ContextCompat.getSystemService(requireContext(), ClipboardManager.class)
            .getPrimaryClip();
    if (clip != null && clip.getItemCount() == 1) {
        CharSequence candidate = clip.getItemAt(0).getText();
        if (candidate != null && candidate.length() == VERIFICATION_CODE_LENGTH) {
            try {
                Integer.parseInt(candidate.toString());

                // We have a number! Try to submit it.
                mConfirmationCodeEditText.setText(candidate);
            } catch (NumberFormatException ignored) {
                // Turns out it wasn't a number
            }
        }
    }

    mLooper.removeCallbacks(mCountdown);
    mLooper.postDelayed(mCountdown, TICK_INTERVAL_MILLIS);
}
 
Example #27
Source File: MyAddressActivity.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(KEY_ADDRESS, wallet.getAddress());
    if (clipboard != null) {
        clipboard.setPrimaryClip(clip);
    }
    Toast.makeText(this, "Copied to clipboard", Toast.LENGTH_SHORT).show();
}
 
Example #28
Source File: AboutFragment.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private void copyToClipboard(String text) {
    ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    if (cmb != null) {
        cmb.setPrimaryClip(ClipData.newPlainText(null, text));
        Toast.makeText(getActivity(), R.string.settings_about_donate_copied, Toast.LENGTH_SHORT).show();
    }
}
 
Example #29
Source File: EditFragment.java    From masterpassword with GNU General Public License v3.0 5 votes vote down vote up
@OnClick(R.id.password)
void copyPasswordToClipboard() {
    final ClipboardManager clipboard = (ClipboardManager) App.get()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("password", password.getText());
    clipboard.setPrimaryClip(clip);

    Intent service = new Intent(App.get(), ClearClipboardService.class);
    App.get().startService(service);
}
 
Example #30
Source File: CatnutUtils.java    From catnut with MIT License 5 votes vote down vote up
/**
 * copy plain text to clip board
 *
 * @param context
 * @param tag
 * @param text
 * @param toastText may null, no toast at all
 */
public static void copy2ClipBoard(Context context, String tag, String text, String toastText) {
	ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
	ClipData clip = ClipData.newPlainText(tag, text);
	clipboard.setPrimaryClip(clip);
	if (toastText != null) {
		Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show();
	}
}