Example usage for android.text ClipboardManager setText

List of usage examples for android.text ClipboardManager setText

Introduction

In this page you can find the example usage for android.text ClipboardManager setText.

Prototype

public abstract void setText(CharSequence text);

Source Link

Document

Sets the contents of the clipboard to the specified text.

Usage

From source file:com.hypodiabetic.happ.MainActivity.java

public void showAlgorithmJSON(View view) {
    Date dateVar = new Date();
    Profile profileNow = new Profile(dateVar, view.getContext());

    //Shows the JSON output of the selected Algorithm
    String rawAPSJSON = APS.rawJSON(view.getContext(), profileNow).toString();
    Snackbar snackbar = Snackbar.make(view, "RAW JSON: " + rawAPSJSON, Snackbar.LENGTH_INDEFINITE);

    View snackbarView = snackbar.getView();
    TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setMaxLines(5); //set the max lines for textview to show multiple lines

    snackbar.show();/*w w w . j a  v a 2  s .  c  om*/

    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    clipboard.setText(rawAPSJSON);
    Toast.makeText(view.getContext(), "Raw JSON sent to clipboard", Toast.LENGTH_SHORT).show();
}

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final void setClipboardContent(String newText) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    clipboard.setText(newText);
}

From source file:tm.alashow.datmusic.ui.activity.MainActivity.java

private void search(String query, final boolean refresh, long captchaSid, String captchaKey,
        boolean performerOnly) {
    oldQuery = query;//from ww  w.jav  a  2  s  .  c  o  m
    RequestParams params = new RequestParams();

    params.put("q", query);
    params.put("autocomplete", Config.VK_CONFIG_AUTOCOMPLETE);
    params.put("sort", CONFIG_SORT);
    params.put("count", CONFIG_COUNT);

    params.put("performer_only", (performerOnly) ? 1 : CONFIG_PERFORMER_ONLY);

    if (captchaSid > 1) {
        params.put("captcha_sid", captchaSid);
        params.put("captcha_key", captchaKey);
    }

    //change search method to getPopular, if query empty. get popular music.

    ApiClient.get(Config.SEARCH, params, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            U.hideView(errorView);
            if (refresh) {
                swipeRefreshLayout.setRefreshing(true);
            } else {
                U.showView(progressBar);
                U.hideView(mListView);
            }
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                clearList();//clear old data
                if (response.has("error")) { //if we have error
                    //Result errors
                    JSONObject errorObject = response.getJSONObject("error");
                    int errorCode = errorObject.getInt("error_code");
                    //showing error
                    switch (errorCode) {
                    case 5:
                        showError("token");
                        break;
                    case 6: // "Too many requests per second" error, retry
                        search(oldQuery);
                        break;
                    case 14:
                        showCaptcha(errorObject.getString("captcha_img"), errorObject.getLong("captcha_sid"));
                        showError("captcha");
                        break;
                    default:
                        showError(errorObject.getString("error_msg"));
                        break;
                    }
                    return;
                }
                JSONArray audios = response.getJSONArray("response");
                if (audios.length() >= 2) {
                    for (int i = 1; i < audios.length(); i++)
                        audioList.add(new Audio((JSONObject) audios.get(i)));
                    audioListAdapter = new AudioListAdapter(MainActivity.this, audioList);
                    mListView.setAdapter(audioListAdapter);
                    mListView.setFastScrollEnabled(audioList.size() > 10);

                    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            final Audio audio = audioList.get(position);
                            final BottomSheet bottomSheet = new BottomSheet.Builder(MainActivity.this)
                                    .title(audio.getArtist() + " - " + audio.getTitle())
                                    .sheet(R.menu.audio_actions)
                                    .listener(new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            switch (which) {
                                            case R.id.download:
                                                DownloadManager mgr = (DownloadManager) getSystemService(
                                                        DOWNLOAD_SERVICE);
                                                Uri downloadUri = Uri.parse(audio.getDownloadUrl());
                                                DownloadManager.Request request = new DownloadManager.Request(
                                                        downloadUri);

                                                if (U.isAboveOfVersion(11)) {
                                                    request.setNotificationVisibility(
                                                            DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                                }

                                                request.setAllowedNetworkTypes(
                                                        DownloadManager.Request.NETWORK_WIFI
                                                                | DownloadManager.Request.NETWORK_MOBILE);
                                                mgr.enqueue(request);
                                                break;
                                            case R.id.play:
                                                playAudio(audio);
                                                break;
                                            case R.id.copy:
                                                if (!U.isAboveOfVersion(11)) {
                                                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                                                            CLIPBOARD_SERVICE);
                                                    clipboard.setText(audio.getSecureDownloadUrl());
                                                } else {
                                                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                                                            CLIPBOARD_SERVICE);
                                                    android.content.ClipData clip = android.content.ClipData
                                                            .newPlainText("Link", audio.getSecureDownloadUrl());
                                                    clipboard.setPrimaryClip(clip);
                                                    U.showCenteredToast(MainActivity.this,
                                                            R.string.audio_copied);
                                                }
                                                break;
                                            case R.id.share:
                                                String shareText = getString(R.string.share_text)
                                                        + audio.getSecureDownloadUrl();
                                                Intent sendIntent = new Intent();
                                                sendIntent.setAction(Intent.ACTION_SEND);
                                                sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
                                                sendIntent.setType("text/plain");
                                                startActivity(sendIntent);
                                            }
                                        }
                                    }).show();

                            //If file size already set, show it
                            if (audio.getBytes() > 1) {
                                setSizeAndBitrate(bottomSheet, audio);
                            } else {
                                try {
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            try {
                                                URLConnection ucon;
                                                final URL uri = new URL(audio.getDownloadUrl());
                                                ucon = uri.openConnection();
                                                ucon.connect();
                                                final long bytes = Long
                                                        .parseLong(ucon.getHeaderField("content-length"));
                                                runOnUiThread(new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        audio.setBytes(bytes);
                                                        setSizeAndBitrate(bottomSheet, audio);
                                                    }
                                                });
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    }).start();
                                } catch (final Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    });

                    if (refresh) {
                        swipeRefreshLayout.setRefreshing(false);
                    } else {
                        U.hideView(progressBar);
                    }
                } else {
                    showError("notFound");
                }
            } catch (Exception e) {
                U.showCenteredToast(MainActivity.this, R.string.exception);
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            showError("network");
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            showError("network");
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
            showError("network");
        }

        @Override
        public void onFinish() {
            U.showView(mListView);
            if (refresh) {
                swipeRefreshLayout.setRefreshing(false);
            } else {
                U.hideView(progressBar);
            }
        }
    });
}

