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:com.suyonoion.easyviewpagerui.ExpandedViewpagerUI.java

public ExpandedViewpagerUI(Context context, AttributeSet attrs) {
    super(context, attrs);

    List<String> mengisi_Tempat_judul = new ArrayList<>();
    final List<String> kodestringsxml_str = new ArrayList<>();
    final List<String> kodeutama_str = new ArrayList<>();

    for (int i = 1; i <= Jumlah_Page; i++) {
        try {//from   w w  w .  j ava  2  s .  c o m
            mengisi_Tempat_judul.add(getResources().getString(setResource("judul_halaman_" + i, "string")));
        }

        catch (Throwable e) {

            if (Jumlah_Page > 25) {
                mengisi_Tempat_judul.add("Judul " + i + " belum ditambahkan di strings.xml");
                AlertDialog.Builder b = new AlertDialog.Builder(getContext());
                final String st = "<LinearLayout android:background=\"@drawable/a3\" android:id=\"@+id/id_halaman_4\" android:layout_width=\"match_parent\" android:layout_height=\"match_parent\" android:orientation=\"vertical\" android:gravity=\"center\">\n"
                        + "<TextView android:textSize=\"70sp\" android:layout_gravity=\"center\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:text=\"3\" android:textColor=\"#ff473eff\"/>\n"
                        + "</LinearLayout>";

                b.setMessage(
                        "Berbahaya Jumlah_Page terlalu banyak lebih dari 25 pages, penambahan kode utama tidak akan ditampilkan...!! Dan"
                                + "Kodeutama->strings.xml->smali belum sinkron (tidak sama). Mengedit 0x3 saja tidak cukup, anda juga perlu mengedit kodeutama dan strings.xml, agar sama. \n \n"
                                + "Jika anda telah mengubah/mengedit/menambah/menghapus Jumlah_Page = 3 (0x3) menjadi Jumlah_Page = "
                                + Jumlah_Page
                                + ", kodeutama, dan strings.xml maka, \n \n Tolong cek dan edit kembali kode utama di expanded anda dan strings.xml di value , sesuaikan dengan jumlah page yaitu "
                                + Jumlah_Page
                                + " dalam smali. dan tambahkan ini sejumlah pages yang anda mau :\n \n" + st
                                + "\n\n" + "sesuaikan dengan id_halaman");
                b.setCancelable(true);
                b.setNeutralButton("Copy to Clipboard", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext()
                                    .getSystemService(Context.CLIPBOARD_SERVICE);
                            clipboard.setText(st);
                            Toast.makeText(getContext(), "Text Telah Ter-Copy ke Clipboard", Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext()
                                    .getSystemService(Context.CLIPBOARD_SERVICE);
                            android.content.ClipData clip = android.content.ClipData.newPlainText("Clip", st);
                            Toast.makeText(getContext(), "Text Telah Ter-Copy ke Clipboard", Toast.LENGTH_SHORT)
                                    .show();
                            clipboard.setPrimaryClip(clip);
                        }
                        dialog.dismiss();
                    }
                });
                b.setTitle("Pesan Saya...!!!");
                AlertDialog ad = b.create();
                ad.show();
            } else {
                mengisi_Tempat_judul.add("Judul " + i + " belum ditambahkan di strings.xml");
                AlertDialog.Builder b = new AlertDialog.Builder(getContext());
                kodeutama_str.add(
                        "<LinearLayout android:background=\"@drawable/a3\" android:id=\"@+id/id_halaman_" + i
                                + "\" android:layout_width=\"match_parent\" android:layout_height=\"match_parent\" android:orientation=\"vertical\" android:gravity=\"center\">\n"
                                + " <TextView android:textSize=\"70sp\" android:layout_gravity=\"center\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:text=\""
                                + i + "\" android:textColor=\"#ff473eff\"/>\n" + "</LinearLayout> \n \n");

                b.setMessage(
                        "Kodeutama->strings.xml->smali belum sinkron (tidak sama). Mengedit 0x3 saja tidak cukup, anda juga perlu mengedit kodeutama dan strings.xml, agar sama. \n \n"
                                + "Jika anda telah mengubah/mengedit/menambah/menghapus Jumlah_Page = 3 (0x3) menjadi Jumlah_Page = "
                                + Jumlah_Page
                                + ", kodeutama, dan strings.xml maka, \n \n Tolong cek dan edit kembali kode utama di expanded anda dan strings.xml di value , sesuaikan dengan jumlah page yaitu "
                                + Jumlah_Page
                                + " dalam smali atau perhatikan kode utama dibawah ini silahkan dicontek dan tambahkan ke expanded:\n \n"
                                + kodeutama_str + "\n \n"
                                + "Copy to Clipboard dan oh iyah Hapus koma(,) kurung buka dan tutup [ ] yah :)");
                b.setCancelable(true);
                b.setNeutralButton("Copy to Clipboard", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext()
                                    .getSystemService(Context.CLIPBOARD_SERVICE);
                            clipboard.setText(kodeutama_str.toString());
                            Toast.makeText(getContext(), "Text Telah Ter-Copy ke Clipboard", Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext()
                                    .getSystemService(Context.CLIPBOARD_SERVICE);
                            android.content.ClipData clip = android.content.ClipData.newPlainText("Clip",
                                    kodeutama_str.toString());
                            Toast.makeText(getContext(), "Text Telah Ter-Copy ke Clipboard", Toast.LENGTH_SHORT)
                                    .show();
                            clipboard.setPrimaryClip(clip);
                        }
                        dialog.dismiss();
                    }
                });
                b.setTitle("Pesan Saya...!!!");
                AlertDialog ad = b.create();
                ad.show();
            }

        }
    }

    AdapterExpandedViewpagerUI adapter = new AdapterExpandedViewpagerUI(mengisi_Tempat_judul);
    final ViewPager EasyExpandedViewPagerUI = (ViewPager) this.findViewById(setResource("id_viewpager", "id"));
    EasyExpandedViewPagerUI.setPageTransformer(true, new CubeOutTransformer());
    EasyExpandedViewPagerUI.setAdapter(adapter);
    EasyExpandedViewPagerUI.setOffscreenPageLimit(Jumlah_Page);
    if (EasyExpandedViewPagerUI.getWidth() > 0) {
        Bitmap image = JadikanBlur.blur(EasyExpandedViewPagerUI);
        EasyExpandedViewPagerUI.setBackgroundDrawable(new BitmapDrawable(getContext().getResources(), image));
    } else {
        EasyExpandedViewPagerUI.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Bitmap image = JadikanBlur.blur(EasyExpandedViewPagerUI);
                        EasyExpandedViewPagerUI
                                .setBackgroundDrawable(new BitmapDrawable(getContext().getResources(), image));
                    }
                });
    }

    adapter.notifyDataSetChanged();
}

