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:org.hopestarter.wallet.ui.RequestCoinsFragment.java

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

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.loaderManager = getLoaderManager();
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
}

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

@Nullable
@Override//  w ww .j ava2 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:cc.mintcoin.wallet.ui.RequestCoinsFragment.java

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

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.loaderManager = getLoaderManager();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}

From source file:com.manzdagratiano.gobbledygook.Gobbledygook.java

/**
 * @brief   Called after onCreate() (and onStart(),
 * when the activity begins interacting with the user)
 * @return  Does not return a value//from w  w w  .j  av a2s.c om
 */
@Override
public void onResume() {
    Log.i(Env.LOG_CATEGORY, "onResume(): Configuring...");
    super.onResume();

    // ----------------------------------------------------------------
    // Retrieve saved preferences
    // The SharedPreferences handle
    Log.i(Env.LOG_CATEGORY, "Reading saved preferences...");
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    // The salt key 
    String saltKey = "";
    Integer defaultIterations = Attributes.DEFAULT_ITERATIONS;
    String encodedAttributesList = "";
    // Catch all exceptions when reading from SharedPreferences
    try {
        saltKey = sharedPrefs.getString(getString(R.string.pref_saltKey_key), "");
        // The default number of PBKDF2 iterations.
        // Since the preference is an EditTextPreference,
        // even though it has the numeric attribute,
        // and is entered as an integer,
        // it is saved as a string.
        // Therefore, it must be retrieved as a string and then cast.
        String defaultIterationsStr = sharedPrefs.getString(getString(R.string.pref_defaultIterations_key), "");
        // If non-empty, parse as an Integer.
        // The empty case will leave defaultIterations at
        // Attributes.DEFAULT_ITERATIONS.
        if (!defaultIterationsStr.isEmpty()) {
            defaultIterations = Integer.parseInt(defaultIterationsStr);
        }
        // The encoded siteAttributesList
        encodedAttributesList = sharedPrefs.getString(getString(R.string.pref_siteAttributesList_key), "");
    } catch (Exception e) {
        Log.e(Env.LOG_CATEGORY, "ERROR: Caught " + e);
        e.printStackTrace();
    }

    Log.d(Env.LOG_CATEGORY, "savedPreferences=[ saltKey='" + saltKey + "', " + "defaultIterations="
            + defaultIterations.toString() + ", " + "siteAttributesList='" + encodedAttributesList + "' ]");

    // ----------------------------------------------------------------
    // Create the "actors"

    AttributesCodec codec = new AttributesCodec();
    Configurator config = new Configurator();

    // ----------------------------------------------------------------
    // Read the url from the clipboard
    Log.i(Env.LOG_CATEGORY, "Reading url from clipboard...");
    String url = "";
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {
        ClipData.Item clipItem = clipboard.getPrimaryClip().getItemAt(0);
        CharSequence clipText = clipItem.getText();
        if (null != clipText) {
            url = clipText.toString();
        }
    }
    Log.i(Env.LOG_CATEGORY, "url='" + url + "'");

    // ----------------------------------------------------------------
    // Extract the domain from the url

    String domain = config.extractDomain(url);
    Log.i(Env.LOG_CATEGORY, "domain='" + domain + "'");

    // ----------------------------------------------------------------
    // Saved and Proposed Attributes

    // Obtain the saved attributes for this domain, if any
    Attributes savedAttributes = codec.getSavedAttributes(domain, encodedAttributesList);
    Log.i(Env.LOG_CATEGORY, "savedAttributes='" + codec.encode(savedAttributes) + "'");

    // The "proposed" attributes,
    // which would be used to generate the proxy password,
    // unless overridden
    Attributes proposedAttributes = new Attributes(config.configureDomain(domain, savedAttributes.domain()),
            config.configureIterations(defaultIterations, savedAttributes.iterations()),
            config.configureTruncation(savedAttributes.truncation()));

    config.configureHash();
}

From source file:com.timrae.rikaidroid.MainActivity.java

private void loadContentFromClipboard() {
    if (mWebView == null) {
        Log.e(TAG, "Webview is null");
        return;/*from www  . java 2  s . co m*/
    }
    // Get clipboard
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (!(clipboard.hasPrimaryClip())) {
        Log.w(TAG, "Clipboard is empty");
        return;
    }
    // Get string from clipboard
    ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
    String pasteData = item.getText().toString();
    //pasteData = "??????????";
    if (pasteData == null) {
        Log.w(TAG, "Clipboard doesn't contain text");
        return;
    }
    mEditText.setText(pasteData);
}

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. j  a v  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);//from  www.j a  va2s. c  om
    } else {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    }
}

From source file:com.codebutler.farebot.fragment.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    try {//from   ww w  .  j a  v a 2s.co  m
        int itemId = item.getItemId();
        switch (itemId) {
        case R.id.import_file:
            Intent target = new Intent(Intent.ACTION_GET_CONTENT);
            target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory()));
            target.setType("*/*");
            startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)),
                    REQUEST_SELECT_FILE);
            return true;
        case R.id.import_clipboard:
            ClipData clip = clipboardManager.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                String text = clip.getItemAt(0).coerceToText(getActivity()).toString();
                onCardsImported(mExportHelper.importCards(text));
            }
            return true;
        case R.id.copy:
            clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards()));
            Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.share:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards());
            startActivity(intent);
            return true;
        case R.id.save:
            exportToFile();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}

From source file:org.kontalk.ui.DonationFragment.java

private void donateBitcoin() {
    final String address = getString(R.string.bitcoin_address);
    Uri uri = Uri.parse("bitcoin:" + address);
    Intent intent = SystemUtils.externalIntent(Intent.ACTION_VIEW, Uri.parse(uri.toString()));

    Activity ctx = getActivity();/*from   w w  w.  jav a 2s  . c o  m*/
    final PackageManager pm = ctx.getPackageManager();
    if (pm.resolveActivity(intent, 0) != null)
        startActivity(intent);
    else
        new MaterialDialog.Builder(getActivity()).title(R.string.title_bitcoin_dialog)
                .content(getString(R.string.text_bitcoin_dialog, address)).positiveText(android.R.string.ok)
                .neutralText(R.string.copy_clipboard).onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        ClipboardManager cpm = (ClipboardManager) getActivity()
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        cpm.setText(address);

                        Toast.makeText(getActivity(), R.string.bitcoin_clipboard_copied, Toast.LENGTH_LONG)
                                .show();
                    }
                }).show();
}

From source file:com.scm.reader.resultPage.webview.ShortcutWebViewClient.java

private void overrideCopy(String text) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);//  w w  w. j  a  v  a 2  s  .c  o m
    }
}