List of usage examples for android.text ClipboardManager getText
public abstract CharSequence getText();
From source file:org.mozilla.gecko.GeckoAppShell.java
static String getClipboardText() { getHandler().post(new Runnable() { @SuppressWarnings("deprecation") public void run() { Context context = GeckoApp.mAppContext; String text = null;/*from ww w . j a va 2 s. co m*/ if (Build.VERSION.SDK_INT >= 11) { android.content.ClipboardManager cm = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (cm.hasPrimaryClip()) { ClipData clip = cm.getPrimaryClip(); if (clip != null) { ClipData.Item item = clip.getItemAt(0); text = item.coerceToText(context).toString(); } } } else { android.text.ClipboardManager cm = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (cm.hasText()) text = cm.getText().toString(); } try { sClipboardQueue.put(text != null ? text : EMPTY_STRING); } catch (InterruptedException ie) { } } }); try { String ret = sClipboardQueue.take(); return (EMPTY_STRING.equals(ret) ? null : ret); } catch (InterruptedException ie) { } return null; }
From source file:ru.valle.btc.MainActivity.java
@SuppressWarnings("deprecation") private String getTextInClipboard() { CharSequence textInClipboard = ""; if (Build.VERSION.SDK_INT >= 11) { if (clipboardHelper.hasTextInClipboard()) { textInClipboard = clipboardHelper.getTextInClipboard(); }/*from w w w . ja v a 2s .c o m*/ } else { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); if (clipboard.hasText()) { textInClipboard = clipboard.getText(); } } return textInClipboard == null ? "" : textInClipboard.toString(); }
From source file:net.phase.wallet.Currency.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.updateItem: updateWalletBalance(wallets[info.position], false, maxlength); return true; case R.id.removeItem: removeWallet(wallets[info.position].name); updateWalletList();/*from w w w . j a va 2 s .co m*/ return true; case R.id.pasteClipKeys: ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clip != null) { if (clip.getText() != null) { int added = 0; try { InputStream is = new ByteArrayInputStream(clip.getText().toString().getBytes()); BufferedReader br = new BufferedReader(new InputStreamReader(is)); added = wallets[info.position].addFromReader(br); } catch (IOException e) { } if (added > 0) { toastMessage("Added " + added + " key(s)"); updateWalletList(); } else { toastMessage("Found no new keys "); } } else { toastMessage("Nothing on clipboard"); } } else { toastMessage("Could not obtain clipboard"); } return true; case R.id.viewItem: if (wallets[info.position].transactions == null) { toastMessage("Please update wallet first"); } else { showTransactions(wallets[info.position]); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:net.kidlogger.kidlogger.KLService.java
private void doScanClipboard() { ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); String content = ""; int cSize = 0; if (cm.hasText()) { CharSequence tmp = cm.getText(); cSize = tmp.length();//from ww w . j a v a2 s. c om if ((prevClipSize != cSize) && (cSize != 0)) { if (cSize > 30) content = tmp.subSequence(0, 30).toString(); else content = tmp.toString(); prevClipSize = cSize; // Log clipboard content final String cnt = new String(content); new Thread(new Runnable() { public void run() { sync.writeLog(".htm", Templates.getClipboardLog(cnt)); } }).start(); //WriteThread wcb = new WriteThread(sync, ".htm", // Templates.getClipboardLog(content)); } } }
From source file:com.thomasokken.free42.Free42Activity.java
private void doPaste() { android.text.ClipboardManager clip = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clip.hasText()) core_paste(clip.getText().toString()); }
From source file:com.androzic.MapActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.menuSearch: onSearchRequested();/*ww w .j av a 2 s. co m*/ return true; case R.id.menuAddWaypoint: { double[] loc = application.getMapCenter(); Waypoint waypoint = new Waypoint("", "", loc[0], loc[1]); waypoint.date = Calendar.getInstance().getTime(); int wpt = application.addWaypoint(waypoint); waypoint.name = "WPT" + wpt; application.saveDefaultWaypoints(); map.update(); return true; } case R.id.menuNewWaypoint: startActivityForResult(new Intent(this, WaypointProperties.class).putExtra("INDEX", -1), RESULT_SAVE_WAYPOINT); return true; case R.id.menuProjectWaypoint: startActivityForResult(new Intent(this, WaypointProject.class), RESULT_SAVE_WAYPOINT); return true; case R.id.menuManageWaypoints: startActivityForResult(new Intent(this, WaypointList.class), RESULT_MANAGE_WAYPOINTS); return true; case R.id.menuLoadWaypoints: startActivityForResult(new Intent(this, WaypointFileList.class), RESULT_LOAD_WAYPOINTS); return true; case R.id.menuManageTracks: startActivityForResult(new Intent(this, TrackList.class), RESULT_MANAGE_TRACKS); return true; case R.id.menuExportCurrentTrack: FragmentManager fm = getSupportFragmentManager(); TrackExportDialog trackExportDialog = new TrackExportDialog(locationService); trackExportDialog.show(fm, "track_export"); return true; case R.id.menuExpandCurrentTrack: new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.warning) .setMessage(R.string.msg_expandcurrenttrack) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (application.currentTrackOverlay != null) { Track track = locationService.getTrack(); track.show = true; application.currentTrackOverlay.setTrack(track); } } }).setNegativeButton(R.string.no, null).show(); return true; case R.id.menuClearCurrentTrack: new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.warning) .setMessage(R.string.msg_clearcurrenttrack) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (application.currentTrackOverlay != null) application.currentTrackOverlay.clear(); locationService.clearTrack(); } }).setNegativeButton(R.string.no, null).show(); return true; case R.id.menuManageRoutes: startActivityForResult(new Intent(this, RouteList.class).putExtra("MODE", RouteList.MODE_MANAGE), RESULT_MANAGE_ROUTES); return true; case R.id.menuStartNavigation: if (application.getRoutes().size() > 1) { startActivity(new Intent(this, RouteList.class).putExtra("MODE", RouteList.MODE_START)); } else { startActivity(new Intent(this, RouteStart.class).putExtra("INDEX", 0)); } return true; case R.id.menuNavigationDetails: startActivity(new Intent(this, RouteDetails.class) .putExtra("index", application.getRouteIndex(navigationService.navRoute)) .putExtra("nav", true)); return true; case R.id.menuNextNavPoint: navigationService.nextRouteWaypoint(); return true; case R.id.menuPrevNavPoint: navigationService.prevRouteWaypoint(); return true; case R.id.menuStopNavigation: { navigationService.stopNavigation(); return true; } case R.id.menuHSI: startActivity(new Intent(this, HSIActivity.class)); return true; case R.id.menuInformation: startActivity(new Intent(this, Information.class)); return true; case R.id.menuMapInfo: startActivity(new Intent(this, MapInformation.class)); return true; case R.id.menuCursorMaps: startActivityForResult(new Intent(this, MapList.class).putExtra("pos", true), RESULT_LOAD_MAP_ATPOSITION); return true; case R.id.menuAllMaps: startActivityForResult(new Intent(this, MapList.class), RESULT_LOAD_MAP); return true; case R.id.menuShare: Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, R.string.currentloc); double[] sloc = application.getMapCenter(); String spos = StringFormatter.coordinates(application.coordinateFormat, " ", sloc[0], sloc[1]); i.putExtra(Intent.EXTRA_TEXT, spos); startActivity(Intent.createChooser(i, getString(R.string.menu_share))); return true; case R.id.menuCopyLocation: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); double[] cloc = application.getMapCenter(); String cpos = StringFormatter.coordinates(application.coordinateFormat, " ", cloc[0], cloc[1]); clipboard.setText(cpos); return true; } case R.id.menuPasteLocation: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasText()) { String q = clipboard.getText().toString(); try { double c[] = CoordinateParser.parse(q); if (!Double.isNaN(c[0]) && !Double.isNaN(c[1])) { boolean mapChanged = application.setMapCenter(c[0], c[1], true, false); if (mapChanged) map.updateMapInfo(); map.update(); map.setFollowing(false); } } catch (IllegalArgumentException e) { } } return true; } case R.id.menuSetAnchor: if (showDistance > 0) { application.distanceOverlay.setAncor(application.getMapCenter()); application.distanceOverlay.setEnabled(true); } return true; case R.id.menuPreferences: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { startActivity(new Intent(this, Preferences.class)); } else { startActivity(new Intent(this, PreferencesHC.class)); } return true; } return false; }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private boolean doSwipeAction(String action) { //Log.i(TAG, "doSwipeAction + " + action); if (action == null || action.equals("") || action.equals("none")) { return false; } else if (action.equals("close")) { handleClose();// w ww . ja v a2 s . c om } else if (action.equals("settings")) { launchSettings(); } else if (action.equals("suggestions")) { if (mSuggestionForceOn) { mSuggestionForceOn = false; mSuggestionForceOff = true; } else if (mSuggestionForceOff) { mSuggestionForceOn = true; mSuggestionForceOff = false; } else if (isPredictionWanted()) { mSuggestionForceOff = true; } else { mSuggestionForceOn = true; } setCandidatesViewShown(isPredictionOn()); } else if (action.equals("lang_prev")) { toggleLanguage(false, false); } else if (action.equals("lang_next")) { toggleLanguage(false, true); } else if (action.equals("debug_auto_play")) { if (TKKeyboardView.DEBUG_AUTO_PLAY) { ClipboardManager cm = ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)); CharSequence text = cm.getText(); if (!TextUtils.isEmpty(text)) { mKeyboardSwitcher.getInputView().startPlaying(text.toString()); } } } else if (action.equals("full_mode")) { if (isPortrait()) { mKeyboardModeOverridePortrait = (mKeyboardModeOverridePortrait + 1) % mNumKeyboardModes; } else { mKeyboardModeOverrideLandscape = (mKeyboardModeOverrideLandscape + 1) % mNumKeyboardModes; } toggleLanguage(true, true); } else if (action.equals("extension")) { sKeyboardSettings.useExtension = !sKeyboardSettings.useExtension; reloadKeyboards(); } else if (action.equals("height_up")) { if (isPortrait()) { mHeightPortrait += 5; if (mHeightPortrait > 70) mHeightPortrait = 70; } else { mHeightLandscape += 5; if (mHeightLandscape > 70) mHeightLandscape = 70; } toggleLanguage(true, true); } else if (action.equals("height_down")) { if (isPortrait()) { mHeightPortrait -= 5; if (mHeightPortrait < 15) mHeightPortrait = 15; } else { mHeightLandscape -= 5; if (mHeightLandscape < 15) mHeightLandscape = 15; } toggleLanguage(true, true); } else { Log.i(TAG, "Unsupported swipe action config: " + action); } return true; }
From source file:org.petero.droidfish.DroidFish.java
private final Dialog clipBoardDialog() { final int COPY_GAME = 0; final int COPY_POSITION = 1; final int PASTE = 2; setAutoMode(AutoMode.OFF);// w w w. ja va 2 s . c o m List<CharSequence> lst = new ArrayList<CharSequence>(); List<Integer> actions = new ArrayList<Integer>(); 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; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.tools_menu); builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case COPY_GAME: { String pgn = ctrl.getPGN(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(pgn); break; } case COPY_POSITION: { String fen = ctrl.getFEN() + "\n"; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(fen); break; } case PASTE: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasText()) { String fenPgn = clipboard.getText().toString(); try { ctrl.setFENOrPGN(fenPgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT) .show(); } } break; } } } }); AlertDialog alert = builder.create(); return alert; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog clipBoardDialog() { final int COPY_GAME = 0; final int COPY_POSITION = 1; final int PASTE = 2; List<CharSequence> lst = new ArrayList<CharSequence>(); List<Integer> actions = new ArrayList<Integer>(); lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME);//from w w w . j a v a 2 s . c o m 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; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.tools_menu); builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case COPY_GAME: { String pgn = ctrl.getPGN(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(pgn); break; } case COPY_POSITION: { String fen = ctrl.getFEN() + "\n"; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(fen); break; } case PASTE: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasText()) { String fenPgn = clipboard.getText().toString(); try { ctrl.setFENOrPGN(fenPgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT) .show(); } } break; } } } }); AlertDialog alert = builder.create(); return alert; }