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:net.sourceforge.fidocadj.FidoMain.java

/** Stores the given String in the clipboard.
*//*  ww w  .  j  a  v a  2s  .  c o  m*/
public void copyText(String s) {
    // Gets a handle to the clipboard service.
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("simple text", s.toString());
    clipboard.setPrimaryClip(clip);
}

From source file:de.baumann.browser.Browser_right.java

@Override
protected void onResume() {
    super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
    mWebView.onResume();//w ww .  j a  va  2  s.  co  m
    final String URL = sharedPref.getString("openURL", "https://github.com/scoute-dich/browser/");
    new Handler().postDelayed(new Runnable() {
        public void run() {
            if (URL.equals(mWebView.getUrl()) || URL.equals("")) {
                Log.i(TAG, "Tab switched");
            } else if (URL.equals("copyLogin")) {
                Snackbar snackbar = Snackbar
                        .make(mWebView, R.string.pass_copy_userName, Snackbar.LENGTH_INDEFINITE)
                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ClipboardManager clipboard = (ClipboardManager) Browser_right.this
                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                clipboard.setPrimaryClip(
                                        ClipData.newPlainText("userName", sharedPref.getString("copyUN", "")));

                                Snackbar snackbar = Snackbar
                                        .make(mWebView, R.string.pass_copy_userPW, Snackbar.LENGTH_INDEFINITE)
                                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                ClipboardManager clipboard = (ClipboardManager) Browser_right.this
                                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                                clipboard.setPrimaryClip(ClipData.newPlainText("userName",
                                                        sharedPref.getString("copyPW", "")));
                                            }
                                        });
                                snackbar.show();
                            }
                        });
                snackbar.show();
            } else if (URL.contains("openLogin")) {
                mWebView.loadUrl(URL.replace("openLogin", ""));
                Snackbar snackbar = Snackbar
                        .make(mWebView, R.string.pass_copy_userName, Snackbar.LENGTH_INDEFINITE)
                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ClipboardManager clipboard = (ClipboardManager) Browser_right.this
                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                clipboard.setPrimaryClip(
                                        ClipData.newPlainText("userName", sharedPref.getString("copyUN", "")));

                                Snackbar snackbar = Snackbar
                                        .make(mWebView, R.string.pass_copy_userPW, Snackbar.LENGTH_INDEFINITE)
                                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                ClipboardManager clipboard = (ClipboardManager) Browser_right.this
                                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                                clipboard.setPrimaryClip(ClipData.newPlainText("userName",
                                                        sharedPref.getString("copyPW", "")));
                                            }
                                        });
                                snackbar.show();
                            }
                        });
                snackbar.show();
            } else {
                mWebView.loadUrl(URL);
            }
        }
    }, 100);
}

From source file:com.almalence.opencam.Fragment.java