From source file:net.eledge.android.europeana.gui.fragment.RecordDetailsFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupClipboardAction(ListView mListView) {
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override/*from w w  w .j  a  v  a 2s  .  c  o m*/
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            RecordView record = mRecordViewAdapter.getItem(position);
            Activity activity = RecordDetailsFragment.this.getActivity();
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard
                    .setPrimaryClip(
                            ClipData.newPlainText(GuiUtils.getString(getActivity(), record.getLabel()),
                                    StringUtils.join(
                                            record.getValues(recordController.record,
                                                    (EuropeanaApplication) getActivity().getApplication()),
                                            ";")));
            GuiUtils.toast(activity, R.string.msg_copied2clipboard);
            return true;
        }
    });
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletAddressDialogFragment.java

private void handleCopy() {
    ClipboardManager clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setText(address);/* w  w  w .  j a v a2s.  c o  m*/
    activity.toast(R.string.wallet_address_dialog_copy_address);
}

From source file:im.neon.util.VectorUtils.java

/**
 * Copy a text to the clipboard./*from w w w.j  a  va 2 s  . c om*/
 *
 * @param context the context
 * @param text    the text to copy
 */
public static void copyToClipboard(Context context, CharSequence text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText("", text));
    Toast.makeText(context, context.getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
}

From source file:com.artemchep.horario.ui.fragments.details.TeacherDetailsFragment.java

