Example usage for android.content ClipboardManager setPrimaryClip

List of usage examples for android.content ClipboardManager setPrimaryClip

Introduction

In this page you can find the example usage for android.content ClipboardManager setPrimaryClip.

Prototype

public void setPrimaryClip(@NonNull ClipData clip) 

Source Link

Document

Sets the current primary clip on the clipboard.

Usage

From source file:org.secuso.privacyfriendlypasswordgenerator.dialogs.UpdatePasswordDialog.java

public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    rootView = inflater.inflate(R.layout.dialog_update_passwords, null);

    visibility = false;/*from   w  ww  .  j a  va  2  s  . c  o m*/

    spinnerOld = (ProgressBar) rootView.findViewById(R.id.oldProgressBar);
    spinnerOld.setVisibility(View.GONE);

    spinnerNew = (ProgressBar) rootView.findViewById(R.id.newProgressBar);
    spinnerNew.setVisibility(View.GONE);

    Bundle bundle = getArguments();

    position = bundle.getInt("position");
    bindToDevice_enabled = bundle.getBoolean("bindToDevice_enabled");
    hashAlgorithm = bundle.getString("hash_algorithm");
    setOldMetaData(bundle);
    number_iterations = bundle.getInt("number_iterations");

    database = MetaDataSQLiteHelper.getInstance(getActivity());

    builder.setView(rootView);

    builder.setIcon(R.mipmap.ic_drawer);

    builder.setTitle(getActivity().getString(R.string.passwords_heading));

    Button displayButton = (Button) rootView.findViewById(R.id.displayButton);
    displayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            inputManager.hideSoftInputFromWindow(view.getWindowToken(),
                    InputMethodManager.RESULT_UNCHANGED_SHOWN);

            displayPasswords();
        }
    });

    ImageButton copyOldButton = (ImageButton) rootView.findViewById(R.id.copyOldButton);
    ImageButton copyNewButton = (ImageButton) rootView.findViewById(R.id.copyNewButton);

    copyOldButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            TextView oldPassword = (TextView) rootView.findViewById(R.id.textViewOldPassword);
            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("", oldPassword.getText());
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getActivity(), getActivity().getString(R.string.copy_clipboar_old),
                    Toast.LENGTH_SHORT).show();
        }
    });

    copyNewButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            TextView newPassword = (TextView) rootView.findViewById(R.id.textViewNewPassword);
            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("", newPassword.getText());
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getActivity(), getActivity().getString(R.string.copy_clipboar_new),
                    Toast.LENGTH_SHORT).show();
        }
    });

    builder.setPositiveButton(getActivity().getString(R.string.done), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            onClickDone();
        }
    });

    visibilityButton = (ImageButton) rootView.findViewById(R.id.visibilityButton);

    visibilityButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            editTextUpdateMasterpassword = (EditText) rootView.findViewById(R.id.editTextUpdateMasterpassword);

            if (!visibility) {
                visibilityButton.setImageResource(R.drawable.ic_visibility_off);
                editTextUpdateMasterpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                editTextUpdateMasterpassword.setSelection(editTextUpdateMasterpassword.getText().length());
                visibility = true;
            } else {
                visibilityButton.setImageResource(R.drawable.ic_visibility);
                editTextUpdateMasterpassword
                        .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                editTextUpdateMasterpassword.setSelection(editTextUpdateMasterpassword.getText().length());
                visibility = false;
            }
        }
    });

    return builder.create();
}

