1 /* 2 * Copyright (C) 2021 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.quickstep.views; 18 19 import static android.view.View.GONE; 20 21 import android.content.Context; 22 import android.util.AttributeSet; 23 import android.view.View; 24 25 import androidx.annotation.Nullable; 26 import androidx.annotation.Px; 27 28 import com.android.launcher3.R; 29 import com.android.launcher3.views.ArrowTipView; 30 import com.android.quickstep.TaskOverlayFactoryGo.OverlayUICallbacksGo; 31 import com.android.quickstep.util.RecentsOrientedState; 32 33 /** 34 * View for showing Go-specific action buttons in Overview 35 */ 36 public class GoOverviewActionsView extends OverviewActionsView<OverlayUICallbacksGo> { 37 38 @Nullable 39 private ArrowTipView mArrowTipView; 40 GoOverviewActionsView(Context context)41 public GoOverviewActionsView(Context context) { 42 this(context, null); 43 } 44 GoOverviewActionsView(Context context, @Nullable AttributeSet attrs)45 public GoOverviewActionsView(Context context, @Nullable AttributeSet attrs) { 46 this(context, attrs, 0); 47 } 48 GoOverviewActionsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)49 public GoOverviewActionsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 50 super(context, attrs, defStyleAttr); 51 } 52 53 @Override onFinishInflate()54 protected void onFinishInflate() { 55 super.onFinishInflate(); 56 57 if (getResources().getBoolean(R.bool.enable_niu_actions)) { 58 findViewById(R.id.action_listen).setOnClickListener(this); 59 findViewById(R.id.action_translate).setOnClickListener(this); 60 } else { 61 findViewById(R.id.layout_listen).setVisibility(GONE); 62 findViewById(R.id.spacer_listen).setVisibility(GONE); 63 findViewById(R.id.layout_translate).setVisibility(GONE); 64 findViewById(R.id.spacer_translate).setVisibility(GONE); 65 } 66 } 67 68 @Override onClick(View view)69 public void onClick(View view) { 70 super.onClick(view); 71 72 if (mCallbacks == null) { 73 return; 74 } 75 int id = view.getId(); 76 if (id == R.id.action_listen) { 77 mCallbacks.onListen(); 78 } else if (id == R.id.action_translate) { 79 mCallbacks.onTranslate(); 80 } else if (id == R.id.action_search) { 81 mCallbacks.onSearch(); 82 } 83 } 84 85 /** 86 * Shows Tooltip for action icons 87 */ showToolTip(int viewId, int textResourceId)88 private ArrowTipView showToolTip(int viewId, int textResourceId) { 89 int[] location = new int[2]; 90 @Px int topMargin = getResources().getDimensionPixelSize(R.dimen.tooltip_top_margin); 91 findViewById(viewId).getLocationOnScreen(location); 92 mArrowTipView = new ArrowTipView(getContext(), /* isPointingUp= */ false) 93 .showAtLocation(getResources().getString(textResourceId), 94 /* arrowXCoord= */ location[0] + findViewById(viewId).getWidth() / 2, 95 /* yCoord= */ location[1] - topMargin, 96 /* shouldAutoClose= */ false); 97 98 mArrowTipView.bringToFront(); 99 return mArrowTipView; 100 } 101 102 /** 103 * Shows Tooltip for listen action icon 104 */ showListenToolTip()105 public ArrowTipView showListenToolTip() { 106 return showToolTip(/* viewId= */ R.id.action_listen, 107 /* textResourceId= */ R.string.tooltip_listen); 108 } 109 110 /** 111 * Shows Tooltip for translate action icon 112 */ showTranslateToolTip()113 public ArrowTipView showTranslateToolTip() { 114 return showToolTip(/* viewId= */ R.id.action_translate, 115 /* textResourceId= */ R.string.tooltip_translate); 116 } 117 118 /** 119 * Called when device orientation is changed 120 */ updateOrientationState(RecentsOrientedState orientedState)121 public void updateOrientationState(RecentsOrientedState orientedState) { 122 // dismiss tooltip 123 boolean canLauncherRotate = orientedState.isRecentsActivityRotationAllowed(); 124 if (mArrowTipView != null && !canLauncherRotate) { 125 mArrowTipView.close(/* animate= */ false); 126 } 127 } 128 } 129