@Override
protected ViewGroup onCreateContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
        @NonNull List<ContentItem<Teacher>> contentItems, @Nullable Bundle savedInstanceState) {
    getToolbar().inflateMenu(R.menu.details_teacher);

    ViewGroup vg = (ViewGroup) inflater.inflate(R.layout.fragment_details_teacher, container, false);
    initWithFab(R.id.action_edit, R.drawable.ic_pencil_white_24dp);

    mNoteContainer = vg.findViewById(R.id.info_container);
    mPhoneContainer = vg.findViewById(R.id.phone_container);
    mPhoneContainer.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w w  . j  a  va  2s  .  c o  m
        public void onClick(View view) {
            if (TextUtils.isEmpty(mModel.phone)) {
                Timber.tag(TAG).w("Tried to copy an empty phone!");
                return;
            }
            // Copy email to clipboard
            ClipboardManager clipboard = (ClipboardManager) getContext()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(mModel.phone, mModel.phone); // TODO: More informative description of the clip
            clipboard.setPrimaryClip(clip);

            // Show toast message
            String msg = getString(R.string.details_phone_clipboard, mModel.phone);
            Toasty.info(getContext(), msg).show();
        }
    });
    mEmailContainer = vg.findViewById(R.id.email_container);
    mEmailContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TextUtils.isEmpty(mModel.email)) {
                Timber.tag(TAG).w("Tried to copy an empty email!");
                return;
            }
            // Copy email to clipboard
            ClipboardManager clipboard = (ClipboardManager) getContext()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(mModel.email, mModel.email); // TODO: More informative description of the clip
            clipboard.setPrimaryClip(clip);

            // Show toast message
            String msg = getString(R.string.details_email_clipboard, mModel.email);
            Toasty.info(getContext(), msg).show();
        }
    });
    mPhoneButton = (Button) mPhoneContainer.findViewById(R.id.phone_send);
    mPhoneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TextUtils.isEmpty(mModel.phone)) {
                Timber.tag(TAG).w("Tried to call an empty phone!");
                return;
            }

            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:" + mModel.phone));

            try {
                startActivity(intent);
            } catch (ActivityNotFoundException ignored) {
            }
        }
    });
    mEmailButton = (Button) mEmailContainer.findViewById(R.id.email_send);
    mEmailButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TextUtils.isEmpty(mModel.email)) {
                Timber.tag(TAG).w("Tried to send to an empty email!");
                return;
            }

            String[] recipients = { mModel.email };
            Intent intent = new Intent().putExtra(Intent.EXTRA_EMAIL, recipients);
            intent.setAction(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:")); // only email apps should handle it

            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // TODO:!!!!!
                String msg = "No email app"; //getString(R.string.feedback_error_no_app);
                Toasty.info(getContext(), msg).show();
            }
        }
    });

    mNoteTextView = (TextView) mNoteContainer.findViewById(R.id.info);
    mEmailTextView = (TextView) mEmailContainer.findViewById(R.id.email);
    mPhoneTextView = (TextView) mPhoneContainer.findViewById(R.id.phone);

    // Note
    contentItems.add(new ContentItem<Teacher>() {
        @Override
        public void onSet(@Nullable Teacher model) {
            if (model == null || TextUtils.isEmpty(model.info)) {
                mNoteContainer.setVisibility(View.GONE);
            } else {
                mNoteContainer.setVisibility(View.VISIBLE);
                mNoteTextView.setText(model.info);
            }
        }

        @Override
        public boolean hasChanged(@Nullable Teacher old, @Nullable Teacher model) {
            String a = old != null ? old.info : null;
            String b = model != null ? model.info : null;
            return !TextUtils.equals(a, b);
        }
    });
    // Email
    contentItems.add(new ContentItem<Teacher>() {
        @Override
        public void onSet(@Nullable Teacher model) {
            if (model == null || TextUtils.isEmpty(model.email)) {
                mEmailContainer.setVisibility(View.GONE);
            } else {
                mEmailContainer.setVisibility(View.VISIBLE);
                mEmailTextView.setText(model.info);

                if (PatternUtils.isEmail(model.email)) {
                    mEmailButton.setVisibility(View.VISIBLE);
                } else
                    mEmailButton.setVisibility(View.GONE);
            }
        }

        @Override
        public boolean hasChanged(@Nullable Teacher old, @Nullable Teacher model) {
            String a = old != null ? old.email : null;
            String b = model != null ? model.email : null;
            return !TextUtils.equals(a, b);
        }
    });
    // Phone
    contentItems.add(new ContentItem<Teacher>() {
        @Override
        public void onSet(@Nullable Teacher model) {
            if (model == null || TextUtils.isEmpty(model.phone)) {
                mPhoneContainer.setVisibility(View.GONE);
            } else {
                mPhoneContainer.setVisibility(View.VISIBLE);
                mPhoneTextView.setText(model.phone);

                if (PatternUtils.isPhone(model.phone)) {
                    mPhoneButton.setVisibility(View.VISIBLE);
                } else
                    mPhoneButton.setVisibility(View.GONE);
            }
        }

        @Override
        public boolean hasChanged(@Nullable Teacher old, @Nullable Teacher model) {
            String a = old != null ? old.phone : null;
            String b = model != null ? model.phone : null;
            return !TextUtils.equals(a, b);
        }
    });

    return vg;
}

From source file:org.linphone.compatibility.ApiElevenPlus.java

public static void copyTextToClipboard(Context context, String msg) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Message", msg);
    clipboard.setPrimaryClip(clip);/*from ww  w  .  ja  v  a  2  s.c  o  m*/
}

From source file:com.kaliturin.blacklist.utils.Utils.java

/**
 * Copies passed text to clipboard/*from w  w w  .  ja v a  2  s. c  om*/
 **/
