2016-09-28 16:47:32 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
2018-05-15 13:55:57 -07:00
|
|
|
import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;
|
|
|
|
|
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
|
|
|
|
|
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
|
|
|
|
|
|
|
|
|
import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled;
|
|
|
|
|
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
|
|
|
|
|
|
2017-03-20 17:12:24 -07:00
|
|
|
import android.annotation.SuppressLint;
|
2016-09-28 16:47:32 -07:00
|
|
|
import android.content.Context;
|
|
|
|
|
import android.support.annotation.IntDef;
|
|
|
|
|
import android.util.AttributeSet;
|
2018-05-15 13:55:57 -07:00
|
|
|
import android.util.Pair;
|
2017-03-20 17:12:24 -07:00
|
|
|
import android.view.MotionEvent;
|
2016-09-28 16:47:32 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
2017-09-28 13:43:24 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
|
|
|
|
import com.android.launcher3.util.TouchController;
|
2018-03-14 12:30:11 -07:00
|
|
|
import com.android.launcher3.views.BaseDragLayer;
|
2016-09-28 16:47:32 -07:00
|
|
|
|
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class for a View which shows a floating UI on top of the launcher UI.
|
|
|
|
|
*/
|
2017-09-28 13:43:24 -07:00
|
|
|
public abstract class AbstractFloatingView extends LinearLayout implements TouchController {
|
2016-09-28 16:47:32 -07:00
|
|
|
|
2017-03-20 17:12:24 -07:00
|
|
|
@IntDef(flag = true, value = {
|
|
|
|
|
TYPE_FOLDER,
|
2017-10-09 14:56:21 -07:00
|
|
|
TYPE_ACTION_POPUP,
|
2017-09-28 13:43:24 -07:00
|
|
|
TYPE_WIDGETS_BOTTOM_SHEET,
|
2017-10-10 15:21:15 -07:00
|
|
|
TYPE_WIDGET_RESIZE_FRAME,
|
2017-11-10 14:52:00 -08:00
|
|
|
TYPE_WIDGETS_FULL_SHEET,
|
2017-12-14 18:38:25 -08:00
|
|
|
TYPE_ON_BOARD_POPUP,
|
2018-01-19 11:24:32 -08:00
|
|
|
|
|
|
|
|
TYPE_QUICKSTEP_PREVIEW,
|
|
|
|
|
TYPE_TASK_MENU,
|
|
|
|
|
TYPE_OPTIONS_POPUP
|
2017-03-20 17:12:24 -07:00
|
|
|
})
|
2016-09-28 16:47:32 -07:00
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
|
public @interface FloatingViewType {}
|
|
|
|
|
public static final int TYPE_FOLDER = 1 << 0;
|
2017-10-09 14:56:21 -07:00
|
|
|
public static final int TYPE_ACTION_POPUP = 1 << 1;
|
2017-04-12 18:31:09 -07:00
|
|
|
public static final int TYPE_WIDGETS_BOTTOM_SHEET = 1 << 2;
|
2017-09-28 13:43:24 -07:00
|
|
|
public static final int TYPE_WIDGET_RESIZE_FRAME = 1 << 3;
|
2017-10-10 15:21:15 -07:00
|
|
|
public static final int TYPE_WIDGETS_FULL_SHEET = 1 << 4;
|
2018-01-19 11:24:32 -08:00
|
|
|
public static final int TYPE_ON_BOARD_POPUP = 1 << 5;
|
|
|
|
|
|
|
|
|
|
// Popups related to quickstep UI
|
|
|
|
|
public static final int TYPE_QUICKSTEP_PREVIEW = 1 << 6;
|
2017-12-14 18:38:25 -08:00
|
|
|
public static final int TYPE_TASK_MENU = 1 << 7;
|
2018-01-19 11:24:32 -08:00
|
|
|
public static final int TYPE_OPTIONS_POPUP = 1 << 8;
|
2017-10-10 15:21:15 -07:00
|
|
|
|
|
|
|
|
public static final int TYPE_ALL = TYPE_FOLDER | TYPE_ACTION_POPUP
|
2017-11-10 14:52:00 -08:00
|
|
|
| TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_WIDGETS_FULL_SHEET
|
2018-01-19 11:24:32 -08:00
|
|
|
| TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP | TYPE_TASK_MENU | TYPE_OPTIONS_POPUP;
|
2016-09-28 16:47:32 -07:00
|
|
|
|
2017-12-05 15:11:21 -08:00
|
|
|
// Type of popups which should be kept open during launcher rebind
|
|
|
|
|
public static final int TYPE_REBIND_SAFE = TYPE_WIDGETS_FULL_SHEET
|
2018-04-05 11:32:41 -07:00
|
|
|
| TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP;
|
2017-12-05 15:11:21 -08:00
|
|
|
|
2018-04-12 17:26:18 -07:00
|
|
|
// Usually we show the back button when a floating view is open. Instead, hide for these types.
|
|
|
|
|
public static final int TYPE_HIDE_BACK_BUTTON = TYPE_ON_BOARD_POPUP;
|
|
|
|
|
|
2016-09-28 16:47:32 -07:00
|
|
|
protected boolean mIsOpen;
|
|
|
|
|
|
|
|
|
|
public AbstractFloatingView(Context context, AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AbstractFloatingView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-20 17:12:24 -07:00
|
|
|
/**
|
|
|
|
|
* We need to handle touch events to prevent them from falling through to the workspace below.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 16:47:32 -07:00
|
|
|
public final void close(boolean animate) {
|
|
|
|
|
animate &= !Utilities.isPowerSaverOn(getContext());
|
|
|
|
|
handleClose(animate);
|
2018-03-14 12:30:11 -07:00
|
|
|
BaseActivity.fromContext(getContext()).getUserEventDispatcher()
|
Quick step/scrub/switch logging
- state transition happening due to Home and back is handled by
specifying src target as 'from' container and dst target as the 'to'
container
- Source and Destination container shows FROM and TO state for SWIPE/FLING
- event.isStateChange = true indicates that an action resulted in
state transition
- Elapsed container millis is the screen time on the source container
Bug: 70181187
- logcat printout with setprop log.tag.UserEvent VERBOSE
1) State: WORKSPACE -> ALLAPPS
action:FLING direction=UP
Source child:HOTSEAT id=0 parent:WORKSPACE id=0
Destination child:ALLAPPS
Elapsed container 1225 ms, session 1225 ms, action 0 ms
2) ALLAPPS -> HOMESCREEN
action:FLING direction=DOWN
Source child:ALLAPPS parent:ALLAPPS
Destination child:WORKSPACE id=0
Elapsed container 971 ms, session 2197 ms, action 0 ms
3) HOMESCREEN -> OVERVIEW
action:FLING direction=UP
Source child:NAVBAR parent:WORKSPACE id=0
Destination child:TASKSWITCHER
Elapsed container 4834 ms, session 4834 ms, action 0 ms
4) OVERVIEW-> ALLAPPS
action:FLING direction=UP
Source child:TASK parent:TASKSWITCHER
Destination child:ALLAPPS
Elapsed container 2176 ms, session 7010 ms, action 0 ms
5) ALLAPPS->OVERVIEW
action:FLING direction=DOWN
Source child:ALLAPPS parent:ALLAPPS
Destination child:TASKSWITCHER
Elapsed container 3683 ms, session 10693 ms, action 0 ms
6) OVERVIEW-> HOMESCREEN
action:FLING direction=DOWN
Source child:TASK parent:TASKSWITCHER
Destination child:WORKSPACE id=0
Elapsed container 2108 ms, session 12801 ms, action 0 ms
7) APPS-> OVERVIEW
action:FLING direction=UP
Source child:NAVBAR parent:APP
Destination child:TASKSWITCHER
Elapsed container 104 ms, session 104 ms, action 0 ms
8) Quickscrub: action:DRAGANDDROP Source child: QUICK
9) Quickswitch: action:FLING Source child: QUICK
Change-Id: I5898230859ff600f48a2a873a40b670fe4d39a0d
2018-02-14 13:40:25 -08:00
|
|
|
.resetElapsedContainerMillis("container closed");
|
2018-04-24 12:21:28 -07:00
|
|
|
mIsOpen = false;
|
2016-09-28 16:47:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void handleClose(boolean animate);
|
|
|
|
|
|
2017-09-28 13:43:24 -07:00
|
|
|
public abstract void logActionCommand(int command);
|
2016-09-28 16:47:32 -07:00
|
|
|
|
|
|
|
|
public final boolean isOpen() {
|
|
|
|
|
return mIsOpen;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-20 17:12:24 -07:00
|
|
|
protected void onWidgetsBound() {
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 16:47:32 -07:00
|
|
|
protected abstract boolean isOfType(@FloatingViewType int type);
|
|
|
|
|
|
2017-09-28 13:43:24 -07:00
|
|
|
public void onBackPressed() {
|
|
|
|
|
logActionCommand(Action.Command.BACK);
|
|
|
|
|
close(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onControllerTouchEvent(MotionEvent ev) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 13:55:57 -07:00
|
|
|
protected void announceAccessibilityChanges() {
|
|
|
|
|
Pair<View, String> targetInfo = getAccessibilityTarget();
|
|
|
|
|
if (targetInfo == null || !isAccessibilityEnabled(getContext())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sendCustomAccessibilityEvent(
|
|
|
|
|
targetInfo.first, TYPE_WINDOW_STATE_CHANGED, targetInfo.second);
|
|
|
|
|
|
|
|
|
|
if (mIsOpen) {
|
|
|
|
|
sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
|
|
|
|
|
}
|
|
|
|
|
BaseDraggingActivity.fromContext(getContext()).getDragLayer()
|
|
|
|
|
.sendAccessibilityEvent(TYPE_WINDOW_CONTENT_CHANGED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Pair<View, String> getAccessibilityTarget() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 16:47:32 -07:00
|
|
|
protected static <T extends AbstractFloatingView> T getOpenView(
|
2018-03-14 12:30:11 -07:00
|
|
|
BaseDraggingActivity activity, @FloatingViewType int type) {
|
|
|
|
|
BaseDragLayer dragLayer = activity.getDragLayer();
|
2016-09-28 16:47:32 -07:00
|
|
|
// Iterate in reverse order. AbstractFloatingView is added later to the dragLayer,
|
|
|
|
|
// and will be one of the last views.
|
|
|
|
|
for (int i = dragLayer.getChildCount() - 1; i >= 0; i--) {
|
|
|
|
|
View child = dragLayer.getChildAt(i);
|
|
|
|
|
if (child instanceof AbstractFloatingView) {
|
|
|
|
|
AbstractFloatingView view = (AbstractFloatingView) child;
|
|
|
|
|
if (view.isOfType(type) && view.isOpen()) {
|
|
|
|
|
return (T) view;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
public static void closeOpenContainer(BaseDraggingActivity activity,
|
|
|
|
|
@FloatingViewType int type) {
|
|
|
|
|
AbstractFloatingView view = getOpenView(activity, type);
|
2016-09-28 16:47:32 -07:00
|
|
|
if (view != null) {
|
|
|
|
|
view.close(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
public static void closeOpenViews(BaseDraggingActivity activity, boolean animate,
|
2017-10-10 15:21:15 -07:00
|
|
|
@FloatingViewType int type) {
|
2018-03-14 12:30:11 -07:00
|
|
|
BaseDragLayer dragLayer = activity.getDragLayer();
|
2016-09-28 16:47:32 -07:00
|
|
|
// Iterate in reverse order. AbstractFloatingView is added later to the dragLayer,
|
|
|
|
|
// and will be one of the last views.
|
|
|
|
|
for (int i = dragLayer.getChildCount() - 1; i >= 0; i--) {
|
|
|
|
|
View child = dragLayer.getChildAt(i);
|
|
|
|
|
if (child instanceof AbstractFloatingView) {
|
2017-10-10 15:21:15 -07:00
|
|
|
AbstractFloatingView abs = (AbstractFloatingView) child;
|
|
|
|
|
if (abs.isOfType(type)) {
|
|
|
|
|
abs.close(animate);
|
|
|
|
|
}
|
2016-09-28 16:47:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
public static void closeAllOpenViews(BaseDraggingActivity activity, boolean animate) {
|
|
|
|
|
closeOpenViews(activity, animate, TYPE_ALL);
|
|
|
|
|
activity.finishAutoCancelActionMode();
|
2017-10-10 15:21:15 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
public static void closeAllOpenViews(BaseDraggingActivity activity) {
|
|
|
|
|
closeAllOpenViews(activity, true);
|
2016-09-28 16:47:32 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
public static AbstractFloatingView getTopOpenView(BaseDraggingActivity activity) {
|
2018-04-12 17:26:18 -07:00
|
|
|
return getTopOpenViewWithType(activity, TYPE_ALL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AbstractFloatingView getTopOpenViewWithType(BaseDraggingActivity activity,
|
|
|
|
|
@FloatingViewType int type) {
|
|
|
|
|
return getOpenView(activity, type);
|
2016-09-28 16:47:32 -07:00
|
|
|
}
|
|
|
|
|
}
|