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