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