Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

From source file:fr.free.nrw.commons.Utils.java

public static void copy(String label, String text, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, text);
    clipboard.setPrimaryClip(clip);//from ww  w . j  av a 2 s.  c om
}

From source file:org.protocoderrunner.apprunner.api.PDevice.java

@ProtoMethod(description = "Get the content from the clipboard", example = "")
@ProtoMethodParam(params = { "label", "text" })
public String getFromClipboard(String label, String text) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    return clipboard.getPrimaryClip().getItemAt(clipboard.getPrimaryClip().getItemCount()).getText().toString();
}

From source file:com.keylesspalace.tusky.fragment.SFragment.java

protected void more(final Status status, View view, final int position) {
    final String id = status.getActionableId();
    final String accountId = status.getActionableStatus().getAccount().getId();
    final String accountUsename = status.getActionableStatus().getAccount().getUsername();
    final Spanned content = status.getActionableStatus().getContent();
    final String statusUrl = status.getActionableStatus().getUrl();
    PopupMenu popup = new PopupMenu(getContext(), view);
    // Give a different menu depending on whether this is the user's own toot or not.
    if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
        popup.inflate(R.menu.status_more);
    } else {/*  w w  w.j  a  va2s. c om*/
        popup.inflate(R.menu.status_more_for_user);
        Menu menu = popup.getMenu();
        if (status.getVisibility() == Status.Visibility.PRIVATE) {
            boolean reblogged = status.getReblogged();
            if (status.getReblog() != null)
                reblogged = status.getReblog().getReblogged();
            menu.findItem(R.id.status_reblog_private).setVisible(!reblogged);
            menu.findItem(R.id.status_unreblog_private).setVisible(reblogged);
        }
    }
    popup.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
        case R.id.status_share_content: {
            StringBuilder sb = new StringBuilder();
            sb.append(status.getAccount().getUsername());
            sb.append(" - ");
            sb.append(status.getContent().toString());

            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendIntent.setType("text/plain");
            startActivity(
                    Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to)));
            return true;
        }
        case R.id.status_share_link: {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl);
            sendIntent.setType("text/plain");
            startActivity(
                    Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
            return true;
        }
        case R.id.status_copy_link: {
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(null, statusUrl);
            clipboard.setPrimaryClip(clip);
            return true;
        }
        case R.id.status_mute: {
            timelineCases().mute(accountId);
            return true;
        }
        case R.id.status_block: {
            timelineCases().block(accountId);
            return true;
        }
        case R.id.status_report: {
            openReportPage(accountId, accountUsename, id, content);
            return true;
        }
        case R.id.status_unreblog_private: {
            onReblog(false, position);
            return true;
        }
        case R.id.status_reblog_private: {
            onReblog(true, position);
            return true;
        }
        case R.id.status_delete: {
            timelineCases().delete(id);
            removeItem(position);
            return true;
        }
        }
        return false;
    });
    popup.show();
}

From source file:org.torproject.android.Orbot.java

private void doLayout() {
    setContentView(R.layout.layout_main);

    mViewMain = findViewById(R.id.viewMain);
    lblStatus = (TextView) findViewById(R.id.lblStatus);
    lblStatus.setOnLongClickListener(this);
    imgStatus = (ImageProgressView) findViewById(R.id.imgStatus);
    imgStatus.setOnLongClickListener(this);
    imgStatus.setOnTouchListener(this);

    lblStatus.setText("Initializing the application...");

    downloadText = (TextView) findViewById(R.id.trafficDown);
    uploadText = (TextView) findViewById(R.id.trafficUp);
    mTxtOrbotLog = (TextView) findViewById(R.id.orbotLog);

    mDrawer = ((SlidingDrawer) findViewById(R.id.SlidingDrawer));
    Button slideButton = (Button) findViewById(R.id.slideButton);
    if (slideButton != null) {
        slideButton.setOnTouchListener(new OnTouchListener() {

            @Override/*from w  ww.  ja  v a  2s .c  o  m*/
            public boolean onTouch(View v, MotionEvent event) {

                if (event.equals(MotionEvent.ACTION_DOWN)) {
                    mDrawerOpen = !mDrawerOpen;
                    mTxtOrbotLog.setEnabled(mDrawerOpen);
                }
                return false;
            }

        });
    }

    ScrollingMovementMethod smm = new ScrollingMovementMethod();

    mTxtOrbotLog.setMovementMethod(smm);
    mTxtOrbotLog.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            cm.setText(mTxtOrbotLog.getText());
            Toast.makeText(Orbot.this, "LOG COPIED TO CLIPBOARD", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    downloadText.setText(formatCount(0) + " / " + formatTotal(0));
    uploadText.setText(formatCount(0) + " / " + formatTotal(0));

    // Gesture detection
    mGestureDetector = new GestureDetector(this, new MyGestureDetector());

}

From source file:in.shick.diode.common.util.Util.java

public static void copyPlainTextToClipboard(Context context, String textToCopy) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(textToCopy);/* w w  w . j  a  va  2  s . c o m*/
    } else {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText(textToCopy, textToCopy);
        clipboard.setPrimaryClip(clip);
    }
}

From source file:com.mobshep.mobileshepherd.BrokenCrypto.java

public void copyMessage5(View v) {

    String copiedMessage5 = messageFive.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message5", copiedMessage5);
    clipboard.setPrimaryClip(clip);//from w w  w  . j a  v a  2s .co  m

    showToast();

}

