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:Main.java

public static Intent getLaunchIntent(Context context, String title, String url, String sel) {
    Intent intent = null;/*from   w ww  .j  a  v  a2 s  .co  m*/
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        } else if (isYouTubeURL(url)) {
            intent.setPackage(YT_PACKAGE_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }

    if (sel != null && sel.length() > 0) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(sel);
    }

    return intent;
}

From source file:Main.java

/**
 * Copy intent to Clipboard/*w ww . j  ava  2  s.com*/
 *
 * @param context
 * @param intent
 */
public static void copy(Context context, Intent intent) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newIntent(null, intent));
}

From source file:Main.java

@SuppressWarnings("ConstantConditions")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static String getClipboardTextNew(Context ctx) {
    String txt = null;//from w w  w  .j av  a 2 s  .c om
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ctx
            .getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard != null) {
        if (clipboard.hasPrimaryClip()) {
            txt = clipboard.getPrimaryClip().getItemAt(0).getText().toString();
        }
    }
    return txt;
}

From source file:Main.java

/**
 * This is only called when we are on API level < Honeycomb
 * @param context The context, required to get the Cliboard System Service.  
 * @return Returns the latest text copied to the clipboard by the user
 *//*from   ww  w  .  ja  v a  2s.c om*/
@SuppressWarnings("deprecation")
private static String getTextFromClipboard(final Context context) {
    android.text.ClipboardManager manager = (android.text.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    String text = (String) manager.getText(); //Yep, that much simpler. 
    if (text == null)
        text = EMPTY_STRING;
    return text;
}

From source file:com.btmura.android.reddit.app.MenuHelper.java

/**
 * Sets a plain text {@link ClipData} with the provided label and text to the
 * clipboard and shows a toast with the text.
 *///from  w ww. j a  va2s  . c o m
public static void copyUrl(Context context, CharSequence label, CharSequence text) {
    context = context.getApplicationContext();
    ClipboardManager cb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cb.setPrimaryClip(ClipData.newPlainText(label, text));
    Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

/**
 * This is only called when oldAPi is passed as false on {@link #addItemToClipboard(Context, String, String, boolean)}
 * @param context The context, required to get the Cliboard System Service. 
 * @param label The label to show to the user via {@code ClipDescription}
 * @param value The value to store on the clipboard. 
 *///from  www  .j a v  a  2  s  . c om
@SuppressLint("NewApi")
private static void addItemToClipboard(final Context context, final String label, final String value) {
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData.Item item = new Item(value);
    ClipDescription description = new ClipDescription(label,
            new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN });
    ClipData data = new ClipData(description, item);
    manager.setPrimaryClip(data);
}

From source file:me.zchang.onchart.ui.DonateFragment.java

@NonNull
@Override//from   w ww .j a va2  s .  c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(getString(R.string.button_donate), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = getActivity().getPackageManager()
                    .getLaunchIntentForPackage("com.eg.android.AlipayGphone");
            ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData data = ClipData.newPlainText(ClipDescription.MIMETYPE_TEXT_PLAIN,
                    getString(R.string.alipay_account));
            clipboardManager.setPrimaryClip(data);
            if (intent != null) {
                Toast.makeText(getActivity(), getString(R.string.alert_clipboard_complete), Toast.LENGTH_LONG)
                        .show();
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), getString(R.string.alert_no_alipay), Toast.LENGTH_SHORT).show();
            }
        }
    }).setView(getActivity().getLayoutInflater().inflate(R.layout.fragment_donate, null));
    return builder.create();
}

From source file:com.coloreight.plugin.clipboard.Clipboard.java

public void copy(final String text, final CallbackContext callbackContext) {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            ClipboardManager clipboard = (ClipboardManager) cordova.getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);

            try {
                ClipData clip = ClipData.newPlainText("Public.Text", text);

                clipboard.setPrimaryClip(clip);

                callbackContext.success(text);
            } catch (Exception e) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
            }//from w w w .j  a v  a 2  s.c  o m
        }
    });
}

From source file:com.druk.bonjour.browser.ui.adapter.TxtRecordsAdapter.java

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);//from   ww w  .  j a va  2  s.  c  o  m

    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();
}

From source file:org.connectbot.util.TerminalTextViewOverlay.java

public TerminalTextViewOverlay(Context context, TerminalView terminalView) {
    super(context);

    this.terminalView = terminalView;
    clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);

    setTextColor(Color.TRANSPARENT);
    setTypeface(Typeface.MONOSPACE);/*from w  w w.  j a va  2 s. c o  m*/
    setTextIsSelectable(true);
    setCustomSelectionActionModeCallback(new TextSelectionActionModeCallback());
}