@SuppressWarnings("deprecation")
public static boolean copyTextToClipboard(Context context, String text) {
    try {
        if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(text);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData.newPlainText("", text);
            clipboard.setPrimaryClip(clip);
        }
        return true;
    } catch (Exception e) {
        Log.w(TAG, e);
        return false;
    }
}

From source file:piuk.blockchain.android.ui.AbstractWalletActivity.java

static void handleCopyToClipboard(final Context context, final String address) {
    final ClipboardManager clipboardManager = (ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setText(address);/*w ww  . j  av a 2 s .com*/

    Toast.makeText(context, R.string.wallet_address_fragment_clipboard_msg, Toast.LENGTH_SHORT).show();
}

From source file:marto.rtl_tcp_andro.StreamActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stream);
    prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

    terminal = (TextView) findViewById(R.id.terminal);
    scroll = (ScrollView) findViewById(R.id.ScrollArea);
    arguments = (EditText) findViewById(R.id.commandline);

    terminal.setText(Log.getFullLog());//from   www. jav  a  2 s .c o  m

    ((Button) findViewById(R.id.enable_gui)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.statusmsg).setVisibility(View.GONE);
            findViewById(R.id.gui).setVisibility(View.VISIBLE);
        }
    });

    (forceroot = (CheckBox) findViewById(R.id.forceRoot))
            .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    final SharedPreferences.Editor editor = prefs.edit();

                    editor.putBoolean(DISABLE_JAVA_FIX_PREF, isChecked);

                    editor.commit();
                }
            });
    forceroot.setChecked(prefs.getBoolean(DISABLE_JAVA_FIX_PREF, false));

    (onoff = (ToggleButton) findViewById(R.id.onoff)).setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            onoff.setChecked(false);
            Log.clear();
            startActivityForResult(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("iqsrc://" + arguments.getText().toString())), START_REQ_CODE);
        }
    });

    ((Button) findViewById(R.id.copybutton)).setOnClickListener(new Button.OnClickListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            final String textToClip = terminal.getText().toString();
            int sdk = android.os.Build.VERSION.SDK_INT;
            if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                        Context.CLIPBOARD_SERVICE);
                clipboard.setText(textToClip);
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                        Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("text label", textToClip);
                clipboard.setPrimaryClip(clip);
            }
            Toast.makeText(getApplicationContext(), R.string.copied_to_clip, Toast.LENGTH_LONG).show();
        }
    });

    ((Button) findViewById(R.id.clearbutton)).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.clear();
        }
    });

    ((Button) findViewById(R.id.help)).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(dialogs.DIAG_ABOUT);
        }
    });

    ((Button) findViewById(R.id.license)).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(dialogs.DIAG_LICENSE);
        }
    });
}

From source file:me.acristoffers.tracker.fragments.PackageDetailsFragment.java

private void setupUI() {
    final Activity activity = getActivity();
    final View view = getView();

    if (activity == null || view == null) {
        return;//from  w  ww .j a va  2  s  . co  m
    }

    String code = null;

    final Bundle arguments = getArguments();
    if (arguments != null) {
        code = arguments.getString(PackageDetailsActivity.PACKAGE_CODE);
    }

    if (code == null || code.isEmpty()) {
        final Intent intent = activity.getIntent();
        if (intent != null) {
            code = intent.getStringExtra(PackageDetailsActivity.PACKAGE_CODE);
        }
    }

    if (code == null || code.isEmpty()) {
        return;
    }

    final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.steps);

    final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(activity);
    recyclerView.setLayoutManager(layoutManager);

    pkg = new Package(code, getActivity(), null);

    final StepListAdapter stepListAdapter = new StepListAdapter(pkg, activity);
    recyclerView.setAdapter(stepListAdapter);

    TextView textView = (TextView) view.findViewById(R.id.name);
    textView.setText(pkg.getName());

    textView = (TextView) view.findViewById(R.id.code);
    textView.setText(pkg.getCod());
    textView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            final ClipboardManager clipboardManager = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipboardManager != null) {
                final String code = pkg.getCod();

                final ClipData clipData = ClipData.newPlainText(code, code);
                clipboardManager.setPrimaryClip(clipData);

                final Toast toast = Toast.makeText(activity, R.string.code_copied, Toast.LENGTH_SHORT);
                toast.show();

                return true;
            }

            return false;
        }
    });

    if (!pkg.getSteps().isEmpty()) {
        textView = (TextView) view.findViewById(R.id.emptyStepView);
        textView.setVisibility(View.INVISIBLE);
    }

    final NotificationManager nm = (NotificationManager) activity
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(pkg.getId());
}