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.
Example 1
Project: 365browser   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
Project: delion   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
Project: ETHWallet   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
Project: LaunchTime   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
Project: a   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
Project: styT   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
Project: javaide   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
Project: 365browser   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
Project: DanDanPlayForAndroid   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
Project: user-interface-samples   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
Project: FireFiles   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
Project: DanDanPlayForAndroid   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
Project: pc-android-controller-android   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
Project: 365browser   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
Project: XposedSmsCode   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
Project: open-rmbt   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
Project: Android-REST-API-Explorer   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
Project: pandora   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
Project: QPM   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
Project: PowerFileExplorer   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
Project: SkyTube   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
Project: codeexamples-android   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
Project: masterpassword   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
Project: SmileEssence   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
Project: openapk   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
Project: ShizuruNotes   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
Project: Last-Launcher   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
Project: Ruisi   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
Project: 920-text-editor-v2   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
Project: EFRConnect-android   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();
            }
        }
    });
}
 
Example 31
Project: Android-Keyboard   File: ClipManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onPrimaryClipChanged() {
    if (mCbMan == null) {
        return;
    }
    ClipData cd = mCbMan.getPrimaryClip();
    if (cd != null && cd.getItemCount() > 0) {
        ClipData.Item item = cd.getItemAt(0);
        if (item != null) {
            CharSequence s = item.getText();
            addClipString(s);
        }
    }
}
 
Example 32
Project: codeexamples-android   File: ContentFragment.java    License: Eclipse Public License 1.0 5 votes vote down vote up
boolean processDrop(DragEvent event, ImageView imageView) {
    // Attempt to parse clip data with expected format: category||entry_id.
    // Ignore event if data does not conform to this format.
    ClipData data = event.getClipData();
    if (data != null) {
        if (data.getItemCount() > 0) {
            Item item = data.getItemAt(0);
            String textData = (String) item.getText();
            if (textData != null) {
                StringTokenizer tokenizer = new StringTokenizer(textData, "||");
                if (tokenizer.countTokens() != 2) {
                    return false;
                }
                int category = -1;
                int entryId = -1;
                try {
                    category = Integer.parseInt(tokenizer.nextToken());
                    entryId = Integer.parseInt(tokenizer.nextToken());
                } catch (NumberFormatException exception) {
                    return false;
                }
                updateContentAndRecycleBitmap(category, entryId);
                // Update list fragment with selected entry.
                TitlesFragment titlesFrag = (TitlesFragment)
                        getFragmentManager().findFragmentById(R.id.titles_frag);
                titlesFrag.selectPosition(entryId);
                return true;
            }
        }
    }
    return false;
}
 
Example 33
Project: open_flood   File: GameActivity.java    License: MIT License 5 votes vote down vote up
public void onGetSeedClick() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("seed", game.getSeed());
    clipboard.setPrimaryClip(clip);
    Toast toast = Toast.makeText(this, getString(R.string.game_seed_copied), Toast.LENGTH_SHORT);
    toast.show();
    return;
}
 
Example 34
Project: JianDanRxJava   File: TextUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void copy(Activity activity, String copyText) {
    ClipboardManager clip = (ClipboardManager)
            activity.getSystemService(Context
                    .CLIPBOARD_SERVICE);
    clip.setPrimaryClip(ClipData.newPlainText
            (null, copyText));
    ToastHelper.Short(ConstantString.COPY_SUCCESS);
}
 
Example 35
Project: PoetryWeather   File: AboutActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void copyToClipboard(String label, String string) {
    //复制
    ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText(label, string);
    if (clipboardManager != null) {
        clipboardManager.setPrimaryClip(clipData);
        Toast.makeText(this, "成功复制" + label, Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "获取剪贴板失败,无法复制", Toast.LENGTH_SHORT).show();
    }
}
 
Example 36
Project: android_9.0.0_r45   File: ClipboardService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setPrimaryClip(ClipData clip, String callingPackage) {
    synchronized (this) {
        if (clip == null || clip.getItemCount() <= 0) {
            throw new IllegalArgumentException("No items");
        }
        final int callingUid = Binder.getCallingUid();
        if (!clipboardAccessAllowed(AppOpsManager.OP_WRITE_CLIPBOARD, callingPackage,
                    callingUid)) {
            return;
        }
        checkDataOwnerLocked(clip, callingUid);
        setPrimaryClipInternal(clip, callingUid);
    }
}
 
Example 37
Project: android-wallet-app   File: CopySeedDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    generatedSeed = bundle.getString("generatedSeed");

    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.copy_seed)
            .setMessage(R.string.messages_copy_seed)
            .setCancelable(false)
            .setPositiveButton(R.string.buttons_ok, null)
            .setNegativeButton(R.string.buttons_cancel, null)
            .create();

    alertDialog.setOnShowListener(dialog -> {

        Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(view -> {
            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(getActivity().getString(R.string.seed), generatedSeed);
            clipboard.setPrimaryClip(clip);
            dialog.dismiss();
        });
    });

    alertDialog.show();
    return alertDialog;
}
 
Example 38
Project: user-interface-samples   File: ImageDragListener.java    License: Apache License 2.0 5 votes vote down vote up
private boolean processDrop(View view, DragEvent event) {
    ClipData clipData = event.getClipData();
    if (clipData == null || clipData.getItemCount() == 0) {
        return false;
    }
    ClipData.Item item = clipData.getItemAt(0);
    if (item == null) {
        return false;
    }
    Uri uri = item.getUri();
    if (uri == null) {
        return false;
    }
    return setImageUri(view, event, uri);
}
 
Example 39
Project: android_9.0.0_r45   File: ClipboardService.java    License: Apache License 2.0 5 votes vote down vote up
private final void grantItemLocked(ClipData.Item item, int sourceUid, String targetPkg,
        int targetUserId) {
    if (item.getUri() != null) {
        grantUriLocked(item.getUri(), sourceUid, targetPkg, targetUserId);
    }
    Intent intent = item.getIntent();
    if (intent != null && intent.getData() != null) {
        grantUriLocked(intent.getData(), sourceUid, targetPkg, targetUserId);
    }
}
 
Example 40
Project: BonjourBrowser   File: TxtRecordsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onItemClick(View view, int position){
    Context context = view.getContext();

    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getKey(position), getValue(position));
    clipboard.setPrimaryClip(clip);

    Snackbar snackbar = Snackbar.make(view, context.getResources().getString(R.string.copy_toast_message, getKey(position)), Snackbar.LENGTH_LONG);
    snackbar.getView().setBackgroundResource(R.color.accent);
    snackbar.show();
}