private void processDrop(DragEvent event) { final ClipData data = event.getClipData(); final int N = data.getItemCount(); for (int i = 0; i < N; i++) { ClipData.Item item = data.getItemAt(i); String text = item.coerceToText(getContext()).toString(); if (this.tile.type.equalsIgnoreCase(Constants.BLANK)) { String[] tileArgs = text.split(";"); this.setTile( new Tile( this.tile.posOnBoard, tileArgs[1], Integer.parseInt(tileArgs[0]), MoveDirection.NONE, tileArgs[4], Constants.stringToBmp.get(tileArgs[1]))); Constants.droppedOnBlank = true; // Communicator.getInstance(null, // null).sendMoveTile(tileArgs[1]); ClientCommunicator.getInstance(getContext(), null).sendMoveRequset(tile); } else { Constants.droppedOnBlank = false; } } }
@Override protected void onResume() { super.onResume(); final int entryCount = getSupportFragmentManager().getBackStackEntryCount(); final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (entryCount == 0 && clipboardManager.hasPrimaryClip() && clipboardManager.getPrimaryClip().getItemCount() > 0) { final ClipData primaryClip = clipboardManager.getPrimaryClip(); final ClipData.Item item = primaryClip.getItemAt(0); final String text = item.coerceToText(this).toString(); if (text.trim().length() > 0) { final Snackbar snackbar = Snackbar.with(this) .text(getString(R.string.paste_from_clipboard_prompt)) .actionLabel(getString(R.string.paste_clipboard_action)) .actionColorResource(R.color.sharelock_orange) .actionListener( new ActionClickListener() { @Override public void onActionClicked(Snackbar snackbar) { bus.postSticky(new ClipboardSecretEvent(text)); clipboardManager.setPrimaryClip(ClipData.newPlainText("", "")); } }) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE); SnackbarManager.show(snackbar); } } }
private void readClipboard() { ClipboardManager cm = (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData cmContent = cm.getPrimaryClip(); if (cmContent == null) { return; } ClipData.Item item = cmContent.getItemAt(0); if (item != null) { String url = item.coerceToText(this).toString(); boolean a = !TextUtils.isEmpty(url) && !url.equals(SettingUtility.getLastFoundWeiboAccountLink()); boolean b = Utility.isWeiboAccountIdLink(url) || Utility.isWeiboAccountDomainLink(url); if (a && b) { OpenWeiboAccountLinkDialog dialog = new OpenWeiboAccountLinkDialog(url); dialog.show(getSupportFragmentManager(), ""); SettingUtility.setLastFoundWeiboAccountLink(url); } } }