Java Code Examples for android.content.ClipData

The following examples show how to use android.content.ClipData. 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: 365browser   Author: mogoweb   File: Clipboard.java    License: Apache License 2.0 6 votes vote down vote up
public String clipDataToHtmlText(ClipData clipData) {
    ClipDescription description = clipData.getDescription();
    if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
        return clipData.getItemAt(0).getHtmlText();
    }

    if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        CharSequence text = clipData.getItemAt(0).getText();
        if (!(text instanceof Spanned)) return null;
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) {
            return ApiCompatibilityUtils.toHtml(
                    spanned, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
        }
    }
    return null;
}
 
Example #2
Source Project: delion   Author: derry   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 #3
Source Project: ETHWallet   Author: snailflying   File: ConfirmationActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #4
Source Project: LaunchTime   Author: quaap   File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void startDragCategory(View view, String category) {
    ClipData data = ClipData.newPlainText(category, category);
    View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
    //view.startDrag(data, shadowBuilder, view, 0);

    boolean dragstarted;
    if (Build.VERSION.SDK_INT>=24) {
        dragstarted = view.startDragAndDrop(data, shadowBuilder, view, 0);
    } else {
        dragstarted = view.startDrag(data, shadowBuilder, view, 0);
    }

    if (dragstarted) {
        mDragDropSource = mCategoriesLayout;
        if (!Categories.isSpeacialCategory(category)) {
            showRemoveDropzone();
        }
        showHiddenCategories();
    }
    cancelHide();
}
 
Example #5
Source Project: a   Author: 804463258   File: CrashHandler.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 收集错误信息.发送到服务器
 *
 * @return 处理了该异常返回true, 否则false
 */
private boolean handleException(Throwable ex) {
    if (ex == null) {
        return false;
    }
    //收集设备参数信息
    collectDeviceInfo(mContext);
    //添加自定义信息
    addCustomInfo();
    try {
        //复制错误报告到剪贴板
        ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText(null, ex.getMessage());
        if (clipboard != null) {
            clipboard.setPrimaryClip(clipData);
        }
        //使用Toast来显示异常信息
        new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(mContext, ex.getMessage(), Toast.LENGTH_LONG).show());
    } catch (Exception ignored) {
    }
    //保存日志文件
    saveCrashInfo2File(ex);
    return false;
}
 
Example #6
Source Project: styT   Author: stytooldex   File: Main2Activity.java    License: Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
    if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null) return;
    Uri[] results = null;
    if (resultCode == AppCompatActivity.RESULT_OK) {
        if (intent != null) {
            String dataString = intent.getDataString();
            ClipData clipData = intent.getClipData();
            if (clipData != null) {
                results = new Uri[clipData.getItemCount()];
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    results[i] = item.getUri();
                }
            }
            if (dataString != null)
                results = new Uri[]{Uri.parse(dataString)};
        }
    }
    uploadMessageAboveL.onReceiveValue(results);
    uploadMessageAboveL = null;
}
 
Example #7
Source Project: javaide   Author: tranleduy2000   File: LogcatActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #8
Source Project: 365browser   Author: mogoweb   File: SelectFileDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(Uri result) {
    mCameraOutputUri = result;
    if (mCameraOutputUri == null && captureCamera()) {
        onFileNotSelected();
        return;
    }

    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    camera.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        camera.setClipData(ClipData.newUri(
                mWindowAndroid.getApplicationContext().getContentResolver(),
                UiUtils.IMAGE_FILE_PATH, mCameraOutputUri));
    }
    if (mDirectToCamera) {
        mWindow.showIntent(camera, mCallback, R.string.low_memory_error);
    } else {
        launchSelectFileWithCameraIntent(true, camera);
    }
}
 
