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.os.Bundle; 20 import android.telecom.VideoProfile; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.view.ViewGroup; 24 25 import com.android.dialer.R; 26 27 public class GlowPadAnswerFragment extends AnswerFragment { 28 29 private GlowPadWrapper mGlowpad; 30 GlowPadAnswerFragment()31 public GlowPadAnswerFragment() { 32 } 33 34 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)35 public View onCreateView(LayoutInflater inflater, ViewGroup container, 36 Bundle savedInstanceState) { 37 mGlowpad = (GlowPadWrapper) inflater.inflate(R.layout.answer_fragment, 38 container, false); 39 40 Log.d(this, "Creating view for answer fragment ", this); 41 Log.d(this, "Created from activity", getActivity()); 42 mGlowpad.setAnswerFragment(this); 43 44 return mGlowpad; 45 } 46 47 @Override onResume()48 public void onResume() { 49 super.onResume(); 50 mGlowpad.requestFocus(); 51 } 52 53 @Override onDestroyView()54 public void onDestroyView() { 55 Log.d(this, "onDestroyView"); 56 if (mGlowpad != null) { 57 mGlowpad.stopPing(); 58 mGlowpad = null; 59 } 60 super.onDestroyView(); 61 } 62 63 @Override onShowAnswerUi(boolean shown)64 public void onShowAnswerUi(boolean shown) { 65 Log.d(this, "Show answer UI: " + shown); 66 if (shown) { 67 mGlowpad.startPing(); 68 } else { 69 mGlowpad.stopPing(); 70 } 71 } 72 73 /** 74 * Sets targets on the glowpad according to target set identified by the parameter. 75 * 76 * @param targetSet Integer identifying the set of targets to use. 77 */ showTargets(int targetSet)78 public void showTargets(int targetSet) { 79 showTargets(targetSet, VideoProfile.STATE_BIDIRECTIONAL); 80 } 81 82 /** 83 * Sets targets on the glowpad according to target set identified by the parameter. 84 * 85 * @param targetSet Integer identifying the set of targets to use. 86 */ 87 @Override showTargets(int targetSet, int videoState)88 public void showTargets(int targetSet, int videoState) { 89 final int targetResourceId; 90 final int targetDescriptionsResourceId; 91 final int directionDescriptionsResourceId; 92 final int handleDrawableResourceId; 93 mGlowpad.setVideoState(videoState); 94 95 switch (targetSet) { 96 case TARGET_SET_FOR_AUDIO_WITH_SMS: 97 targetResourceId = R.array.incoming_call_widget_audio_with_sms_targets; 98 targetDescriptionsResourceId = 99 R.array.incoming_call_widget_audio_with_sms_target_descriptions; 100 directionDescriptionsResourceId = 101 R.array.incoming_call_widget_audio_with_sms_direction_descriptions; 102 handleDrawableResourceId = R.drawable.ic_incall_audio_handle; 103 break; 104 case TARGET_SET_FOR_VIDEO_WITHOUT_SMS: 105 targetResourceId = R.array.incoming_call_widget_video_without_sms_targets; 106 targetDescriptionsResourceId = 107 R.array.incoming_call_widget_video_without_sms_target_descriptions; 108 directionDescriptionsResourceId = 109 R.array.incoming_call_widget_video_without_sms_direction_descriptions; 110 handleDrawableResourceId = R.drawable.ic_incall_video_handle; 111 break; 112 case TARGET_SET_FOR_VIDEO_WITH_SMS: 113 targetResourceId = R.array.incoming_call_widget_video_with_sms_targets; 114 targetDescriptionsResourceId = 115 R.array.incoming_call_widget_video_with_sms_target_descriptions; 116 directionDescriptionsResourceId = 117 R.array.incoming_call_widget_video_with_sms_direction_descriptions; 118 handleDrawableResourceId = R.drawable.ic_incall_video_handle; 119 break; 120 case TARGET_SET_FOR_VIDEO_ACCEPT_REJECT_REQUEST: 121 targetResourceId = 122 R.array.incoming_call_widget_video_request_targets; 123 targetDescriptionsResourceId = 124 R.array.incoming_call_widget_video_request_target_descriptions; 125 directionDescriptionsResourceId = R.array 126 .incoming_call_widget_video_request_target_direction_descriptions; 127 handleDrawableResourceId = R.drawable.ic_incall_video_handle; 128 break; 129 case TARGET_SET_FOR_AUDIO_WITHOUT_SMS: 130 default: 131 targetResourceId = R.array.incoming_call_widget_audio_without_sms_targets; 132 targetDescriptionsResourceId = 133 R.array.incoming_call_widget_audio_without_sms_target_descriptions; 134 directionDescriptionsResourceId = 135 R.array.incoming_call_widget_audio_without_sms_direction_descriptions; 136 handleDrawableResourceId = R.drawable.ic_incall_audio_handle; 137 break; 138 } 139 140 if (targetResourceId != mGlowpad.getTargetResourceId()) { 141 mGlowpad.setTargetResources(targetResourceId); 142 mGlowpad.setTargetDescriptionsResourceId(targetDescriptionsResourceId); 143 mGlowpad.setDirectionDescriptionsResourceId(directionDescriptionsResourceId); 144 mGlowpad.setHandleDrawable(handleDrawableResourceId); 145 mGlowpad.reset(false); 146 } 147 } 148 149 @Override onMessageDialogCancel()150 protected void onMessageDialogCancel() { 151 if (mGlowpad != null) { 152 mGlowpad.startPing(); 153 } 154 } 155 } 156