List of usage examples for android.content Context CLIPBOARD_SERVICE
String CLIPBOARD_SERVICE
To view the source code for android.content Context CLIPBOARD_SERVICE.
Click Source Link
From source file:com.ysls.imhere.ChatActivity.java
private void setUpView() { activityInstance = this; iv_emoticons_normal.setOnClickListener(this); iv_emoticons_checked.setOnClickListener(this); // position = getIntent().getIntExtra("position", -1); clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // ???/* ww w. j a va2 s . c om*/ chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE); if (chatType == CHATTYPE_SINGLE) { // ?? toChatUsername = getIntent().getStringExtra("userId"); ((TextView) findViewById(R.id.name)).setText(toChatUsername); } else { // ? findViewById(R.id.container_to_group).setVisibility(View.VISIBLE); findViewById(R.id.container_remove).setVisibility(View.GONE); toChatUsername = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(toChatUsername); ((TextView) findViewById(R.id.name)).setText(group.getGroupName()); } conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnsetMsgCount(); adapter = new MessageAdapter(this, toChatUsername, chatType); // ? listView.setAdapter(adapter); listView.setOnScrollListener(new ListScrollListener()); int count = listView.getCount(); if (count > 0) { listView.setSelection(count - 1); } listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { hideKeyboard(); more.setVisibility(View.GONE); iv_emoticons_normal.setVisibility(View.VISIBLE); iv_emoticons_checked.setVisibility(View.INVISIBLE); expressionContainer.setVisibility(View.GONE); btnContainer.setVisibility(View.GONE); return false; } }); // ? receiver = new NewMessageBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction()); // Mainacitivity,??chat?????? intentFilter.setPriority(5); registerReceiver(receiver, intentFilter); // ack?BroadcastReceiver IntentFilter ackMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getAckMessageBroadcastAction()); ackMessageIntentFilter.setPriority(5); registerReceiver(ackMessageReceiver, ackMessageIntentFilter); // show forward message if the message is not null String forward_msg_id = getIntent().getStringExtra("forward_msg_id"); if (forward_msg_id != null) { // ????? forwardMessage(forward_msg_id); } }
From source file:org.linphone.compatibility.ApiFivePlus.java
public static void copyTextToClipboard(Context context, String msg) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(msg);//from w w w .j a va2s . co m }
From source file:im.afterclass.android.activity.ChatActivity.java
private void setUpView() { activityInstance = this; iv_emoticons_normal.setOnClickListener(this); iv_emoticons_checked.setOnClickListener(this); // position = getIntent().getIntExtra("position", -1); clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo"); // ???//from www .j a v a 2 s . c o m chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE); if (chatType == CHATTYPE_SINGLE) { // ?? toChatUsername = getIntent().getStringExtra("userId"); ((TextView) findViewById(R.id.name)).setText(toChatUsername); } else { // ? findViewById(R.id.container_to_group).setVisibility(View.VISIBLE); findViewById(R.id.container_remove).setVisibility(View.GONE); toChatUsername = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(toChatUsername); ((TextView) findViewById(R.id.name)).setText(group.getGroupName()); } conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnsetMsgCount(); adapter = new MessageAdapter(this, toChatUsername, chatType); // ? listView.setAdapter(adapter); listView.setOnScrollListener(new ListScrollListener()); int count = listView.getCount(); if (count > 0) { listView.setSelection(count - 1); } listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { hideKeyboard(); more.setVisibility(View.GONE); iv_emoticons_normal.setVisibility(View.VISIBLE); iv_emoticons_checked.setVisibility(View.INVISIBLE); expressionContainer.setVisibility(View.GONE); btnContainer.setVisibility(View.GONE); return false; } }); // ? receiver = new NewMessageBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction()); // Mainacitivity,??chat?????? intentFilter.setPriority(5); registerReceiver(receiver, intentFilter); // ack?BroadcastReceiver IntentFilter ackMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getAckMessageBroadcastAction()); ackMessageIntentFilter.setPriority(5); registerReceiver(ackMessageReceiver, ackMessageIntentFilter); // show forward message if the message is not null String forward_msg_id = getIntent().getStringExtra("forward_msg_id"); if (forward_msg_id != null) { // ????? forwardMessage(forward_msg_id); } }
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 ww . j a v a 2 s.co m*/ 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:de.baumann.browser.popups.Popup_history.java
private void setHistoryList() { //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "history_title", "history_content", "history_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0); //display data by filter final String note_search = sharedPref.getString("filter_historyBY", "history_title"); sharedPref.edit().putString("filter_historyBY", "history_title").apply(); editText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { }/*from w ww .j a va 2 s .c o m*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row = (Cursor) listView.getItemAtPosition(position); final String history_content = row.getString(row.getColumnIndexOrThrow("history_content")); sharedPref.edit().putString("openURL", history_content).apply(); finish(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String history_title = row2.getString(row2.getColumnIndexOrThrow("history_title")); final String history_content = row2.getString(row2.getColumnIndexOrThrow("history_content")); final String history_icon = row2.getString(row2.getColumnIndexOrThrow("history_icon")); final String history_attachment = row2.getString(row2.getColumnIndexOrThrow("history_attachment")); final String history_creation = row2.getString(row2.getColumnIndexOrThrow("history_creation")); final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save), getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_history.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.bookmark_edit_title))) { sharedPref.edit().putString("edit_id", _id).apply(); sharedPref.edit().putString("edit_content", history_content).apply(); sharedPref.edit().putString("edit_icon", history_icon).apply(); sharedPref.edit().putString("edit_attachment", history_attachment).apply(); sharedPref.edit().putString("edit_creation", history_creation).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_history.this, editText, 2, history_title, getString(R.string.bookmark_edit_title)); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setHistoryList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.menu_share))) { final CharSequence[] options = { getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Popup_history.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, history_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, history_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (options[item] .equals(getString(R.string.menu_share_link_copy))) { ClipboardManager clipboard = (ClipboardManager) Popup_history.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip( ClipData.newPlainText("text", history_content)); Snackbar.make(listView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } } }).show(); } if (options[item].equals(getString(R.string.menu_save))) { final CharSequence[] options = { getString(R.string.menu_save_bookmark), getString(R.string.menu_save_readLater), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Popup_history.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_save_pass))) { helper_editText.editText_savePass(Popup_history.this, listView, history_title, history_content); } if (options[item] .equals(getString(R.string.menu_save_bookmark))) { DbAdapter_Bookmarks db = new DbAdapter_Bookmarks( Popup_history.this); db.open(); if (db.isExist(history_content)) { Snackbar.make(listView, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(history_title, history_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_save_readLater))) { DbAdapter_ReadLater db = new DbAdapter_ReadLater( Popup_history.this); db.open(); if (db.isExist(history_content)) { Snackbar.make(listView, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(history_title, history_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Popup_history.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(history_content)); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, history_title); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext( Popup_history.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction( "com.android.launcher.action.INSTALL_SHORTCUT"); Popup_history.this.sendBroadcast(shortcut); Snackbar.make(listView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } } }).show(); } } }).show(); return true; } }); listView.post(new Runnable() { public void run() { listView.setSelection(listView.getCount() - 1); } }); }
From source file:com.z299studio.pb.DetailFragment.java
private void copyToClipboard(String label, String text) { ClipboardManager clipboardManager = (ClipboardManager) (getActivity() .getSystemService(Context.CLIPBOARD_SERVICE)); ClipData clipData = ClipData.newPlainText(label, text); clipboardManager.setPrimaryClip(clipData); Application.showToast(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT); }
From source file:org.matrix.console.fragments.ConsoleMessageListFragment.java
/*** MessageAdapter listener ***/ @Override//from ww w .ja va2 s . c om public void onRowClick(int position) { final MessageRow messageRow = mAdapter.getItem(position); final List<Integer> textIds = new ArrayList<>(); final List<Integer> iconIds = new ArrayList<Integer>(); String mediaUrl = null; String mediaMimeType = null; Uri mediaUri = null; Message message = JsonUtils.toMessage(messageRow.getEvent().content); if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(messageRow.getEvent().type) || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(messageRow.getEvent().type) || Event.EVENT_TYPE_STATE_ROOM_NAME.equals(messageRow.getEvent().type) || Message.MSGTYPE_EMOTE.equals(message.msgtype)) { if (!messageRow.getEvent().getSender().equals(getSession().getCredentials().userId)) { textIds.add(R.string.paste_username); iconIds.add(R.drawable.ic_material_paste); } textIds.add(R.string.copy); iconIds.add(R.drawable.ic_material_copy); } else { // copy the message body if (Event.EVENT_TYPE_MESSAGE.equals(messageRow.getEvent().type)) { if (!messageRow.getEvent().getSender().equals(getSession().getCredentials().userId)) { textIds.add(R.string.paste_username); iconIds.add(R.drawable.ic_material_paste); } if (Message.MSGTYPE_TEXT.equals(message.msgtype)) { textIds.add(R.string.copy); iconIds.add(R.drawable.ic_material_copy); } } if (messageRow.getEvent().canBeResent()) { textIds.add(R.string.resend); iconIds.add(R.drawable.ic_material_send); } else if (messageRow.getEvent().mSentState == Event.SentState.SENT) { textIds.add(R.string.redact); iconIds.add(R.drawable.ic_material_clear); if (Event.EVENT_TYPE_MESSAGE.equals(messageRow.getEvent().type)) { Boolean supportShare = true; // check if the media has been downloaded if ((message instanceof ImageMessage) || (message instanceof FileMessage)) { if (message instanceof ImageMessage) { ImageMessage imageMessage = (ImageMessage) message; mediaUrl = imageMessage.url; mediaMimeType = imageMessage.getMimeType(); } else { FileMessage fileMessage = (FileMessage) message; mediaUrl = fileMessage.url; mediaMimeType = fileMessage.getMimeType(); } supportShare = false; MXMediasCache cache = getMXMediasCache(); File mediaFile = cache.mediaCacheFile(mediaUrl, mediaMimeType); if (null != mediaFile) { try { mediaUri = ConsoleContentProvider.absolutePathToUri(getActivity(), mediaFile.getAbsolutePath()); supportShare = true; } catch (Exception e) { } } } if (supportShare) { textIds.add(R.string.share); iconIds.add(R.drawable.ic_material_share); textIds.add(R.string.forward); iconIds.add(R.drawable.ic_material_forward); textIds.add(R.string.save); iconIds.add(R.drawable.ic_material_save); } } } } // display the JSON textIds.add(R.string.message_details); iconIds.add(R.drawable.ic_material_description); FragmentManager fm = getActivity().getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_MESSAGE_OPTIONS); if (fragment != null) { fragment.dismissAllowingStateLoss(); } Integer[] lIcons = iconIds.toArray(new Integer[iconIds.size()]); Integer[] lTexts = textIds.toArray(new Integer[iconIds.size()]); final String fmediaMimeType = mediaMimeType; final Uri fmediaUri = mediaUri; final String fmediaUrl = mediaUrl; final Message fMessage = message; fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { final Integer selectedVal = textIds.get(position); if (selectedVal == R.string.copy) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); Event event = messageRow.getEvent(); String text = ""; if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(messageRow.getEvent().type) || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(messageRow.getEvent().type) || Event.EVENT_TYPE_STATE_ROOM_NAME.equals(messageRow.getEvent().type)) { RoomState roomState = messageRow.getRoomState(); EventDisplay display = new EventDisplay(getActivity(), event, roomState); text = display.getTextualDisplay().toString(); } else { text = JsonUtils.toMessage(event.content).body; } ClipData clip = ClipData.newPlainText("", text); clipboard.setPrimaryClip(clip); } }); } else if (selectedVal == R.string.resend) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { resend(messageRow.getEvent()); } }); } else if (selectedVal == R.string.save) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { save(fMessage, fmediaUrl, fmediaMimeType); } }); } else if (selectedVal == R.string.redact) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { redactEvent(messageRow.getEvent().eventId); } }); } else if ((selectedVal == R.string.share) || (selectedVal == R.string.forward)) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); Event event = messageRow.getEvent(); Message message = JsonUtils.toMessage(event.content); if (null != fmediaUri) { sendIntent.setType(fmediaMimeType); sendIntent.putExtra(Intent.EXTRA_STREAM, fmediaUri); } else { sendIntent.putExtra(Intent.EXTRA_TEXT, message.body); sendIntent.setType("text/plain"); } if (selectedVal == R.string.forward) { CommonActivityUtils.sendFilesTo(getActivity(), sendIntent); } else { startActivity(sendIntent); } } }); } else if (selectedVal == R.string.message_details) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { FragmentManager fm = getActivity().getSupportFragmentManager(); MessageDetailsFragment fragment = (MessageDetailsFragment) fm .findFragmentByTag(TAG_FRAGMENT_MESSAGE_DETAILS); if (fragment != null) { fragment.dismissAllowingStateLoss(); } fragment = MessageDetailsFragment.newInstance(messageRow.getEvent().toString()); fragment.show(fm, TAG_FRAGMENT_MESSAGE_DETAILS); } }); } else if (selectedVal == R.string.paste_username) { String displayName = messageRow.getEvent().getSender(); RoomState state = messageRow.getRoomState(); if (null != state) { displayName = state.getMemberName(displayName); } onSenderNameClick(messageRow.getEvent().getSender(), displayName); } } }); // GA issue // can not perform this action after onSaveInstanceState.... // it seems that the linked activity is stopped. try { fragment.show(fm, TAG_FRAGMENT_MESSAGE_OPTIONS); } catch (Exception e) { } }
From source file:org.kde.kdeconnect.Plugins.SharePlugin.SharePlugin.java
@Override public boolean onPackageReceived(NetworkPackage np) { try {/*from ww w .j a v a 2 s . c om*/ if (np.hasPayload()) { Log.i("SharePlugin", "hasPayload"); final InputStream input = np.getPayload(); final long fileLength = np.getPayloadSize(); final String originalFilename = np.getString("filename", Long.toString(System.currentTimeMillis())); //We need to check for already existing files only when storing in the default path. //User-defined paths use the new Storage Access Framework that already handles this. final boolean customDestination = ShareSettingsActivity.isCustomDestinationEnabled(context); final String defaultPath = ShareSettingsActivity.getDefaultDestinationDirectory().getAbsolutePath(); final String filename = customDestination ? originalFilename : FilesHelper.findNonExistingNameForNewFile(defaultPath, originalFilename); String displayName = FilesHelper.getFileNameWithoutExt(filename); final String mimeType = FilesHelper.getMimeTypeFromFile(filename); if ("*/*".equals(mimeType)) { displayName = filename; } final DocumentFile destinationFolderDocument = ShareSettingsActivity .getDestinationDirectory(context); final DocumentFile destinationDocument = destinationFolderDocument.createFile(mimeType, displayName); final OutputStream destinationOutput = context.getContentResolver() .openOutputStream(destinationDocument.getUri()); final Uri destinationUri = destinationDocument.getUri(); final int notificationId = (int) System.currentTimeMillis(); Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(res.getString(R.string.incoming_file_title, device.getName())) .setContentText(res.getString(R.string.incoming_file_text, filename)) .setTicker(res.getString(R.string.incoming_file_title, device.getName())) .setSmallIcon(android.R.drawable.stat_sys_download).setAutoCancel(true).setOngoing(true) .setProgress(100, 0, true); final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build()); new Thread(new Runnable() { @Override public void run() { boolean successful = true; try { byte data[] = new byte[1024]; long progress = 0, prevProgressPercentage = 0; int count; while ((count = input.read(data)) >= 0) { progress += count; destinationOutput.write(data, 0, count); if (fileLength > 0) { if (progress >= fileLength) break; long progressPercentage = (progress * 100 / fileLength); if (progressPercentage != prevProgressPercentage) { prevProgressPercentage = progressPercentage; builder.setProgress(100, (int) progressPercentage, false); NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build()); } } //else Log.e("SharePlugin", "Infinite loop? :D"); } destinationOutput.flush(); } catch (Exception e) { successful = false; Log.e("SharePlugin", "Receiver thread exception"); e.printStackTrace(); } finally { try { destinationOutput.close(); } catch (Exception e) { } try { input.close(); } catch (Exception e) { } } try { Log.i("SharePlugin", "Transfer finished: " + destinationUri.getPath()); //Update the notification and allow to open the file from it Resources res = context.getResources(); String message = successful ? res.getString(R.string.received_file_title, device.getName()) : res.getString(R.string.received_file_fail_title, device.getName()); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(message).setTicker(message) .setSmallIcon(android.R.drawable.stat_sys_download_done).setAutoCancel(true); if (successful) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(destinationUri, mimeType); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentText( res.getString(R.string.received_file_text, destinationDocument.getName())) .setContentIntent(resultPendingIntent); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean("share_notification_preference", true)) { builder.setDefaults(Notification.DEFAULT_ALL); } NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build()); if (successful) { if (!customDestination && Build.VERSION.SDK_INT >= 12) { Log.i("SharePlugin", "Adding to downloads"); DownloadManager manager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); manager.addCompletedDownload(destinationUri.getLastPathSegment(), device.getName(), true, mimeType, destinationUri.getPath(), fileLength, false); } else { //Make sure it is added to the Android Gallery anyway MediaStoreHelper.indexFile(context, destinationUri); } } } catch (Exception e) { Log.e("SharePlugin", "Receiver thread exception"); e.printStackTrace(); } } }).start(); } else if (np.has("text")) { Log.i("SharePlugin", "hasText"); String text = np.getString("text"); if (Build.VERSION.SDK_INT >= 11) { ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(text); } else { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); } Toast.makeText(context, R.string.shareplugin_text_saved, Toast.LENGTH_LONG).show(); } else if (np.has("url")) { String url = np.getString("url"); Log.i("SharePlugin", "hasUrl: " + url); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (openUrlsDirectly) { context.startActivity(browserIntent); } else { Resources res = context.getResources(); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(browserIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Notification noti = new NotificationCompat.Builder(context) .setContentTitle(res.getString(R.string.received_url_title, device.getName())) .setContentText(res.getString(R.string.received_url_text, url)) .setContentIntent(resultPendingIntent) .setTicker(res.getString(R.string.received_url_title, device.getName())) .setSmallIcon(R.drawable.ic_notification).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, (int) System.currentTimeMillis(), noti); } } else { Log.e("SharePlugin", "Error: Nothing attached!"); } } catch (Exception e) { Log.e("SharePlugin", "Exception"); e.printStackTrace(); } return true; }
From source file:syncthing.android.service.SyncthingUtils.java
public static boolean isClipBoardSupported(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); return clipboard != null; }
From source file:com.runye.express.chat.activity.ChatActivity.java
private void setUpView() { activityInstance = this; iv_emoticons_normal.setOnClickListener(this); iv_emoticons_checked.setOnClickListener(this); // position = getIntent().getIntExtra("position", -1); clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo"); // ???/* www . j a va2s . co m*/ chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE); if (chatType == CHATTYPE_SINGLE) { // ?? toChatUsername = getIntent().getStringExtra("userId"); ((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("nick")); } else { // ? findViewById(R.id.container_to_group).setVisibility(View.VISIBLE); findViewById(R.id.container_remove).setVisibility(View.GONE); toChatUsername = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(toChatUsername); ((TextView) findViewById(R.id.name)).setText(group.getGroupName()); } conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnsetMsgCount(); adapter = new MessageAdapter(this, toChatUsername, chatType); // ? listView.setAdapter(adapter); listView.setOnScrollListener(new ListScrollListener()); int count = listView.getCount(); if (count > 0) { listView.setSelection(count - 1); } listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { hideKeyboard(); more.setVisibility(View.GONE); iv_emoticons_normal.setVisibility(View.VISIBLE); iv_emoticons_checked.setVisibility(View.INVISIBLE); expressionContainer.setVisibility(View.GONE); btnContainer.setVisibility(View.GONE); return false; } }); // ? receiver = new NewMessageBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction()); // Mainacitivity,??chat?????? intentFilter.setPriority(5); registerReceiver(receiver, intentFilter); // ack?BroadcastReceiver IntentFilter ackMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getAckMessageBroadcastAction()); ackMessageIntentFilter.setPriority(5); registerReceiver(ackMessageReceiver, ackMessageIntentFilter); // ????T groupListener = new GroupListener(); EMGroupManager.getInstance().addGroupChangeListener(groupListener); // show forward message if the message is not null String forward_msg_id = getIntent().getStringExtra("forward_msg_id"); if (forward_msg_id != null) { // ????? forwardMessage(forward_msg_id); } }