blob: 8d7561a08b10cac63e359c9db50769871dfb0932 [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
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
17package com.android.contacts;
18
Flavio Lerdad1333a22011-08-11 16:19:47 +010019import com.android.contacts.BackScrollManager.ScrollableHeader;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010020import com.android.contacts.calllog.CallDetailHistoryAdapter;
21import com.android.contacts.calllog.CallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010022import com.android.contacts.calllog.PhoneNumberHelper;
Hugo Hudson9c747ac2011-08-17 00:23:01 +010023import com.android.contacts.util.AsyncTaskExecutor;
24import com.android.contacts.util.AsyncTaskExecutors;
Hugo Hudsonb002f512011-07-15 17:41:12 +010025import com.android.contacts.voicemail.VoicemailPlaybackFragment;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +010026import com.android.contacts.voicemail.VoicemailStatusHelper;
27import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
28import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070029
Flavio Lerdad44e83a2011-07-24 23:10:17 +010030import android.app.ActionBar;
Flavio Lerdab184ed62011-08-10 18:17:55 +010031import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080032import android.content.ContentResolver;
33import android.content.ContentUris;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010034import android.content.ContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080035import android.content.Context;
36import android.content.Intent;
37import android.content.res.Resources;
38import android.database.Cursor;
39import android.net.Uri;
Hugo Hudsona2625e42011-08-10 21:13:23 +010040import android.os.AsyncTask;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080041import android.os.Bundle;
42import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010044import android.provider.Contacts.Intents.Insert;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +010045import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070046import android.provider.ContactsContract.Contacts;
47import android.provider.ContactsContract.PhoneLookup;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010048import android.provider.VoicemailContract.Voicemails;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080049import android.telephony.PhoneNumberUtils;
50import android.telephony.TelephonyManager;
51import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010052import android.util.Log;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080053import android.view.KeyEvent;
54import android.view.LayoutInflater;
Flavio Lerda94d7bab2011-07-22 16:52:34 +010055import android.view.Menu;
56import android.view.MenuItem;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080057import android.view.View;
Daniel Lehmannd260de42011-08-01 18:08:38 -070058import android.widget.ImageButton;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080059import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010060import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080061import android.widget.TextView;
62import android.widget.Toast;
63
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080064import java.util.List;
65
66/**
67 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010068 * <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 Project7aa0e4c2009-03-03 19:32:21 -080071 */
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010072public class CallDetailActivity extends Activity implements ProximitySensorAware {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080073 private static final String TAG = "CallDetail";
74
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010075 /** The time to wait before enabling the blank the screen due to the proximity sensor. */
76 private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100;
77 /** The time to wait before disabling the blank the screen due to the proximity sensor. */
78 private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500;
79
Hugo Hudson9c747ac2011-08-17 00:23:01 +010080 /** The enumeration of {@link AsyncTask} objects used in this class. */
81 public enum Tasks {
82 MARK_VOICEMAIL_READ,
83 DELETE_VOICEMAIL_AND_FINISH,
84 REMOVE_FROM_CALL_LOG_AND_FINISH,
85 UPDATE_PHONE_CALL_DETAILS,
86 }
87
Flavio Lerda178eeeb2011-07-11 19:51:40 +010088 /** A long array extra containing ids of call log entries to display. */
Hugo Hudsonb002f512011-07-15 17:41:12 +010089 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
90 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
91 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
92 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
93 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
Flavio Lerda178eeeb2011-07-11 19:51:40 +010094
Flavio Lerda9a208cc2011-07-12 21:05:47 +010095 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010096 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010097 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdab88abaa2011-08-02 23:38:36 +010098 private TextView mHeaderTextView;
Flavio Lerdafb63c432011-07-07 17:16:53 +010099 private ImageView mMainActionView;
Daniel Lehmannd260de42011-08-01 18:08:38 -0700100 private ImageButton mMainActionPushLayerView;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100101 private ImageView mContactBackgroundView;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100102 private AsyncTaskExecutor mAsyncTaskExecutor;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800103
104 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +0800105 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700106
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800107 /* package */ LayoutInflater mInflater;
108 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100109 /** Helper to load contact photos. */
110 private ContactPhotoManager mContactPhotoManager;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100111 /** Helper to make async queries to content resolver. */
112 private CallDetailActivityQueryHandler mAsyncQueryHandler;
113 /** Helper to get voicemail status messages. */
114 private VoicemailStatusHelper mVoicemailStatusHelper;
115 // Views related to voicemail status message.
116 private View mStatusMessageView;
117 private TextView mStatusMessageText;
118 private TextView mStatusMessageAction;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700119
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100120 /** Whether we should show "edit number before call" in the options menu. */
121 private boolean mHasEditNumberBeforeCall;
122
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100123 private ProximitySensorManager mProximitySensorManager;
124 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
125
126 /** Listener to changes in the proximity sensor state. */
127 private class ProximitySensorListener implements ProximitySensorManager.Listener {
128 /** Used to show a blank view and hide the action bar. */
129 private final Runnable mBlankRunnable = new Runnable() {
130 @Override
131 public void run() {
132 View blankView = findViewById(R.id.blank);
133 blankView.setVisibility(View.VISIBLE);
134 getActionBar().hide();
135 }
136 };
137 /** Used to remove the blank view and show the action bar. */
138 private final Runnable mUnblankRunnable = new Runnable() {
139 @Override
140 public void run() {
141 View blankView = findViewById(R.id.blank);
142 blankView.setVisibility(View.GONE);
143 getActionBar().show();
144 }
145 };
146
147 @Override
148 public synchronized void onNear() {
149 clearPendingRequests();
150 postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS);
151 }
152
153 @Override
154 public synchronized void onFar() {
155 clearPendingRequests();
156 postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS);
157 }
158
159 /** Removed any delayed requests that may be pending. */
160 public synchronized void clearPendingRequests() {
161 View blankView = findViewById(R.id.blank);
162 blankView.removeCallbacks(mBlankRunnable);
163 blankView.removeCallbacks(mUnblankRunnable);
164 }
165
166 /** Post a {@link Runnable} with a delay on the main thread. */
167 private synchronized void postDelayed(Runnable runnable, long delayMillis) {
168 // Post these instead of executing immediately so that:
169 // - They are guaranteed to be executed on the main thread.
170 // - If the sensor values changes rapidly for some time, the UI will not be
171 // updated immediately.
172 View blankView = findViewById(R.id.blank);
173 blankView.postDelayed(runnable, delayMillis);
174 }
175 }
176
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800177 static final String[] CALL_LOG_PROJECTION = new String[] {
178 CallLog.Calls.DATE,
179 CallLog.Calls.DURATION,
180 CallLog.Calls.NUMBER,
181 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +0800182 CallLog.Calls.COUNTRY_ISO,
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100183 CallLog.Calls.GEOCODED_LOCATION,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800184 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700185
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800186 static final int DATE_COLUMN_INDEX = 0;
187 static final int DURATION_COLUMN_INDEX = 1;
188 static final int NUMBER_COLUMN_INDEX = 2;
189 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +0800190 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100191 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700192
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800193 static final String[] PHONES_PROJECTION = new String[] {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700194 PhoneLookup._ID,
195 PhoneLookup.DISPLAY_NAME,
196 PhoneLookup.TYPE,
197 PhoneLookup.LABEL,
198 PhoneLookup.NUMBER,
Bai Tao09eb04f2010-09-01 15:34:16 +0800199 PhoneLookup.NORMALIZED_NUMBER,
Daniel Lehmann362654a2011-07-17 14:16:47 -0700200 PhoneLookup.PHOTO_URI,
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100201 PhoneLookup.LOOKUP_KEY,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800202 };
203 static final int COLUMN_INDEX_ID = 0;
204 static final int COLUMN_INDEX_NAME = 1;
205 static final int COLUMN_INDEX_TYPE = 2;
206 static final int COLUMN_INDEX_LABEL = 3;
207 static final int COLUMN_INDEX_NUMBER = 4;
Bai Tao09eb04f2010-09-01 15:34:16 +0800208 static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700209 static final int COLUMN_INDEX_PHOTO_URI = 6;
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100210 static final int COLUMN_INDEX_LOOKUP_KEY = 7;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800211
Flavio Lerdab184ed62011-08-10 18:17:55 +0100212 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
213 @Override
214 public void onClick(View view) {
215 startActivity(((ViewEntry) view.getTag()).primaryIntent);
216 }
217 };
218
219 private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() {
220 @Override
221 public void onClick(View view) {
222 startActivity(((ViewEntry) view.getTag()).secondaryIntent);
223 }
224 };
225
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800226 @Override
227 protected void onCreate(Bundle icicle) {
228 super.onCreate(icicle);
229
230 setContentView(R.layout.call_detail);
231
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100232 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800233 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
234 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700235
Daniel Lehmann6ecb7322011-08-01 21:39:29 -0700236 mCallTypeHelper = new CallTypeHelper(getResources());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100237 mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber());
Flavio Lerda40569562011-07-22 21:51:29 +0100238 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100239 mPhoneNumberHelper);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100240 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
241 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100242 mHeaderTextView = (TextView) findViewById(R.id.header_text);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100243 mStatusMessageView = findViewById(R.id.voicemail_status);
244 mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message);
245 mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100246 mMainActionView = (ImageView) findViewById(R.id.main_action);
Daniel Lehmannd260de42011-08-01 18:08:38 -0700247 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100248 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800249 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100250 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100251 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100252 configureActionBar();
Hugo Hudson51ada362011-08-05 14:36:14 +0100253 optionallyHandleVoicemail();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800254 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700255
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800256 @Override
257 public void onResume() {
258 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100259 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100260 }
261
262 /**
263 * Handle voicemail playback or hide voicemail ui.
264 * <p>
265 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
266 * playback. If it doesn't, then hide the voicemail ui.
267 */
Hugo Hudson757aa552011-07-20 01:15:25 +0100268 private void optionallyHandleVoicemail() {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100269 View voicemailContainer = findViewById(R.id.voicemail_container);
Hugo Hudson157dde12011-07-21 23:28:13 +0100270 if (hasVoicemail()) {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100271 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
272 // to play and optionally start the playback.
Hugo Hudson757aa552011-07-20 01:15:25 +0100273 // Do a query to fetch the voicemail status messages.
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100274 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
275 Bundle fragmentArguments = new Bundle();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100276 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100277 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
278 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
279 }
280 playbackFragment.setArguments(fragmentArguments);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100281 voicemailContainer.setVisibility(View.VISIBLE);
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100282 getFragmentManager().beginTransaction()
Minh Pham4b25da72011-08-25 13:50:38 -0700283 .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100284 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100285 markVoicemailAsRead(getVoicemailUri());
Hugo Hudson757aa552011-07-20 01:15:25 +0100286 } else {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100287 // No voicemail uri: hide the status view.
Hugo Hudson757aa552011-07-20 01:15:25 +0100288 mStatusMessageView.setVisibility(View.GONE);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100289 voicemailContainer.setVisibility(View.GONE);
Hugo Hudsonb002f512011-07-15 17:41:12 +0100290 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100291 }
292
Hugo Hudson157dde12011-07-21 23:28:13 +0100293 private boolean hasVoicemail() {
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100294 return getVoicemailUri() != null;
295 }
296
297 private Uri getVoicemailUri() {
298 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
Hugo Hudson157dde12011-07-21 23:28:13 +0100299 }
300
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100301 private void markVoicemailAsRead(final Uri voicemailUri) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100302 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100303 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100304 public Void doInBackground(Void... params) {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100305 ContentValues values = new ContentValues();
306 values.put(Voicemails.IS_READ, true);
307 getContentResolver().update(voicemailUri, values, null, null);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100308 return null;
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100309 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100310 });
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100311 }
312
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100313 /**
314 * Returns the list of URIs to show.
315 * <p>
316 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
317 * a list of ids in the call log added as an extra on the URI.
318 * <p>
319 * If both are available, the data on the intent takes precedence.
320 */
321 private Uri[] getCallLogEntryUris() {
322 Uri uri = getIntent().getData();
323 if (uri != null) {
324 // If there is a data on the intent, it takes precedence over the extra.
325 return new Uri[]{ uri };
326 }
327 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
328 Uri[] uris = new Uri[ids.length];
329 for (int index = 0; index < ids.length; ++index) {
330 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
331 }
332 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800333 }
334
335 @Override
336 public boolean onKeyDown(int keyCode, KeyEvent event) {
337 switch (keyCode) {
338 case KeyEvent.KEYCODE_CALL: {
339 // Make sure phone isn't already busy before starting direct call
340 TelephonyManager tm = (TelephonyManager)
341 getSystemService(Context.TELEPHONY_SERVICE);
342 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
343 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
344 Uri.fromParts("tel", mNumber, null));
345 startActivity(callIntent);
346 return true;
347 }
348 }
349 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700350
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800351 return super.onKeyDown(keyCode, event);
352 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700353
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800354 /**
355 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700356 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100357 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800358 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100359 private void updateData(final Uri... callUris) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100360 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
Flavio Lerda12592e82011-08-10 15:36:32 +0100361 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100362 public PhoneCallDetails[] doInBackground(Void... params) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100363 // TODO: All phone calls correspond to the same person, so we can make a single
364 // lookup.
365 final int numCalls = callUris.length;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100366 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
Flavio Lerda12592e82011-08-10 15:36:32 +0100367 try {
368 for (int index = 0; index < numCalls; ++index) {
369 details[index] = getPhoneCallDetailsForUri(callUris[index]);
370 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100371 return details;
Flavio Lerda12592e82011-08-10 15:36:32 +0100372 } catch (IllegalArgumentException e) {
373 // Something went wrong reading in our primary data.
374 Log.w(TAG, "invalid URI starting call details", e);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100375 return null;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100376 }
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100377 }
378
Flavio Lerda12592e82011-08-10 15:36:32 +0100379 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100380 public void onPostExecute(PhoneCallDetails[] details) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100381 if (details == null) {
382 // Somewhere went wrong: we're going to bail out and show error to users.
383 Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
384 Toast.LENGTH_SHORT).show();
385 finish();
386 return;
387 }
388
389 // We know that all calls are from the same number and the same contact, so pick the
390 // first.
391 PhoneCallDetails firstDetails = details[0];
392 mNumber = firstDetails.number.toString();
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100393 final Uri contactUri = firstDetails.contactUri;
Flavio Lerda12592e82011-08-10 15:36:32 +0100394 final Uri photoUri = firstDetails.photoUri;
395
396 // Set the details header, based on the first phone call.
Flavio Lerdad5678d32011-08-28 13:49:56 +0100397 mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails);
Flavio Lerda12592e82011-08-10 15:36:32 +0100398
399 // Cache the details about the phone number.
400 final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber);
401 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
402 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
403 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
404
405 // Let user view contact details if they exist, otherwise add option to create new
406 // contact from this number.
407 final Intent mainActionIntent;
408 final int mainActionIcon;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100409 final String mainActionDescription;
410
411 final CharSequence nameOrNumber;
412 if (!TextUtils.isEmpty(firstDetails.name)) {
413 nameOrNumber = firstDetails.name;
414 } else {
415 nameOrNumber = firstDetails.number;
416 }
Flavio Lerda12592e82011-08-10 15:36:32 +0100417
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100418 if (contactUri != null) {
419 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
Flavio Lerda12592e82011-08-10 15:36:32 +0100420 mainActionIcon = R.drawable.ic_contacts_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100421 mainActionDescription =
422 getString(R.string.description_view_contact, nameOrNumber);
Flavio Lerda12592e82011-08-10 15:36:32 +0100423 } else if (isVoicemailNumber) {
424 mainActionIntent = null;
425 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100426 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100427 } else if (isSipNumber) {
428 // TODO: This item is currently disabled for SIP addresses, because
429 // the Insert.PHONE extra only works correctly for PSTN numbers.
430 //
431 // To fix this for SIP addresses, we need to:
432 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
433 // the current number is a SIP address
434 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
435 // updating the SipAddress field
436 // and then we can remove the "!isSipNumber" check above.
437 mainActionIntent = null;
438 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100439 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100440 } else if (canPlaceCallsTo) {
441 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
442 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
443 mainActionIntent.putExtra(Insert.PHONE, mNumber);
444 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100445 mainActionDescription = getString(R.string.description_add_contact);
Flavio Lerda12592e82011-08-10 15:36:32 +0100446 } else {
447 // If we cannot call the number, when we probably cannot add it as a contact either.
448 // This is usually the case of private, unknown, or payphone numbers.
449 mainActionIntent = null;
450 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100451 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100452 }
453
454 if (mainActionIntent == null) {
455 mMainActionView.setVisibility(View.INVISIBLE);
456 mMainActionPushLayerView.setVisibility(View.GONE);
457 } else {
458 mMainActionView.setVisibility(View.VISIBLE);
459 mMainActionView.setImageResource(mainActionIcon);
460 mMainActionPushLayerView.setVisibility(View.VISIBLE);
461 mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
462 @Override
463 public void onClick(View v) {
464 startActivity(mainActionIntent);
465 }
466 });
Flavio Lerdab184ed62011-08-10 18:17:55 +0100467 mMainActionPushLayerView.setContentDescription(mainActionDescription);
Flavio Lerda12592e82011-08-10 15:36:32 +0100468 }
469
Flavio Lerda12592e82011-08-10 15:36:32 +0100470 // This action allows to call the number that places the call.
471 if (canPlaceCallsTo) {
472 final CharSequence displayNumber =
473 mPhoneNumberHelper.getDisplayNumber(
474 firstDetails.number, firstDetails.formattedNumber);
475
476 ViewEntry entry = new ViewEntry(
477 getString(R.string.menu_callNumber, displayNumber),
Flavio Lerdab184ed62011-08-10 18:17:55 +0100478 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri),
479 getString(R.string.description_call, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100480
481 // Only show a label if the number is shown and it is not a SIP address.
Flavio Lerda35be86e2011-08-12 14:13:22 +0100482 if (!TextUtils.isEmpty(firstDetails.name)
483 && !TextUtils.isEmpty(firstDetails.number)
Flavio Lerda12592e82011-08-10 15:36:32 +0100484 && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) {
485 entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType,
486 firstDetails.numberLabel);
487 }
488
489 // The secondary action allows to send an SMS to the number that placed the
490 // call.
491 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerdab184ed62011-08-10 18:17:55 +0100492 entry.setSecondaryAction(
493 R.drawable.ic_text_holo_dark,
Flavio Lerda12592e82011-08-10 15:36:32 +0100494 new Intent(Intent.ACTION_SENDTO,
Flavio Lerdab184ed62011-08-10 18:17:55 +0100495 Uri.fromParts("sms", mNumber, null)),
496 getString(R.string.description_send_text_message, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100497 }
498
Flavio Lerdab184ed62011-08-10 18:17:55 +0100499 configureCallButton(entry);
500 } else {
501 disableCallButton();
Flavio Lerda12592e82011-08-10 15:36:32 +0100502 }
503
504 mHasEditNumberBeforeCall = canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Flavio Lerda599853d2011-09-05 17:50:14 +0100505 invalidateOptionsMenu();
Flavio Lerda12592e82011-08-10 15:36:32 +0100506
Flavio Lerda12592e82011-08-10 15:36:32 +0100507 ListView historyList = (ListView) findViewById(R.id.history);
508 historyList.setAdapter(
509 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
Flavio Lerdab5a3f5c2011-09-21 19:27:33 +0100510 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
511 findViewById(R.id.controls)));
Flavio Lerdad1333a22011-08-11 16:19:47 +0100512 BackScrollManager.bind(
513 new ScrollableHeader() {
514 private View controls = findViewById(R.id.controls);
515 private View photo = findViewById(R.id.contact_background_sizer);
516 private View nameHeader = findViewById(R.id.photo_text_bar);
517
518 @Override
519 public void setOffset(int offset) {
520 controls.setY(-offset);
521 }
522
523 @Override
524 public int getMaximumScrollableHeaderOffset() {
525 // We can scroll the photo out, but we should keep the header.
526 return photo.getHeight() - nameHeader.getHeight();
527 }
528 },
529 historyList);
Flavio Lerda12592e82011-08-10 15:36:32 +0100530 loadContactPhotos(photoUri);
Flavio Lerda4e63bab2011-08-10 18:26:46 +0100531 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100532 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100533 }
534 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100535 }
536
537 /** Return the phone call details for a given call log URI. */
538 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800539 ContentResolver resolver = getContentResolver();
540 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
541 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100542 if (callCursor == null || !callCursor.moveToFirst()) {
543 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800544 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100545
546 // Read call log specifics.
547 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
548 long date = callCursor.getLong(DATE_COLUMN_INDEX);
549 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
550 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
551 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100552 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
553
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100554 if (TextUtils.isEmpty(countryIso)) {
555 countryIso = mDefaultCountryIso;
556 }
557
558 // Formatted phone number.
559 final CharSequence numberText;
560 // Read contact specifics.
561 CharSequence nameText = "";
562 int numberType = 0;
563 CharSequence numberLabel = "";
Daniel Lehmann362654a2011-07-17 14:16:47 -0700564 Uri photoUri = null;
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100565 Uri contactUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100566 // If this is not a regular number, there is no point in looking it up in the contacts.
567 if (!mPhoneNumberHelper.canPlaceCallsTo(number)) {
568 numberText = mPhoneNumberHelper.getDisplayNumber(number, null);
569 } else {
570 // Perform a reverse-phonebook lookup to find the contact details.
571 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
572 Uri.encode(number));
573 Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null);
574 String candidateNumberText = number;
575 try {
576 if (phonesCursor != null && phonesCursor.moveToFirst()) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100577 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
Daniel Lehmann362654a2011-07-17 14:16:47 -0700578 String photoUriString = phonesCursor.getString(COLUMN_INDEX_PHOTO_URI);
579 photoUri = photoUriString == null ? null : Uri.parse(photoUriString);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100580 candidateNumberText = PhoneNumberUtils.formatNumber(
581 phonesCursor.getString(COLUMN_INDEX_NUMBER),
582 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
583 countryIso);
584 numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE);
585 numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL);
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100586 long personId = phonesCursor.getLong(COLUMN_INDEX_ID);
587 if (personId > 0) {
588 contactUri = Contacts.getLookupUri(personId,
589 phonesCursor.getString(COLUMN_INDEX_LOOKUP_KEY));
590 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100591 } else {
592 // We could not find this contact in the contacts, just format the phone
593 // number as best as we can. All the other fields will have their default
594 // values.
595 candidateNumberText =
596 PhoneNumberUtils.formatNumber(number, countryIso);
597 }
598 } finally {
599 if (phonesCursor != null) phonesCursor.close();
600 numberText = candidateNumberText;
601 }
602 }
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100603 return new PhoneCallDetails(number, numberText, countryIso, geocode,
Flavio Lerdacb805e82011-07-18 10:31:44 +0100604 new int[]{ callType }, date, duration,
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100605 nameText, numberType, numberLabel, contactUri, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800606 } finally {
607 if (callCursor != null) {
608 callCursor.close();
609 }
610 }
611 }
612
Flavio Lerda9cafe472011-06-08 14:06:13 +0100613 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700614 private void loadContactPhotos(Uri photoUri) {
Daniel Lehmannecfc26c2011-09-12 17:44:35 -0700615 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, true, true);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100616 }
617
Flavio Lerda696e8132011-07-05 19:00:23 +0100618 private String getVoicemailNumber() {
619 TelephonyManager telephonyManager =
620 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
621 return telephonyManager.getVoiceMailNumber();
622 }
623
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800624 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100625 public final String text;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100626 public final Intent primaryIntent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100627 /** The description for accessibility of the primary action. */
628 public final String primaryDescription;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100629
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100630 public CharSequence label = null;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100631 /** Icon for the secondary action. */
632 public int secondaryIcon = 0;
633 /** Intent for the secondary action. If not null, an icon must be defined. */
634 public Intent secondaryIntent = null;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100635 /** The description for accessibility of the secondary action. */
636 public String secondaryDescription = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700637
Flavio Lerdab184ed62011-08-10 18:17:55 +0100638 public ViewEntry(String text, Intent intent, String description) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800639 this.text = text;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100640 primaryIntent = intent;
641 primaryDescription = description;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100642 }
643
Flavio Lerdab184ed62011-08-10 18:17:55 +0100644 public void setSecondaryAction(int icon, Intent intent, String description) {
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100645 secondaryIcon = icon;
646 secondaryIntent = intent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100647 secondaryDescription = description;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800648 }
649 }
650
Flavio Lerdab184ed62011-08-10 18:17:55 +0100651 /** Disables the call button area, e.g., for private numbers. */
652 private void disableCallButton() {
653 findViewById(R.id.call_and_sms).setVisibility(View.GONE);
654 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700655
Flavio Lerdab184ed62011-08-10 18:17:55 +0100656 /** Configures the call button area using the given entry. */
657 private void configureCallButton(ViewEntry entry) {
658 View convertView = findViewById(R.id.call_and_sms);
659 convertView.setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100660
Flavio Lerdab184ed62011-08-10 18:17:55 +0100661 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
662 View divider = convertView.findViewById(R.id.call_and_sms_divider);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100663 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100664
Flavio Lerdab184ed62011-08-10 18:17:55 +0100665 View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
666 mainAction.setOnClickListener(mPrimaryActionListener);
667 mainAction.setTag(entry);
668 mainAction.setContentDescription(entry.primaryDescription);
669
670 if (entry.secondaryIntent != null) {
671 icon.setOnClickListener(mSecondaryActionListener);
672 icon.setImageResource(entry.secondaryIcon);
673 icon.setVisibility(View.VISIBLE);
674 icon.setTag(entry);
675 icon.setContentDescription(entry.secondaryDescription);
676 divider.setVisibility(View.VISIBLE);
677 } else {
678 icon.setVisibility(View.GONE);
679 divider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800680 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100681 text.setText(entry.text);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700682
Flavio Lerda35be86e2011-08-12 14:13:22 +0100683 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
684 if (TextUtils.isEmpty(entry.label)) {
685 label.setVisibility(View.GONE);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100686 } else {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100687 label.setText(entry.label);
688 label.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800689 }
690 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700691
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100692 protected void updateVoicemailStatusMessage(Cursor statusCursor) {
693 if (statusCursor == null) {
694 mStatusMessageView.setVisibility(View.GONE);
695 return;
696 }
697 final StatusMessage message = getStatusMessage(statusCursor);
698 if (message == null || !message.showInCallDetails()) {
699 mStatusMessageView.setVisibility(View.GONE);
700 return;
701 }
702
703 mStatusMessageView.setVisibility(View.VISIBLE);
704 mStatusMessageText.setText(message.callDetailsMessageId);
705 if (message.actionMessageId != -1) {
706 mStatusMessageAction.setText(message.actionMessageId);
707 }
708 if (message.actionUri != null) {
709 mStatusMessageAction.setClickable(true);
710 mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
711 @Override
712 public void onClick(View v) {
713 startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri));
714 }
715 });
716 } else {
717 mStatusMessageAction.setClickable(false);
718 }
719 }
720
721 private StatusMessage getStatusMessage(Cursor statusCursor) {
722 List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor);
723 Log.d(TAG, "Num status messages: " + messages.size());
724 if (messages.size() == 0) {
725 return null;
726 }
727 // There can only be a single status message per source package, so num of messages can
728 // at most be 1.
729 if (messages.size() > 1) {
730 Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." +
731 " Will use the first one.", messages.size()));
732 }
733 return messages.get(0);
734 }
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100735
736 @Override
737 public boolean onCreateOptionsMenu(Menu menu) {
738 getMenuInflater().inflate(R.menu.call_details_options, menu);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100739 return super.onCreateOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100740 }
741
742 @Override
743 public boolean onPrepareOptionsMenu(Menu menu) {
744 // This action deletes all elements in the group from the call log.
745 // We don't have this action for voicemails, because you can just use the trash button.
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100746 menu.findItem(R.id.menu_remove_from_call_log).setVisible(!hasVoicemail());
747 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCall);
748 menu.findItem(R.id.menu_trash).setVisible(hasVoicemail());
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100749 return super.onPrepareOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100750 }
751
752 @Override
753 public boolean onMenuItemSelected(int featureId, MenuItem item) {
754 switch (item.getItemId()) {
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100755 case android.R.id.home: {
756 onHomeSelected();
757 return true;
758 }
759
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100760 // All the options menu items are handled by onMenu... methods.
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100761 default:
762 throw new IllegalArgumentException();
763 }
764 }
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100765
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100766 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100767 final StringBuilder callIds = new StringBuilder();
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100768 for (Uri callUri : getCallLogEntryUris()) {
769 if (callIds.length() != 0) {
770 callIds.append(",");
771 }
772 callIds.append(ContentUris.parseId(callUri));
773 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100774 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
775 new AsyncTask<Void, Void, Void>() {
776 @Override
777 public Void doInBackground(Void... params) {
778 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
779 Calls._ID + " IN (" + callIds + ")", null);
780 return null;
781 }
782
783 @Override
784 public void onPostExecute(Void result) {
785 finish();
786 }
787 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100788 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100789
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100790 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
791 startActivity(new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber)));
792 }
793
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100794 public void onMenuTrashVoicemail(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100795 final Uri voicemailUri = getVoicemailUri();
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100796 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
797 new AsyncTask<Void, Void, Void>() {
798 @Override
799 public Void doInBackground(Void... params) {
800 getContentResolver().delete(voicemailUri, null, null);
801 return null;
802 }
803 @Override
804 public void onPostExecute(Void result) {
805 finish();
806 }
807 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100808 }
809
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100810 private void configureActionBar() {
811 ActionBar actionBar = getActionBar();
812 if (actionBar != null) {
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100813 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100814 }
815 }
816
817 /** Invoked when the user presses the home button in the action bar. */
818 private void onHomeSelected() {
819 Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
820 // This will open the call log even if the detail view has been opened directly.
821 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
822 startActivity(intent);
823 finish();
824 }
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100825
826 @Override
827 protected void onPause() {
828 // Immediately stop the proximity sensor.
829 disableProximitySensor(false);
830 mProximitySensorListener.clearPendingRequests();
831 super.onPause();
832 }
833
834 @Override
835 public void enableProximitySensor() {
836 mProximitySensorManager.enable();
837 }
838
839 @Override
840 public void disableProximitySensor(boolean waitForFarState) {
841 mProximitySensorManager.disable(waitForFarState);
842 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800843}