Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

From source file:com.safeness.im.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 av  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);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).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,true);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    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);
            emojiIconContainer.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);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????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);
    }

}

From source file:la.zmkm.agent.activity.ChatActivity.java

private void setUpView() {
    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 w  w w .  jav  a 2 s  . co  m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        ((TextView) findViewById(R.id.name)).setText(toChatUsername);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        if (group != null)
            ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
        else
            ((TextView) findViewById(R.id.name)).setText(toChatUsername);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0      
    conversation.resetUnreadMsgCount();

    // ?db?conversationgetChatOptions().getNumberOfMessagesLoaded
    // ???
    final List<EMMessage> msgs = conversation.getAllMessages();
    int msgCount = msgs != null ? msgs.size() : 0;
    if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
        String msgId = null;
        if (msgs != null && msgs.size() > 0) {
            msgId = msgs.get(0).getMsgId();
        }
        if (chatType == CHATTYPE_SINGLE) {
            conversation.loadMoreMsgFromDB(msgId, pagesize);
        } else {
            conversation.loadMoreGroupMsgFromDB(msgId, pagesize);
        }
    }
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    adapter.refreshSelectLast();

    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);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });

    // ????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);
    }
}

From source file:com.dtr.zxing.activity.CaptureActivity.java

private void showCopyTextOption(final String text) {
    DialogHelp.getConfirmDialog(this, text, new DialogInterface.OnClickListener() {
        @Override//from   www . ja v  a 2s  .  co m
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager cbm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            cbm.setText(text);
            AppContext.showToast("??");
            finish();
        }
    }, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            finish();
        }
    }).show();
}

From source file:com.normalexception.app.rx8club.view.threadpost.PostView.java

/**
 * Setup our view here.  After the view has been inflated and all of the
 * view objects have been initialized, we can inflate our view here
 * @param post      The model we are going to use to populate the view
 * @param position   Get the position of this view on the window
 * @param listener  The listener object to attach to the view
 *///  w w w .jav a2 s .  c om
