@Override public void onPrimaryClipChanged() { ClipData data = mClipManager.getPrimaryClip(); if (null != data) { Item item = data.getItemAt(data.getItemCount() - 1); CharSequence text = item.getText(); if (shouldTranslate(text)) { TranslateRequest request = new TranslateRequest(); request.mFromLanguage = "auto"; request.mToLanguage = AppSettings.getInstance().mDestLanguage; mLastText = text.toString(); request.mQuery = mLastText; mTranslator.startTranslate(request); lazyResetLastText(); } } }
@TargetApi(16) public static void a(Intent paramIntent, String paramString, List<jpx> paramList, Context paramContext) { if (Build.VERSION.SDK_INT < 16) { return; } Iterator localIterator = paramList.iterator(); ClipData localClipData = null; while (localIterator.hasNext()) { ClipData.Item localItem = new ClipData.Item(a(((jpx)localIterator.next()).e(), paramString, paramContext)); if (localClipData == null) { localClipData = new ClipData(a, localItem); } else { localClipData.addItem(localItem); } } paramIntent.setClipData(localClipData); }
boolean processDrop(DragEvent event, ImageView imageView) { // Attempt to parse clip data with expected format: category||entry_id. // Ignore event if data does not conform to this format. ClipData data = event.getClipData(); if (data != null) { if (data.getItemCount() > 0) { Item item = data.getItemAt(0); String textData = (String) item.getText(); if (textData != null) { StringTokenizer tokenizer = new StringTokenizer(textData, "||"); if (tokenizer.countTokens() != 2) { return false; } int category = -1; int entryId = -1; try { category = Integer.parseInt(tokenizer.nextToken()); entryId = Integer.parseInt(tokenizer.nextToken()); } catch (NumberFormatException exception) { return false; } updateContentAndRecycleBitmap(category, entryId); // Update list fragment with selected entry. TitlesFragment titlesFrag = (TitlesFragment) getFragmentManager().findFragmentById(R.id.titles_frag); titlesFrag.selectPosition(entryId); return true; } } } return false; }
@SuppressLint("NewApi") public static String getClip(ClipboardManager cliper) { try { ClipData data = cliper.getPrimaryClip(); Item item = data.getItemAt(0); return String.valueOf(item.getText()); } catch (Exception e) { } return null; }
protected String extractURL() { String url = null; ClipData clipboard = getIntent().getClipData(); if ( clipboard.getItemCount() > 0 ) { Item item = clipboard.getItemAt( 0 ); if ( item != null && item.getText() != null ) { url = item.getText().toString(); } } return url; }
boolean processDrop(DragEvent event, ImageView imageView) { // Attempt to parse clip data with expected format: category||entry_id. // Ignore event if data does not conform to this format. ClipData data = event.getClipData(); if (data != null) { if (data.getItemCount() > 0) { Item item = data.getItemAt(0); String textData = (String) item.getText(); if (textData != null) { StringTokenizer tokenizer = new StringTokenizer(textData, "||"); if (tokenizer.countTokens() != 2) { return false; } int category = -1; int entryId = -1; try { category = Integer.parseInt(tokenizer.nextToken()); entryId = Integer.parseInt(tokenizer.nextToken()); } catch (NumberFormatException exception) { return false; } updateContentAndRecycleBitmap(category, entryId); // Update list fragment with selected entry. TitlesFragment titlesFrag = (TitlesFragment) getFragmentManager().findFragmentById(R.id.frag_title); titlesFrag.selectPosition(entryId); return true; } } } return false; }