Merge "NIU Actions: Add NIU Actions tooltip" into sc-dev am: 4e74ccb082

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15126744

Change-Id: I3229482f572feb6e5fbfa8fc338bad23a9525c45
This commit is contained in:
Ashish Gupta
2021-07-08 07:41:46 +00:00
committed by Automerger Merge Worker
8 changed files with 126 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
<!--
Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/arrow_tip_view_bg" />
<corners android:radius="@dimen/tooltip_corner_radius" />
</shape>

View File

@@ -23,4 +23,8 @@
<!-- Modal Dialogs -->
<color name="go_modal_dialog_background">#FFFFFF</color>
<color name="go_modal_dialog_background_dark">#424242</color>
<!-- Tooltip Color -->
<color name="arrow_tip_view_bg">#1A73E8</color>
<color name="arrow_tip_view_content">#FFFFFF</color>
</resources>

View File

@@ -36,4 +36,8 @@
<dimen name="modal_dialog_vertical_spacer">12dp</dimen>
<dimen name="modal_dialog_corner_radius">8dp</dimen>
<dimen name="confirmation_dialog_text_height">216dp</dimen>
<!-- Tooltip -->
<dimen name="tooltip_corner_radius">8dp</dimen>
<dimen name="tooltip_top_margin">3dp</dimen>
</resources>

View File

@@ -16,6 +16,8 @@
package com.android.quickstep;
import static android.view.Surface.ROTATION_0;
import static com.android.quickstep.views.OverviewActionsView.DISABLED_NO_THUMBNAIL;
import static com.android.quickstep.views.OverviewActionsView.DISABLED_ROTATED;
@@ -30,6 +32,7 @@ import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserManager;
import android.provider.Settings;
@@ -46,7 +49,8 @@ import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.quickstep.util.AssistContentRequester;
import com.android.quickstep.views.OverviewActionsView;
import com.android.quickstep.util.RecentsOrientedState;
import com.android.quickstep.views.GoOverviewActionsView;
import com.android.quickstep.views.TaskThumbnailView;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
@@ -67,6 +71,9 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory {
private static final String NIU_ACTIONS_CONFIRMED = "launcher_go.niu_actions_confirmed";
private static final String TAG = "TaskOverlayFactoryGo";
public static final String LISTEN_TOOL_TIP_SEEN = "launcher.go_listen_tip_seen";
public static final String TRANSLATE_TOOL_TIP_SEEN = "launcher.go_translate_tip_seen";
private AssistContentRequester mContentRequester;
public TaskOverlayFactoryGo(Context context) {
@@ -84,7 +91,7 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory {
* Overlay on each task handling Overview Action Buttons.
* @param <T> The type of View in which the overlay will be placed
*/
public static final class TaskOverlayGo<T extends OverviewActionsView> extends TaskOverlay {
public static final class TaskOverlayGo<T extends GoOverviewActionsView> extends TaskOverlay {
private String mNIUPackageName;
private String mTaskPackageName;
private String mWebUrl;
@@ -99,6 +106,7 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory {
AssistContentRequester assistContentRequester) {
super(taskThumbnailView);
mFactoryContentRequester = assistContentRequester;
mSharedPreferences = Utilities.getPrefs(mApplicationContext);
}
/**
@@ -134,6 +142,18 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory {
int taskId = task.key.id;
mFactoryContentRequester.requestAssistContent(taskId, this::onAssistContentReceived);
RecentsOrientedState orientedState =
mThumbnailView.getTaskView().getRecentsView().getPagedViewOrientedState();
boolean isInLandscape = orientedState.getDisplayRotation() != ROTATION_0;
// show tooltips in portrait mode only
// TODO: remove If check once b/183714277 is fixed
if (!isInLandscape) {
new Handler().post(() -> {
showTooltipsIfUnseen();
});
}
}
/** Provide Assist Content to the overlay. */
@@ -149,6 +169,12 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory {
mWebUrl = null;
}
@Override
public void updateOrientationState(RecentsOrientedState state) {
super.updateOrientationState(state);
((GoOverviewActionsView) getActionsView()).updateOrientationState(state);
}
/**
* Creates and sends an Intent corresponding to the button that was clicked
*/
@@ -275,6 +301,20 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory {
private void onNiuActionsConfirmationReject(View v) {
mConfirmationDialog.cancel();
}
/**
* Checks and Shows the tooltip if they are not seen by user
* Order of tooltips are translate and then listen
*/
private void showTooltipsIfUnseen() {
if (!mSharedPreferences.getBoolean(TRANSLATE_TOOL_TIP_SEEN, false)) {
((GoOverviewActionsView) getActionsView()).showTranslateToolTip();
mSharedPreferences.edit().putBoolean(TRANSLATE_TOOL_TIP_SEEN, true).apply();
} else if (!mSharedPreferences.getBoolean(LISTEN_TOOL_TIP_SEEN, false)) {
((GoOverviewActionsView) getActionsView()).showListenToolTip();
mSharedPreferences.edit().putBoolean(LISTEN_TOOL_TIP_SEEN, true).apply();
}
}
}
/**

View File

@@ -21,14 +21,20 @@ import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import com.android.launcher3.R;
import com.android.launcher3.views.ArrowTipView;
import com.android.quickstep.TaskOverlayFactoryGo.OverlayUICallbacksGo;
import com.android.quickstep.util.RecentsOrientedState;
/**
* View for showing Go-specific action buttons in Overview
*/
public final class GoOverviewActionsView extends OverviewActionsView<OverlayUICallbacksGo> {
public class GoOverviewActionsView extends OverviewActionsView<OverlayUICallbacksGo> {
private ArrowTipView mArrowTipView;
public GoOverviewActionsView(Context context) {
this(context, null);
}
@@ -72,4 +78,46 @@ public final class GoOverviewActionsView extends OverviewActionsView<OverlayUICa
mCallbacks.onSearch();
}
}
/**
* Shows Tooltip for action icons
*/
private void showToolTip(int viewId, int textResourceId) {
int[] location = new int[2];
@Px int topMargin = getResources().getDimensionPixelSize(R.dimen.tooltip_top_margin);
findViewById(viewId).getLocationOnScreen(location);
mArrowTipView = new ArrowTipView(getContext(), /* isPointingUp= */ false)
.showAtLocation(getResources().getString(textResourceId),
/* arrowXCoord= */ location[0] + findViewById(viewId).getWidth() / 2,
/* yCoord= */ location[1] - topMargin);
mArrowTipView.bringToFront();
}
/**
* Shows Tooltip for listen action icon
*/
public void showListenToolTip() {
showToolTip(/* viewId= */ R.id.action_listen,
/* textResourceId= */ R.string.tooltip_listen);
}
/**
* Shows Tooltip for translate action icon
*/
public void showTranslateToolTip() {
showToolTip(/* viewId= */ R.id.action_translate,
/* textResourceId= */ R.string.tooltip_translate);
}
/**
* Called when device orientation is changed
*/
public void updateOrientationState(RecentsOrientedState orientedState) {
// dismiss tooltip
boolean canLauncherRotate = orientedState.canRecentsActivityRotate();
if (mArrowTipView != null && !canLauncherRotate) {
mArrowTipView.close(/* animate= */ false);
}
}
}