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