From source file:com.secupwn.aimsicd.ui.activities.DebugLogs.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Show the Up button in the action bar.
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    runOnUiThread(new Runnable() {
        @Override/*from   w  ww  .  j av  a2  s. c  om*/
        public void run() {
            logView.setFocusable(false);
        }
    });

    btnClear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                clearLogs();
            } catch (IOException e) {
                log.error("Error clearing logs", e);
            }
        }
    });

    btnCopy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData cd = ClipData.newPlainText("log", logView.getText());
            clipboard.setPrimaryClip(cd);
            Helpers.msgShort(DebugLogs.this, getString(R.string.msg_copied_to_clipboard));
        }
    });

    btnStop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (updateLogs) {
                updateLogs = false;
                btnStop.setText(getString(R.string.btn_start_logs));
            } else {
                startLogging();
            }
        }
    });

    /*
    // logcat radio buffer toggle on/off
    btnRadio.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (isRadioLogs) {
            isRadioLogs = false;
            btnRadio.setText(getString(R.string.btn_radio_logs));
        } else {
            isRadioLogs = true;
            btnRadio.setText(getString(R.string.btn_main_logs));
        }
    }
    });
    */

}

From source file:org.secuso.privacyfriendlypasswordgenerator.dialogs.GeneratePasswordDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    rootView = inflater.inflate(R.layout.dialog_generate_password, null);

    Bundle bundle = getArguments();/*  w  w  w. j a v a  2  s. c om*/

    position = bundle.getInt("position");
    clipboard_enabled = bundle.getBoolean("clipboard_enabled");
    bindToDevice_enabled = bundle.getBoolean("bindToDevice_enabled");
    hashAlgorithm = bundle.getString("hash_algorithm");
    number_iterations = bundle.getInt("number_iterations");
    visibility = false;

    spinner = (ProgressBar) rootView.findViewById(R.id.progressBar);
    spinner.setVisibility(View.GONE);

    database = MetaDataSQLiteHelper.getInstance(getActivity());
    metaData = database.getMetaData(position);

    TextView domain = (TextView) rootView.findViewById(R.id.domainHeadingTextView);
    domain.setText(metaData.getDOMAIN());

    TextView username = (TextView) rootView.findViewById(R.id.domainUsernameTextView);

    username.setText(metaData.getUSERNAME());

    TextView iteration = (TextView) rootView.findViewById(R.id.textViewIteration);
    iteration.setText(String.valueOf(metaData.getITERATION()));

    builder.setView(rootView);
    builder.setIcon(R.mipmap.ic_drawer);
    builder.setTitle(getActivity().getString(R.string.generate_heading));
    builder.setPositiveButton(getActivity().getString(R.string.done), null);

    Button generateButton = (Button) rootView.findViewById(R.id.generatorButton);
    generateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            TextView textViewPassword = (TextView) rootView.findViewById(R.id.textViewPassword);
            textViewPassword.setText("");

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            inputManager.hideSoftInputFromWindow(view.getWindowToken(),
                    InputMethodManager.RESULT_UNCHANGED_SHOWN);

            editTextMasterpassword = (EditText) rootView.findViewById(R.id.editTextMasterpassword);

            if (editTextMasterpassword.getText().toString().length() == 0) {
                Toast toast = Toast.makeText(getActivity().getBaseContext(),
                        getString(R.string.enter_masterpassword), Toast.LENGTH_SHORT);
                toast.show();
            } else if (editTextMasterpassword.getText().toString().length() < 8) {
                Toast toast = Toast.makeText(getActivity().getBaseContext(),
                        getString(R.string.masterpassword_length), Toast.LENGTH_SHORT);
                toast.show();
            } else {

                spinner.setVisibility(View.VISIBLE);

                generatePassword();
            }
        }
    });

    ImageButton copyButton = (ImageButton) rootView.findViewById(R.id.copyButton);

    copyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            TextView password = (TextView) rootView.findViewById(R.id.textViewPassword);

            if (password.getText().toString().length() > 0) {
                ClipboardManager clipboard = (ClipboardManager) getActivity()
                        .getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("", password.getText());
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getActivity(), getActivity().getString(R.string.password_copied),
                        Toast.LENGTH_SHORT).show();
            }

        }
    });

    visibilityButton = (ImageButton) rootView.findViewById(R.id.visibilityButton);

    visibilityButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            editTextMasterpassword = (EditText) rootView.findViewById(R.id.editTextMasterpassword);

            if (!visibility) {
                visibilityButton.setImageResource(R.drawable.ic_visibility_off);
                editTextMasterpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                editTextMasterpassword.setSelection(editTextMasterpassword.getText().length());
                visibility = true;
            } else {
                visibilityButton.setImageResource(R.drawable.ic_visibility);
                editTextMasterpassword
                        .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                editTextMasterpassword.setSelection(editTextMasterpassword.getText().length());
                visibility = false;
            }
        }
    });

    return builder.create();
}

