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