From source file:org.mozilla.gecko.toolbar.SiteIdentityPopup.java

private void addSelectLoginDoorhanger(Tab tab) throws JSONException {
    final SiteLogins siteLogins = tab.getSiteLogins();
    if (siteLogins == null) {
        return;/*from www  .ja va  2  s .co m*/
    }

    final JSONArray logins = siteLogins.getLogins();
    if (logins.length() == 0) {
        return;
    }

    final JSONObject login = (JSONObject) logins.get(0);

    // Create button click listener for copying a password to the clipboard.
    final OnButtonClickListener buttonClickListener = new OnButtonClickListener() {
        @Override
        public void onButtonClick(JSONObject response, DoorHanger doorhanger) {
            try {
                final int buttonId = response.getInt("callback");
                if (buttonId == ButtonType.COPY.ordinal()) {
                    final ClipboardManager manager = (ClipboardManager) mContext
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    String password;
                    if (response.has("password")) {
                        // Click listener being called from List Dialog.
                        password = response.optString("password");
                    } else {
                        password = login.getString("password");
                    }
                    if (AppConstants.Versions.feature11Plus) {
                        manager.setPrimaryClip(ClipData.newPlainText("password", password));
                    } else {
                        manager.setText(password);
                    }
                    Toast.makeText(mContext, R.string.doorhanger_login_select_toast_copy, Toast.LENGTH_SHORT)
                            .show();
                }
                dismiss();
            } catch (JSONException e) {
                Log.e(LOGTAG, "Error handling Select login button click", e);
                Toast.makeText(mContext, R.string.doorhanger_login_select_toast_copy_error, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    };

    final DoorhangerConfig config = new DoorhangerConfig(DoorHanger.Type.LOGIN, buttonClickListener);

    // Set buttons.
    config.setButton(mContext.getString(R.string.button_cancel), ButtonType.CANCEL.ordinal(), false);
    config.setButton(mContext.getString(R.string.button_copy), ButtonType.COPY.ordinal(), true);

    // Set message.
    String username = ((JSONObject) logins.get(0)).getString("username");
    if (TextUtils.isEmpty(username)) {
        username = mContext.getString(R.string.doorhanger_login_no_username);
    }

    final String message = mContext.getString(R.string.doorhanger_login_select_message).replace(FORMAT_S,
            username);
    config.setMessage(message);

    // Set options.
    final JSONObject options = new JSONObject();

    // Add action text only if there are other logins to select.
    if (logins.length() > 1) {

        final JSONObject actionText = new JSONObject();
        actionText.put("type", "SELECT");

        final JSONObject bundle = new JSONObject();
        bundle.put("logins", logins);

        actionText.put("bundle", bundle);
        options.put("actionText", actionText);
    }

    config.setOptions(options);

    ThreadUtils.postToUiThread(new Runnable() {
        @Override
        public void run() {
            if (!mInflated) {
                init();
            }

            removeSelectLoginDoorhanger();

            mSelectLoginDoorhanger = DoorHanger.Get(mContext, config);
            mContent.addView(mSelectLoginDoorhanger);
            mDivider.setVisibility(View.VISIBLE);
        }
    });
}

From source file:io.github.marktony.espresso.mvp.packagedetails.PackageDetailsFragment.java

/**
 * Copy the package number(id) to clipboard.
 * @param packageId The package number./*from www  .j  a va2 s  .  c om*/
 */
@Override
public void copyPackageNumber(@NonNull String packageId) {
    ClipboardManager manager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = ClipData.newPlainText("text", packageId);
    manager.setPrimaryClip(data);
    Snackbar.make(fab, R.string.package_number_copied, Snackbar.LENGTH_SHORT).show();
}

From source file:com.undatech.opaque.RemoteCanvas.java

public RemoteCanvas(final Context context, AttributeSet attrSet) {
    super(context, attrSet);
    clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    final Display display = ((Activity) context).getWindow().getWindowManager().getDefaultDisplay();
    displayWidth = display.getWidth();// w w  w  .j  a  v  a2s.c om
    displayHeight = display.getHeight();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    displayDensity = metrics.density;

    canvasZoomer = new CanvasZoomer(this);
    setScaleType(ImageView.ScaleType.MATRIX);

    if (android.os.Build.MODEL.contains("BlackBerry") || android.os.Build.BRAND.contains("BlackBerry")
            || android.os.Build.MANUFACTURER.contains("BlackBerry")) {
        bb = true;
    }
}

From source file:com.ruesga.rview.fragments.SnippetFragment.java

public void onActionPressed() {
    if (mNeedPermissions) {
        return;/*w ww . jav a  2 s.  com*/
    }
    if (!mReadOnly) {
        // Paste
        //noinspection ConstantConditions
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        if (clipboard.getPrimaryClip() != null && clipboard.getPrimaryClip().getItemCount() > 0) {
            ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
            CharSequence data = item.getText();
            if (data != null) {
                byte[] content = data.toString().getBytes();
                loadContent(content);
                mUiHandler.post(() -> saveContent(content));
            }
        }

    } else {
        // Open in external
        String action = getString(R.string.action_share);
        //noinspection ConstantConditions
        Uri uri = FileProvider.getUriForFile(getContext(), "com.ruesga.rview.content",
                new File(mUri.getPath()));
        ActivityHelper.open(getContext(), action, uri, "text/plain");
        dismiss();
    }
}