From source file:com.sdrtouch.rtlsdr.StreamActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stream);

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

    terminal.setText(Log.getFullLog());//from www . j a  v  a 2s .  c  om

    findViewById(R.id.enable_gui).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mInterstitialAd.show();
            StreamActivity.this.findViewById(R.id.statusmsg).setVisibility(View.GONE);
            StreamActivity.this.findViewById(R.id.gui).setVisibility(View.VISIBLE);
        }
    });

    (onoff = (ToggleButton) findViewById(R.id.onoff)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Check.isNotNull(service);
            if (service.isRunning()) {
                service.closeService();
            } else {
                Intent intent = new Intent(Intent.ACTION_VIEW)
                        .setData(Uri.parse("iqsrc://" + arguments.getText().toString()));
                intent.setClass(StreamActivity.this, DeviceOpenActivity.class);
                StreamActivity.this.startActivityForResult(intent, START_REQ_CODE);
            }
            onoff.setChecked(service.isRunning());
        }
    });

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

    findViewById(R.id.copybutton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View ignored) {
            final String textToClip = terminal.getText().toString();
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("text label", textToClip);
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getApplicationContext(), R.string.copied_to_clip, Toast.LENGTH_LONG).show();
            mInterstitialAd.show();
        }
    });

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

    findViewById(R.id.help).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            StreamActivity.this.showDialog(dialogs.DIAG_ABOUT);
            mInterstitialAd.show();

        }
    });

    if (!RtlSdrApplication.IS_PLATFORM_SUPPORTED) {
        ((TextView) findViewById(R.id.warntext)).setText(R.string.platform_not_supported);
    }

    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
            .addTestDevice("E9DEB34031182776A4E765DCEF19F10D") // My phone
            .build();
    mAdView.loadAd(adRequest);

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-6887589184636373/7691977648");
    AdRequest adRequestInterstial = new AdRequest.Builder().addTestDevice("E9DEB34031182776A4E765DCEF19F10D")
            .build();
    mInterstitialAd.loadAd(adRequestInterstial);

    //listner for adClosed
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            AdRequest adRequest = new AdRequest.Builder().addTestDevice("E9DEB34031182776A4E765DCEF19F10D")
                    .build();
            mInterstitialAd.loadAd(adRequest);
        }
    });

}

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

@ProtoMethod(description = "Copy the content into the clipboard", example = "")
@ProtoMethodParam(params = { "label", "text" })
public void copyToClipboard(String label, String text) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(label, text));
}

From source file:co.dilaver.quoter.fragments.PopularFragment.java