Example #9
Source Project: DanDanPlayForAndroid   Author: xyoye   File: ShooterSubActivity.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.about_download) {
        new CommonDialog.Builder(ShooterSubActivity.this)
                .setAutoDismiss()
                .setCancelListener(dialog -> {
                    String link = "https://secure.assrt.net/user/logon.xml";
                    ClipboardManager clipboardManagerMagnet = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData mClipDataMagnet = ClipData.newPlainText("Label", link);
                    if (clipboardManagerMagnet != null) {
                        clipboardManagerMagnet.setPrimaryClip(mClipDataMagnet);
                        ToastUtils.showShort("登录链接已复制");
                    }
                })
                .build()
                .show(getResources().getString(R.string.about_download_subtitle), "关于API", "确定", "复制登录链接");
    }
    return super.onOptionsItemSelected(item);
}
 
Example #10
Source Project: user-interface-samples   Author: android   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    TextView thisTextView = (TextView) v;
    String dragContent = "Dragged Text: " + thisTextView.getText();

    //Set the drag content and type.
    ClipData.Item item = new ClipData.Item(dragContent);
    ClipData dragData = new ClipData(dragContent,
            new String[] {ClipDescription.MIMETYPE_TEXT_PLAIN}, item);

    //Set the visual look of the dragged object.
    //Can be extended and customized. Default is used here.
    View.DragShadowBuilder dragShadow = new View.DragShadowBuilder(v);

    // Starts the drag, note: global flag allows for cross-application drag.
    v.startDragAndDrop(dragData, dragShadow, null, DRAG_FLAG_GLOBAL);

    return false;
}
 
Example #11
Source Project: FireFiles   Author: gigabytedevelopers   File: StandaloneActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));
    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);
        }
        else{
            intent.setData(uris[0]);
        }
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example #12
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FeedbackActivity.java    License: MIT License 6 votes vote down vote up
@OnClick({R.id.feedback_by_qq_rl, R.id.feedback_by_qq_group_rl, R.id.feedback_more_rl})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.feedback_by_qq_rl:
            String qq = qqTv.getText().toString();
            ClipboardManager qqCM = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData qqCD = ClipData.newPlainText("Label", qq);
            if (qqCM != null) {
                qqCM.setPrimaryClip(qqCD);
                ToastUtils.showShort("已复制QQ号:" + qq);
            }
            break;
        case R.id.feedback_by_qq_group_rl:
            String qqGroup = qqGroupTv.getText().toString();
            ClipboardManager qqGCM = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData qqGCD = ClipData.newPlainText("Label", qqGroup);
            if (qqGCM != null) {
                qqGCM.setPrimaryClip(qqGCD);
                ToastUtils.showShort("已复制QQ群号:" + qqGroup);
            }
            break;
        case R.id.feedback_more_rl:
            showDialog();
            break;
    }
}
 
Example #13
Source Project: pc-android-controller-android   Author: kaixuanluo   File: AccessUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void inputText(Context context, AccessibilityService service, AccessibilityNodeInfo nodeInfo,
                                 final String hello) {
        //找到当前获取焦点的view
//        AccessibilityNodeInfo target = nodeInfo.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
        AccessUtil.findNodeInfosByName(nodeInfo, "android.widget.EditText");
        AccessibilityNodeInfo target = editText;
        if (target == null) {
            L.d("inputHello: null");

            return;
        } else {
            L.d("inputHello: not null " + target.getText());
        }
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("message", hello);
        clipboard.setPrimaryClip(clip);
        L.d("设置粘贴板");
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//            target.performAction(AccessibilityNodeInfo.ACTION_PASTE);
//        }
        target.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
        L.d("获取焦点");
        target.performAction(AccessibilityNodeInfo.ACTION_PASTE);
        L.d("粘贴内容");
//        openNext2("发送", nodeInfo, service);//点击发送
    }
 
Example #14
Source Project: 365browser   Author: mogoweb   File: SelectionPopupController.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public boolean canPasteAsPlainText() {
    // String resource "paste_as_plain_text" only exist in O.
    // Also this is an O feature, we need to make it consistant with TextView.
    if (!BuildInfo.isAtLeastO()) return false;
    if (!mCanEditRichlyForPastePopup) return false;
    ClipboardManager clipMgr =
            (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
    if (!clipMgr.hasPrimaryClip()) return false;

    ClipData clipData = clipMgr.getPrimaryClip();
    ClipDescription description = clipData.getDescription();
    CharSequence text = clipData.getItemAt(0).getText();
    boolean isPlainType = description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    // On Android, Spanned could be copied to Clipboard as plain_text MIME type, but in some
    // cases, Spanned could have text format, we need to show "paste as plain text" when
    // that happens.
    if (isPlainType && (text instanceof Spanned)) {
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) return true;
    }
    return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
}
 