public void setPost(final PostModel post, final int position, final OnClickListener listener) {
    username.setText(post.getUserName());
    userTitle.setText(post.getUserTitle());
    userPosts.setText(post.getUserPostCount());
    userJoin.setText(post.getJoinDate());
    postDate.setText(post.getPostDate());
    reportbutton.setVisibility(View.VISIBLE);

    if (PreferenceHelper.isShowLikes(getContext())) {
        if (post.getLikes().size() > 0) {
            String delim = "", likes = "Liked by: ";
            for (String like : post.getLikes()) {
                likes += delim + like;
                delim = ", ";
            }
            likeText.setText(likes);
        } else {
            likeText.setVisibility(View.GONE);
        }
    } else {
        likeText.setVisibility(View.GONE);
    }

    // Lets make sure we remove any font formatting that was done within
    // the text
    String trimmedPost = post.getUserPost().replaceAll("(?i)<(/*)font(.*?)>", "");

    // Show attachments if the preference allows it
    if (PreferenceHelper.isShowAttachments(getContext()))
        trimmedPost = appendAttachments(trimmedPost, post.getAttachments());

    // Show signatures if the preference allows it
    if (PreferenceHelper.isShowSignatures(getContext()) && post.getUserSignature() != null)
        trimmedPost = appendSignature(trimmedPost, post.getUserSignature());

    // Set html Font color
    trimmedPost = Utils.postFormatter(trimmedPost, getContext());
    postText.setBackgroundColor(Color.DKGRAY);
    postText.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    postText.getSettings().setAppCachePath(Cache.getExternalCacheDir(getContext()).getAbsolutePath());
    postText.getSettings().setAllowFileAccess(false);
    postText.getSettings().setAppCacheEnabled(true);
    postText.getSettings().setJavaScriptEnabled(false);
    postText.getSettings().setSupportZoom(false);
    postText.getSettings().setSupportMultipleWindows(false);
    postText.getSettings().setUserAgentString(WebUrls.USER_AGENT);
    postText.getSettings().setDatabaseEnabled(false);
    postText.getSettings().setDomStorageEnabled(false);
    postText.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    postText.setOnTouchListener(new View.OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        public boolean onTouch(View v, MotionEvent event) {
            return (event.getAction() == MotionEvent.ACTION_MOVE);
        }
    });
    postText.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // Check if the URL for the site, and if it is a thread or a category
            Log.d(TAG, "User Clicked Embedded url");
            boolean isThread = false;
            if (url.contains("rx8club.com")) {
                isThread = url.matches(".*\\-\\d+\\/$");
                Log.d(TAG, String.format("The Link (%s) is %sa thread", url, (isThread) ? "" : "NOT "));

                Bundle args = new Bundle();
                args.putString("link", url);

                if (isThread) {
                    FragmentUtils.fragmentTransaction((FragmentActivity) view.getContext(),
                            ThreadFragment.newInstance(), false, true, args);
                    return true;
                }
            }

            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            MainApplication.getAppContext().startActivity(intent);
            return true;
        }
    });

    postText.loadDataWithBaseURL(WebUrls.rootUrl, trimmedPost, "text/html", "utf-8", "");

    // Load up the avatar of hte user, but remember to remove
    // the dateline at the end of the file so that we aren't
    // creating multiple images for a user.  The image still
    // gets returned without a date
    if (PreferenceHelper.isShowAvatars(getContext())) {
        String nodate_avatar = post.getUserImageUrl().indexOf('?') == -1 ? post.getUserImageUrl()
                : post.getUserImageUrl().substring(0, post.getUserImageUrl().indexOf('?'));

        if (!nodate_avatar.isEmpty()) {
            imageLoader.DisplayImage(nodate_avatar, avatar);
        } else {
            avatar.setImageResource(R.drawable.rotor_icon);
        }
    }

    // Display the right items if the user is logged in
    setUserIcons(this, post.isLoggedInUser());

    downButton.setOnClickListener(listener);

    // Set click listeners if we are logged in, hide the buttons
    // if we are not logged in
    if (LoginFactory.getInstance().isGuestMode()) {
        quoteButton.setVisibility(View.GONE);
        editButton.setVisibility(View.GONE);
        pmButton.setVisibility(View.GONE);
        deleteButton.setVisibility(View.GONE);
        reportbutton.setVisibility(View.GONE);
    } else {
        quoteButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Log.d(TAG, "Quote Clicked");
                String txt = Html.fromHtml(post.getUserPost()).toString();
                String finalText = String.format("[quote=%s]%s[/quote]", post.getUserName(), txt);
                postBox.setText(finalText);
                postBox.requestFocus();
            }
        });

        editButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Log.d(TAG, "Edit Clicked");

                // Create new fragment and transaction
                Bundle args = new Bundle();
                args.putString("postid", post.getPostId());
                args.putString("securitytoken", post.getToken());
                Fragment newFragment = new EditPostFragment();

                FragmentUtils.fragmentTransaction((FragmentActivity) getContext(), newFragment, true, true,
                        args);
            }
        });

        reportbutton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Log.d(TAG, "Report Clicked");
                new ReportPostDialog(getContext(), post.getToken(), post.getPostId()).show();
            }
        });

        linkbutton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Log.d(TAG, "Link Clicked");
                ClipboardManager clipboard = (android.content.ClipboardManager) getContext()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("thread link",
                        post.getRootThreadUrl());
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getContext(), "Thread Link Copied To Clipboard", Toast.LENGTH_LONG).show();
            }
        });

        pmButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Log.d(TAG, "PM Clicked");

                // Create new fragment and transaction
                Bundle args = new Bundle();
                args.putString("user", post.getUserName());
                Fragment newFragment = new NewPrivateMessageFragment();
                FragmentUtils.fragmentTransaction((FragmentActivity) getContext(), newFragment, false, true,
                        args);
            }
        });

        final boolean isFirstPost = (position == 0);
        deleteButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                        case DialogInterface.BUTTON_POSITIVE:
                            // Create new fragment and transaction
                            Bundle args = new Bundle();
                            args.putString("postid", post.getPostId());
                            args.putString("securitytoken", post.getToken());
                            args.putBoolean("delete", true);
                            args.putBoolean("deleteThread", isFirstPost && post.isLoggedInUser());
                            Fragment newFragment = new EditPostFragment();
                            FragmentUtils.fragmentTransaction((FragmentActivity) getContext(), newFragment,
                                    false, true, args);
                            break;
                        }
                    }
                };

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setMessage("Are you sure you want to delete your post?")
                        .setPositiveButton("Yes", dialogClickListener)
                        .setNegativeButton("No", dialogClickListener).show();
            }
        });
    }
}