private void showAlertDialog(final int pos) {
    CharSequence[] items = { getString(R.string.str_Save), getString(R.string.str_Share),
            getString(R.string.str_Copy) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                SharedPrefStorage sharedPrefStorage = new SharedPrefStorage(getActivity());
                Gson gson = new Gson();

                if (!MyApplication.savedQuotesList.contains(popularQuotesList.get(pos))) {
                    MyApplication.savedQuotesList.add(popularQuotesList.get(pos));
                    sharedPrefStorage.setSavedQuotes(gson.toJson(MyApplication.savedQuotesList));
                }/*from  www .  jav  a2 s . c o  m*/

                Snackbar.make(rootLayout, getString(R.string.str_AddedToFavoriteQuotes), Snackbar.LENGTH_SHORT)
                        .show();
            } else if (item == 1) {
                Intent shareIntent = new Intent(getActivity(), ShareActivity.class);
                shareIntent.putExtra("quote", popularQuotesList.get(pos).getQuoteText());
                shareIntent.putExtra("author", popularQuotesList.get(pos).getQuoteAuthor());
                startActivity(shareIntent);
            } else if (item == 2) {
                ClipboardManager clipboard = (ClipboardManager) getActivity()
                        .getSystemService(Activity.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Copied Text", popularQuotesList.get(pos).getQuoteText()
                        + " - " + popularQuotesList.get(pos).getQuoteAuthor());
                clipboard.setPrimaryClip(clip);

                Snackbar.make(rootLayout, getString(R.string.str_QuoteCopied), Snackbar.LENGTH_SHORT).show();
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java

private void copyToClipboard(String inputData) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(inputData, inputData);
    clipboard.setPrimaryClip(clip);
}

From source file:com.mohammedsazid.android.tagger.TaggerFragment.java

public boolean copyToClipboard(Context context, String text) {
    try {//from  ww w.j  a v  a  2  s .c o m
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                .getSystemService(context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText(getString(R.string.app_name),
                text);
        clipboard.setPrimaryClip(clip);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:de.msal.shoutemo.fragments.ChatFragment.java

@Override
public void onItemLongClicked(int position, final Post post) {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override/*from w w  w  .j a v a  2  s. c  om*/
        public void onClick(DialogInterface dialog, int which) {
            @SuppressLint("SimpleDateFormat")
            SimpleDateFormat sdf = new SimpleDateFormat("d. MMM, HH:mm", Locale.ENGLISH);
            String shareString = getString(R.string.clipboard_post, sdf.format(post.getDate()),
                    post.getAuthor(), post.getMessage().getText());
            switch (which) {
            case DialogInterface.BUTTON_NEGATIVE:
                break;
            case 0: // clipboard
                ClipData clip = ClipData.newPlainText(shareString, shareString);
                ClipboardManager clipboard = (ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getActivity(), R.string.dialog_copied, Toast.LENGTH_SHORT).show();
                break;
            case 1: // share
                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(Intent.EXTRA_TEXT, shareString);
                startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_title)));
                break;
            case 2: // user profile
                String url = "http://www.autemo.com/profiles/?id=";
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url + post.getAuthor()));
                startActivity(i);
                break;
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    @SuppressWarnings("unchecked")
    final Pair<String, Integer>[] items = new Pair[] {
            new Pair<>(getString(R.string.dialog_post_clipboard), R.drawable.ic_content_copy_white_24dp),
            new Pair<>(getString(R.string.dialog_post_share), R.drawable.ic_share_white_24dp), new Pair<>(
                    getString(R.string.dialog_post_user, post.getAuthor()), R.drawable.ic_person_white_24dp) };
    builder.setAdapter(new ArrayAdapter<Pair<String, Integer>>(getActivity(), R.layout.row_dialog_listitem,
            R.id.text, items) {
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            // text
            TextView tv = (TextView) v.findViewById(R.id.text);
            tv.setText(items[position].first);

            // icon
            ImageView iv = (ImageView) v.findViewById(R.id.icon);
            iv.setImageResource(items[position].second);

            return v;
        }
    }, listener).setNegativeButton(android.R.string.cancel, listener);

    AlertDialog dialog = builder.create();
    dialog.show();
}

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

private void performCopyCommand(String label, String command) {
    // Check we still in a valid context
    if (getActivity() == null) {
        return;/*  w ww  .  j  a  v a2 s.com*/
    }

    // Copy to clipboard
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, command);
    clipboard.setPrimaryClip(clip);

    // Show a confirmation message
    final String msg = getString(R.string.download_commands_dialog_copy_message, label);
    Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
}