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