From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.activity.ChatActivity.java

private void setUpView() {
    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  w ww .  ja  va2 s .  c  om*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        //doctor avatar
        String name = getIntent().getStringExtra("name");
        if (!TextUtils.isEmpty(name)) {
            ((TextView) findViewById(R.id.name)).setText(name);
        } else {
            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
            pairs.add(new BasicNameValuePair("userid", toChatUsername));
            Request.doRequest(this, pairs, ServerConfig.URL_QUERY_USER_INFO, Request.GET,
                    new Request.RequestListener() {
                        @Override
                        public void onException(Request.RequestException e) {
                            ((TextView) findViewById(R.id.name)).setText(toChatUsername);
                        }

                        @Override
                        public void onComplete(String response) {
                            UserInfoModel model = HCApplicaton.getInstance().getGson()
                                    .fromJsonWithNoException(response, UserInfoModel.class);
                            if (model != null && model.result == 1) {
                                ((TextView) findViewById(R.id.name)).setText(model.nickname);
                            } else {
                                ((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);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");

        if (chatType == CHATTYPE_GROUP) {
            onGroupViewCreation();
        } else {
            onChatRoomViewCreation();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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:com.android.talkback.SpeechController.java

/**
 * Copies the last phrase spoken by TalkBack to clipboard
 */// w  w  w  .  j av a 2  s  . c  o m
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:info.papdt.blacklight.support.Utility.java

public static void copyToClipboard(Context context, String data) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData cd = ClipData.newPlainText("msg", data);
    cm.setPrimaryClip(cd);//from  w w  w . jav  a  2 s . c  o m

    // Inform the user
    Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show();
}

From source file:com.wenwen.chatuidemo.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");
    // ???/*  w  ww .  j a  v a 2  s  .co  m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);
    toAccountname = getIntent().getStringExtra("accountname");
    type = getIntent().getStringExtra("type");
    if (!type.equals("1")) {
        toChatUsername = MD5.md5(toChatUsername);
    }
    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("username");//acuntName
        DebugLog.i(TAG, "toChatUsername==" + toChatUsername);
        ((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("accountname"));
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).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.resetUnreadMsgCount();
    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);
            emojiIconContainer.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);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????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);
    }

}

From source file:com.app.uafeed.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//ww  w  . ja  v  a 2  s.  c o  m

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            if (link != null) {
                String title = cursor.getString(mTitlePos);
                startActivity(Intent.createChooser(
                        new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                        getString(R.string.menu_share)));
            }
            break;
        }
        case R.id.menu_full_screen: {
            toggleFullScreen();
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:com.xiaoyu.HeartConsultation.chat.chatuidemo.activity.ChatActivity.java

private void setUpView() {
    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   w ww. java  2 s .c  o m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        //doctor avatar
        String name = getIntent().getStringExtra("name");
        if (!TextUtils.isEmpty(name)) {
            ((TextView) findViewById(R.id.name)).setText(name);
        } else {
            final ChatUserInfoUtil.UserInfo userInfo = ChatUserInfoUtil.getUserInfo(toChatUsername);
            if (userInfo != null) {
                ((TextView) findViewById(R.id.name)).setText(userInfo.name);
            } else {
                List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                pairs.add(new BasicNameValuePair("userid", toChatUsername));
                Request.doRequest(this, pairs, ServerConfig.URL_QUERY_USER_INFO, Request.GET,
                        new Request.RequestListener() {
                            @Override
                            public void onException(Request.RequestException e) {
                                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
                            }

                            @Override
                            public void onComplete(String response) {
                                UserInfoModel model = HCApplicaton.getInstance().getGson()
                                        .fromJsonWithNoException(response, UserInfoModel.class);
                                if (model != null && model.result == 1) {
                                    ChatUserInfoUtil.UserInfo userInfo1 = new ChatUserInfoUtil.UserInfo();
                                    userInfo1.avatar = model.imagepath;
                                    userInfo1.name = model.nickname;
                                    ChatUserInfoUtil.putUserInfo(toChatUsername, userInfo1);
                                    ((TextView) findViewById(R.id.name)).setText(userInfo1.name);
                                } else {
                                    ((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);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");

        if (chatType == CHATTYPE_GROUP) {
            onGroupViewCreation();
        } else {
            onChatRoomViewCreation();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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);
        }
    }
}