• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.phone;
18 
19 import android.content.Context;
20 import android.graphics.Rect;
21 import android.graphics.drawable.Drawable;
22 import android.util.AttributeSet;
23 import android.util.Log;
24 import android.view.FocusFinder;
25 import android.view.KeyEvent;
26 import android.view.MotionEvent;
27 import android.view.View;
28 import android.view.ViewConfiguration;
29 import android.view.ViewGroup;
30 import android.widget.LinearLayout;
31 
32 import java.util.ArrayList;
33 
34 /**
35  * DTMFTwelveKeyDialerView is the view logic that the DTMFDialer uses.
36  * This is really a thin wrapper around Linear Layout that intercepts
37  * some user interactions to provide the correct UI behaviour for the
38  * dialer.
39  */
40 class DTMFTwelveKeyDialerView extends LinearLayout {
41 
42     private static final String LOG_TAG = "PHONE/DTMFTwelveKeyDialerView";
43     private static final boolean DBG = false;
44 
45     private DTMFTwelveKeyDialer mDialer;
46     private ButtonGridLayout mButtonGrid;
47 
DTMFTwelveKeyDialerView(Context context)48     public DTMFTwelveKeyDialerView (Context context) {
49         super(context);
50     }
51 
DTMFTwelveKeyDialerView(Context context, AttributeSet attrs)52     public DTMFTwelveKeyDialerView(Context context, AttributeSet attrs) {
53         super(context, attrs);
54     }
55 
setDialer(DTMFTwelveKeyDialer dialer)56     void setDialer (DTMFTwelveKeyDialer dialer) {
57         mDialer = dialer;
58         mButtonGrid = (ButtonGridLayout)findViewById(R.id.dialpad);
59     }
60 
61     /**
62      * Normally we ignore everything except for the BACK and CALL keys.
63      * For those, we pass them to the model (and then the InCallScreen).
64      */
65     @Override
dispatchKeyEvent(KeyEvent event)66     public boolean dispatchKeyEvent(KeyEvent event) {
67         if (DBG) log("dispatchKeyEvent(" + event + ")...");
68 
69         int keyCode = event.getKeyCode();
70         if (mDialer != null) {
71             switch (keyCode) {
72                 case KeyEvent.KEYCODE_BACK:
73                 case KeyEvent.KEYCODE_CALL:
74                     return event.isDown() ? mDialer.onKeyDown(keyCode, event) :
75                         mDialer.onKeyUp(keyCode, event);
76             }
77         }
78 
79         if (DBG) log("==> dispatchKeyEvent: forwarding event to the DTMFDialer");
80         return super.dispatchKeyEvent(event);
81     }
82 
83     /**
84      * Set the background of all the dialpad keys. Typically a selector to
85      * change the background based on some combination of the
86      * attributes.
87      * @param resid Is a resource id to be used for each button's background.
88      */
setKeysBackgroundResource(int resid)89     public void setKeysBackgroundResource(int resid) {
90         mButtonGrid.setChildrenBackgroundResource(resid);
91     }
92 
log(String msg)93     private void log(String msg) {
94         Log.d(LOG_TAG, msg);
95     }
96 
97 }
98