The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.contacts; |
| 18 | |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 19 | import com.android.contacts.calllog.CallDetailHistoryAdapter; |
| 20 | import com.android.contacts.calllog.CallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 21 | import com.android.contacts.calllog.PhoneNumberHelper; |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 22 | import com.android.contacts.voicemail.VoicemailPlaybackFragment; |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 23 | import com.android.contacts.voicemail.VoicemailStatusHelper; |
| 24 | import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage; |
| 25 | import com.android.contacts.voicemail.VoicemailStatusHelperImpl; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 26 | |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 27 | import android.app.FragmentManager; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 28 | import android.app.ListActivity; |
| 29 | import android.content.ContentResolver; |
| 30 | import android.content.ContentUris; |
| 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
| 33 | import android.content.res.Resources; |
| 34 | import android.database.Cursor; |
| 35 | import android.net.Uri; |
| 36 | import android.os.Bundle; |
| 37 | import android.provider.CallLog; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 38 | import android.provider.CallLog.Calls; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 39 | import android.provider.Contacts.Intents.Insert; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 40 | import android.provider.ContactsContract.Contacts; |
| 41 | import android.provider.ContactsContract.PhoneLookup; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 42 | import android.telephony.PhoneNumberUtils; |
| 43 | import android.telephony.TelephonyManager; |
| 44 | import android.text.TextUtils; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 45 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 46 | import android.view.KeyEvent; |
| 47 | import android.view.LayoutInflater; |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 48 | import android.view.Menu; |
| 49 | import android.view.MenuItem; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 50 | import android.view.View; |
| 51 | import android.view.ViewGroup; |
| 52 | import android.widget.AdapterView; |
| 53 | import android.widget.BaseAdapter; |
| 54 | import android.widget.ImageView; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 55 | import android.widget.ListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 56 | import android.widget.TextView; |
| 57 | import android.widget.Toast; |
| 58 | |
| 59 | import java.util.ArrayList; |
| 60 | import java.util.List; |
| 61 | |
| 62 | /** |
| 63 | * Displays the details of a specific call log entry. |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 64 | * <p> |
| 65 | * This activity can be either started with the URI of a single call log entry, or with the |
| 66 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 67 | */ |
| 68 | public class CallDetailActivity extends ListActivity implements |
| 69 | AdapterView.OnItemClickListener { |
| 70 | private static final String TAG = "CallDetail"; |
| 71 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 72 | /** A long array extra containing ids of call log entries to display. */ |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 73 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 74 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 75 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 76 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 77 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 78 | |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 79 | /** The views representing the details of a phone call. */ |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 80 | private PhoneCallDetailsViews mPhoneCallDetailsViews; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 81 | private CallTypeHelper mCallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 82 | private PhoneNumberHelper mPhoneNumberHelper; |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 83 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 84 | private View mHomeActionView; |
| 85 | private ImageView mMainActionView; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 86 | private ImageView mContactBackgroundView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 87 | |
| 88 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 89 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 90 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 91 | /* package */ LayoutInflater mInflater; |
| 92 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 93 | /** Helper to load contact photos. */ |
| 94 | private ContactPhotoManager mContactPhotoManager; |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 95 | /** Helper to make async queries to content resolver. */ |
| 96 | private CallDetailActivityQueryHandler mAsyncQueryHandler; |
| 97 | /** Helper to get voicemail status messages. */ |
| 98 | private VoicemailStatusHelper mVoicemailStatusHelper; |
| 99 | // Views related to voicemail status message. |
| 100 | private View mStatusMessageView; |
| 101 | private TextView mStatusMessageText; |
| 102 | private TextView mStatusMessageAction; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 103 | |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 104 | /** Whether we should show "remove from call log" in the options menu. */ |
| 105 | private boolean mHasRemoveFromCallLog; |
| 106 | /** Whether we should show "edit number before call" in the options menu. */ |
| 107 | private boolean mHasEditNumberBeforeCall; |
| 108 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 109 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 110 | CallLog.Calls.DATE, |
| 111 | CallLog.Calls.DURATION, |
| 112 | CallLog.Calls.NUMBER, |
| 113 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 114 | CallLog.Calls.COUNTRY_ISO, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 115 | }; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 116 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 117 | static final int DATE_COLUMN_INDEX = 0; |
| 118 | static final int DURATION_COLUMN_INDEX = 1; |
| 119 | static final int NUMBER_COLUMN_INDEX = 2; |
| 120 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 121 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 122 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 123 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 124 | PhoneLookup._ID, |
| 125 | PhoneLookup.DISPLAY_NAME, |
| 126 | PhoneLookup.TYPE, |
| 127 | PhoneLookup.LABEL, |
| 128 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 129 | PhoneLookup.NORMALIZED_NUMBER, |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 130 | PhoneLookup.PHOTO_URI, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 131 | }; |
| 132 | static final int COLUMN_INDEX_ID = 0; |
| 133 | static final int COLUMN_INDEX_NAME = 1; |
| 134 | static final int COLUMN_INDEX_TYPE = 2; |
| 135 | static final int COLUMN_INDEX_LABEL = 3; |
| 136 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 137 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 138 | static final int COLUMN_INDEX_PHOTO_URI = 6; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 139 | |
| 140 | @Override |
| 141 | protected void onCreate(Bundle icicle) { |
| 142 | super.onCreate(icicle); |
| 143 | |
| 144 | setContentView(R.layout.call_detail); |
| 145 | |
| 146 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 147 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 148 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 149 | mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView()); |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 150 | mCallTypeHelper = new CallTypeHelper(getResources(), |
Flavio Lerda | 693d1f8 | 2011-07-13 18:20:46 +0100 | [diff] [blame] | 151 | getResources().getDrawable(R.drawable.ic_call_incoming_holo_dark), |
| 152 | getResources().getDrawable(R.drawable.ic_call_outgoing_holo_dark), |
| 153 | getResources().getDrawable(R.drawable.ic_call_missed_holo_dark), |
| 154 | getResources().getDrawable(R.drawable.ic_call_voicemail_holo_dark)); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 155 | mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber()); |
| 156 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, mResources, mCallTypeHelper, |
| 157 | mPhoneNumberHelper); |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 158 | mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); |
| 159 | mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); |
| 160 | mStatusMessageView = findViewById(R.id.voicemail_status); |
| 161 | mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message); |
| 162 | mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 163 | mHomeActionView = findViewById(R.id.action_bar_home); |
| 164 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 165 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 166 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 167 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 168 | getListView().setOnItemClickListener(this); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 169 | mHomeActionView.setOnClickListener(new View.OnClickListener() { |
| 170 | @Override |
| 171 | public void onClick(View v) { |
| 172 | // We want this to start the call log if this activity was not started from the |
| 173 | // call log itself. |
| 174 | CallDetailActivity.this.finish(); |
| 175 | } |
| 176 | }); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 177 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 178 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 179 | @Override |
| 180 | public void onResume() { |
| 181 | super.onResume(); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 182 | updateData(getCallLogEntryUris()); |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 183 | optionallyHandleVoicemail(); |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Handle voicemail playback or hide voicemail ui. |
| 188 | * <p> |
| 189 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
| 190 | * playback. If it doesn't, then hide the voicemail ui. |
| 191 | */ |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 192 | private void optionallyHandleVoicemail() { |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 193 | if (hasVoicemail()) { |
| 194 | // Has voicemail: leave the fragment visible. Optionally start the playback. |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 195 | // Do a query to fetch the voicemail status messages. |
| 196 | boolean startPlayback = getIntent().getBooleanExtra( |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 197 | EXTRA_VOICEMAIL_START_PLAYBACK, false); |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 198 | Uri voicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 199 | getVoicemailPlaybackFragment().setVoicemailUri(voicemailUri, startPlayback); |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 200 | mAsyncQueryHandler.startVoicemailStatusQuery(voicemailUri); |
| 201 | } else { |
| 202 | // No voicemail uri: hide the voicemail fragment and the status view. |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 203 | getFragmentManager().beginTransaction().hide(getVoicemailPlaybackFragment()).commit(); |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 204 | mStatusMessageView.setVisibility(View.GONE); |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 205 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 208 | private boolean hasVoicemail() { |
| 209 | return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI) != null; |
| 210 | } |
| 211 | |
| 212 | private VoicemailPlaybackFragment getVoicemailPlaybackFragment() { |
| 213 | FragmentManager manager = getFragmentManager(); |
| 214 | return (VoicemailPlaybackFragment) manager.findFragmentById( |
| 215 | R.id.voicemail_playback_fragment); |
| 216 | } |
| 217 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 218 | /** |
| 219 | * Returns the list of URIs to show. |
| 220 | * <p> |
| 221 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 222 | * a list of ids in the call log added as an extra on the URI. |
| 223 | * <p> |
| 224 | * If both are available, the data on the intent takes precedence. |
| 225 | */ |
| 226 | private Uri[] getCallLogEntryUris() { |
| 227 | Uri uri = getIntent().getData(); |
| 228 | if (uri != null) { |
| 229 | // If there is a data on the intent, it takes precedence over the extra. |
| 230 | return new Uri[]{ uri }; |
| 231 | } |
| 232 | long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 233 | Uri[] uris = new Uri[ids.length]; |
| 234 | for (int index = 0; index < ids.length; ++index) { |
| 235 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 236 | } |
| 237 | return uris; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 242 | switch (keyCode) { |
| 243 | case KeyEvent.KEYCODE_CALL: { |
| 244 | // Make sure phone isn't already busy before starting direct call |
| 245 | TelephonyManager tm = (TelephonyManager) |
| 246 | getSystemService(Context.TELEPHONY_SERVICE); |
| 247 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 248 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 249 | Uri.fromParts("tel", mNumber, null)); |
| 250 | startActivity(callIntent); |
| 251 | return true; |
| 252 | } |
| 253 | } |
| 254 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 255 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 256 | return super.onKeyDown(keyCode, event); |
| 257 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 258 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 259 | /** |
| 260 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 261 | * |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 262 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 263 | */ |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 264 | private void updateData(final Uri... callUris) { |
| 265 | // TODO: All phone calls correspond to the same person, so we can make a single lookup. |
| 266 | final int numCalls = callUris.length; |
| 267 | final PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 268 | try { |
| 269 | for (int index = 0; index < numCalls; ++index) { |
| 270 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 271 | } |
| 272 | } catch (IllegalArgumentException e) { |
| 273 | // Something went wrong reading in our primary data, so we're going to |
| 274 | // bail out and show error to users. |
| 275 | Log.w(TAG, "invalid URI starting call details", e); |
| 276 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 277 | Toast.LENGTH_SHORT).show(); |
| 278 | finish(); |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | // We know that all calls are from the same number and the same contact, so pick the first. |
| 283 | mNumber = details[0].number.toString(); |
| 284 | final long personId = details[0].personId; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 285 | final Uri photoUri = details[0].photoUri; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 286 | |
| 287 | // Set the details header, based on the first phone call. |
| 288 | mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, |
Flavio Lerda | 7692190 | 2011-07-13 21:11:51 +0100 | [diff] [blame] | 289 | details[0], false, false); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 290 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 291 | // Cache the details about the phone number. |
| 292 | final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber); |
| 293 | final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber); |
| 294 | final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber); |
| 295 | final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber); |
| 296 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 297 | // Let user view contact details if they exist, otherwise add option to create new contact |
| 298 | // from this number. |
| 299 | final Intent mainActionIntent; |
| 300 | final int mainActionIcon; |
| 301 | |
| 302 | if (details[0].personId != -1) { |
| 303 | Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId); |
| 304 | mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 305 | mainActionIcon = R.drawable.sym_action_view_contact; |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 306 | } else if (isVoicemailNumber) { |
| 307 | mainActionIntent = null; |
| 308 | mainActionIcon = 0; |
| 309 | } else if (isSipNumber) { |
| 310 | // TODO: This item is currently disabled for SIP addresses, because |
| 311 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 312 | // |
| 313 | // To fix this for SIP addresses, we need to: |
| 314 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 315 | // the current number is a SIP address |
| 316 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 317 | // updating the SipAddress field |
| 318 | // and then we can remove the "!isSipNumber" check above. |
| 319 | mainActionIntent = null; |
| 320 | mainActionIcon = 0; |
Flavio Lerda | 8e40340 | 2011-07-20 16:25:49 +0100 | [diff] [blame] | 321 | } else if (canPlaceCallsTo) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 322 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 323 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 324 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 325 | mainActionIcon = R.drawable.sym_action_add; |
Flavio Lerda | 8e40340 | 2011-07-20 16:25:49 +0100 | [diff] [blame] | 326 | } else { |
| 327 | // If we cannot call the number, when we probably cannot add it as a contact either. |
| 328 | // This is usually the case of private, unknown, or payphone numbers. |
| 329 | mainActionIntent = null; |
| 330 | mainActionIcon = 0; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 333 | if (mainActionIntent == null) { |
| 334 | mMainActionView.setVisibility(View.INVISIBLE); |
| 335 | } else { |
| 336 | mMainActionView.setVisibility(View.VISIBLE); |
| 337 | mMainActionView.setImageResource(mainActionIcon); |
| 338 | mMainActionView.setOnClickListener(new View.OnClickListener() { |
| 339 | @Override |
| 340 | public void onClick(View v) { |
| 341 | startActivity(mainActionIntent); |
| 342 | } |
| 343 | }); |
| 344 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 345 | |
| 346 | // Build list of various available actions. |
| 347 | final List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
| 348 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 349 | // This action allows to call the number that places the call. |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 350 | if (canPlaceCallsTo) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 351 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 352 | getString(R.string.menu_callNumber, mNumber), |
| 353 | new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri))); |
| 354 | } |
| 355 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 356 | // This action allows to send an SMS to the number that placed the call. |
| 357 | if (mPhoneNumberHelper.canSendSmsTo(mNumber)) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 358 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 359 | Uri.fromParts("sms", mNumber, null)); |
| 360 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 361 | getString(R.string.menu_sendTextMessage), smsIntent)); |
| 362 | } |
| 363 | |
| 364 | // This action deletes all elements in the group from the call log. |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 365 | // We don't have this action for voicemails, because you can just use the trash button. |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 366 | mHasRemoveFromCallLog = !hasVoicemail(); |
| 367 | mHasEditNumberBeforeCall = canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 368 | |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 369 | if (actions.size() != 0) { |
| 370 | // Set the actions for this phone number. |
| 371 | setListAdapter(new ViewAdapter(this, actions)); |
| 372 | getListView().setVisibility(View.VISIBLE); |
| 373 | } else { |
| 374 | getListView().setVisibility(View.GONE); |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 375 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 376 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 377 | ListView historyList = (ListView) findViewById(R.id.history); |
| 378 | historyList.setAdapter( |
| 379 | new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details)); |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 380 | loadContactPhotos(photoUri); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /** Return the phone call details for a given call log URI. */ |
| 384 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 385 | ContentResolver resolver = getContentResolver(); |
| 386 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 387 | try { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 388 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 389 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 390 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 391 | |
| 392 | // Read call log specifics. |
| 393 | String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 394 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 395 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 396 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
| 397 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 398 | if (TextUtils.isEmpty(countryIso)) { |
| 399 | countryIso = mDefaultCountryIso; |
| 400 | } |
| 401 | |
| 402 | // Formatted phone number. |
| 403 | final CharSequence numberText; |
| 404 | // Read contact specifics. |
| 405 | CharSequence nameText = ""; |
| 406 | int numberType = 0; |
| 407 | CharSequence numberLabel = ""; |
| 408 | long personId = -1L; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 409 | Uri photoUri = null; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 410 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 411 | if (!mPhoneNumberHelper.canPlaceCallsTo(number)) { |
| 412 | numberText = mPhoneNumberHelper.getDisplayNumber(number, null); |
| 413 | } else { |
| 414 | // Perform a reverse-phonebook lookup to find the contact details. |
| 415 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 416 | Uri.encode(number)); |
| 417 | Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null); |
| 418 | String candidateNumberText = number; |
| 419 | try { |
| 420 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 421 | personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 422 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 423 | String photoUriString = phonesCursor.getString(COLUMN_INDEX_PHOTO_URI); |
| 424 | photoUri = photoUriString == null ? null : Uri.parse(photoUriString); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 425 | candidateNumberText = PhoneNumberUtils.formatNumber( |
| 426 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 427 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 428 | countryIso); |
| 429 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 430 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
| 431 | } else { |
| 432 | // We could not find this contact in the contacts, just format the phone |
| 433 | // number as best as we can. All the other fields will have their default |
| 434 | // values. |
| 435 | candidateNumberText = |
| 436 | PhoneNumberUtils.formatNumber(number, countryIso); |
| 437 | } |
| 438 | } finally { |
| 439 | if (phonesCursor != null) phonesCursor.close(); |
| 440 | numberText = candidateNumberText; |
| 441 | } |
| 442 | } |
Flavio Lerda | 9c46637 | 2011-07-19 17:38:17 +0100 | [diff] [blame] | 443 | return new PhoneCallDetails(number, numberText, countryIso, |
Flavio Lerda | cb805e8 | 2011-07-18 10:31:44 +0100 | [diff] [blame] | 444 | new int[]{ callType }, date, duration, |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 445 | nameText, numberType, numberLabel, personId, photoUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 446 | } finally { |
| 447 | if (callCursor != null) { |
| 448 | callCursor.close(); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 453 | /** Load the contact photos and places them in the corresponding views. */ |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 454 | private void loadContactPhotos(Uri photoUri) { |
| 455 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 458 | private String getVoicemailNumber() { |
| 459 | TelephonyManager telephonyManager = |
| 460 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 461 | return telephonyManager.getVoiceMailNumber(); |
| 462 | } |
| 463 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 464 | static final class ViewEntry { |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 465 | public final int icon; |
| 466 | public final String text; |
| 467 | public final Intent intent; |
| 468 | public final View.OnClickListener action; |
| 469 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 470 | public String label = null; |
| 471 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 472 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 473 | public ViewEntry(int icon, String text, Intent intent) { |
| 474 | this.icon = icon; |
| 475 | this.text = text; |
| 476 | this.intent = intent; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 477 | this.action = null; |
| 478 | } |
| 479 | |
| 480 | public ViewEntry(int icon, String text, View.OnClickListener listener) { |
| 481 | this.icon = icon; |
| 482 | this.text = text; |
| 483 | this.intent = null; |
| 484 | this.action = listener; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
| 488 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 489 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 490 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 491 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 492 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 493 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 494 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 495 | mActions = actions; |
| 496 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 497 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 498 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 499 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 500 | public int getCount() { |
| 501 | return mActions.size(); |
| 502 | } |
| 503 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 504 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 505 | public Object getItem(int position) { |
| 506 | return mActions.get(position); |
| 507 | } |
| 508 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 509 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 510 | public long getItemId(int position) { |
| 511 | return position; |
| 512 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 513 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 514 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 515 | public View getView(int position, View convertView, ViewGroup parent) { |
| 516 | // Make sure we have a valid convertView to start with |
| 517 | if (convertView == null) { |
| 518 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 519 | } |
| 520 | |
| 521 | // Fill action with icon and text. |
| 522 | ViewEntry entry = mActions.get(position); |
| 523 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 524 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 525 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 526 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 527 | |
| 528 | icon.setImageResource(entry.icon); |
| 529 | text.setText(entry.text); |
| 530 | |
| 531 | View line2 = convertView.findViewById(R.id.line2); |
| 532 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 533 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 534 | if (labelEmpty && numberEmpty) { |
| 535 | line2.setVisibility(View.GONE); |
| 536 | } else { |
| 537 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 538 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 539 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 540 | if (labelEmpty) { |
| 541 | label.setVisibility(View.GONE); |
| 542 | } else { |
| 543 | label.setText(entry.label); |
| 544 | label.setVisibility(View.VISIBLE); |
| 545 | } |
| 546 | |
| 547 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 548 | number.setText(entry.number); |
| 549 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 550 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 551 | return convertView; |
| 552 | } |
| 553 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 554 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 555 | @Override |
| 556 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 557 | // Handle passing action off to correct handler. |
| 558 | if (view.getTag() instanceof ViewEntry) { |
| 559 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 560 | if (entry.intent != null) { |
| 561 | startActivity(entry.intent); |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 562 | } else if (entry.action != null) { |
| 563 | entry.action.onClick(view); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 564 | } |
| 565 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 566 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 567 | |
| 568 | @Override |
| 569 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 570 | boolean globalSearch) { |
| 571 | if (globalSearch) { |
| 572 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 573 | } else { |
| 574 | ContactsSearchManager.startSearch(this, initialQuery); |
| 575 | } |
| 576 | } |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 577 | |
| 578 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 579 | if (statusCursor == null) { |
| 580 | mStatusMessageView.setVisibility(View.GONE); |
| 581 | return; |
| 582 | } |
| 583 | final StatusMessage message = getStatusMessage(statusCursor); |
| 584 | if (message == null || !message.showInCallDetails()) { |
| 585 | mStatusMessageView.setVisibility(View.GONE); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 590 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 591 | if (message.actionMessageId != -1) { |
| 592 | mStatusMessageAction.setText(message.actionMessageId); |
| 593 | } |
| 594 | if (message.actionUri != null) { |
| 595 | mStatusMessageAction.setClickable(true); |
| 596 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 597 | @Override |
| 598 | public void onClick(View v) { |
| 599 | startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri)); |
| 600 | } |
| 601 | }); |
| 602 | } else { |
| 603 | mStatusMessageAction.setClickable(false); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 608 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 609 | Log.d(TAG, "Num status messages: " + messages.size()); |
| 610 | if (messages.size() == 0) { |
| 611 | return null; |
| 612 | } |
| 613 | // There can only be a single status message per source package, so num of messages can |
| 614 | // at most be 1. |
| 615 | if (messages.size() > 1) { |
| 616 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 617 | " Will use the first one.", messages.size())); |
| 618 | } |
| 619 | return messages.get(0); |
| 620 | } |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 621 | |
| 622 | @Override |
| 623 | public boolean onCreateOptionsMenu(Menu menu) { |
| 624 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 625 | return true; |
| 626 | } |
| 627 | |
| 628 | @Override |
| 629 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 630 | // This action deletes all elements in the group from the call log. |
| 631 | // We don't have this action for voicemails, because you can just use the trash button. |
| 632 | menu.findItem(R.id.remove_from_call_log).setVisible(mHasRemoveFromCallLog); |
| 633 | menu.findItem(R.id.edit_number_before_call).setVisible(mHasEditNumberBeforeCall); |
| 634 | return mHasRemoveFromCallLog || mHasEditNumberBeforeCall; |
| 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
| 639 | switch (item.getItemId()) { |
| 640 | case R.id.remove_from_call_log: { |
| 641 | StringBuilder callIds = new StringBuilder(); |
| 642 | for (Uri callUri : getCallLogEntryUris()) { |
| 643 | if (callIds.length() != 0) { |
| 644 | callIds.append(","); |
| 645 | } |
| 646 | callIds.append(ContentUris.parseId(callUri)); |
| 647 | } |
| 648 | |
| 649 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 650 | Calls._ID + " IN (" + callIds + ")", null); |
| 651 | // Also close the activity. |
| 652 | finish(); |
| 653 | return true; |
| 654 | } |
| 655 | |
| 656 | case R.id.edit_number_before_call: |
| 657 | startActivity( |
| 658 | new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber))); |
| 659 | return true; |
| 660 | |
| 661 | default: |
| 662 | throw new IllegalArgumentException(); |
| 663 | } |
| 664 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 665 | } |