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:de.schildbach.wallet.ui.RequestCoinsFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
}

From source file:com.zephyrteam.costituzione.DetailedActivity.java

@SuppressWarnings("static-access")
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.copy_entry:
        String toCopy = mEntry.getTitle() + ": \n" + mEntry.getBody().replace("\n\n", "\n");

        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("Costituzione", toCopy));
        new Toast(this).makeText(this, R.string.text_copied_to_clipboard, 2000).show();

        break;//from w w  w .ja v a2s  .c  om

    case R.id.favourite_status:
        DatabaseHandler dbh = new DatabaseHandler(this);
        dbh.open(true);
        mEntry.setIsFavourite(!mEntry.isFavourite());
        dbh.updateFavoriteStatus(mEntry);
        dbh.close();

        new Toast(this)
                .makeText(this, mEntry.isFavourite() ? R.string.added_to_fav : R.string.removed_from_fav, 2000)
                .show();
        updateFavoriteButton(item);
    }
    return true;
}

From source file:com.feathercoin.wallet.feathercoin.ui.RequestCoinsFragment.java

@SuppressLint("InlinedApi")
@Override/*w w  w. ja v a  2  s  .c o m*/
public void onAttach(final Activity activity) {
    super.onAttach(activity);
    this.activity = (AbstractWalletActivity) activity;
    application = (WalletApplication) activity.getApplication();

    nfcManager = activity.getSystemService(Context.NFC_SERVICE);
    clipboardManager = (android.text.ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
}

From source file:org.emergent.android.weave.PasswordListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Activity activity = getActivity();//from w w w.j  a v  a 2s.  co m
    if (activity == null) {
        Log.w(TAG, "onListItemClick: Activity was null!");
        return;
    }

    ListAdapter listAdapter = getListAdapter();

    Cursor cursor = (Cursor) listAdapter.getItem(position);
    String pword = cursor.getString(cursor.getColumnIndex(Passwords.Columns.PASSWORD));

    ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setText(pword);
    String msg = "Password copied to clipboard.";
    Toast toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
    toast.show();
}

From source file:com.kobi.metalsexchange.app.CalculateFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_copy) {
        // Gets a handle to the clipboard service.
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);

        String price = Utility.getFormattedCurrency(calculateFragmentViewHelper.getPriceResult(),
                Utility.getPreferredCurrency(getActivity()), getActivity(), false);

        ClipData clip = ClipData.newPlainText("rate", price);
        clipboard.setPrimaryClip(clip);/*from   w  w w  . j a v a2 s .c om*/

        Toast toast = Toast.makeText(getActivity().getBaseContext(),
                getString(R.string.copy_to_clipboard_toast, price), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.mikifus.padland.PadListActivity.java

/**
 * If there is a share intent this function gets the extra text
 * and copies it into clipboard//from  w  w  w  .jav  a  2  s. co m
 */
private void _textFromIntent() {
    String extra_text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
    if (extra_text != null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(extra_text);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", extra_text);
            clipboard.setPrimaryClip(clip);
        }

        Toast.makeText(this, getString(R.string.activity_padlist_implicitintent_text_copied), Toast.LENGTH_LONG)
                .show();
    }
}

From source file:test.ya.translater.wgjuh.yaapitmvptest.view.fragments.translate.fragment.TranslateFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    translatePresenterImpl = new TranslatePresenterImpl(ModelImpl.getInstance(), EventBusImpl.getInstance());
    translatePresenterImpl.onBindView(this);
    viewAdapter = new DictionaryTranslateRecyclerViewAdapter(translatePresenterImpl.getDictionaryState(),
            getActivity());/*w  w  w.  j  ava  2s.co m*/
    translatePresenterImpl.restoreState();
    recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
    recyclerView.setAdapter(viewAdapter);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
            LinearLayout.VERTICAL);
    recyclerView.addItemDecoration(dividerItemDecoration);
    btnFavorite.setOnClickListener(btn -> {
        if (btnFavorite.isChecked()) {
            translatePresenterImpl.addFavorite();
        } else {
            translatePresenterImpl.deleteFavorite();
        }
    });
    btn_retry.setOnClickListener(btn_retry -> translatePresenterImpl.startRetry());
    translate.setOnClickListener(textView -> {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(((TextView) textView).getText(), ((TextView) textView).getText());
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getActivity().getApplicationContext(),
                getActivity().getResources().getText(R.string.copy_to_clipdoard), Toast.LENGTH_SHORT).show();
    });

}

From source file:at.alladin.rmbt.android.sync.RMBTSyncRequestCodeFragment.java

@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);/*from w  ww  .  j  a  va2  s.co  m*/
        return true;
    }
    return super.onContextItemSelected(mi);
}

From source file:com.softminds.matrixcalculator.OperationFragments.TraceFragment.java

private void RunToGetTrace(int position, ProgressDialog progressDialog) {
    double result = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getTrace();
    final String formatted = GetText(result);
    progressDialog.dismiss();//from w  w w . j  a  va  2s . co  m
    String formatted2 = getString(R.string.trace_is) + " " + formatted;
    new AlertDialog.Builder(getContext()).setCancelable(true).setMessage(formatted2)
            .setTitle(R.string.trace_text)
            .setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ClipboardManager manager = (ClipboardManager) getContext()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData data = ClipData.newPlainText("TRACE_RES", formatted);
                    manager.setPrimaryClip(data);
                    if (manager.hasPrimaryClip())
                        Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show();
                    else
                        Log.e(TAG, "Cannot Put Data to Clip");
                    dialog.dismiss();
                }
            }).setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();
}

From source file:com.air.mobilebrowser.ActivityWatchService.java

@Override
public void onCreate() {
    super.onCreate();

    //Create an application whitelist, by default, we include android :-)
    mApplicationWhitelist = new ArrayList<String>();
    mApplicationWhitelist.add("android");

    String[] blackApps = super.getResources().getStringArray(R.array.blacklist_apps);
    for (String bapp : blackApps) {
        mAppBlacklist.add(bapp);/*ww w.  j av a  2s .  com*/
    }

    // For Android 5, also add com.google.android.music:main to the block list.
    // We need to detect if music is being played while the browser is running.
    // This process is shown on Android 5 only when the music is being played, while for
    // older Androids, the process list does not reflect whether music is being played or not
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.KITKAT) {
        String musicAppProcess = "com.google.android.music:main";
        mAppBlacklist.add(musicAppProcess);
    }

    //Save current keyboard
    mLastKeyboard = KeyboardUtil.getKeyboardPackage(super.getContentResolver());

    mClipboardManager = (ClipboardManager) super.getSystemService(Context.CLIPBOARD_SERVICE);

    //Save current keyboard
    mLastKeyboard = KeyboardUtil.getKeyboardPackage(super.getContentResolver());

    //Get a reference to the AudioManager to check mic mute status
    mAudioManager = (AudioManager) super.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    mMicMute = mAudioManager.isMicrophoneMute();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setWhen(System.currentTimeMillis());
    builder.setTicker("Secure Browser");
    builder.setSmallIcon(android.R.drawable.alert_light_frame);
    builder.setOngoing(true);

    startForeground(SERVICE_ID, builder.build());
}