@TargetApi(13)
private void showCameraParameters() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle(R.string.Pref_CameraParameters_Title);
    final StringBuilder about_string = new StringBuilder();
    String version = "UNKNOWN_VERSION";
    int version_code = -1;
    try {/* www  .j  a  v  a 2  s  .c  o m*/
        PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        version = pInfo.versionName;
        version_code = pInfo.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    about_string.append("\nApplication name: ");
    about_string.append(MainScreen.getInstance().getResources().getString(R.string.Pref_About));
    about_string.append("\nAndroid API version: ");
    about_string.append(Build.VERSION.SDK_INT);
    about_string.append("\nDevice manufacturer: ");
    about_string.append(Build.MANUFACTURER);
    about_string.append("\nDevice model: ");
    about_string.append(Build.MODEL);
    about_string.append("\nDevice code-name: ");
    about_string.append(Build.HARDWARE);
    about_string.append("\nDevice variant: ");
    about_string.append(Build.DEVICE);
    {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Activity.ACTIVITY_SERVICE);
        about_string.append("\nStandard max heap (MB): ");
        about_string.append(activityManager.getMemoryClass());
        about_string.append("\nLarge max heap (MB): ");
        about_string.append(activityManager.getLargeMemoryClass());
    }
    {
        Point display_size = new Point();
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        display.getSize(display_size);
        about_string.append("\nDisplay size: ");
        about_string.append(display_size.x);
        about_string.append("x");
        about_string.append(display_size.y);
    }

    //show camera 2 support level
    int level = CameraController.getCamera2Level();
    about_string.append("\nCamera2 API: ");
    switch (level) {
    case 0://limited
        about_string.append("limited");
        break;
    case 1://full
        about_string.append("full");
        break;
    case 2://legacy
        about_string.append("legacy");
        break;
    default:
        about_string.append("not supported");
    }

    //      about_string.append("\nSensor orientation, back camera: ");
    //      about_string.append(CameraController.getSensorOrientation(0));
    //      about_string.append("\nSensor orientation, front camera: ");
    //      about_string.append(CameraController.getSensorOrientation(1));

    if (MainScreen.getInstance().preview_sizes != null) {
        about_string.append("\nPreview resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().preview_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().preview_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().preview_sizes.get(i).getHeight());
        }
    }

    about_string.append("\nCurrent camera ID: ");
    about_string.append(MainScreen.getInstance().cameraId);

    if (MainScreen.getInstance().picture_sizes != null) {
        about_string.append("\nPhoto resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().picture_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().picture_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().picture_sizes.get(i).getHeight());
        }
    }

    if (MainScreen.getInstance().video_sizes != null) {
        about_string.append("\nVideo resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().video_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().video_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().video_sizes.get(i).getHeight());
        }
    }

    about_string.append("\nVideo stabilization: ");
    about_string.append(MainScreen.getInstance().supports_video_stabilization ? "true" : "false");

    about_string.append("\nFlash modes: ");
    if (MainScreen.getInstance().flash_values != null && MainScreen.getInstance().flash_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().flash_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().flash_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nFocus modes: ");
    if (MainScreen.getInstance().focus_values != null && MainScreen.getInstance().focus_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().focus_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().focus_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nScene modes: ");
    if (MainScreen.getInstance().scene_modes_values != null
            && MainScreen.getInstance().scene_modes_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().scene_modes_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().scene_modes_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nWhite balances: ");
    if (MainScreen.getInstance().white_balances_values != null
            && MainScreen.getInstance().white_balances_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().white_balances_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().white_balances_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nISOs: ");
    if (MainScreen.getInstance().isos != null && MainScreen.getInstance().isos.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().isos.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().isos.get(i));
        }
    } else {
        about_string.append("None");
    }

    String save_location = SavingService.getSaveToPath();
    about_string.append("\nSave Location: " + save_location);

    if (MainScreen.getInstance().flattenParamteters != null
            && !MainScreen.getInstance().flattenParamteters.equals("")) {
        about_string.append("\nFULL INFO:\n");
        about_string.append(MainScreen.getInstance().flattenParamteters);
    }

    alertDialog.setMessage(about_string);
    alertDialog.setPositiveButton(R.string.Pref_CameraParameters_Ok, null);
    alertDialog.setNegativeButton(R.string.Pref_CameraParameters_CopyToClipboard,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(Activity.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("OpenCamera About", about_string);
                    clipboard.setPrimaryClip(clip);
                }
            });
    alertDialog.show();
}

From source file:com.gmail.charleszq.picorner.ui.ImageDetailFragment.java

