• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.incallui;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.util.AttributeSet;
23 import android.view.View;
24 
25 import com.android.incallui.widget.multiwaveview.GlowPadView;
26 
27 /**
28  *
29  */
30 public class GlowPadWrapper extends GlowPadView implements GlowPadView.OnTriggerListener {
31 
32     // Parameters for the GlowPadView "ping" animation; see triggerPing().
33     private static final int PING_MESSAGE_WHAT = 101;
34     private static final boolean ENABLE_PING_AUTO_REPEAT = true;
35     private static final long PING_REPEAT_DELAY_MS = 1200;
36 
37     private final Handler mPingHandler = new Handler() {
38         @Override
39         public void handleMessage(Message msg) {
40             switch (msg.what) {
41                 case PING_MESSAGE_WHAT:
42                     triggerPing();
43                     break;
44             }
45         }
46     };
47 
48     private AnswerListener mAnswerListener;
49     private boolean mPingEnabled = true;
50     private boolean mTargetTriggered = false;
51 
GlowPadWrapper(Context context)52     public GlowPadWrapper(Context context) {
53         super(context);
54         Log.d(this, "class created " + this + " ");
55     }
56 
GlowPadWrapper(Context context, AttributeSet attrs)57     public GlowPadWrapper(Context context, AttributeSet attrs) {
58         super(context, attrs);
59         Log.d(this, "class created " + this);
60     }
61 
62     @Override
onFinishInflate()63     protected void onFinishInflate() {
64         Log.d(this, "onFinishInflate()");
65         super.onFinishInflate();
66         setOnTriggerListener(this);
67     }
68 
startPing()69     public void startPing() {
70         Log.d(this, "startPing");
71         mPingEnabled = true;
72         triggerPing();
73     }
74 
stopPing()75     public void stopPing() {
76         Log.d(this, "stopPing");
77         mPingEnabled = false;
78         mPingHandler.removeMessages(PING_MESSAGE_WHAT);
79     }
80 
triggerPing()81     private void triggerPing() {
82         Log.d(this, "triggerPing(): " + mPingEnabled + " " + this);
83         if (mPingEnabled && !mPingHandler.hasMessages(PING_MESSAGE_WHAT)) {
84             ping();
85 
86             if (ENABLE_PING_AUTO_REPEAT) {
87                 mPingHandler.sendEmptyMessageDelayed(PING_MESSAGE_WHAT, PING_REPEAT_DELAY_MS);
88             }
89         }
90     }
91 
92     @Override
onGrabbed(View v, int handle)93     public void onGrabbed(View v, int handle) {
94         Log.d(this, "onGrabbed()");
95         stopPing();
96     }
97 
98     @Override
onReleased(View v, int handle)99     public void onReleased(View v, int handle) {
100         Log.d(this, "onReleased()");
101         if (mTargetTriggered) {
102             mTargetTriggered = false;
103         } else {
104             startPing();
105         }
106     }
107 
108     @Override
onTrigger(View v, int target)109     public void onTrigger(View v, int target) {
110         Log.d(this, "onTrigger()");
111         final int resId = getResourceIdForTarget(target);
112         switch (resId) {
113             case R.drawable.ic_lockscreen_answer:
114                 mAnswerListener.onAnswer();
115                 mTargetTriggered = true;
116                 break;
117             case R.drawable.ic_lockscreen_decline:
118                 mAnswerListener.onDecline();
119                 mTargetTriggered = true;
120                 break;
121             case R.drawable.ic_lockscreen_text:
122                 mAnswerListener.onText();
123                 mTargetTriggered = true;
124                 break;
125             default:
126                 // Code should never reach here.
127                 Log.e(this, "Trigger detected on unhandled resource. Skipping.");
128         }
129     }
130 
131     @Override
onGrabbedStateChange(View v, int handle)132     public void onGrabbedStateChange(View v, int handle) {
133 
134     }
135 
136     @Override
onFinishFinalAnimation()137     public void onFinishFinalAnimation() {
138 
139     }
140 
setAnswerListener(AnswerListener listener)141     public void setAnswerListener(AnswerListener listener) {
142         mAnswerListener = listener;
143     }
144 
145     public interface AnswerListener {
onAnswer()146         void onAnswer();
onDecline()147         void onDecline();
onText()148         void onText();
149     }
150 }
151