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; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 44 | import android.provider.ContactsContract.Contacts; |
| 45 | import android.provider.ContactsContract.PhoneLookup; |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 46 | import android.provider.VoicemailContract.Voicemails; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 47 | import android.telephony.PhoneNumberUtils; |
| 48 | import android.telephony.TelephonyManager; |
| 49 | import android.text.TextUtils; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 50 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 51 | import android.view.KeyEvent; |
| 52 | import android.view.LayoutInflater; |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 53 | import android.view.Menu; |
| 54 | import android.view.MenuItem; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 55 | import android.view.View; |
| 56 | import android.view.ViewGroup; |
| 57 | import android.widget.AdapterView; |
| 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 | */ |
| 74 | public class CallDetailActivity extends ListActivity implements |
| 75 | AdapterView.OnItemClickListener { |
| 76 | private static final String TAG = "CallDetail"; |
| 77 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 78 | /** A long array extra containing ids of call log entries to display. */ |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 79 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 80 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 81 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 82 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 83 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 84 | |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 85 | private CallTypeHelper mCallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 86 | private PhoneNumberHelper mPhoneNumberHelper; |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 87 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
Flavio Lerda | b88abaa | 2011-08-02 23:38:36 +0100 | [diff] [blame] | 88 | private TextView mHeaderTextView; |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 89 | private ImageView mMainActionView; |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 90 | private ImageButton mMainActionPushLayerView; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 91 | private ImageView mContactBackgroundView; |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 92 | private BackgroundTaskService mBackgroundTaskService; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 93 | |
| 94 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 95 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 96 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 97 | /* package */ LayoutInflater mInflater; |
| 98 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 99 | /** Helper to load contact photos. */ |
| 100 | private ContactPhotoManager mContactPhotoManager; |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 101 | /** Helper to make async queries to content resolver. */ |
| 102 | private CallDetailActivityQueryHandler mAsyncQueryHandler; |
| 103 | /** Helper to get voicemail status messages. */ |
| 104 | private VoicemailStatusHelper mVoicemailStatusHelper; |
| 105 | // Views related to voicemail status message. |
| 106 | private View mStatusMessageView; |
| 107 | private TextView mStatusMessageText; |
| 108 | private TextView mStatusMessageAction; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 109 | |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 110 | /** Whether we should show "edit number before call" in the options menu. */ |
| 111 | private boolean mHasEditNumberBeforeCall; |
| 112 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 113 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 114 | CallLog.Calls.DATE, |
| 115 | CallLog.Calls.DURATION, |
| 116 | CallLog.Calls.NUMBER, |
| 117 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 118 | CallLog.Calls.COUNTRY_ISO, |
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; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 126 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 127 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 128 | PhoneLookup._ID, |
| 129 | PhoneLookup.DISPLAY_NAME, |
| 130 | PhoneLookup.TYPE, |
| 131 | PhoneLookup.LABEL, |
| 132 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 133 | PhoneLookup.NORMALIZED_NUMBER, |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 134 | PhoneLookup.PHOTO_URI, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 135 | }; |
| 136 | static final int COLUMN_INDEX_ID = 0; |
| 137 | static final int COLUMN_INDEX_NAME = 1; |
| 138 | static final int COLUMN_INDEX_TYPE = 2; |
| 139 | static final int COLUMN_INDEX_LABEL = 3; |
| 140 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 141 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 142 | static final int COLUMN_INDEX_PHOTO_URI = 6; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 143 | |
| 144 | @Override |
| 145 | protected void onCreate(Bundle icicle) { |
| 146 | super.onCreate(icicle); |
| 147 | |
| 148 | setContentView(R.layout.call_detail); |
| 149 | |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 150 | mBackgroundTaskService = (BackgroundTaskService) getApplicationContext().getSystemService( |
| 151 | BackgroundTaskService.BACKGROUND_TASK_SERVICE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 152 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 153 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 154 | |
Daniel Lehmann | 6ecb732 | 2011-08-01 21:39:29 -0700 | [diff] [blame] | 155 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 156 | mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber()); |
Flavio Lerda | 4056956 | 2011-07-22 21:51:29 +0100 | [diff] [blame] | 157 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper, |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 158 | mPhoneNumberHelper); |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 159 | mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); |
| 160 | mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); |
Flavio Lerda | b88abaa | 2011-08-02 23:38:36 +0100 | [diff] [blame] | 161 | mHeaderTextView = (TextView) findViewById(R.id.header_text); |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 162 | mStatusMessageView = findViewById(R.id.voicemail_status); |
| 163 | mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message); |
| 164 | mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 165 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 166 | mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 167 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 168 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 169 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 170 | getListView().setOnItemClickListener(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) { |
| 275 | // TODO: All phone calls correspond to the same person, so we can make a single lookup. |
| 276 | final int numCalls = callUris.length; |
| 277 | final PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 278 | try { |
| 279 | for (int index = 0; index < numCalls; ++index) { |
| 280 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 281 | } |
| 282 | } catch (IllegalArgumentException e) { |
| 283 | // Something went wrong reading in our primary data, so we're going to |
| 284 | // bail out and show error to users. |
| 285 | Log.w(TAG, "invalid URI starting call details", e); |
| 286 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 287 | Toast.LENGTH_SHORT).show(); |
| 288 | finish(); |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | // We know that all calls are from the same number and the same contact, so pick the first. |
| 293 | mNumber = details[0].number.toString(); |
| 294 | final long personId = details[0].personId; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 295 | final Uri photoUri = details[0].photoUri; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 296 | |
| 297 | // Set the details header, based on the first phone call. |
Flavio Lerda | b88abaa | 2011-08-02 23:38:36 +0100 | [diff] [blame] | 298 | mPhoneCallDetailsHelper.setPhoneCallName(mHeaderTextView, details[0]); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 299 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 300 | // Cache the details about the phone number. |
| 301 | final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber); |
| 302 | final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber); |
| 303 | final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber); |
| 304 | final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber); |
| 305 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 306 | // Let user view contact details if they exist, otherwise add option to create new contact |
| 307 | // from this number. |
| 308 | final Intent mainActionIntent; |
| 309 | final int mainActionIcon; |
| 310 | |
| 311 | if (details[0].personId != -1) { |
| 312 | Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId); |
| 313 | mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri); |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 314 | mainActionIcon = R.drawable.ic_contacts_holo_dark; |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 315 | } else if (isVoicemailNumber) { |
| 316 | mainActionIntent = null; |
| 317 | mainActionIcon = 0; |
| 318 | } else if (isSipNumber) { |
| 319 | // TODO: This item is currently disabled for SIP addresses, because |
| 320 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 321 | // |
| 322 | // To fix this for SIP addresses, we need to: |
| 323 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 324 | // the current number is a SIP address |
| 325 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 326 | // updating the SipAddress field |
| 327 | // and then we can remove the "!isSipNumber" check above. |
| 328 | mainActionIntent = null; |
| 329 | mainActionIcon = 0; |
Flavio Lerda | 8e40340 | 2011-07-20 16:25:49 +0100 | [diff] [blame] | 330 | } else if (canPlaceCallsTo) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 331 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 332 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 333 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 334 | mainActionIcon = R.drawable.ic_add_contact_holo_dark; |
Flavio Lerda | 8e40340 | 2011-07-20 16:25:49 +0100 | [diff] [blame] | 335 | } else { |
| 336 | // If we cannot call the number, when we probably cannot add it as a contact either. |
| 337 | // This is usually the case of private, unknown, or payphone numbers. |
| 338 | mainActionIntent = null; |
| 339 | mainActionIcon = 0; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 342 | if (mainActionIntent == null) { |
| 343 | mMainActionView.setVisibility(View.INVISIBLE); |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 344 | mMainActionPushLayerView.setVisibility(View.GONE); |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 345 | } else { |
| 346 | mMainActionView.setVisibility(View.VISIBLE); |
| 347 | mMainActionView.setImageResource(mainActionIcon); |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 348 | mMainActionPushLayerView.setVisibility(View.VISIBLE); |
| 349 | mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() { |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 350 | @Override |
| 351 | public void onClick(View v) { |
| 352 | startActivity(mainActionIntent); |
| 353 | } |
| 354 | }); |
| 355 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 356 | |
| 357 | // Build list of various available actions. |
| 358 | final List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
| 359 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 360 | // This action allows to call the number that places the call. |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 361 | if (canPlaceCallsTo) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 362 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 363 | getString(R.string.menu_callNumber, mNumber), |
| 364 | new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri))); |
| 365 | } |
| 366 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 367 | // This action allows to send an SMS to the number that placed the call. |
| 368 | if (mPhoneNumberHelper.canSendSmsTo(mNumber)) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 369 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 370 | Uri.fromParts("sms", mNumber, null)); |
| 371 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 372 | getString(R.string.menu_sendTextMessage), smsIntent)); |
| 373 | } |
| 374 | |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 375 | mHasEditNumberBeforeCall = canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 376 | |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 377 | if (actions.size() != 0) { |
| 378 | // Set the actions for this phone number. |
| 379 | setListAdapter(new ViewAdapter(this, actions)); |
| 380 | getListView().setVisibility(View.VISIBLE); |
| 381 | } else { |
| 382 | getListView().setVisibility(View.GONE); |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 383 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 384 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 385 | ListView historyList = (ListView) findViewById(R.id.history); |
| 386 | historyList.setAdapter( |
| 387 | new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details)); |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 388 | loadContactPhotos(photoUri); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** Return the phone call details for a given call log URI. */ |
| 392 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 393 | ContentResolver resolver = getContentResolver(); |
| 394 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 395 | try { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 396 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 397 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 398 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 399 | |
| 400 | // Read call log specifics. |
| 401 | String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 402 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 403 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 404 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
| 405 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 406 | if (TextUtils.isEmpty(countryIso)) { |
| 407 | countryIso = mDefaultCountryIso; |
| 408 | } |
| 409 | |
| 410 | // Formatted phone number. |
| 411 | final CharSequence numberText; |
| 412 | // Read contact specifics. |
| 413 | CharSequence nameText = ""; |
| 414 | int numberType = 0; |
| 415 | CharSequence numberLabel = ""; |
| 416 | long personId = -1L; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 417 | Uri photoUri = null; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 418 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 419 | if (!mPhoneNumberHelper.canPlaceCallsTo(number)) { |
| 420 | numberText = mPhoneNumberHelper.getDisplayNumber(number, null); |
| 421 | } else { |
| 422 | // Perform a reverse-phonebook lookup to find the contact details. |
| 423 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 424 | Uri.encode(number)); |
| 425 | Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null); |
| 426 | String candidateNumberText = number; |
| 427 | try { |
| 428 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 429 | personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 430 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 431 | String photoUriString = phonesCursor.getString(COLUMN_INDEX_PHOTO_URI); |
| 432 | photoUri = photoUriString == null ? null : Uri.parse(photoUriString); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 433 | candidateNumberText = PhoneNumberUtils.formatNumber( |
| 434 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 435 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 436 | countryIso); |
| 437 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 438 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
| 439 | } else { |
| 440 | // We could not find this contact in the contacts, just format the phone |
| 441 | // number as best as we can. All the other fields will have their default |
| 442 | // values. |
| 443 | candidateNumberText = |
| 444 | PhoneNumberUtils.formatNumber(number, countryIso); |
| 445 | } |
| 446 | } finally { |
| 447 | if (phonesCursor != null) phonesCursor.close(); |
| 448 | numberText = candidateNumberText; |
| 449 | } |
| 450 | } |
Flavio Lerda | 9c46637 | 2011-07-19 17:38:17 +0100 | [diff] [blame] | 451 | return new PhoneCallDetails(number, numberText, countryIso, |
Flavio Lerda | cb805e8 | 2011-07-18 10:31:44 +0100 | [diff] [blame] | 452 | new int[]{ callType }, date, duration, |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 453 | nameText, numberType, numberLabel, personId, photoUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 454 | } finally { |
| 455 | if (callCursor != null) { |
| 456 | callCursor.close(); |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 461 | /** Load the contact photos and places them in the corresponding views. */ |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 462 | private void loadContactPhotos(Uri photoUri) { |
| 463 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 466 | private String getVoicemailNumber() { |
| 467 | TelephonyManager telephonyManager = |
| 468 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 469 | return telephonyManager.getVoiceMailNumber(); |
| 470 | } |
| 471 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 472 | static final class ViewEntry { |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 473 | public final int icon; |
| 474 | public final String text; |
| 475 | public final Intent intent; |
| 476 | public final View.OnClickListener action; |
| 477 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 478 | public String label = null; |
| 479 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 480 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 481 | public ViewEntry(int icon, String text, Intent intent) { |
| 482 | this.icon = icon; |
| 483 | this.text = text; |
| 484 | this.intent = intent; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 485 | this.action = null; |
| 486 | } |
| 487 | |
| 488 | public ViewEntry(int icon, String text, View.OnClickListener listener) { |
| 489 | this.icon = icon; |
| 490 | this.text = text; |
| 491 | this.intent = null; |
| 492 | this.action = listener; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 497 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 498 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 499 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 500 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 501 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 502 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 503 | mActions = actions; |
| 504 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 505 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 506 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 507 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 508 | public int getCount() { |
| 509 | return mActions.size(); |
| 510 | } |
| 511 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 512 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 513 | public Object getItem(int position) { |
| 514 | return mActions.get(position); |
| 515 | } |
| 516 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 517 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 518 | public long getItemId(int position) { |
| 519 | return position; |
| 520 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 521 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 522 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 523 | public View getView(int position, View convertView, ViewGroup parent) { |
| 524 | // Make sure we have a valid convertView to start with |
| 525 | if (convertView == null) { |
| 526 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 527 | } |
| 528 | |
| 529 | // Fill action with icon and text. |
| 530 | ViewEntry entry = mActions.get(position); |
| 531 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 532 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 533 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 534 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 535 | |
| 536 | icon.setImageResource(entry.icon); |
| 537 | text.setText(entry.text); |
| 538 | |
| 539 | View line2 = convertView.findViewById(R.id.line2); |
| 540 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 541 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 542 | if (labelEmpty && numberEmpty) { |
| 543 | line2.setVisibility(View.GONE); |
| 544 | } else { |
| 545 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 546 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 547 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 548 | if (labelEmpty) { |
| 549 | label.setVisibility(View.GONE); |
| 550 | } else { |
| 551 | label.setText(entry.label); |
| 552 | label.setVisibility(View.VISIBLE); |
| 553 | } |
| 554 | |
| 555 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 556 | number.setText(entry.number); |
| 557 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 558 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 559 | return convertView; |
| 560 | } |
| 561 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 562 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 563 | @Override |
| 564 | 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] | 565 | // Handle passing action off to correct handler. |
| 566 | if (view.getTag() instanceof ViewEntry) { |
| 567 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 568 | if (entry.intent != null) { |
| 569 | startActivity(entry.intent); |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 570 | } else if (entry.action != null) { |
| 571 | entry.action.onClick(view); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 572 | } |
| 573 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 574 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 575 | |
| 576 | @Override |
| 577 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 578 | boolean globalSearch) { |
| 579 | if (globalSearch) { |
| 580 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 581 | } else { |
| 582 | ContactsSearchManager.startSearch(this, initialQuery); |
| 583 | } |
| 584 | } |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 585 | |
| 586 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 587 | if (statusCursor == null) { |
| 588 | mStatusMessageView.setVisibility(View.GONE); |
| 589 | return; |
| 590 | } |
| 591 | final StatusMessage message = getStatusMessage(statusCursor); |
| 592 | if (message == null || !message.showInCallDetails()) { |
| 593 | mStatusMessageView.setVisibility(View.GONE); |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 598 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 599 | if (message.actionMessageId != -1) { |
| 600 | mStatusMessageAction.setText(message.actionMessageId); |
| 601 | } |
| 602 | if (message.actionUri != null) { |
| 603 | mStatusMessageAction.setClickable(true); |
| 604 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 605 | @Override |
| 606 | public void onClick(View v) { |
| 607 | startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri)); |
| 608 | } |
| 609 | }); |
| 610 | } else { |
| 611 | mStatusMessageAction.setClickable(false); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 616 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 617 | Log.d(TAG, "Num status messages: " + messages.size()); |
| 618 | if (messages.size() == 0) { |
| 619 | return null; |
| 620 | } |
| 621 | // There can only be a single status message per source package, so num of messages can |
| 622 | // at most be 1. |
| 623 | if (messages.size() > 1) { |
| 624 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 625 | " Will use the first one.", messages.size())); |
| 626 | } |
| 627 | return messages.get(0); |
| 628 | } |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 629 | |
| 630 | @Override |
| 631 | public boolean onCreateOptionsMenu(Menu menu) { |
| 632 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 633 | return super.onCreateOptionsMenu(menu); |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 638 | // This action deletes all elements in the group from the call log. |
| 639 | // 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] | 640 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(!hasVoicemail()); |
| 641 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCall); |
| 642 | menu.findItem(R.id.menu_trash).setVisible(hasVoicemail()); |
| 643 | menu.findItem(R.id.menu_share_voicemail).setVisible(hasVoicemail()); |
| 644 | return super.onPrepareOptionsMenu(menu); |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | @Override |
| 648 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
| 649 | switch (item.getItemId()) { |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 650 | case android.R.id.home: { |
| 651 | onHomeSelected(); |
| 652 | return true; |
| 653 | } |
| 654 | |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 655 | // All the options menu items are handled by onMenu... methods. |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 656 | default: |
| 657 | throw new IllegalArgumentException(); |
| 658 | } |
| 659 | } |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 660 | |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 661 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 662 | final StringBuilder callIds = new StringBuilder(); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 663 | for (Uri callUri : getCallLogEntryUris()) { |
| 664 | if (callIds.length() != 0) { |
| 665 | callIds.append(","); |
| 666 | } |
| 667 | callIds.append(ContentUris.parseId(callUri)); |
| 668 | } |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 669 | mBackgroundTaskService.submit(new BackgroundTask() { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 670 | @Override |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 671 | public void doInBackground() { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 672 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 673 | Calls._ID + " IN (" + callIds + ")", null); |
| 674 | } |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 675 | @Override |
| 676 | public void onPostExecute() { |
| 677 | finish(); |
| 678 | } |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 679 | }); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 680 | } |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 681 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
| 682 | startActivity(new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber))); |
| 683 | } |
| 684 | |
| 685 | public void onMenuShareVoicemail(MenuItem menuItem) { |
| 686 | Log.w(TAG, "onMenuShareVoicemail not yet implemented"); |
| 687 | } |
| 688 | |
| 689 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 690 | final Uri voicemailUri = getVoicemailUri(); |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 691 | mBackgroundTaskService.submit(new BackgroundTask() { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 692 | @Override |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 693 | public void doInBackground() { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 694 | getContentResolver().delete(voicemailUri, null, null); |
| 695 | } |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 696 | @Override |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 697 | public void onPostExecute() { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 698 | finish(); |
| 699 | } |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame^] | 700 | }); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 701 | } |
| 702 | |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 703 | private void configureActionBar() { |
| 704 | ActionBar actionBar = getActionBar(); |
| 705 | if (actionBar != null) { |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 706 | actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME); |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | /** Invoked when the user presses the home button in the action bar. */ |
| 711 | private void onHomeSelected() { |
| 712 | Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI); |
| 713 | // This will open the call log even if the detail view has been opened directly. |
| 714 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 715 | startActivity(intent); |
| 716 | finish(); |
| 717 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 718 | } |