• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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.activities;
18 
19 import com.android.contacts.R;
20 import com.android.contacts.calllog.CallLogFragment;
21 import com.android.internal.telephony.ITelephony;
22 import com.google.common.annotations.VisibleForTesting;
23 
24 import android.app.Activity;
25 import android.content.ActivityNotFoundException;
26 import android.content.Intent;
27 import android.os.Bundle;
28 import android.os.RemoteException;
29 import android.os.ServiceManager;
30 import android.os.SystemClock;
31 import android.view.KeyEvent;
32 import android.view.ViewConfiguration;
33 
34 /**
35  * Displays a list of call log entries.
36  */
37 public class CallLogActivity extends Activity {
38     private static final String TAG = "CallLogActivity";
39 
40     private CallLogFragment mFragment;
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45 
46 
47         setContentView(R.layout.call_log_activity);
48 
49         // Typing here goes to the dialer
50         setDefaultKeyMode(DEFAULT_KEYS_DIALER);
51 
52         mFragment = (CallLogFragment) getFragmentManager().findFragmentById(
53                 R.id.call_log_fragment);
54     }
55 
56     @VisibleForTesting
getFragment()57     /*package*/ CallLogFragment getFragment() {
58         return mFragment;
59     }
60 
61     @Override
onKeyDown(int keyCode, KeyEvent event)62     public boolean onKeyDown(int keyCode, KeyEvent event) {
63         switch (keyCode) {
64             case KeyEvent.KEYCODE_CALL: {
65                 long callPressDiff = SystemClock.uptimeMillis() - event.getDownTime();
66                 if (callPressDiff >= ViewConfiguration.getLongPressTimeout()) {
67                     // Launch voice dialer
68                     Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
69                     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
70                     try {
71                         startActivity(intent);
72                     } catch (ActivityNotFoundException e) {
73                     }
74                     return true;
75                 }
76             }
77         }
78         return super.onKeyDown(keyCode, event);
79     }
80 
81     @Override
onKeyUp(int keyCode, KeyEvent event)82     public boolean onKeyUp(int keyCode, KeyEvent event) {
83         switch (keyCode) {
84             case KeyEvent.KEYCODE_CALL:
85                 try {
86                     ITelephony phone = ITelephony.Stub.asInterface(
87                             ServiceManager.checkService("phone"));
88                     if (phone != null && !phone.isIdle()) {
89                         // Let the super class handle it
90                         break;
91                     }
92                 } catch (RemoteException re) {
93                     // Fall through and try to call the contact
94                 }
95 
96                 mFragment.callSelectedEntry();
97                 return true;
98         }
99         return super.onKeyUp(keyCode, event);
100     }
101 }
102