From source file:tv.acfun.a63.CommentsActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override//from   w w w.java  2  s.c om
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Object o = parent.getItemAtPosition(position);
    if (o == null || !(o instanceof Comment))
        return false;
    Comment c = (Comment) o;
    ClipboardManager ma = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ClipData text = ClipData.newHtmlText(c.userName, c.content, c.content);
        ((android.content.ClipboardManager) ma).setPrimaryClip(text);
    } else {
        ma.setText(c.content);
    }
    Toast.makeText(this, "#" + c.count + "?", 0).show();
    return true;
}

From source file:com.irccloud.android.activity.PreferencesActivity.java

@SuppressWarnings("deprecation")
@Override/*www .j a  v a  2  s  .  co m*/
public void onCreate(Bundle icicle) {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    super.onCreate(icicle);
    getDelegate().installViewFactory();
    getDelegate().onCreate(icicle);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));
        cloud.recycle();
    }
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.actionbar_prefs);

    Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    toolbar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));

    if (Build.VERSION.SDK_INT >= 21)
        toolbar.setElevation(0);

    conn = NetworkConnection.getInstance();
    addPreferencesFromResource(R.xml.preferences_account);
    addPreferencesFromResource(R.xml.preferences_display);
    addPreferencesFromResource(R.xml.preferences_device);
    addPreferencesFromResource(R.xml.preferences_photos);
    addPreferencesFromResource(R.xml.preferences_notifications);
    addPreferencesFromResource(R.xml.preferences_dashclock);
    findPreference("dashclock_showmsgs").setOnPreferenceChangeListener(dashclocktoggle);
    try {
        int pebbleVersion = getPackageManager().getPackageInfo("com.getpebble.android", 0).versionCode;
        if (pebbleVersion < 553)
            addPreferencesFromResource(R.xml.preferences_pebble);
    } catch (Exception e) {
    }
    boolean foundSony = false;
    try {
        getPackageManager().getPackageInfo("com.sonyericsson.extras.liveware", 0);
        addPreferencesFromResource(R.xml.preferences_sony);
        foundSony = true;
    } catch (Exception e) {
    }
    if (!foundSony) {
        try {
            getPackageManager().getPackageInfo("com.sonyericsson.extras.smartwatch", 0);
            addPreferencesFromResource(R.xml.preferences_sony);
            foundSony = true;
        } catch (Exception e) {
        }
    }
    if (!foundSony) {
        try {
            getPackageManager().getPackageInfo("com.sonyericsson.extras.liveview", 0);
            addPreferencesFromResource(R.xml.preferences_sony);
            foundSony = true;
        } catch (Exception e) {
        }
    }
    if (foundSony)
        findPreference("notify_sony").setOnPreferenceChangeListener(sonytoggle);
    if (BuildConfig.DEBUG)
        addPreferencesFromResource(R.xml.preferences_debug);
    addPreferencesFromResource(R.xml.preferences_about);
    findPreference("name").setOnPreferenceChangeListener(settingstoggle);

    findPreference("autoaway").setOnPreferenceChangeListener(settingstoggle);
    findPreference("time-24hr").setOnPreferenceChangeListener(prefstoggle);
    findPreference("time-seconds").setOnPreferenceChangeListener(prefstoggle);
    findPreference("mode-showsymbol").setOnPreferenceChangeListener(prefstoggle);
    findPreference("pastebin-disableprompt").setOnPreferenceChangeListener(prefstoggle);
    if (findPreference("emoji-disableconvert") != null) {
        findPreference("emoji-disableconvert").setOnPreferenceChangeListener(prefstoggle);
        findPreference("emoji-disableconvert").setSummary(":thumbsup:  \uD83D\uDC4D");
    }
    findPreference("nick-colors").setOnPreferenceChangeListener(prefstoggle);
    findPreference("faq").setOnPreferenceClickListener(urlClick);
    findPreference("feedback").setOnPreferenceClickListener(urlClick);
    findPreference("licenses").setOnPreferenceClickListener(licensesClick);
    findPreference("imageviewer").setOnPreferenceChangeListener(imageviewertoggle);
    findPreference("imgur_account_username").setOnPreferenceClickListener(imgurClick);
    //findPreference("subscriptions").setOnPreferenceClickListener(urlClick);
    //findPreference("changes").setOnPreferenceClickListener(urlClick);
    findPreference("notify_type").setOnPreferenceChangeListener(notificationstoggle);
    findPreference("notify_led_color").setOnPreferenceChangeListener(ledtoggle);
    findPreference("photo_size").setOnPreferenceChangeListener(photosizetoggle);

    imgurPreference = findPreference("imgur_account_username");
    if (NetworkConnection.getInstance().uploadsAvailable()) {
        if (!PreferenceManager.getDefaultSharedPreferences(this).getString("image_service", "IRCCloud")
                .equals("imgur")) {
            PreferenceCategory c = (PreferenceCategory) findPreference("photos");
            c.removePreference(imgurPreference);
        }
        findPreference("image_service").setOnPreferenceChangeListener(imageservicetoggle);
    } else {
        PreferenceCategory c = (PreferenceCategory) findPreference("photos");
        c.removePreference(findPreference("image_service"));
    }

    try {
        final String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        findPreference("version").setSummary(version);
        findPreference("version").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            CLIPBOARD_SERVICE);
                    clipboard.setText(version);
                } else {
                    @SuppressLint("ServiceCast")
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("IRCCloud Version",
                            version);
                    clipboard.setPrimaryClip(clip);
                }
                Toast.makeText(PreferencesActivity.this, "Version number copied to clipboard",
                        Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.torproject.android.Orbot.java

private void doLayout() {
    setContentView(R.layout.layout_main);

    mViewMain = findViewById(R.id.viewMain);
    lblStatus = (TextView) findViewById(R.id.lblStatus);
    lblStatus.setOnLongClickListener(this);
    imgStatus = (ImageProgressView) findViewById(R.id.imgStatus);
    imgStatus.setOnLongClickListener(this);
    imgStatus.setOnTouchListener(this);

    lblStatus.setText("Initializing the application...");

    downloadText = (TextView) findViewById(R.id.trafficDown);
    uploadText = (TextView) findViewById(R.id.trafficUp);
    mTxtOrbotLog = (TextView) findViewById(R.id.orbotLog);

    mDrawer = ((SlidingDrawer) findViewById(R.id.SlidingDrawer));
    Button slideButton = (Button) findViewById(R.id.slideButton);
    if (slideButton != null) {
        slideButton.setOnTouchListener(new OnTouchListener() {

            @Override/*from   w  w w.j  a va  2s  . com*/
            public boolean onTouch(View v, MotionEvent event) {

                if (event.equals(MotionEvent.ACTION_DOWN)) {
                    mDrawerOpen = !mDrawerOpen;
                    mTxtOrbotLog.setEnabled(mDrawerOpen);
                }
                return false;
            }

        });
    }

    ScrollingMovementMethod smm = new ScrollingMovementMethod();

    mTxtOrbotLog.setMovementMethod(smm);
    mTxtOrbotLog.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            cm.setText(mTxtOrbotLog.getText());
            Toast.makeText(Orbot.this, "LOG COPIED TO CLIPBOARD", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    downloadText.setText(formatCount(0) + " / " + formatTotal(0));
    uploadText.setText(formatCount(0) + " / " + formatTotal(0));

    // Gesture detection
    mGestureDetector = new GestureDetector(this, new MyGestureDetector());

}

From source file:net.momodalo.app.vimtouch.VimTouch.java

private void doCopyAll() {
    ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    clip.setText(Exec.getCurrBuffer());
}

From source file:org.uguess.android.sysinfo.NetStateManager.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    int pos = ((AdapterContextMenuInfo) item.getMenuInfo()).position;

    if (pos > 0 && pos < getListView().getCount()) {
        ConnectionItem itm = (ConnectionItem) getListView().getItemAtPosition(pos);

        if (itm != null && !TextUtils.isEmpty(itm.remote)) {
            ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

            if (cm != null) {
                cm.setText(itm.remoteName == null ? itm.remote : itm.remoteName);

                Util.shortToast(getActivity(), R.string.copied_hint);
            }//from   w w w .j  av a 2 s  . com
        }

        return true;
    }

    return false;
}

From source file:info.staticfree.android.units.Units.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final ContextMenuInfo ctxMenuInfo = item.getMenuInfo();
    int position = history.getCount() - 1;
    if (ctxMenuInfo instanceof AdapterContextMenuInfo) {
        position = ((AdapterContextMenuInfo) ctxMenuInfo).position;
    }/*  w  w  w  .java2s  .c o  m*/
    final Uri itemUri = ContentUris.withAppendedId(HistoryEntry.CONTENT_URI,
            mHistoryAdapter.getItemId(position));

    switch (item.getItemId()) {
    case MENU_COPY: {
        final CharSequence itemText = getEntryAsCharSequence(itemUri);
        final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipboard.setText(itemText);
        Toast.makeText(this, getString(R.string.toast_copy, itemText), Toast.LENGTH_SHORT).show();
    }
        break;

    case MENU_REEDIT: {
        setCurrentEntry(itemUri);
        setHistoryVisible(false);
    }
        break;

    case MENU_SEND: {
        final CharSequence itemText = getEntryAsCharSequence(itemUri);
        startActivity(Intent.createChooser(
                new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, itemText),
                getText(R.string.ctx_menu_send_title)));
    }
        break;

    case MENU_USE_RESULT: {
        final Cursor c = getContentResolver().query(itemUri, PROJECTION_LOAD_FROM_HISTORY, null, null, null);
        if (c.moveToFirst()) {
            final int resultCol = c.getColumnIndex(HistoryEntry._RESULT);
            setCurrentEntry((c.isNull(resultCol) ? "" : (c.getDouble(resultCol) + " "))
                    + c.getString(c.getColumnIndex(HistoryEntry._WANT)), "");
            setHistoryVisible(false);
        }
        c.close();
    }
        break;
    }

    return super.onContextItemSelected(item);
}