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