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