Example #15
Source Project: XposedSmsCode   Author: tianma8023   File: ClipboardUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void copyToClipboard(Context context, String text) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (cm == null) {
        XLog.e("Copy failed, clipboard manager is null");
        return;
    }
    ClipData clipData = ClipData.newPlainText("Copy text", text);
    cm.setPrimaryClip(clipData);
    XLog.i("Copy to clipboard succeed");
}
 
Example #16
Source Project: open-rmbt   Author: alladin-IT   File: RMBTSyncRequestCodeFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem mi)
{
    if (mi.getItemId() == codeText.getId())
    {
    	ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    	ClipData clip = ClipData.newPlainText("sync_code", codeText.getText());
    	clipboard.setPrimaryClip(clip);
        return true;
    }
    return super.onContextItemSelected(mi);
}
 
Example #17
Source Project: Android-REST-API-Explorer   Author: OneNoteDev   File: SnippetDetailFragment.java    License: MIT License 5 votes vote down vote up
@TargetApi(11)
private void clipboard11(TextView tv) {
    android.content.ClipboardManager clipboardManager =
            (android.content.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("OneNote", tv.getText());
    clipboardManager.setPrimaryClip(clipData);
}
 
Example #18
Source Project: pandora   Author: whataa   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void copy2ClipBoard(String msg) {
    ClipboardManager cm = (ClipboardManager)
            CONTEXT.getSystemService(Context.CLIPBOARD_SERVICE);
    try {
        ClipData mClipData = ClipData.newPlainText("text", msg);
        cm.setPrimaryClip(mClipData);
        Utils.toast(R.string.pd_copy_2_clipboard);
    } catch (Throwable t) {
        Utils.toast(t.getMessage());
    }
}
 
Example #19
Source Project: QPM   Author: ZhuoKeTeam   File: ClipboardUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取剪贴板的意图
 *
 * @return 剪贴板的意图
 */
public static Intent getIntent() {
    ClipboardManager cm = (ClipboardManager) Utils.getApp().getSystemService(Context.CLIPBOARD_SERVICE);
    //noinspection ConstantConditions
    ClipData clip = cm.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getIntent();
    }
    return null;
}
 
