當前位置: 首頁>>代碼示例>>Java>>正文


Java ClipboardManager類代碼示例

本文整理匯總了Java中android.content.ClipboardManager的典型用法代碼示例。如果您正苦於以下問題:Java ClipboardManager類的具體用法?Java ClipboardManager怎麽用?Java ClipboardManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClipboardManager類屬於android.content包,在下文中一共展示了ClipboardManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onMenuItemClick

import android.content.ClipboardManager; //導入依賴的package包/類
@Override
public boolean onMenuItemClick(MenuItem item, LogLine logLine) {
    if (logLine != null) {
        switch (item.getItemId()) {
            case CONTEXT_MENU_COPY_ID:
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

                clipboard.setPrimaryClip(ClipData.newPlainText(null, logLine.getOriginalLine()));
                Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
                return true;
            case CONTEXT_MENU_FILTER_ID:

                if (logLine.getProcessId() == -1) {
                    // invalid line
                    return false;
                }

                showSearchByDialog(logLine);
                return true;
        }
    }
    return false;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:24,代碼來源:LogcatActivity.java

示例2: copyText

import android.content.ClipboardManager; //導入依賴的package包/類
@Override
public void copyText() {
    if (checkNull()) {
        view.showCopyTextError();
        return;
    }

    ClipboardManager manager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
    ClipData clipData = null;
    switch (type) {
        case TYPE_ZHIHU:
            clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + zhihuDailyStory.getBody()).toString());
            break;
        case TYPE_GUOKR:
            clipData = ClipData.newPlainText("text", Html.fromHtml(guokrStory).toString());
            break;
        case TYPE_DOUBAN:
            clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + doubanMomentStory.getContent()).toString());
    }
    manager.setPrimaryClip(clipData);
    view.showTextCopied();

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:DetailPresenter.java

示例3: getIntent

import android.content.ClipboardManager; //導入依賴的package包/類
/**
 * 獲取剪貼板的意圖
 *
 * @return 剪貼板的意圖
 */
public static Intent getIntent() {
    ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getIntent();
    }
    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:ClipboardUtils.java

示例4: onTransaction

import android.content.ClipboardManager; //導入依賴的package包/類
private void onTransaction(String hash) {
    hideDialog();
    dialog = new AlertDialog.Builder(this)
            .setTitle(R.string.transaction_succeeded)
            .setMessage(hash)
            .setPositiveButton(R.string.button_ok, (dialog1, id) -> {
                finish();
            })
            .setNeutralButton(R.string.copy, (dialog1, id) -> {
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("transaction hash", hash);
                clipboard.setPrimaryClip(clip);
                finish();
            })
            .create();
    dialog.show();
}
 
開發者ID:TrustWallet,項目名稱:trust-wallet-android,代碼行數:18,代碼來源:ConfirmationActivity.java

示例5: onLongClick

import android.content.ClipboardManager; //導入依賴的package包/類
@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);
        Tab tab = getCurrentTab();
        if (tab == null) return false;
        String url = tab.getOriginalUrl();
        ClipData clip = ClipData.newPlainText("url", url);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:20,代碼來源:CustomTabToolbar.java

示例6: onBindViewHolder

import android.content.ClipboardManager; //導入依賴的package包/類
@Override
public void onBindViewHolder(CodigoDeBarraAdapter.ViewHolder holder, final int position) {

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Codigo de barras copiado", extractList.get(position).getCodigoDeBarras());
            clipboard.setPrimaryClip(clip);

            Toast.makeText(v.getContext(), "Codigo de barras copiado", Toast.LENGTH_LONG).show();
        }
    });

    holder.bindExtractViewModel(extractList.get(position));
}
 
開發者ID:ViniciusSossela,項目名稱:meuboleto,代碼行數:17,代碼來源:CodigoDeBarraAdapter.java

示例7: TerminalLinesAdapter

import android.content.ClipboardManager; //導入依賴的package包/類
public TerminalLinesAdapter(Activity a, List<TerminalPrintedLine> lines) {
    this.activity = a;
    this.lines = lines;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    uiHandler = new Handler();
    copyRunnable = new Runnable() {
        @Override
        public void run() {
            clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                if (!copyLine.equals("")) {
                    clipboardManager.setPrimaryClip(ClipData.newPlainText("OneSheeldClipboard", copyLine));
                    Toast.makeText(activity.getApplicationContext(), R.string.terminal_line_copied_toast, Toast.LENGTH_SHORT).show();
                }else
                    Toast.makeText(activity.getApplicationContext(), R.string.terminal_couldnt_copy_empty_line_toast, Toast.LENGTH_SHORT).show();
            }
        }
    };
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:21,代碼來源:TerminalLinesAdapter.java

示例8: onCreate

import android.content.ClipboardManager; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    context=getApplicationContext();

    mClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    createNotificationChannel();


    listener = new ClipboardManager.OnPrimaryClipChangedListener() {
        public void onPrimaryClipChanged() {
            performClipboardCheck();
        }
    };
}
 