private void saveToClipboard(String s) {
    ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = ClipData.newPlainText(getString(R.string.app_name), s);
    cm.setPrimaryClip(data);/*from  w w  w .j av a2  s  .  c  o  m*/
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * //from w w  w.j  a v a2s .c o m
 */
private void setTextToView(AccessibilityNodeInfo node, String text) {
    Bundle arguments = new Bundle();
    arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
            AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
    arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
    node.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments);
    /*?*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bundle args = new Bundle();
        args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
        node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    } else {
        ClipData data = ClipData.newPlainText("reply", text);
        ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setPrimaryClip(data);
        node.performAction(AccessibilityNodeInfo.ACTION_FOCUS); // ?
        node.performAction(AccessibilityNodeInfo.ACTION_PASTE); // 
    }

}

From source file:sjizl.com.ChatFriendListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int index = info.position;
    String textTocopy = stock_list3.get(index);

    switch (item.getItemId()) {
    case R.id.delete:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        naam_to_delete = stock_list2.get(info.position);
        new DeleteConversation().execute();

        return false;

    case R.id.copy:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("simple text", textTocopy);
            clipboard.setPrimaryClip(clip);
        } else {//from   w  ww .ja va 2  s  .c o m
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(textTocopy);

        }

        //place your TextView's text in clipboard

        Toast.makeText(getActivity().getApplicationContext(), "Item copied", Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}

From source file:de.baumann.browser.Browser_left.java

@Override
protected void onResume() {
    super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
    mWebView.onResume();//from   w  w w  .jav a 2 s. c o m
    final String URL = sharedPref.getString("openURL", "https://github.com/scoute-dich/browser/");
    new Handler().postDelayed(new Runnable() {
        public void run() {
            if (URL.equals(mWebView.getUrl()) || URL.equals("")) {
                Log.i(TAG, "Tab switched");
            } else if (URL.equals("copyLogin")) {
                Snackbar snackbar = Snackbar
                        .make(mWebView, R.string.pass_copy_userName, Snackbar.LENGTH_INDEFINITE)
                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ClipboardManager clipboard = (ClipboardManager) Browser_left.this
                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                clipboard.setPrimaryClip(
                                        ClipData.newPlainText("userName", sharedPref.getString("copyUN", "")));

                                Snackbar snackbar = Snackbar
                                        .make(mWebView, R.string.pass_copy_userPW, Snackbar.LENGTH_INDEFINITE)
                                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                ClipboardManager clipboard = (ClipboardManager) Browser_left.this
                                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                                clipboard.setPrimaryClip(ClipData.newPlainText("userName",
                                                        sharedPref.getString("copyPW", "")));
                                            }
                                        });
                                snackbar.show();
                            }
                        });
                snackbar.show();
            } else if (URL.contains("openLogin")) {
                Snackbar snackbar = Snackbar
                        .make(mWebView, R.string.pass_copy_userName, Snackbar.LENGTH_INDEFINITE)
                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ClipboardManager clipboard = (ClipboardManager) Browser_left.this
                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                clipboard.setPrimaryClip(
                                        ClipData.newPlainText("userName", sharedPref.getString("copyUN", "")));

                                Snackbar snackbar = Snackbar
                                        .make(mWebView, R.string.pass_copy_userPW, Snackbar.LENGTH_INDEFINITE)
                                        .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                ClipboardManager clipboard = (ClipboardManager) Browser_left.this
                                                        .getSystemService(Context.CLIPBOARD_SERVICE);
                                                clipboard.setPrimaryClip(ClipData.newPlainText("userName",
                                                        sharedPref.getString("copyPW", "")));
                                            }
                                        });
                                snackbar.show();
                            }
                        });
                snackbar.show();
                mWebView.loadUrl(URL.replace("openLogin", ""));
            } else {
                mWebView.loadUrl(URL);
            }
        }
    }, 100);
}

From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java

@TargetApi(11)
private void copyAliasCurrentChatBox() {
    ChatBox chatBox = mCurrentChatBoxManager.getCurrentChatBox();
    if (chatBox == null || chatBox.getAlias() == null) {
        return;/*from   w  ww. j ava  2s.c  o  m*/
    }
    AppCompatActivity activity = mActivityDelegate.getActivity();

    if (Build.VERSION.SDK_INT >= 11) {
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(activity.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("alias_copied", constructAliasLink(chatBox.getAlias())));
    } else {
        android.text.ClipboardManager oldClipboard = (android.text.ClipboardManager) activity
                .getSystemService(activity.CLIPBOARD_SERVICE);
        oldClipboard.setText(constructAliasLink(chatBox.getAlias()));
    }

    Toast.makeText(activity, R.string.message_current_chat_box_alias_copied, Toast.LENGTH_SHORT).show();
}

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

private void onDeviceRegistration(int statusCode, final JSONObject deviceDefinition, final boolean simulation)
        throws JSONException {
    // run in UI thread
    switch (statusCode) {
    case 201://w w w .j a va 2 s  .  co m
    case 202:

        final String authToken = deviceDefinition.getString("authToken");
        final String deviceId = deviceDefinition.getString("deviceId");
        iotpDevice.setDeviceToken(deviceId, authToken);

        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this,
                R.style.AppCompatAlertDialogStyle);
        final View authTokenAlert = getLayoutInflater().inflate(R.layout.activity_home_authtokenalert, null,
                false);
        final EditText authTokenField = (EditText) authTokenAlert.findViewById(R.id.authTokenField);
        authTokenField.setText(authToken);

        final Button copyToClipboard = (Button) authTokenAlert.findViewById(R.id.copyToClipboard);
        copyToClipboard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(
                        CLIPBOARD_SERVICE);
                final ClipData clipData = ClipData.newPlainText("authToken", authToken);
                clipboardManager.setPrimaryClip(clipData);

                Toast.makeText(Home.this, "Successfully copied to your Clipboard!", Toast.LENGTH_SHORT).show();
            }
        });
        storeSetting(SettingsFragment.DEVICE_TOKEN, authToken);

        alertDialog.setView(authTokenAlert);
        alertDialog.setCancelable(false).setTitle("Your Device is Now Registered!")
                .setMessage("Please take note of this Autentication Token as you will need it in the future")
                .setPositiveButton("Close", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        deviceRegistered(deviceDefinition, simulation);
                    }
                }).show();
        break;
    default:
        break;
    }
    progressBar.setVisibility(View.GONE);
}

From source file:org.mozilla.gecko.GeckoAppShell.java

static void setClipboardText(final String text) {
    getHandler().post(new Runnable() {
        @SuppressWarnings("deprecation")
        public void run() {
            Context context = GeckoApp.mAppContext;
            if (Build.VERSION.SDK_INT >= 11) {
                android.content.ClipboardManager cm = (android.content.ClipboardManager) context
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setPrimaryClip(ClipData.newPlainText("Text", text));
            } else {
                android.text.ClipboardManager cm = (android.text.ClipboardManager) context
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(text);/*from w  w  w . j a  v a 2  s. co  m*/
            }
        }
    });
}