Example #20
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ClipboardManagerUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static boolean hasText() {
    android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
    if (APILevel.require(11)) {
        ClipboardManager cm = (ClipboardManager) clipboardManager;
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        return clipData != null
                && description != null
                && (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
    } else {
        return clipboardManager.hasText();
    }
}
 
Example #21
Source Project: SkyTube   Author: ram-on   File: Linker.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void longClick(String clickedText) {
	AlertDialog.Builder builder = new AlertDialog.Builder(ctx)
			.setTitle(clickedText)
			.setItems(new CharSequence[] {
							ctx.getString(R.string.open_in_browser),
							ctx.getString(R.string.copy_url),
							ctx.getString(R.string.share_via)},
					(dialog, which) -> {
						switch (which) {
							case 0:
								SkyTubeApp.viewInBrowser(clickedText, ctx);
								break;
							case 1:
								ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
								ClipData clip = ClipData.newPlainText("URL", clickedText);
								clipboard.setPrimaryClip(clip);
								Toast.makeText(ctx, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show();
								break;
							case 2:
								Intent intent = new Intent(Intent.ACTION_SEND);
								intent.setType("text/plain");
								intent.putExtra(Intent.EXTRA_TEXT, clickedText);
								ctx.startActivity(Intent.createChooser(intent, ctx.getString(R.string.share_via)));
								break;
						}
					});
	builder.create().show();
}
 
Example #22
Source Project: codeexamples-android   Author: vogellacompany   File: ClipboardSample.java    License: Eclipse Public License 1.0 5 votes vote down vote up
void updateClipData() {
    ClipData clip = mClipboard.getPrimaryClip();
    String[] mimeTypes = clip != null ? clip.getDescription().filterMimeTypes("*/*") : null;
    mMimeTypes.setText("");
    if (mimeTypes != null) {
        for (int i=0; i<mimeTypes.length; i++) {
            mMimeTypes.append(mimeTypes[i]);
            mMimeTypes.append("\n");
        }
    }
    if (clip == null) {
        mSpinner.setSelection(0);
        mEditText.setText("");
    } else if (clip.getItemAt(0).getText() != null) {
        mSpinner.setSelection(1);
        mEditText.setText(clip.getItemAt(0).getText());
    } else if (clip.getItemAt(0).getIntent() != null) {
        mSpinner.setSelection(2);
        mEditText.setText(clip.getItemAt(0).getIntent().toUri(0));
    } else if (clip.getItemAt(0).getUri() != null) {
        mSpinner.setSelection(3);
        mEditText.setText(clip.getItemAt(0).getUri().toString());
    } else {
        mSpinner.setSelection(0);
        mEditText.setText("Clip containing no data");
    }
}
 
Example #23
Source Project: masterpassword   Author: dkunzler   File: ClearClipboardService.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    DefaultPrefs defaultPrefs = Esperandro.getPreferences(DefaultPrefs.class,
            getApplicationContext());
    Handler handler = new Handler();
    final ClipboardManager clipboard = (ClipboardManager) getApplicationContext().getSystemService(
            Context.CLIPBOARD_SERVICE);

    int clipboardDuration = Integer.parseInt(defaultPrefs.clipboardDuration());
    Activity activity = App.get().getCurrentForegroundActivity();
    if (clipboardDuration > 0) {
        if (activity != null) {
            SnackbarUtil.showShort(activity, String.format(getApplicationContext().getString(
                            R.string.copiedToClipboardWithDuration),
                    clipboardDuration));
        }

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ClipData clip = ClipData.newPlainText("", "");
                clipboard.setPrimaryClip(clip);
                stopSelf();
            }
        }, clipboardDuration * 1000);
    } else {
        if (activity != null) {
            SnackbarUtil.showShort(activity, R.string.copiedToClipboard);
        }
    }
    return Service.START_STICKY;
}
 
Example #24
Source Project: SmileEssence   Author: lacolaco   File: StatusCommandCopyURLToClipboard.java    License: MIT License 5 votes vote down vote up
@Override
public boolean execute() {
    String statusURL = TwitterUtils.getStatusURL(getOriginalStatus());
    ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(ClipData.newPlainText("tweet url", statusURL));
    Notificator.publish(getActivity(), R.string.notice_copy_clipboard);
    return true;
}
 
Example #25
Source Project: openapk   Author: dkanada   File: OtherUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void saveClipboard(Context context, PackageInfo packageInfo) {
    ClipData clipData;
    clipData = ClipData.newPlainText("text", packageInfo.packageName);

    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setPrimaryClip(clipData);
}
 
Example #26
Source Project: ShizuruNotes   Author: MalitsPlus   File: LogUtils.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private static void clipData2String(ClipData clipData, StringBuilder sb) {
    ClipData.Item item = clipData.getItemAt(0);
    if (item == null) {
        sb.append("ClipData.Item {}");
        return;
    }
    sb.append("ClipData.Item { ");
    String mHtmlText = item.getHtmlText();
    if (mHtmlText != null) {
        sb.append("H:");
        sb.append(mHtmlText);
        sb.append("}");
        return;
    }
    CharSequence mText = item.getText();
    if (mText != null) {
        sb.append("T:");
        sb.append(mText);
        sb.append("}");
        return;
    }
    Uri uri = item.getUri();
    if (uri != null) {
        sb.append("U:").append(uri);
        sb.append("}");
        return;
    }
    Intent intent = item.getIntent();
    if (intent != null) {
        sb.append("I:");
        sb.append(intent2String(intent));
        sb.append("}");
        return;
    }
    sb.append("NULL");
    sb.append("}");
}
 