開發者ID:emmanuelkehinde,項目名稱:TwittaSave-Android,代碼行數:18,代碼來源:AutoListenService.java

示例9: getString

import android.content.ClipboardManager; //導入依賴的package包/類
@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
    Context context = mWXSDKInstance.getContext();
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    Map<String, Object> map = new HashMap<>(2);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        ClipData.Item item = clip.getItemAt(0);
        CharSequence text = coerceToText(context, item);

        map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
        map.put(DATA, text != null ? text : "");
    } else {
        map.put(RESULT, RESULT_FAILED);
        map.put(DATA, "");
    }

    if (null != callback) {
        callback.invoke(map);
    }
}
 
開發者ID:erguotou520,項目名稱:weex-uikit,代碼行數:24,代碼來源:WXClipboardModule.java

示例10: setPrimaryClip

import android.content.ClipboardManager; //導入依賴的package包/類
private void setPrimaryClip(final ClipData clipData) {
    try {
        mUiThreadRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ClipboardManager clipboardManager =
                        (ClipboardManager) InstrumentationRegistry.getTargetContext().getSystemService(CLIPBOARD_SERVICE);
                clipboardManager.setPrimaryClip(clipData);
            }
        });
        // ensure clipboard listener has time to react to the changes
        // so that subsequent calls can verify what the listener has done.
        delay(90);
    } catch (Throwable t) {
        fail("Unexpected error in setting clipboard. " + t.getMessage());
    }
}
 
開發者ID:orionlee,項目名稱:aDictOnCopy,代碼行數:18,代碼來源:DictionaryOnCopyServiceTest.java

示例11: paste

import android.content.ClipboardManager; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void paste() {
    ClipboardManager clipboard = (
            ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    //noinspection StatementWithEmptyBody
    if (clipboard.getText() == null || clipboard.getText() == "") {
        //nothing to paste
    }
    if (!clipboard.hasText()) {
        return;
    }
    if (getSelectionEnd() > getSelectionStart()) {
        getText().replace(getSelectionStart(), getSelectionEnd(), clipboard.getText());
    } else {
        getText().replace(getSelectionEnd(), getSelectionStart(), clipboard.getText());
    }
}
 
開發者ID:Light-Team,項目名稱:ModPE-IDE-Source,代碼行數:19,代碼來源:LModEditor.java

示例12: ua

import android.content.ClipboardManager; //導入依賴的package包/類
public void ua()
   {
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);
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:17,代碼來源:gifa.java

示例13: onOptionsItemSelected

import android.content.ClipboardManager; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.fenlei_share:
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, url);
            startActivity(Intent.createChooser(intent, getTitle()));
            break;
        case R.id.fenlei_web_open:
            Intent intent1 = new Intent();
            intent1.setAction(Intent.ACTION_VIEW);
            intent1.setData(Uri.parse(url));
            startActivity(intent1);
            break;
        case R.id.fenlei_copy_link:
            ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newRawUri("label", Uri.parse(url));
            clipboardManager.setPrimaryClip(clipData);
            Snackbar.make(mWebView, "已複製到黏貼版", Snackbar.LENGTH_SHORT).show();
            break;
    }
    return true;
}
 
開發者ID:struggledhard,項目名稱:USay,代碼行數:26,代碼來源:WebViewFenLeiActivity.java

示例14: copy

import android.content.ClipboardManager; //導入依賴的package包/類
/**
 * 實現文本複製功能
 */
public static void copy(String content, Context context) {
    if (context == null || content == null) {
        return;
    }
    // 得到剪貼板管理器
    ClipboardManager cmb = (ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    if (cmb == null) {
        return;
    }
    try {
        cmb.setPrimaryClip(ClipData.newPlainText(null, content.trim()));
    } catch (Exception e) {
        LogUtils.e(e);
    }
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:20,代碼來源:ClipboardUtil.java

示例15: onTouch

import android.content.ClipboardManager; //導入依賴的package包/類
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
	if (mSearch.getCompoundDrawables()[2] != null) {
		boolean tappedX = event.getX() > (mSearch.getWidth()
				- mSearch.getPaddingRight() - mIcon.getIntrinsicWidth());
		if (tappedX) {
			if (event.getAction() == MotionEvent.ACTION_UP) {
				if (mSearch.hasFocus()) {
					ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
					ClipData clip = ClipData.newPlainText("label", mSearch.getText()
							.toString());
					clipboard.setPrimaryClip(clip);
					Utils.showToast(
							mActivity,
							mActivity.getResources().getString(
									R.string.message_text_copied));
				} else {
					refreshOrStop();
				}
			}
			return true;
		}
	}
	return false;
}
 
開發者ID:NewCasino,項目名稱:browser,代碼行數:27,代碼來源:BrowserActivity.java


注:本文中的android.content.ClipboardManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。