Example usage for android.content ClipData newPlainText

List of usage examples for android.content ClipData newPlainText

Introduction

In this page you can find the example usage for android.content ClipData newPlainText.

Prototype

static public ClipData newPlainText(CharSequence label, CharSequence text) 

Source Link

Document

Create a new ClipData holding data of the type ClipDescription#MIMETYPE_TEXT_PLAIN .

Usage

From source file:de.dknapps.pswgendroid.ServiceDetailFragment.java

/**
 * Generiert das Passwort und kopiert es in die Zwischenablage.
 * /*w  w w.  j av  a2  s  .  c  o m*/
 * FIXME dkn Die callingActivity kann durch getActivity() ersetzt werden.
 */
public void onClickButtonCopyPassword(final Activity callingActivity, final View buttonOpenUrl) {
    try {
        String password = getValidatedOrGeneratedPassword();
        ClipboardManager clipboard = (ClipboardManager) callingActivity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, password));
    } catch (Exception e) {
        PswGenAdapter.handleThrowable(callingActivity, e);
    }
}

From source file:com.physphil.android.unitconverterultimate.fragments.ConversionFragment.java

@Nullable
@Override/*from w  ww  .  ja v  a2 s.  c  o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_conversion, container, false);

    mTxtValue = (EditText) v.findViewById(R.id.header_value_from);
    if (savedInstanceState == null) {
        String value = mPrefs.getLastValue();
        if (mConversionId != Conversion.TEMPERATURE) {
            // adjust value if it was negative coming from temperature conversion
            value = value.replace("-", "");
            value = value.replace("+", "");
        }
        mTxtValue.setText(value);
        mTxtValue.setSelection(mTxtValue.getText().length());
    }

    // Only allow negative values for temperature
    if (mConversionId == Conversion.TEMPERATURE) {
        mTxtValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);
    } else {
        mTxtValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    }

    mTxtResult = (EditText) v.findViewById(R.id.header_value_to);
    mTxtResult.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // Copy text to clipboard
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Conversion Result", ((EditText) v).getText().toString());
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getActivity(), R.string.toast_copied_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    mGrpFrom = (RadioGroup) v.findViewById(R.id.radio_group_from);
    mGrpTo = (RadioGroup) v.findViewById(R.id.radio_group_to);
    addUnits();

    ObservableScrollView scrollView = (ObservableScrollView) v.findViewById(R.id.list_conversion);
    FloatingActionButton fab = (FloatingActionButton) v.findViewById(R.id.fab);
    fab.attachToScrollView(scrollView);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            swapUnits();
        }
    });

    return v;
}

From source file:cat.ereza.customactivityoncrash.activity.DefaultErrorReportActivity.java

private void copyErrorToClipboard() {
    String errorInformation = CustomActivityOnCrash
            .getAllErrorDetailsFromIntent(DefaultErrorReportActivity.this, getIntent());

    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(
            getString(R.string.customactivityoncrash_error_activity_error_details_clipboard_label),
            errorInformation);/*from   w  ww  .j ava 2  s .com*/
    clipboard.setPrimaryClip(clip);
}

From source file:com.vsmartcard.acardemulator.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_copy:
        // Code to Copy the content of Text View to the Clip board.
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("simple text", textViewVPCDStatus.getText());
        clipboard.setPrimaryClip(clip);/* w  w  w .j a  v a 2 s .  c om*/
        Toast.makeText(getApplicationContext(), "Log copied to clipboard.", Toast.LENGTH_LONG).show();
        return true;
    case R.id.action_delete:
        textViewVPCDStatus.setText("");
        return true;
    case R.id.action_help:
        showStartupMessage();
        return true;
    case R.id.action_settings:
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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();//from  w w  w  . j  av  a2  s . co  m

    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());//  w  w w  .jav  a  2  s. c o  m

    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:ru.valle.safetrade.BuyActivity.java

@SuppressWarnings("deprecation")
private void copyTextToClipboard(String label, String text) {
    if (Build.VERSION.SDK_INT >= 11) {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(label, text);
        clipboard.setPrimaryClip(clip);/*w  w w .j  a v a2s  .  c o  m*/
    } else {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    }
}

From source file:com.raza.betternts.activities.TabFragment2.java

private void menuOption(Cursor cursor, int selectedOption) {
    String name = cursor.getString(cursor.getColumnIndex(DbSchema.COL_NAME));
    String url = cursor.getString(cursor.getColumnIndex(DbSchema.COL_URL));
    switch (selectedOption) {
    //Open in browser
    case 0: {//  w w  w  .java  2  s.  co m
        Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(browse);
        break;
    }
    //Copy to clipboard
    case 1: {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(name, url);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), "Link copied to clipboard", Toast.LENGTH_SHORT).show();
        break;
    }
    //Share
    case 2: {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, url);
        sendIntent.setType("text/plain");
        startActivity(sendIntent);
        break;
    }
    case 3: {
        moveToMain(cursor);
        Toast.makeText(getContext(), name + "\nrestored to Vacancies tab", Toast.LENGTH_SHORT).show();
    }
    }
}

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

public void copyMessage3(View v) {

    String copiedMessage3 = messageThree.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message3", copiedMessage3);
    clipboard.setPrimaryClip(clip);/*  w  ww .  j a  v  a  2s. co  m*/

    showToast();
}

From source file:com.torygaurnier.openpalette.MainFragment.java

/**
 * Color action is selected.//w w w. ja v a  2s  .  c  o m
 */
public boolean onContextItemSelected(MenuItem item) {
    int position = (int) ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).id;
    final Palette selected_palette = palette_list.getSelectedPalette();
    final HexColor color = selected_palette.getColor(position);

    switch (item.getItemId()) {
    case R.id.copyHexAction:
        String hex = color.getHex();
        clip = ClipData.newPlainText("HEX", hex);
        clipboard.setPrimaryClip(clip);
        Msg.log(Msg.INFO, "onContextItemSelected()", hex + " copied to clipboard");
        return true;

    case R.id.copyRgbAction:
        String rgb = "" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue();
        clip = ClipData.newPlainText("RGB", rgb);
        clipboard.setPrimaryClip(clip);
        Msg.log(Msg.INFO, "onContextItemSelected()", rgb + " copied to clipboard");
        return true;

    case R.id.copyHsvAction:
        String hsv = "" + color.getHue() + ", " + color.getSaturation() + ", " + color.getValue();
        clip = ClipData.newPlainText("HSV", hsv);
        clipboard.setPrimaryClip(clip);
        Msg.log(Msg.INFO, "onContextItemSelected()", hsv + " copied to clipboard");
        return true;

    case R.id.duplicateColorAction:
        if (color.getName() != null) {
            selected_palette.add(new HexColor(color.getHex(), color.getName()));
        } else {
            selected_palette.add(new HexColor(color.getHex()));
        }

        Data.getInstance().save();
        return true;

    case R.id.editColorAction:
        new ColorChooserDialog(activity).show(color);
        return true;

    case R.id.deleteColorAction:
        selected_palette.remove(color);
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}