Example #27
Source Project: Last-Launcher   Author: SubhamTyagi   File: LauncherActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Map<String, Integer> clipboardData() {
    Map<String, Integer> result = null;
    // Log.d(TAG, "clipboardData: ");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        try {
            ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = clipboardManager.getPrimaryClip();
            if (clipData.getItemCount() > 0) {
                ClipData.Item item = clipData.getItemAt(0);
                String tabSepratedData = item.getText().toString();
                //Log.d(TAG, "clipboardData: " + tabSepratedData);
                //validate tabSepratedData and get its data
                //unique id bae73ae068dacc6cb659d1fb231e7b11 i.e LastLauncher-ColorSniffer MD5-128

                String[] line = tabSepratedData.split("\n");//get each line

                Map<String, Integer> colorsAndId = new ArrayMap<>(); // map to put all values in key and values format
                // iterate over every line
                for (String entry : line) {
                    String[] activityIdAndColor = entry.split("\t");// split line into id and color
                    int color = Color.parseColor(activityIdAndColor[1]);
                    colorsAndId.put(activityIdAndColor[0], color);// put id and color to map

                    //   Log.d(TAG, "clipboardData: app:" + activityIdAndColor[0] + "  color==" + color);

                }
                setAppsColorFromClipboard(colorsAndId);
                result = colorsAndId;// return map
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // return empty null/
    return result;
}
 
Example #28
Source Project: Ruisi   Author: xidian-rs   File: PostAdapter.java    License: Apache License 2.0 5 votes vote down vote up
CommentViewHolder(View itemView) {
    super(itemView);

    avatar = itemView.findViewById(R.id.article_user_image);
    btnReplyCz = itemView.findViewById(R.id.btn_reply_cz);
    btnMore = itemView.findViewById(R.id.btn_more);
    username = itemView.findViewById(R.id.replay_author);
    index = itemView.findViewById(R.id.replay_index);
    replyTime = itemView.findViewById(R.id.replay_time);
    comment = itemView.findViewById(R.id.html_text);
    labelLz = itemView.findViewById(R.id.bt_lable_lz);

    comment.setOnLongClickListener(view -> {
        String user = datalist.get(getAdapterPosition()).username;
        String content = comment.getText().toString().trim();
        ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        if (cm != null) {
            cm.setPrimaryClip(ClipData.newPlainText(null, content));
            Toast.makeText(activity, "已复制" + user + "的评论", Toast.LENGTH_SHORT).show();
        }

        return true;
    });

    avatar.setOnClickListener(v -> {
        if (datalist.get(getAdapterPosition()).uid > 0) {
            UserDetailActivity.openWithAnimation(
                    activity, datalist.get(getAdapterPosition()).username,
                    avatar, datalist.get(getAdapterPosition()).uid);
        }
    });


    btnReplyCz.setOnClickListener(this);
    btnMore.setOnClickListener(this);
}
 
Example #29
Source Project: 920-text-editor-v2   Author: jecelyin   File: EditAreaView.java    License: Apache License 2.0 5 votes vote down vote up
public boolean copy() {
    getSelectedText(new JsCallback<String>() {
        @Override
        public void onCallback(String data) {
            setPrimaryClip(ClipData.newPlainText(null, data));
            execCommand(new EditorCommand.Builder("onCopy").build());
        }
    });

    return true;
}
 
Example #30
Source Project: EFRConnect-android   Author: SiliconLabs   File: FragmentCharacteristicDetail.java    License: Apache License 2.0 5 votes vote down vote up
private void setCopyListener(final EditText copyFromET, final ImageView copyIV) {
    copyIV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClipboardManager clipboardManager = context.getSystemService(ClipboardManager.class);
            ClipData clip = ClipData.newPlainText("characteristic-value", copyFromET.getText().toString());
            if (clipboardManager != null) {
                clipboardManager.setPrimaryClip(clip);
                Toast.makeText(context, getString(R.string.Copied_to_clipboard), Toast.LENGTH_SHORT).show();
            }
        }
    });
}