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 | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame^] | 22 | import com.android.contacts.voicemail.VoicemailPlaybackFragment; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 23 | |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame^] | 24 | import android.app.FragmentManager; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 25 | import android.app.ListActivity; |
| 26 | import android.content.ContentResolver; |
| 27 | import android.content.ContentUris; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
| 30 | import android.content.res.Resources; |
| 31 | import android.database.Cursor; |
| 32 | import android.net.Uri; |
| 33 | import android.os.Bundle; |
| 34 | import android.provider.CallLog; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 35 | import android.provider.CallLog.Calls; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 36 | import android.provider.Contacts.Intents.Insert; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 37 | import android.provider.ContactsContract.Contacts; |
| 38 | import android.provider.ContactsContract.PhoneLookup; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 39 | import android.telephony.PhoneNumberUtils; |
| 40 | import android.telephony.TelephonyManager; |
| 41 | import android.text.TextUtils; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 42 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 43 | import android.view.KeyEvent; |
| 44 | import android.view.LayoutInflater; |
| 45 | import android.view.View; |
| 46 | import android.view.ViewGroup; |
| 47 | import android.widget.AdapterView; |
| 48 | import android.widget.BaseAdapter; |
| 49 | import android.widget.ImageView; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 50 | import android.widget.ListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 51 | import android.widget.TextView; |
| 52 | import android.widget.Toast; |
| 53 | |
| 54 | import java.util.ArrayList; |
| 55 | import java.util.List; |
| 56 | |
| 57 | /** |
| 58 | * Displays the details of a specific call log entry. |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 59 | * <p> |
| 60 | * This activity can be either started with the URI of a single call log entry, or with the |
| 61 | * {@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] | 62 | */ |
| 63 | public class CallDetailActivity extends ListActivity implements |
| 64 | AdapterView.OnItemClickListener { |
| 65 | private static final String TAG = "CallDetail"; |
| 66 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 67 | /** A long array extra containing ids of call log entries to display. */ |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame^] | 68 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 69 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 70 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 71 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 72 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 73 | |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 74 | /** The views representing the details of a phone call. */ |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 75 | private PhoneCallDetailsViews mPhoneCallDetailsViews; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 76 | private CallTypeHelper mCallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 77 | private PhoneNumberHelper mPhoneNumberHelper; |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 78 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 79 | private View mHomeActionView; |
| 80 | private ImageView mMainActionView; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 81 | private ImageView mContactBackgroundView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 82 | |
| 83 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 84 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 85 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 86 | /* package */ LayoutInflater mInflater; |
| 87 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 88 | /** Helper to load contact photos. */ |
| 89 | private ContactPhotoManager mContactPhotoManager; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 90 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 91 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 92 | CallLog.Calls.DATE, |
| 93 | CallLog.Calls.DURATION, |
| 94 | CallLog.Calls.NUMBER, |
| 95 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 96 | CallLog.Calls.COUNTRY_ISO, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 97 | }; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 99 | static final int DATE_COLUMN_INDEX = 0; |
| 100 | static final int DURATION_COLUMN_INDEX = 1; |
| 101 | static final int NUMBER_COLUMN_INDEX = 2; |
| 102 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 103 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 104 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 105 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 106 | PhoneLookup._ID, |
| 107 | PhoneLookup.DISPLAY_NAME, |
| 108 | PhoneLookup.TYPE, |
| 109 | PhoneLookup.LABEL, |
| 110 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 111 | PhoneLookup.NORMALIZED_NUMBER, |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 112 | PhoneLookup.PHOTO_ID, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 113 | }; |
| 114 | static final int COLUMN_INDEX_ID = 0; |
| 115 | static final int COLUMN_INDEX_NAME = 1; |
| 116 | static final int COLUMN_INDEX_TYPE = 2; |
| 117 | static final int COLUMN_INDEX_LABEL = 3; |
| 118 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 119 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 120 | static final int COLUMN_INDEX_PHOTO_ID = 6; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 121 | |
| 122 | @Override |
| 123 | protected void onCreate(Bundle icicle) { |
| 124 | super.onCreate(icicle); |
| 125 | |
| 126 | setContentView(R.layout.call_detail); |
| 127 | |
| 128 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 129 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 130 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 131 | mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView()); |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 132 | mCallTypeHelper = new CallTypeHelper(getResources(), |
Flavio Lerda | 693d1f8 | 2011-07-13 18:20:46 +0100 | [diff] [blame] | 133 | getResources().getDrawable(R.drawable.ic_call_incoming_holo_dark), |
| 134 | getResources().getDrawable(R.drawable.ic_call_outgoing_holo_dark), |
| 135 | getResources().getDrawable(R.drawable.ic_call_missed_holo_dark), |
| 136 | getResources().getDrawable(R.drawable.ic_call_voicemail_holo_dark)); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 137 | mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber()); |
| 138 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, mResources, mCallTypeHelper, |
| 139 | mPhoneNumberHelper); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 140 | mHomeActionView = findViewById(R.id.action_bar_home); |
| 141 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 142 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 143 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 144 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 145 | getListView().setOnItemClickListener(this); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 146 | mHomeActionView.setOnClickListener(new View.OnClickListener() { |
| 147 | @Override |
| 148 | public void onClick(View v) { |
| 149 | // We want this to start the call log if this activity was not started from the |
| 150 | // call log itself. |
| 151 | CallDetailActivity.this.finish(); |
| 152 | } |
| 153 | }); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 154 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 155 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 156 | @Override |
| 157 | public void onResume() { |
| 158 | super.onResume(); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 159 | updateData(getCallLogEntryUris()); |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame^] | 160 | optionallyHandleVoicemail(); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Handle voicemail playback or hide voicemail ui. |
| 165 | * <p> |
| 166 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
| 167 | * playback. If it doesn't, then hide the voicemail ui. |
| 168 | */ |
| 169 | private void optionallyHandleVoicemail() { |
| 170 | FragmentManager manager = getFragmentManager(); |
| 171 | VoicemailPlaybackFragment fragment = (VoicemailPlaybackFragment) manager.findFragmentById( |
| 172 | R.id.voicemail_playback_fragment); |
| 173 | Uri voicemailUri = getIntent().getExtras().getParcelable(EXTRA_VOICEMAIL_URI); |
| 174 | if (voicemailUri == null) { |
| 175 | // No voicemail uri: hide the voicemail fragment. |
| 176 | manager.beginTransaction().hide(fragment).commit(); |
| 177 | } else { |
| 178 | // A voicemail: extra tells us if we should start playback or not. |
| 179 | boolean startPlayback = getIntent().getExtras().getBoolean( |
| 180 | EXTRA_VOICEMAIL_START_PLAYBACK, false); |
| 181 | fragment.setVoicemailUri(voicemailUri, startPlayback); |
| 182 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Returns the list of URIs to show. |
| 187 | * <p> |
| 188 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 189 | * a list of ids in the call log added as an extra on the URI. |
| 190 | * <p> |
| 191 | * If both are available, the data on the intent takes precedence. |
| 192 | */ |
| 193 | private Uri[] getCallLogEntryUris() { |
| 194 | Uri uri = getIntent().getData(); |
| 195 | if (uri != null) { |
| 196 | // If there is a data on the intent, it takes precedence over the extra. |
| 197 | return new Uri[]{ uri }; |
| 198 | } |
| 199 | long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 200 | Uri[] uris = new Uri[ids.length]; |
| 201 | for (int index = 0; index < ids.length; ++index) { |
| 202 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 203 | } |
| 204 | return uris; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | @Override |
| 208 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 209 | switch (keyCode) { |
| 210 | case KeyEvent.KEYCODE_CALL: { |
| 211 | // Make sure phone isn't already busy before starting direct call |
| 212 | TelephonyManager tm = (TelephonyManager) |
| 213 | getSystemService(Context.TELEPHONY_SERVICE); |
| 214 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 215 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 216 | Uri.fromParts("tel", mNumber, null)); |
| 217 | startActivity(callIntent); |
| 218 | return true; |
| 219 | } |
| 220 | } |
| 221 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 222 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 223 | return super.onKeyDown(keyCode, event); |
| 224 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 225 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 226 | /** |
| 227 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 228 | * |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 229 | * @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] | 230 | */ |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 231 | private void updateData(final Uri... callUris) { |
| 232 | // TODO: All phone calls correspond to the same person, so we can make a single lookup. |
| 233 | final int numCalls = callUris.length; |
| 234 | final PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 235 | try { |
| 236 | for (int index = 0; index < numCalls; ++index) { |
| 237 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 238 | } |
| 239 | } catch (IllegalArgumentException e) { |
| 240 | // Something went wrong reading in our primary data, so we're going to |
| 241 | // bail out and show error to users. |
| 242 | Log.w(TAG, "invalid URI starting call details", e); |
| 243 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 244 | Toast.LENGTH_SHORT).show(); |
| 245 | finish(); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | // We know that all calls are from the same number and the same contact, so pick the first. |
| 250 | mNumber = details[0].number.toString(); |
| 251 | final long personId = details[0].personId; |
| 252 | final long photoId = details[0].photoId; |
| 253 | |
| 254 | // Set the details header, based on the first phone call. |
| 255 | mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, |
Flavio Lerda | 7692190 | 2011-07-13 21:11:51 +0100 | [diff] [blame] | 256 | details[0], false, false); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 257 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 258 | // Cache the details about the phone number. |
| 259 | final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber); |
| 260 | final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber); |
| 261 | final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber); |
| 262 | final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber); |
| 263 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 264 | // Let user view contact details if they exist, otherwise add option to create new contact |
| 265 | // from this number. |
| 266 | final Intent mainActionIntent; |
| 267 | final int mainActionIcon; |
| 268 | |
| 269 | if (details[0].personId != -1) { |
| 270 | Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId); |
| 271 | mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 272 | mainActionIcon = R.drawable.sym_action_view_contact; |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 273 | } else if (isVoicemailNumber) { |
| 274 | mainActionIntent = null; |
| 275 | mainActionIcon = 0; |
| 276 | } else if (isSipNumber) { |
| 277 | // TODO: This item is currently disabled for SIP addresses, because |
| 278 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 279 | // |
| 280 | // To fix this for SIP addresses, we need to: |
| 281 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 282 | // the current number is a SIP address |
| 283 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 284 | // updating the SipAddress field |
| 285 | // and then we can remove the "!isSipNumber" check above. |
| 286 | mainActionIntent = null; |
| 287 | mainActionIcon = 0; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 288 | } else { |
| 289 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 290 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 291 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 292 | mainActionIcon = R.drawable.sym_action_add; |
| 293 | } |
| 294 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 295 | if (mainActionIntent == null) { |
| 296 | mMainActionView.setVisibility(View.INVISIBLE); |
| 297 | } else { |
| 298 | mMainActionView.setVisibility(View.VISIBLE); |
| 299 | mMainActionView.setImageResource(mainActionIcon); |
| 300 | mMainActionView.setOnClickListener(new View.OnClickListener() { |
| 301 | @Override |
| 302 | public void onClick(View v) { |
| 303 | startActivity(mainActionIntent); |
| 304 | } |
| 305 | }); |
| 306 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 307 | |
| 308 | // Build list of various available actions. |
| 309 | final List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
| 310 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 311 | // This action allows to call the number that places the call. |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 312 | if (canPlaceCallsTo) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 313 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 314 | getString(R.string.menu_callNumber, mNumber), |
| 315 | new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri))); |
| 316 | } |
| 317 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 318 | // This action allows to send an SMS to the number that placed the call. |
| 319 | if (mPhoneNumberHelper.canSendSmsTo(mNumber)) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 320 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 321 | Uri.fromParts("sms", mNumber, null)); |
| 322 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 323 | getString(R.string.menu_sendTextMessage), smsIntent)); |
| 324 | } |
| 325 | |
| 326 | // This action deletes all elements in the group from the call log. |
| 327 | actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel, |
| 328 | getString(R.string.recentCalls_removeFromRecentList), |
| 329 | new View.OnClickListener() { |
| 330 | @Override |
| 331 | public void onClick(View v) { |
| 332 | StringBuilder callIds = new StringBuilder(); |
| 333 | for (Uri callUri : callUris) { |
| 334 | if (callIds.length() != 0) { |
| 335 | callIds.append(","); |
| 336 | } |
| 337 | callIds.append(ContentUris.parseId(callUri)); |
| 338 | } |
| 339 | |
| 340 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 341 | Calls._ID + " IN (" + callIds + ")", null); |
| 342 | finish(); |
| 343 | } |
| 344 | })); |
| 345 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 346 | if (canPlaceCallsTo && !isSipNumber && !isVoicemailNumber) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 347 | // "Edit the number before calling" is only available for PSTN numbers. |
| 348 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 349 | getString(R.string.recentCalls_editNumberBeforeCall), |
| 350 | new Intent(Intent.ACTION_DIAL, numberCallUri))); |
| 351 | } |
| 352 | |
| 353 | // Set the actions for this phone number. |
| 354 | setListAdapter(new ViewAdapter(this, actions)); |
| 355 | |
| 356 | ListView historyList = (ListView) findViewById(R.id.history); |
| 357 | historyList.setAdapter( |
| 358 | new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details)); |
| 359 | loadContactPhotos(photoId); |
| 360 | } |
| 361 | |
| 362 | /** Return the phone call details for a given call log URI. */ |
| 363 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 364 | ContentResolver resolver = getContentResolver(); |
| 365 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 366 | try { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 367 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 368 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 369 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 370 | |
| 371 | // Read call log specifics. |
| 372 | String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 373 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 374 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 375 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
| 376 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 377 | if (TextUtils.isEmpty(countryIso)) { |
| 378 | countryIso = mDefaultCountryIso; |
| 379 | } |
| 380 | |
| 381 | // Formatted phone number. |
| 382 | final CharSequence numberText; |
| 383 | // Read contact specifics. |
| 384 | CharSequence nameText = ""; |
| 385 | int numberType = 0; |
| 386 | CharSequence numberLabel = ""; |
| 387 | long personId = -1L; |
| 388 | long photoId = 0L; |
| 389 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 390 | if (!mPhoneNumberHelper.canPlaceCallsTo(number)) { |
| 391 | numberText = mPhoneNumberHelper.getDisplayNumber(number, null); |
| 392 | } else { |
| 393 | // Perform a reverse-phonebook lookup to find the contact details. |
| 394 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 395 | Uri.encode(number)); |
| 396 | Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null); |
| 397 | String candidateNumberText = number; |
| 398 | try { |
| 399 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 400 | personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 401 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
| 402 | photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID); |
| 403 | candidateNumberText = PhoneNumberUtils.formatNumber( |
| 404 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 405 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 406 | countryIso); |
| 407 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 408 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
| 409 | } else { |
| 410 | // We could not find this contact in the contacts, just format the phone |
| 411 | // number as best as we can. All the other fields will have their default |
| 412 | // values. |
| 413 | candidateNumberText = |
| 414 | PhoneNumberUtils.formatNumber(number, countryIso); |
| 415 | } |
| 416 | } finally { |
| 417 | if (phonesCursor != null) phonesCursor.close(); |
| 418 | numberText = candidateNumberText; |
| 419 | } |
| 420 | } |
| 421 | return new PhoneCallDetails(number, numberText, new int[]{ callType }, date, duration, |
| 422 | nameText, numberType, numberLabel, personId, photoId); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 423 | } finally { |
| 424 | if (callCursor != null) { |
| 425 | callCursor.close(); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 430 | /** Load the contact photos and places them in the corresponding views. */ |
| 431 | private void loadContactPhotos(final long photoId) { |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 432 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 433 | } |
| 434 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 435 | private String getVoicemailNumber() { |
| 436 | TelephonyManager telephonyManager = |
| 437 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 438 | return telephonyManager.getVoiceMailNumber(); |
| 439 | } |
| 440 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 441 | static final class ViewEntry { |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 442 | public final int icon; |
| 443 | public final String text; |
| 444 | public final Intent intent; |
| 445 | public final View.OnClickListener action; |
| 446 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 447 | public String label = null; |
| 448 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 449 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 450 | public ViewEntry(int icon, String text, Intent intent) { |
| 451 | this.icon = icon; |
| 452 | this.text = text; |
| 453 | this.intent = intent; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 454 | this.action = null; |
| 455 | } |
| 456 | |
| 457 | public ViewEntry(int icon, String text, View.OnClickListener listener) { |
| 458 | this.icon = icon; |
| 459 | this.text = text; |
| 460 | this.intent = null; |
| 461 | this.action = listener; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 466 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 467 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 468 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 469 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 470 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 471 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 472 | mActions = actions; |
| 473 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 474 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 475 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 476 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 477 | public int getCount() { |
| 478 | return mActions.size(); |
| 479 | } |
| 480 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 481 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 482 | public Object getItem(int position) { |
| 483 | return mActions.get(position); |
| 484 | } |
| 485 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 486 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 487 | public long getItemId(int position) { |
| 488 | return position; |
| 489 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 490 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 491 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 492 | public View getView(int position, View convertView, ViewGroup parent) { |
| 493 | // Make sure we have a valid convertView to start with |
| 494 | if (convertView == null) { |
| 495 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 496 | } |
| 497 | |
| 498 | // Fill action with icon and text. |
| 499 | ViewEntry entry = mActions.get(position); |
| 500 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 501 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 502 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 503 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 504 | |
| 505 | icon.setImageResource(entry.icon); |
| 506 | text.setText(entry.text); |
| 507 | |
| 508 | View line2 = convertView.findViewById(R.id.line2); |
| 509 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 510 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 511 | if (labelEmpty && numberEmpty) { |
| 512 | line2.setVisibility(View.GONE); |
| 513 | } else { |
| 514 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 515 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 516 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 517 | if (labelEmpty) { |
| 518 | label.setVisibility(View.GONE); |
| 519 | } else { |
| 520 | label.setText(entry.label); |
| 521 | label.setVisibility(View.VISIBLE); |
| 522 | } |
| 523 | |
| 524 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 525 | number.setText(entry.number); |
| 526 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 527 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 528 | return convertView; |
| 529 | } |
| 530 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 531 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 532 | @Override |
| 533 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 534 | // Handle passing action off to correct handler. |
| 535 | if (view.getTag() instanceof ViewEntry) { |
| 536 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 537 | if (entry.intent != null) { |
| 538 | startActivity(entry.intent); |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 539 | } else if (entry.action != null) { |
| 540 | entry.action.onClick(view); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 541 | } |
| 542 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 543 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 544 | |
| 545 | @Override |
| 546 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 547 | boolean globalSearch) { |
| 548 | if (globalSearch) { |
| 549 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 550 | } else { |
| 551 | ContactsSearchManager.startSearch(this, initialQuery); |
| 552 | } |
| 553 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 554 | } |