Java Code Examples for android.content.ClipboardManager

The following examples show how to use android.content.ClipboardManager. 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: react-native-GPay   Source File: ClipboardModule.java    License: 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 Project: stynico   Source File: gifa.java    License: 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 3
Source Project: FileTransfer   Source File: MainActivity.java    License: 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 4
Source Project: delion   Source File: CustomTabToolbar.java    License: 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 5
Source Project: dtube-mobile-unofficial   Source File: DonateActivity.java    License: 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 6
@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 7
Source Project: stynico   Source File: gifa.java    License: 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 8
/**
 * 模拟输入
 *
 * @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 9
Source Project: stynico   Source 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 10
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 11
Source Project: QNotified   Source File: ViewBuilder.java    License: 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 12
Source Project: stynico   Source File: gifa.java    License: 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 Project: xposed-aweme   Source File: AweMeHook.java    License: 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 14
Source Project: hash-checker   Source File: ClipboardTest.java    License: 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 15
Source Project: styT   Source 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 16
@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 17
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 18
Source Project: ankihelper   Source File: PopupActivity.java    License: 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 19
Source Project: DNSHero   Source File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void clickToCopy(@NonNull TextView view, @NonNull String text) {
    view.setOnClickListener(v -> {
        ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        if (clipboard == null) return;
        clipboard.setPrimaryClip(ClipData.newPlainText("", text));
        Toaster.with(view.getContext()).message(R.string.copiedToClipboard).show();
    });
}
 
Example 20
Source Project: EhViewer   Source File: IdentityCookiePreference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
    super.onPrepareDialogBuilder(builder);
    if (message != null) {
        builder.setPositiveButton(R.string.settings_eh_identity_cookies_copy, (dialog, which) -> {
            ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            cmb.setPrimaryClip(ClipData.newPlainText(null, message));
            Toast.makeText(getContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();

            IdentityCookiePreference.this.onClick(dialog, which);
        });
    }
}
 
Example 21
Source Project: alpha-wallet-android   Source File: DappBrowserFragment.java    License: MIT License 5 votes vote down vote up
private void copyToClipboard(String address)
{
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(KEY_ADDRESS, address);
    if (clipboard != null) {
        clipboard.setPrimaryClip(clip);
    }
    Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
 
Example 22
Source Project: android-project-wo2b   Source File: TDevice.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void copyTextToBoard(Context context, String string)
{
	if (TextUtils.isEmpty(string))
		return;
	ClipboardManager clip = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
	clip.setText(string);
}
 
Example 23
@Override
public void copyCompanionId(String companionId) {
    ClipData clip = ClipData.newPlainText("adamant_address", companionId);
    ClipboardManager clipboard = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);

    if (clipboard != null) {
        clipboard.setPrimaryClip(clip);
        Toast.makeText(this.getApplicationContext(), R.string.address_was_copied, Toast.LENGTH_LONG).show();
    }
}
 
Example 24
private void copyWalletAddress() {
    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    // 将文本内容放到系统剪贴板里。
    if (cm != null) {
        // 创建普通字符型ClipData
        ClipData mClipData = ClipData.newPlainText("Label", walletAddress);
        // 将ClipData内容放到系统剪贴板里。
        cm.setPrimaryClip(mClipData);
    }
    ToastUtils.showToast(R.string.gathering_qrcode_copy_success);
    btnCopyAddress.setText(R.string.gathering_qrcode_copy_success);
}
 
Example 25
Source Project: Phonograph   Source File: BugReportActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void copyDeviceInfoToClipBoard() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getString(R.string.device_info), deviceInfo.toMarkdown());
    clipboard.setPrimaryClip(clip);

    Toast.makeText(BugReportActivity.this, R.string.copied_device_info_to_clipboard, Toast.LENGTH_LONG).show();
}
 
Example 26
Source Project: fastedit   Source File: FastEdit.java    License: Apache License 2.0 5 votes vote down vote up
public void copy() throws Exception {
    String selectText = getSelectText();
    if (selectText == null) {
        return;
    }
    try {
        ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setPrimaryClip(ClipData.newPlainText("copy", selectText));
    } catch (Exception e) {
        Toast.makeText(getContext(), "文字太长,复制失败!", Toast.LENGTH_SHORT).show();
        throw e;
    }
}
 
Example 27
Source Project: text_converter   Source File: ClipboardUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void setClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Copied Text", text);
    if (clipboard != null) {
        clipboard.setPrimaryClip(clip);
        Toast.makeText(context, R.string.message_copied, Toast.LENGTH_SHORT).show();
    }
}
 
Example 28
public void onClickTxtInputLink(View view) {


        if (isRadioButtonPrivate.get()) {
            final PopupMenu popup = new PopupMenu(G.fragmentActivity, view);
            //Inflating the Popup using xml file
            popup.getMenuInflater().inflate(R.menu.menu_item_copy, popup.getMenu());

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.menu_link_copy:
                            String copy;
                            copy = edtSetLink.get();
                            ClipboardManager clipboard = (ClipboardManager) G.context.getSystemService(CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("LINK_GROUP", copy);
                            clipboard.setPrimaryClip(clip);

                            break;
                    }
                    return true;
                }
            });

            popup.show(); //
        }
    }
 
Example 29
Source Project: DarkCalculator   Source File: BaseConversionActivity.java    License: MIT License 5 votes vote down vote up
private void initTextOut() {
    textOut = (TextView) findViewById(R.id.text_out);
    AutofitHelper.create(textOut).setMaxLines(5);
    textOut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClipboardManager cmb = (ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            cmb.setText(textOut.getText());
            Snackbar.make(v, "已复制转换结果", Snackbar.LENGTH_SHORT).show();
        }
    });
}
 
Example 30
Source Project: HouSi   Source File: PreferencesFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void initPreferences() {
    mSettingCurrentSourceUrlMulti = (ListPreference) findPreference("setting_current_source_url_multi");
    mSettingSwitchAlarmService = (SwitchPreference) findPreference("setting_switch_alarm_service");
    mSettingServiceStartTime = (PreferenceScreen) findPreference("setting_service_start_time");
    mSettingAlarmRepeat = (ListPreference) findPreference("setting_alarm_repeat");
    mSettingAboutService = (PreferenceScreen) findPreference("setting_about_service");
    mSettingCheckForUpdate = (PreferenceScreen) findPreference("setting_check_for_update");
    mSettingCleanCache = (PreferenceScreen) findPreference("setting_clean_cache");
    mSettingFaq = (PreferenceScreen) findPreference("setting_faq");
    mSettingFeedback = (PreferenceScreen) findPreference("setting_feedback");
    mSettingAbout = (PreferenceScreen) findPreference("setting_about");
    mSettingAboutCache = (PreferenceScreen) findPreference("setting_about_cache");

    mSettingCurrentSourceUrlMulti.setOnPreferenceClickListener(this);
    mSettingServiceStartTime.setOnPreferenceClickListener(this);
    mSettingCheckForUpdate.setOnPreferenceClickListener(this);
    mSettingCleanCache.setOnPreferenceClickListener(this);
    mSettingFaq.setOnPreferenceClickListener(this);
    mSettingFeedback.setOnPreferenceClickListener(this);
    mSettingAbout.setOnPreferenceClickListener(this);

    mSettingCurrentSourceUrlMulti.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String[] urlEntries = (String[]) ((ListPreference) preference).getEntries();

            ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newRawUri("url", Uri.parse(urlEntries[Integer.parseInt((String) newValue)]));
            clipboardManager.setPrimaryClip(clipData);
            Toast.makeText(getActivity(), getString(R.string.clipboard_hint), Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    initSourceUrl();
    initSwitchAlarmService();
    initVersionInfo();
    initCache();
}