diff options
author | Tom Taylor <tomtaylor@google.com> | 2012-09-13 12:00:59 -0700 |
---|---|---|
committer | Tom Taylor <tomtaylor@google.com> | 2012-09-13 12:00:59 -0700 |
commit | ea339a26d0f2de0087d4c6ebf9f55c505b922695 (patch) | |
tree | 54172ae19831fda119fae9bc5e75ef13831a112d /src | |
parent | 8913ee108856f8c94f479b0e1401023567024185 (diff) | |
download | Mms-ea339a26d0f2de0087d4c6ebf9f55c505b922695.tar.gz |
Unable to view all participants of Group MMS thread
Bug 7087996
Bug 7161745
Add a group participants activity so a user can see all the members
of a group chat. Also fix a monkey bug with isCursorValid().
Change-Id: Ic73b6e27a139c74e4c735628ce822d102501da83
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/mms/ui/ComposeMessageActivity.java | 20 | ||||
-rw-r--r-- | src/com/android/mms/ui/MessageListAdapter.java | 2 | ||||
-rw-r--r-- | src/com/android/mms/ui/RecipientListActivity.java | 158 |
3 files changed, 176 insertions, 4 deletions
diff --git a/src/com/android/mms/ui/ComposeMessageActivity.java b/src/com/android/mms/ui/ComposeMessageActivity.java index b1488bc2..d44015b2 100644 --- a/src/com/android/mms/ui/ComposeMessageActivity.java +++ b/src/com/android/mms/ui/ComposeMessageActivity.java @@ -214,6 +214,7 @@ public class ComposeMessageActivity extends Activity private static final int MENU_UNLOCK_MESSAGE = 29; private static final int MENU_SAVE_RINGTONE = 30; private static final int MENU_PREFERENCES = 31; + private static final int MENU_GROUP_PARTICIPANTS = 32; private static final int RECIPIENTS_MAX_LENGTH = 312; @@ -311,6 +312,8 @@ public class ComposeMessageActivity extends Activity */ private boolean mIsRunning; + public final static String THREAD_ID = "thread_id"; // key for extras and icicles + @SuppressWarnings("unused") public static void log(String logMsg) { Thread current = Thread.currentThread(); @@ -1216,7 +1219,7 @@ public class ComposeMessageActivity extends Activity intent.putExtra("exit_on_sent", true); intent.putExtra("forwarded_message", true); if (mTempThreadId > 0) { - intent.putExtra("thread_id", mTempThreadId); + intent.putExtra(THREAD_ID, mTempThreadId); } if (msgItem.mType.equals("sms")) { @@ -1971,7 +1974,7 @@ public class ComposeMessageActivity extends Activity // draft, ensureThreadId gets called async from WorkingMessage.asyncUpdateDraftSmsMessage // the thread will get a threadId behind the UI thread's back. long originalThreadId = mConversation.getThreadId(); - long threadId = intent.getLongExtra("thread_id", 0); + long threadId = intent.getLongExtra(THREAD_ID, 0); Uri intentUri = intent.getData(); boolean sameThread = false; @@ -2549,6 +2552,10 @@ public class ComposeMessageActivity extends Activity R.drawable.ic_menu_emoticons); } + if (getRecipients().size() > 1) { + menu.add(0, MENU_GROUP_PARTICIPANTS, 0, R.string.menu_group_participants); + } + if (mMsgListAdapter.getCount() > 0) { // Removed search as part of b/1205708 //menu.add(0, MENU_SEARCH, 0, R.string.menu_search).setIcon( @@ -2638,6 +2645,13 @@ public class ComposeMessageActivity extends Activity case MENU_INSERT_SMILEY: showSmileyDialog(); break; + case MENU_GROUP_PARTICIPANTS: + { + Intent intent = new Intent(this, RecipientListActivity.class); + intent.putExtra(THREAD_ID, mConversation.getThreadId()); + startActivity(intent); + break; + } case MENU_VIEW_CONTACT: { // View the contact for the first (and only) recipient. ContactList list = getRecipients(); @@ -3698,7 +3712,7 @@ public class ComposeMessageActivity extends Activity } // If we have been passed a thread_id, use that to find our conversation. - long threadId = intent.getLongExtra("thread_id", 0); + long threadId = intent.getLongExtra(THREAD_ID, 0); if (threadId > 0) { if (LogTag.VERBOSE) log("get mConversation by threadId " + threadId); mConversation = Conversation.get(this, threadId, false); diff --git a/src/com/android/mms/ui/MessageListAdapter.java b/src/com/android/mms/ui/MessageListAdapter.java index fa1d65a9..7969e6b0 100644 --- a/src/com/android/mms/ui/MessageListAdapter.java +++ b/src/com/android/mms/ui/MessageListAdapter.java @@ -243,7 +243,7 @@ public class MessageListAdapter extends CursorAdapter { private boolean isCursorValid(Cursor cursor) { // Check whether the cursor is valid or not. - if (cursor.isClosed() || cursor.isBeforeFirst() || cursor.isAfterLast()) { + if (cursor == null || cursor.isClosed() || cursor.isBeforeFirst() || cursor.isAfterLast()) { return false; } return true; diff --git a/src/com/android/mms/ui/RecipientListActivity.java b/src/com/android/mms/ui/RecipientListActivity.java new file mode 100644 index 00000000..9baf660a --- /dev/null +++ b/src/com/android/mms/ui/RecipientListActivity.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mms.ui; + +import android.app.ActionBar; +import android.app.ListActivity; +import android.content.Context; +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.provider.ContactsContract.Profile; +import android.text.TextUtils; +import android.util.Log; +import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.QuickContactBadge; +import android.widget.TextView; + +import com.android.mms.R; +import com.android.mms.data.Contact; +import com.android.mms.data.ContactList; +import com.android.mms.data.Conversation; + +/** + * Display a list of recipients for a group conversation. This activity expects to receive a + * threadId in the intent's extras. + */ +public class RecipientListActivity extends ListActivity { + private final static String TAG = "RecipientListActivity"; + + private long mThreadId; + + @Override + protected void onCreate(Bundle icicle) { + super.onCreate(icicle); + + if (icicle != null) { + // Retrieve previously saved state of this activity. + mThreadId = icicle.getLong(ComposeMessageActivity.THREAD_ID); + } else { + mThreadId = getIntent().getLongExtra(ComposeMessageActivity.THREAD_ID, 0); + } + if (mThreadId == 0) { + Log.w(TAG, "No thread_id specified in extras or icicle. Finishing..."); + finish(); + return; + } + + Conversation conv = Conversation.get(this, mThreadId, true); + if (conv == null) { + Log.w(TAG, "No conversation found for threadId: " + mThreadId + ". Finishing..."); + finish(); + return; + } + final ContactList contacts = conv.getRecipients(); + getListView().setAdapter(new RecipientListAdapter(this, R.layout.recipient_list_item, + contacts)); + + ActionBar actionBar = getActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + int cnt = contacts.size(); + actionBar.setSubtitle(getResources().getQuantityString(R.plurals.recipient_count, + cnt, cnt)); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + outState.putLong(ComposeMessageActivity.THREAD_ID, mThreadId); + super.onSaveInstanceState(outState); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + case R.id.action_settings: + Intent intent = new Intent(this, MessagingPreferenceActivity.class); + startActivity(intent); + break; + } + return true; + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.recipient_list_menu, menu); + return true; + } + + private static class RecipientListAdapter extends ArrayAdapter<Contact> { + private final int mResourceId; + private final LayoutInflater mInflater; + private final Drawable mDefaultContactImage; + + public RecipientListAdapter(Context context, int resource, + ContactList recipients) { + super(context, resource, recipients); + + mResourceId = resource; + mInflater = LayoutInflater.from(context); + mDefaultContactImage = + context.getResources().getDrawable(R.drawable.ic_contact_picture); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final View listItemView = mInflater.inflate(mResourceId, null); + + final TextView nameView = (TextView)listItemView.findViewById(R.id.name); + final TextView numberView = (TextView)listItemView.findViewById(R.id.number); + + final Contact contact = getItem(position); + final String name = contact.getName(); + final String number = contact.getNumber(); + if (!name.equals(number)) { + nameView.setText(name); + numberView.setText(number); + } else { + nameView.setText(number); + numberView.setText(null); + } + + QuickContactBadge badge = (QuickContactBadge)listItemView.findViewById(R.id.avatar); + if (contact.existsInDatabase()) { + badge.assignContactUri(contact.getUri()); + } else { + badge.assignContactFromPhone(contact.getNumber(), true); + } + final Drawable avatarDrawable = contact.getAvatar(getContext(), mDefaultContactImage); + badge.setImageDrawable(avatarDrawable); + + return listItemView; + } + } +} |