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