List of usage examples for android.content ClipboardManager getPrimaryClipDescription
public @Nullable ClipDescription getPrimaryClipDescription()
From source file:com.eng.arab.translator.androidtranslator.translate.TranslateViewActivity.java
public String readFromClipboard() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { android.content.ClipDescription description = clipboard.getPrimaryClipDescription(); android.content.ClipData data = clipboard.getPrimaryClip(); if (data != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) return String.valueOf(data.getItemAt(0).getText()); }//from w w w . j a v a 2 s . com return null; }
From source file:com.google.reviewit.ServerSettingsFragment.java
private void init() { final AutoCompleteTextView urlInput = (AutoCompleteTextView) v(R.id.urlInput); ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.urls)); urlInput.setAdapter(adapter);/*w w w. j a v a 2s .c o m*/ v(R.id.pasteCredentialsButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); String pasteData = item.getText().toString(); if (!pasteData.contains("/.gitcookies")) { return; } pasteData = pasteData.substring(pasteData.indexOf("/.gitcookies")); pasteData = pasteData.substring(pasteData.lastIndexOf(",") + 1); int pos = pasteData.indexOf("="); String user = pasteData.substring(0, pos); pasteData = pasteData.substring(pos + 1); String password = pasteData.substring(0, pasteData.indexOf("\n")); WidgetUtil.setText(v(R.id.userInput), user); WidgetUtil.setText(v(R.id.passwordInput), password); // hide keyboard if it is open View view = getActivity().getCurrentFocus(); if (view != null) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(view.getWindowToken(), 0); } } } }); ((EditText) v(R.id.urlInput)).addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (Strings.isNullOrEmpty(textOf(R.id.nameInput))) { try { String host = new URL(s.toString()).getHost(); int pos = host.indexOf("."); WidgetUtil.setText(v(R.id.nameInput), pos > 0 ? host.substring(0, pos) : host); } catch (MalformedURLException e) { // ignore } } displayCredentialsInfo(s.toString()); } }); v(R.id.saveServerSettings).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { enabledForm(false); if (!isServerInputComplete()) { widgetUtil.showError(R.string.incompleteInput); enabledForm(true); return; } if (!isUrlValid()) { widgetUtil.showError(R.string.invalidUrl); enabledForm(true); return; } if (!hasUniqueName()) { widgetUtil.showError(getString(R.string.duplicate_server_name, textOf(R.id.nameInput))); enabledForm(true); return; } setVisible(v(R.id.statusTestConnection, R.id.statusTestConnectionProgress)); WidgetUtil.setText(v(R.id.statusTestConnectionText), null); new AsyncTask<Void, Void, String>() { private TextView status; private View statusTestConnectionProgress; private View statusTestConnection; @Override protected void onPreExecute() { super.onPreExecute(); status = tv(R.id.statusTestConnectionText); statusTestConnectionProgress = v(R.id.statusTestConnectionProgress); statusTestConnection = v(R.id.statusTestConnection); } @Override protected String doInBackground(Void... v) { return testConnection(); } protected void onPostExecute(String errorMsg) { if (errorMsg != null) { enabledForm(true); status.setTextColor(widgetUtil.color(R.color.statusFailed)); status.setText(getString(R.string.test_server_connection_failed)); setInvisible(statusTestConnectionProgress); new AlertDialog.Builder(getContext()).setTitle(getString(R.string.error_title)) .setMessage(getString(R.string.connection_failed, errorMsg)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setNegativeButton(getString(R.string.save_anyway), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { setGone(statusTestConnection); onServerSave(saveServerSettings()); } }) .setIcon(android.R.drawable.ic_dialog_alert).show(); } else { status.setTextColor(widgetUtil.color(R.color.statusOk)); status.setText(getString(R.string.test_server_connection_ok)); setGone(statusTestConnection); onServerSave(saveServerSettings()); } } }.execute(); } }); enabledForm(true); setGone(v(R.id.statusTestConnection)); }
From source file:github.popeen.dsub.fragments.SelectPodcastsFragment.java
private void addNewPodcast() { View dialogView = context.getLayoutInflater().inflate(R.layout.create_podcast, null); final TextView urlBox = (TextView) dialogView.findViewById(R.id.create_podcast_url); //If a string is in clipboard and it contains http or https, add it to the textbox ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) { String url = clipboard.getPrimaryClip().getItemAt(0).getText().toString(); if (url.contains("http")) { urlBox.setText(url.trim());/* ww w . j a v a2 s.c o m*/ } } AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.menu_add_podcast).setView(dialogView) .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { String url = urlBox.getText().toString(); addNewPodcast(url); } }).setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setCancelable(true); AlertDialog dialog = builder.create(); dialog.show(); }