List of usage examples for android.content ClipboardManager getPrimaryClip
public @Nullable ClipData getPrimaryClip()
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// www. jav a 2 s.c o m */ @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.codebutler.farebot.fragment.CardsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); try {/*from w w w . j a v a 2 s .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.ulteo.ovd.AndRdpActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void startSession(int screen_width, int screen_height) { if (isConnected()) return;/*from w w w .java2s. c om*/ Bundle bundle = getIntent().getExtras(); if (bundle == null) { finish(); return; } Point res; // check if user has chosen a specific resolution if (!Settings.getResolutionAuto(this)) { res = Settings.getResolution(this); } else { res = new Point(screen_width, screen_height); // Prefer wide screen if (!Settings.getResolutionWide(this) && res.y > res.x) { int w = res.x; res.x = res.y; res.y = w; } } Log.i(Config.TAG, "Resolution: " + res.x + "x" + res.y); String gateway_token = null; Boolean gateway_mode = bundle.getBoolean(PARAM_GATEWAYMODE); if (gateway_mode) gateway_token = bundle.getString(PARAM_TOKEN); int drives = Properties.REDIRECT_DRIVES_FULL; Properties prop = smHandler.getResponseProperties(); if (prop != null) drives = prop.isDrives(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN && bundle.getString(PARAM_SM_URI) != null) { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter != null) { NdefRecord rtdUriRecord = NdefRecord.createUri(bundle.getString(PARAM_SM_URI)); NdefMessage ndefMessage = new NdefMessage(rtdUriRecord); nfcAdapter.setNdefPushMessage(ndefMessage, this); } } rdp = new Rdp(res, bundle.getString(PARAM_LOGIN), bundle.getString(PARAM_PASSWD), bundle.getString(PARAM_IP), bundle.getInt(PARAM_PORT, SessionManagerCommunication.DEFAULT_RDP_PORT), gateway_mode, gateway_token, drives, bundle.getString(PARAM_RDPSHELL) == null ? "" : bundle.getString(PARAM_RDPSHELL), Settings.getBulkCompression(AndRdpActivity.this), Settings.getConnexionType(AndRdpActivity.this)); Resources resources = getResources(); Intent notificationIntent = new Intent(this, AndRdpActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon_bw) .setContentTitle(resources.getText(R.string.app_name)).setOngoing(true) .setContentText(resources.getText(R.string.desktop_session_active)).setContentIntent(pendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, mBuilder.build()); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipChangedListener = new ClipboardManager.OnPrimaryClipChangedListener() { @Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onPrimaryClipChanged() { ClipboardManager clipboard = (ClipboardManager) AndRdpActivity.this .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); String text = clip.getItemAt(0).coerceToText(AndRdpActivity.this).toString(); if (Config.DEBUG) Log.d(Config.TAG, "Android clipboard : " + text); if (isLoggedIn()) rdp.sendClipboard(text); } }; clipboard.addPrimaryClipChangedListener(clipChangedListener); } }
From source file:com.android.talkback.SpeechController.java
/** * Copies the last phrase spoken by TalkBack to clipboard *//*from w w w . j av a 2s . com*/ public boolean copyLastUtteranceToClipboard(FeedbackItem item) { if (item == null) { return false; } final ClipboardManager clipboard = (ClipboardManager) mService.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(null, item.getAggregateText()); clipboard.setPrimaryClip(clip); // Verify that we actually have the utterance on the clipboard clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0 && clip.getItemAt(0).getText() != null) { speak(mService.getString(R.string.template_text_copied, clip.getItemAt(0).getText().toString()) /* text */, QUEUE_MODE_INTERRUPT /* queue mode */, 0 /* flags */, null /* speech params */); return true; } else { return false; } }
From source file:com.android.ex.chips.RecipientEditTextView.java
@Override public boolean onTextContextMenuItem(final int id) { if (id == android.R.id.paste) { final ClipboardManager clipboard = (ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); handlePasteClip(clipboard.getPrimaryClip()); return true; }//from www .j a v a2 s . co m return super.onTextContextMenuItem(id); }
From source file:org.mdc.chess.MDChess.java
private void clipBoardDialog() { final int COPY_GAME = 0; final int COPY_POSITION = 1; final int PASTE = 2; setAutoMode(AutoMode.OFF);/* w ww . jav a 2 s . c om*/ List<CharSequence> lst = new ArrayList<>(); List<Integer> actions = new ArrayList<>(); lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME); lst.add(getString(R.string.copy_position)); actions.add(COPY_POSITION); lst.add(getString(R.string.paste)); actions.add(PASTE); final List<Integer> finalActions = actions; new MaterialDialog.Builder(this).title(R.string.tools_menu).items(lst) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { switch (finalActions.get(which)) { case COPY_GAME: { String pgn = ctrl.getPGN(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData("MD Chess game", new String[] { "application/x-chess-pgn", ClipDescription.MIMETYPE_TEXT_PLAIN }, new ClipData.Item(pgn))); break; } case COPY_POSITION: { String fen = ctrl.getFEN() + "\n"; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData(fen, new String[] { "application/x-chess-fen", ClipDescription.MIMETYPE_TEXT_PLAIN }, new ClipData.Item(fen))); break; } case PASTE: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { ClipData clip = clipboard.getPrimaryClip(); StringBuilder fenPgn = new StringBuilder(); for (int i = 0; i < clip.getItemCount(); i++) { fenPgn.append(clip.getItemAt(i).coerceToText(getApplicationContext())); } try { ctrl.setFENOrPGN(fenPgn.toString()); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; } } } }).show(); }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc// w w w. j a v a 2 s . c o m */ public Object getPasteDataFromClipboard() { if (getContext() == null) { return null; } final Object[] response = new Object[1]; runOnUiThreadAndBlock(new Runnable() { @Override public void run() { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); response[0] = clipboard.getText().toString(); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); response[0] = item.getText(); } } }); return response[0]; }