Snap for 5030474 from 884f26bb33 to qt-release

Change-Id: I64c9b08250da4e2faaa20b7723b23fb0d0cbf882
This commit is contained in:
android-build-team Robot
2018-09-26 03:05:42 +00:00
59 changed files with 1000 additions and 647 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta05'
classpath 'com.android.tools.build:gradle:3.2.0-rc03'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
}
}
@@ -16,7 +16,7 @@ apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 28
buildToolsVersion '28.0.0'
buildToolsVersion '28.0.2'
defaultConfig {
minSdkVersion 21
-74
View File
@@ -2,80 +2,6 @@
*;
}
-keep class com.android.launcher3.allapps.AllAppsBackgroundDrawable {
public void setAlpha(int);
public int getAlpha();
}
-keep class com.android.launcher3.BaseRecyclerViewFastScrollBar {
public void setThumbWidth(int);
public int getThumbWidth();
public void setTrackWidth(int);
public int getTrackWidth();
}
-keep class com.android.launcher3.BaseRecyclerViewFastScrollPopup {
public void setAlpha(float);
public float getAlpha();
}
-keep class com.android.launcher3.ButtonDropTarget {
public int getTextColor();
}
-keep class com.android.launcher3.CellLayout {
public float getBackgroundAlpha();
public void setBackgroundAlpha(float);
}
-keep class com.android.launcher3.CellLayout$LayoutParams {
public void setWidth(int);
public int getWidth();
public void setHeight(int);
public int getHeight();
public void setX(int);
public int getX();
public void setY(int);
public int getY();
}
-keep class com.android.launcher3.views.BaseDragLayer$LayoutParams {
public void setWidth(int);
public int getWidth();
public void setHeight(int);
public int getHeight();
public void setX(int);
public int getX();
public void setY(int);
public int getY();
}
-keep class com.android.launcher3.FastBitmapDrawable {
public void setDesaturation(float);
public float getDesaturation();
public void setBrightness(float);
public float getBrightness();
}
-keep class com.android.launcher3.MemoryDumpActivity {
*;
}
-keep class com.android.launcher3.PreloadIconDrawable {
public float getAnimationProgress();
public void setAnimationProgress(float);
}
-keep class com.android.launcher3.pageindicators.CaretDrawable {
public float getCaretProgress();
public void setCaretProgress(float);
}
-keep class com.android.launcher3.Workspace {
public float getBackgroundAlpha();
public void setBackgroundAlpha(float);
}
# Proguard will strip new callbacks in LauncherApps.Callback from
# WrappedCallback if compiled against an older SDK. Don't let this happen.
-keep class com.android.launcher3.compat.** {
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2018 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.uioverrides;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import android.os.RemoteException;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.touch.TouchEventTranslator;
import com.android.launcher3.util.TouchController;
import com.android.quickstep.RecentsModel;
import com.android.systemui.shared.recents.ISystemUiProxy;
/**
* TouchController for handling touch events that get sent to the StatusBar. Once the
* Once the event delta y passes the touch slop, the events start getting forwarded.
* All events are offset by initial Y value of the pointer.
*/
public class StatusBarTouchController implements TouchController {
private static final String TAG = "StatusBarController";
protected final Launcher mLauncher;
protected final TouchEventTranslator mTranslator;
private final float mTouchSlop;
private ISystemUiProxy mSysUiProxy;
/* If {@code false}, this controller should not handle the input {@link MotionEvent}.*/
private boolean mCanIntercept;
public StatusBarTouchController(Launcher l) {
mLauncher = l;
mTouchSlop = ViewConfiguration.get(l).getScaledTouchSlop();
mTranslator = new TouchEventTranslator((MotionEvent ev)-> dispatchTouchEvent(ev));
}
private void dispatchTouchEvent(MotionEvent ev) {
try {
if (mSysUiProxy != null) {
mSysUiProxy.onStatusBarMotionEvent(ev);
}
} catch (RemoteException e) {
Log.e(TAG, "Remote exception on sysUiProxy.", e);
}
}
@Override
public final boolean onControllerInterceptTouchEvent(MotionEvent ev) {
int action = ev.getActionMasked();
if (action == ACTION_DOWN) {
mCanIntercept = canInterceptTouch(ev);
if (!mCanIntercept) {
return false;
}
mTranslator.reset();
mTranslator.setDownParameters(0, ev);
} else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
// Check!! should only set it only when threshold is not entered.
mTranslator.setDownParameters(ev.getActionIndex(), ev);
}
if (!mCanIntercept) {
return false;
}
if (action == ACTION_MOVE) {
float dy = ev.getY() - mTranslator.getDownY();
if (dy > mTouchSlop) {
mTranslator.dispatchDownEvents(ev);
mTranslator.processMotionEvent(ev);
return true;
}
}
return false;
}
@Override
public final boolean onControllerTouchEvent(MotionEvent ev) {
mTranslator.processMotionEvent(ev);
return true;
}
private boolean canInterceptTouch(MotionEvent ev) {
if (!mLauncher.isInState(LauncherState.NORMAL) ||
AbstractFloatingView.getTopOpenViewWithType(mLauncher,
AbstractFloatingView.TYPE_STATUS_BAR_SWIPE_DOWN_DISALLOW) != null) {
return false;
} else {
// For NORMAL state, only listen if the event originated above the navbar height
DeviceProfile dp = mLauncher.getDeviceProfile();
if (ev.getY() > (mLauncher.getDragLayer().getHeight() - dp.getInsets().bottom)) {
return false;
}
}
mSysUiProxy = RecentsModel.INSTANCE.get(mLauncher).getSystemUiProxy();
return mSysUiProxy != null;
}
}
@@ -42,6 +42,7 @@ import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.TouchController;
import com.android.quickstep.OverviewInteractionState;
import com.android.quickstep.RecentsModel;
@@ -52,6 +53,7 @@ import com.android.systemui.shared.system.WindowManagerWrapper;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.zip.Deflater;
public class UiFactory {
@@ -59,24 +61,25 @@ public class UiFactory {
public static TouchController[] createTouchControllers(Launcher launcher) {
boolean swipeUpEnabled = OverviewInteractionState.INSTANCE.get(launcher)
.isSwipeUpGestureEnabled();
if (!swipeUpEnabled) {
return new TouchController[] {
launcher.getDragController(),
new OverviewToAllAppsTouchController(launcher),
new LauncherTaskViewController(launcher)};
ArrayList<TouchController> list = new ArrayList<>();
list.add(launcher.getDragController());
if (!swipeUpEnabled || launcher.getDeviceProfile().isVerticalBarLayout()) {
list.add(new OverviewToAllAppsTouchController(launcher));
}
if (launcher.getDeviceProfile().isVerticalBarLayout()) {
return new TouchController[] {
launcher.getDragController(),
new OverviewToAllAppsTouchController(launcher),
new LandscapeEdgeSwipeController(launcher),
new LauncherTaskViewController(launcher)};
list.add(new LandscapeEdgeSwipeController(launcher));
} else {
return new TouchController[] {
launcher.getDragController(),
new PortraitStatesTouchController(launcher),
new LauncherTaskViewController(launcher)};
list.add(new PortraitStatesTouchController(launcher));
}
if (FeatureFlags.PULL_DOWN_STATUS_BAR && Utilities.IS_DEBUG_DEVICE
&& !launcher.getDeviceProfile().isMultiWindowMode
&& !launcher.getDeviceProfile().isVerticalBarLayout()) {
list.add(new StatusBarTouchController(launcher));
}
list.add(new LauncherTaskViewController(launcher));
return list.toArray(new TouchController[list.size()]);
}
public static void setOnTouchControllersChangedListener(Context context, Runnable listener) {
@@ -239,7 +239,7 @@ public class ClipAnimationHelper {
updateStackBoundsToMultiWindowTaskSize(activity);
} else {
mSourceStackBounds.set(mHomeStackBounds);
mSourceInsets.set(activity.getDeviceProfile().getInsets());
mSourceInsets.set(ttv.getInsets());
}
TransformedRect targetRect = new TransformedRect();
+1 -2
View File
@@ -114,8 +114,7 @@
<string name="action_move_here" msgid="2170188780612570250">"இங்கு நகர்த்து"</string>
<string name="item_added_to_workspace" msgid="4211073925752213539">"முகப்புத் திரையில் சேர்க்கப்பட்டது"</string>
<string name="item_removed" msgid="851119963877842327">"அகற்றப்பட்டது"</string>
<!-- no translation found for undo (4151576204245173321) -->
<skip />
<string name="undo" msgid="4151576204245173321">"செயல்தவிர்"</string>
<string name="action_move" msgid="4339390619886385032">"நகர்த்து"</string>
<string name="move_to_empty_cell" msgid="2833711483015685619">"<xliff:g id="NUMBER_0">%1$s</xliff:g> வரிசை, <xliff:g id="NUMBER_1">%2$s</xliff:g> நெடுவரிசைக்கு நகர்த்து"</string>
<string name="move_to_position" msgid="6750008980455459790">"நிலை <xliff:g id="NUMBER">%1$s</xliff:g>க்கு நகர்த்து"</string>
+2 -17
View File
@@ -79,27 +79,15 @@
<!-- Hotseat -->
<bool name="hotseat_transpose_layout_with_orientation">true</bool>
<!-- Name of a subclass of com.android.launcher3.AppFilter used to
filter the activities shown in the launcher. Can be empty. -->
<!-- Various classes overriden by projects/build flavors. -->
<string name="app_filter_class" translatable="false"></string>
<!-- Name of an icon provider class. -->
<string name="icon_provider_class" translatable="false"></string>
<!-- Name of a drawable factory class. -->
<string name="drawable_factory_class" translatable="false"></string>
<!-- Name of a user event dispatcher class. -->
<string name="user_event_dispatcher_class" translatable="false"></string>
<!-- Name of an app transition manager class. -->
<string name="app_transition_manager_class" translatable="false"></string>
<!-- Name of a subclass of com.android.launcher3.util.InstantAppResolver. Can be empty. -->
<string name="instant_app_resolver_class" translatable="false"></string>
<!-- Name of a main process initializer class. -->
<string name="main_process_initializer_class" translatable="false"></string>
<string name="system_shortcut_factory_class" translatable="false"></string>
<!-- Package name of the default wallpaper picker. -->
<string name="wallpaper_picker_package" translatable="false"></string>
@@ -113,9 +101,6 @@
<!-- View ID used by cell layout to jail its content -->
<item type="id" name="cell_layout_jail_id" />
<!-- Tag id used for view scrim -->
<item type="id" name="view_scrim" />
<!-- View IDs to store item highlight information -->
<item type="id" name="view_unhighlight_background" />
<item type="id" name="view_highlighted" />
@@ -91,6 +91,11 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch
public static final int TYPE_ACCESSIBLE = TYPE_ALL
& ~TYPE_DISCOVERY_BOUNCE & ~TYPE_QUICKSTEP_PREVIEW;
// These view all have particular operation associated with swipe down interaction.
public static final int TYPE_STATUS_BAR_SWIPE_DOWN_DISALLOW = TYPE_WIDGETS_BOTTOM_SHEET |
TYPE_WIDGETS_FULL_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_ON_BOARD_POPUP |
TYPE_DISCOVERY_BOUNCE | TYPE_TASK_MENU ;
protected boolean mIsOpen;
public AbstractFloatingView(Context context, AttributeSet attrs) {
@@ -26,6 +26,7 @@ import android.util.Log;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.ItemInfoMatcher;
@@ -1,5 +1,10 @@
package com.android.launcher3;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X;
import static com.android.launcher3.views.BaseDragLayer.LAYOUT_Y;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
@@ -429,10 +434,10 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
requestLayout();
} else {
ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp,
PropertyValuesHolder.ofInt("width", lp.width, newWidth),
PropertyValuesHolder.ofInt("height", lp.height, newHeight),
PropertyValuesHolder.ofInt("x", lp.x, newX),
PropertyValuesHolder.ofInt("y", lp.y, newY));
PropertyValuesHolder.ofInt(LAYOUT_WIDTH, lp.width, newWidth),
PropertyValuesHolder.ofInt(LAYOUT_HEIGHT, lp.height, newHeight),
PropertyValuesHolder.ofInt(LAYOUT_X, lp.x, newX),
PropertyValuesHolder.ofInt(LAYOUT_Y, lp.y, newY));
mFirstFrameAnimatorHelper.addTo(oa).addUpdateListener(a -> requestLayout());
AnimatorSet set = new AnimatorSet();
@@ -40,8 +40,8 @@ import android.view.ViewConfiguration;
import android.view.ViewDebug;
import android.widget.TextView;
import com.android.launcher3.IconCache.IconLoadRequest;
import com.android.launcher3.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.icons.IconCache.IconLoadRequest;
import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.Launcher.OnResumeCallback;
import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.badge.BadgeRenderer;
@@ -33,6 +33,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Property;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -55,6 +56,20 @@ import com.android.launcher3.util.Thunk;
public abstract class ButtonDropTarget extends TextView
implements DropTarget, DragController.DragListener, OnClickListener {
private static final Property<ButtonDropTarget, Integer> TEXT_COLOR =
new Property<ButtonDropTarget, Integer>(Integer.TYPE, "textColor") {
@Override
public Integer get(ButtonDropTarget target) {
return target.getTextColor();
}
@Override
public void set(ButtonDropTarget target, Integer value) {
target.setTextColor(value);
}
};
private static final int[] sTempCords = new int[2];
private static final int DRAG_VIEW_DROP_DURATION = 285;
@@ -206,7 +221,7 @@ public abstract class ButtonDropTarget extends TextView
});
mCurrentColorAnim.play(anim1);
mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, TEXT_COLOR, targetColor));
mCurrentColorAnim.start();
}
-32
View File
@@ -2678,38 +2678,6 @@ public class CellLayout extends ViewGroup {
public String toString() {
return "(" + this.cellX + ", " + this.cellY + ")";
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return width;
}
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return height;
}
public void setX(int x) {
this.x = x;
}
public int getX() {
return x;
}
public void setY(int y) {
this.y = y;
}
public int getY() {
return y;
}
}
// This class stores info for two purposes:
@@ -68,7 +68,7 @@ public class InsettableFrameLayout extends FrameLayout implements Insettable {
}
public static class LayoutParams extends FrameLayout.LayoutParams {
boolean ignoreInsets = false;
public boolean ignoreInsets = false;
public LayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
+1 -11
View File
@@ -87,6 +87,7 @@ import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.FolderIconPreviewVerifier;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.keyboard.CustomActionsPopup;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.logging.FileLog;
@@ -867,17 +868,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
}
public boolean hasSettings() {
if (mLauncherCallbacks != null) {
return mLauncherCallbacks.hasSettings();
} else {
// On O and above we there is always some setting present settings (add icon to
// home screen or icon badging). On earlier APIs we will have the allow rotation
// setting, on devices with a locked orientation,
return Utilities.ATLEAST_OREO || !getResources().getBoolean(R.bool.allow_rotation);
}
}
public boolean isInState(LauncherState state) {
return mStateManager.getState() == state;
}
@@ -19,6 +19,7 @@ package com.android.launcher3;
import android.graphics.drawable.Drawable;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
public class LauncherAnimUtils {
/**
@@ -64,4 +65,30 @@ public class LauncherAnimUtils {
public static int blockedFlingDurationFactor(float velocity) {
return (int) Utilities.boundToRange(Math.abs(velocity) / 2, 2f, 6f);
}
public static final Property<LayoutParams, Integer> LAYOUT_WIDTH =
new Property<LayoutParams, Integer>(Integer.TYPE, "width") {
@Override
public Integer get(LayoutParams lp) {
return lp.width;
}
@Override
public void set(LayoutParams lp, Integer width) {
lp.width = width;
}
};
public static final Property<LayoutParams, Integer> LAYOUT_HEIGHT =
new Property<LayoutParams, Integer>(Integer.TYPE, "height") {
@Override
public Integer get(LayoutParams lp) {
return lp.height;
}
@Override
public void set(LayoutParams lp, Integer height) {
lp.height = height;
}
};
}
@@ -29,6 +29,7 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.Preconditions;
@@ -39,6 +39,7 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.AddWorkspaceItemsTask;
import com.android.launcher3.model.BaseModelUpdateTask;
import com.android.launcher3.model.BgDataModel;
@@ -88,6 +88,11 @@ public class SettingsActivity extends Activity
@Override
public boolean onPreferenceStartFragment(
PreferenceFragment preferenceFragment, Preference pref) {
if (getFragmentManager().isStateSaved()) {
// Sometimes onClick can come after onPause because of being posted on the handler.
// Skip starting new fragments in that case.
return false;
}
Fragment f = Fragment.instantiate(this, pref.getFragment(), pref.getExtras());
if (f instanceof DialogFragment) {
((DialogFragment) f).show(getFragmentManager(), pref.getKey());
@@ -241,8 +246,7 @@ public class SettingsActivity extends Activity
* Content observer which listens for system badging setting changes,
* and updates the launcher badging setting subtext accordingly.
*/
private static class IconBadgingObserver extends SettingsObserver.Secure
implements Preference.OnPreferenceClickListener {
private static class IconBadgingObserver extends SettingsObserver.Secure {
private final ButtonPreference mBadgingPref;
private final ContentResolver mResolver;
@@ -275,16 +279,11 @@ public class SettingsActivity extends Activity
}
}
mBadgingPref.setWidgetFrameVisible(!serviceEnabled);
mBadgingPref.setOnPreferenceClickListener(serviceEnabled ? null : this);
mBadgingPref.setFragment(
serviceEnabled ? null : NotificationAccessConfirmation.class.getName());
mBadgingPref.setSummary(summary);
}
@Override
public boolean onPreferenceClick(Preference preference) {
new NotificationAccessConfirmation().show(mFragmentManager, "notification_access");
return true;
}
}
public static class NotificationAccessConfirmation
@@ -25,6 +25,7 @@ import android.text.TextUtils;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.ContentWriter;
@@ -33,6 +33,7 @@ import com.android.launcher3.compat.ShortcutConfigActivityInfo;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.graphics.ShadowGenerator;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageUserKey;
+1 -4
View File
@@ -671,9 +671,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
final boolean stripEmptyScreens) {
// XXX: Do we need to update LM workspace screens below?
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f);
final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);
mRemoveEmptyScreenRunnable = new Runnable() {
@@ -692,7 +689,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
};
ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha);
ObjectAnimator oa = ObjectAnimator.ofFloat(cl, ALPHA, 0f);
oa.setDuration(duration);
oa.setStartDelay(delay);
oa.addListener(new AnimatorListenerAdapter() {
@@ -27,7 +27,7 @@ import android.os.UserHandle;
import android.text.TextUtils;
import android.util.SparseArray;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.config.FeatureFlags;
@@ -32,7 +32,7 @@ import android.os.UserHandle;
import android.util.Log;
import android.widget.Toast;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
@@ -36,6 +36,10 @@ abstract class BaseFlags {
// Feature flag to enable moving the QSB on the 0th screen of the workspace.
public static final boolean QSB_ON_FIRST_SCREEN = true;
//Feature flag to enable pulling down navigation shade from workspace.
public static final boolean PULL_DOWN_STATUS_BAR = true;
// When enabled the all-apps icon is not added to the hotseat.
public static final boolean NO_ALL_APPS_ICON = true;
@@ -47,7 +47,6 @@ import com.android.launcher3.Workspace;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.ViewScrim;
import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.uioverrides.UiFactory;
@@ -124,15 +123,6 @@ public class DragLayer extends BaseDragLayer<Launcher> {
return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
ViewScrim scrim = ViewScrim.get(child);
if (scrim != null) {
scrim.draw(canvas, getWidth(), getHeight());
}
return super.drawChild(canvas, child, drawingTime);
}
@Override
protected boolean findActiveController(MotionEvent ev) {
if (mActivity.getStateManager().getState().disableInteraction) {
@@ -28,7 +28,7 @@ import android.os.Build;
import android.os.Process;
import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
@@ -1,65 +0,0 @@
/*
* Copyright (C) 2018 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.graphics;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
import android.view.animation.Interpolator;
import com.android.launcher3.R;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
import androidx.core.graphics.ColorUtils;
/**
* Simple scrim which draws a color
*/
public class ColorScrim extends ViewScrim {
private final int mColor;
private final Interpolator mInterpolator;
private int mCurrentColor;
public ColorScrim(View view, int color, Interpolator interpolator) {
super(view);
mColor = color;
mInterpolator = interpolator;
}
@Override
protected void onProgressChanged() {
mCurrentColor = ColorUtils.setAlphaComponent(mColor,
Math.round(mInterpolator.getInterpolation(mProgress) * Color.alpha(mColor)));
}
@Override
public void draw(Canvas canvas, int width, int height) {
if (mProgress > 0) {
canvas.drawColor(mCurrentColor);
}
}
public static ColorScrim createExtractedColorScrim(View view) {
WallpaperColorInfo colors = WallpaperColorInfo.getInstance(view.getContext());
int alpha = view.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
ColorScrim scrim = new ColorScrim(view, ColorUtils.setAlphaComponent(
colors.getSecondaryColor(), alpha), Interpolators.LINEAR);
scrim.attach();
return scrim;
}
}
@@ -44,7 +44,7 @@ import android.os.UserHandle;
import com.android.launcher3.AppInfo;
import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.LauncherAppState;
@@ -1,77 +0,0 @@
/*
* Copyright (C) 2018 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.graphics;
import android.graphics.Canvas;
import android.util.Property;
import android.view.View;
import android.view.ViewParent;
import com.android.launcher3.R;
/**
* A utility class that can be used to draw a scrim behind a view
*/
public abstract class ViewScrim<T extends View> {
public static Property<ViewScrim, Float> PROGRESS =
new Property<ViewScrim, Float>(Float.TYPE, "progress") {
@Override
public Float get(ViewScrim viewScrim) {
return viewScrim.mProgress;
}
@Override
public void set(ViewScrim object, Float value) {
object.setProgress(value);
}
};
protected final T mView;
protected float mProgress = 0;
public ViewScrim(T view) {
mView = view;
}
public void attach() {
mView.setTag(R.id.view_scrim, this);
}
public void setProgress(float progress) {
if (mProgress != progress) {
mProgress = progress;
onProgressChanged();
invalidate();
}
}
public abstract void draw(Canvas canvas, int width, int height);
protected void onProgressChanged() { }
public void invalidate() {
ViewParent parent = mView.getParent();
if (parent != null) {
((View) parent).invalidate();
}
}
public static ViewScrim get(View view) {
return (ViewScrim) view.getTag(R.id.view_scrim);
}
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.launcher3;
package com.android.launcher3.icons;
import static com.android.launcher3.graphics.BitmapInfo.LOW_RES_ICON;
@@ -38,11 +38,19 @@ import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Process;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.AppInfo;
import com.android.launcher3.IconProvider;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.LauncherFiles;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.graphics.BitmapInfo;
@@ -54,14 +62,9 @@ import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Provider;
import com.android.launcher3.util.SQLiteCacheHelper;
import com.android.launcher3.util.Thunk;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import androidx.annotation.NonNull;
import androidx.core.graphics.ColorUtils;
@@ -81,8 +84,6 @@ public class IconCache {
private static final boolean DEBUG = false;
private static final boolean DEBUG_IGNORE_CACHE = false;
@Thunk static final Object ICON_UPDATE_TOKEN = new Object();
public static class CacheEntry extends BitmapInfo {
public CharSequence title = "";
public CharSequence contentDescription = "";
@@ -93,20 +94,21 @@ public class IconCache {
}
private final HashMap<UserHandle, BitmapInfo> mDefaultIcons = new HashMap<>();
@Thunk final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
private final Context mContext;
private final PackageManager mPackageManager;
private final IconProvider mIconProvider;
@Thunk final UserManagerCompat mUserManager;
private final LauncherAppsCompat mLauncherApps;
final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
final Context mContext;
final PackageManager mPackageManager;
final IconProvider mIconProvider;
final UserManagerCompat mUserManager;
final LauncherAppsCompat mLauncherApps;
private final HashMap<ComponentKey, CacheEntry> mCache =
new HashMap<>(INITIAL_ICON_CACHE_CAPACITY);
private final InstantAppResolver mInstantAppResolver;
private final int mIconDpi;
@Thunk final IconDB mIconDb;
@Thunk final Handler mWorkerHandler;
final IconDB mIconDb;
final Handler mWorkerHandler;
private final BitmapFactory.Options mDecodeOptions;
@@ -247,115 +249,9 @@ public class IconCache {
new String[]{packageName + "/%", Long.toString(userSerial)});
}
public void updateDbIcons(Set<String> ignorePackagesForMainUser) {
// Remove all active icon update tasks.
mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN);
public IconCacheUpdateHandler getUpdateHandler() {
mIconProvider.updateSystemStateString(mContext);
for (UserHandle user : mUserManager.getUserProfiles()) {
// Query for the set of apps
final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
// Fail if we don't have any apps
// TODO: Fix this. Only fail for the current user.
if (apps == null || apps.isEmpty()) {
return;
}
// Update icon cache. This happens in segments and {@link #onPackageIconsUpdated}
// is called by the icon cache when the job is complete.
updateDBIcons(user, apps, Process.myUserHandle().equals(user)
? ignorePackagesForMainUser : Collections.<String>emptySet());
}
}
/**
* Updates the persistent DB, such that only entries corresponding to {@param apps} remain in
* the DB and are updated.
* @return The set of packages for which icons have updated.
*/
private void updateDBIcons(UserHandle user, List<LauncherActivityInfo> apps,
Set<String> ignorePackages) {
long userSerial = mUserManager.getSerialNumberForUser(user);
PackageManager pm = mContext.getPackageManager();
HashMap<String, PackageInfo> pkgInfoMap = new HashMap<>();
for (PackageInfo info : pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
pkgInfoMap.put(info.packageName, info);
}
HashMap<ComponentName, LauncherActivityInfo> componentMap = new HashMap<>();
for (LauncherActivityInfo app : apps) {
componentMap.put(app.getComponentName(), app);
}
HashSet<Integer> itemsToRemove = new HashSet<>();
Stack<LauncherActivityInfo> appsToUpdate = new Stack<>();
Cursor c = null;
try {
c = mIconDb.query(
new String[]{IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT,
IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION,
IconDB.COLUMN_SYSTEM_STATE},
IconDB.COLUMN_USER + " = ? ",
new String[]{Long.toString(userSerial)});
final int indexComponent = c.getColumnIndex(IconDB.COLUMN_COMPONENT);
final int indexLastUpdate = c.getColumnIndex(IconDB.COLUMN_LAST_UPDATED);
final int indexVersion = c.getColumnIndex(IconDB.COLUMN_VERSION);
final int rowIndex = c.getColumnIndex(IconDB.COLUMN_ROWID);
final int systemStateIndex = c.getColumnIndex(IconDB.COLUMN_SYSTEM_STATE);
while (c.moveToNext()) {
String cn = c.getString(indexComponent);
ComponentName component = ComponentName.unflattenFromString(cn);
PackageInfo info = pkgInfoMap.get(component.getPackageName());
if (info == null) {
if (!ignorePackages.contains(component.getPackageName())) {
remove(component, user);
itemsToRemove.add(c.getInt(rowIndex));
}
continue;
}
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_IS_DATA_ONLY) != 0) {
// Application is not present
continue;
}
long updateTime = c.getLong(indexLastUpdate);
int version = c.getInt(indexVersion);
LauncherActivityInfo app = componentMap.remove(component);
if (version == info.versionCode && updateTime == info.lastUpdateTime &&
TextUtils.equals(c.getString(systemStateIndex),
mIconProvider.getIconSystemState(info.packageName))) {
continue;
}
if (app == null) {
remove(component, user);
itemsToRemove.add(c.getInt(rowIndex));
} else {
appsToUpdate.add(app);
}
}
} catch (SQLiteException e) {
Log.d(TAG, "Error reading icon cache", e);
// Continue updating whatever we have read so far
} finally {
if (c != null) {
c.close();
}
}
if (!itemsToRemove.isEmpty()) {
mIconDb.delete(
Utilities.createDbSelectionQuery(IconDB.COLUMN_ROWID, itemsToRemove), null);
}
// Insert remaining apps.
if (!componentMap.isEmpty() || !appsToUpdate.isEmpty()) {
Stack<LauncherActivityInfo> appsToAdd = new Stack<>();
appsToAdd.addAll(componentMap.values());
new SerializedIconUpdateTask(userSerial, pkgInfoMap,
appsToAdd, appsToUpdate).scheduleNext();
}
return new IconCacheUpdateHandler(this);
}
/**
@@ -363,8 +259,9 @@ public class IconCache {
* @param replaceExisting if true, it will recreate the bitmap even if it already exists in
* the memory. This is useful then the previous bitmap was created using
* old data.
* package private
*/
@Thunk synchronized void addIconToDBAndMemCache(LauncherActivityInfo app,
synchronized void addIconToDBAndMemCache(LauncherActivityInfo app,
PackageInfo info, long userSerial, boolean replaceExisting) {
final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
CacheEntry entry = null;
@@ -744,81 +641,23 @@ public class IconCache {
}
}
/**
* A runnable that updates invalid icons and adds missing icons in the DB for the provided
* LauncherActivityInfo list. Items are updated/added one at a time, so that the
* worker thread doesn't get blocked.
*/
@Thunk class SerializedIconUpdateTask implements Runnable {
private final long mUserSerial;
private final HashMap<String, PackageInfo> mPkgInfoMap;
private final Stack<LauncherActivityInfo> mAppsToAdd;
private final Stack<LauncherActivityInfo> mAppsToUpdate;
private final HashSet<String> mUpdatedPackages = new HashSet<>();
@Thunk SerializedIconUpdateTask(long userSerial, HashMap<String, PackageInfo> pkgInfoMap,
Stack<LauncherActivityInfo> appsToAdd,
Stack<LauncherActivityInfo> appsToUpdate) {
mUserSerial = userSerial;
mPkgInfoMap = pkgInfoMap;
mAppsToAdd = appsToAdd;
mAppsToUpdate = appsToUpdate;
}
@Override
public void run() {
if (!mAppsToUpdate.isEmpty()) {
LauncherActivityInfo app = mAppsToUpdate.pop();
String pkg = app.getComponentName().getPackageName();
PackageInfo info = mPkgInfoMap.get(pkg);
addIconToDBAndMemCache(app, info, mUserSerial, true /*replace existing*/);
mUpdatedPackages.add(pkg);
if (mAppsToUpdate.isEmpty() && !mUpdatedPackages.isEmpty()) {
// No more app to update. Notify model.
LauncherAppState.getInstance(mContext).getModel().onPackageIconsUpdated(
mUpdatedPackages, mUserManager.getUserForSerialNumber(mUserSerial));
}
// Let it run one more time.
scheduleNext();
} else if (!mAppsToAdd.isEmpty()) {
LauncherActivityInfo app = mAppsToAdd.pop();
PackageInfo info = mPkgInfoMap.get(app.getComponentName().getPackageName());
// We do not check the mPkgInfoMap when generating the mAppsToAdd. Although every
// app should have package info, this is not guaranteed by the api
if (info != null) {
addIconToDBAndMemCache(app, info, mUserSerial, false /*replace existing*/);
}
if (!mAppsToAdd.isEmpty()) {
scheduleNext();
}
}
}
public void scheduleNext() {
mWorkerHandler.postAtTime(this, ICON_UPDATE_TOKEN, SystemClock.uptimeMillis() + 1);
}
}
private static final class IconDB extends SQLiteCacheHelper {
static final class IconDB extends SQLiteCacheHelper {
private final static int RELEASE_VERSION = 25;
private final static String TABLE_NAME = "icons";
private final static String COLUMN_ROWID = "rowid";
private final static String COLUMN_COMPONENT = "componentName";
private final static String COLUMN_USER = "profileId";
private final static String COLUMN_LAST_UPDATED = "lastUpdated";
private final static String COLUMN_VERSION = "version";
private final static String COLUMN_ICON = "icon";
private final static String COLUMN_ICON_COLOR = "icon_color";
private final static String COLUMN_LABEL = "label";
private final static String COLUMN_SYSTEM_STATE = "system_state";
public final static String TABLE_NAME = "icons";
public final static String COLUMN_ROWID = "rowid";
public final static String COLUMN_COMPONENT = "componentName";
public final static String COLUMN_USER = "profileId";
public final static String COLUMN_LAST_UPDATED = "lastUpdated";
public final static String COLUMN_VERSION = "version";
public final static String COLUMN_ICON = "icon";
public final static String COLUMN_ICON_COLOR = "icon_color";
public final static String COLUMN_LABEL = "label";
public final static String COLUMN_SYSTEM_STATE = "system_state";
private final static String[] COLUMNS_HIGH_RES = new String[] {
public final static String[] COLUMNS_HIGH_RES = new String[] {
IconDB.COLUMN_ICON_COLOR, IconDB.COLUMN_LABEL, IconDB.COLUMN_ICON };
private final static String[] COLUMNS_LOW_RES = new String[] {
public final static String[] COLUMNS_LOW_RES = new String[] {
IconDB.COLUMN_ICON_COLOR, IconDB.COLUMN_LABEL };
public IconDB(Context context, int iconPixelSize) {
@@ -0,0 +1,223 @@
/*
* Copyright (C) 2018 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.icons;
import android.content.ComponentName;
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.Utilities;
import com.android.launcher3.icons.IconCache.IconDB;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Stack;
/**
* Utility class to handle updating the Icon cache
*/
public class IconCacheUpdateHandler {
private static final String TAG = "IconCacheUpdateHandler";
private static final Object ICON_UPDATE_TOKEN = new Object();
private final HashMap<String, PackageInfo> mPkgInfoMap;
private final IconCache mIconCache;
private final HashMap<UserHandle, Set<String>> mPackagesToIgnore = new HashMap<>();
IconCacheUpdateHandler(IconCache cache) {
mIconCache = cache;
mPkgInfoMap = new HashMap<>();
// Remove all active icon update tasks.
mIconCache.mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN);
createPackageInfoMap();
}
public void setPackagesToIgnore(UserHandle userHandle, Set<String> packages) {
mPackagesToIgnore.put(userHandle, packages);
}
private void createPackageInfoMap() {
PackageManager pm = mIconCache.mPackageManager;
HashMap<String, PackageInfo> pkgInfoMap = new HashMap<>();
for (PackageInfo info : pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
pkgInfoMap.put(info.packageName, info);
}
}
/**
* Updates the persistent DB, such that only entries corresponding to {@param apps} remain in
* the DB and are updated.
* @return The set of packages for which icons have updated.
*/
public void updateIcons(List<LauncherActivityInfo> apps) {
if (apps.isEmpty()) {
return;
}
UserHandle user = apps.get(0).getUser();
Set<String> ignorePackages = mPackagesToIgnore.get(user);
if (ignorePackages == null) {
ignorePackages = Collections.emptySet();
}
long userSerial = mIconCache.mUserManager.getSerialNumberForUser(user);
HashMap<ComponentName, LauncherActivityInfo> componentMap = new HashMap<>();
for (LauncherActivityInfo app : apps) {
componentMap.put(app.getComponentName(), app);
}
HashSet<Integer> itemsToRemove = new HashSet<>();
Stack<LauncherActivityInfo> appsToUpdate = new Stack<>();
try (Cursor c = mIconCache.mIconDb.query(
new String[]{IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT,
IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION,
IconDB.COLUMN_SYSTEM_STATE},
IconDB.COLUMN_USER + " = ? ",
new String[]{Long.toString(userSerial)})) {
final int indexComponent = c.getColumnIndex(IconDB.COLUMN_COMPONENT);
final int indexLastUpdate = c.getColumnIndex(IconDB.COLUMN_LAST_UPDATED);
final int indexVersion = c.getColumnIndex(IconDB.COLUMN_VERSION);
final int rowIndex = c.getColumnIndex(IconDB.COLUMN_ROWID);
final int systemStateIndex = c.getColumnIndex(IconDB.COLUMN_SYSTEM_STATE);
while (c.moveToNext()) {
String cn = c.getString(indexComponent);
ComponentName component = ComponentName.unflattenFromString(cn);
PackageInfo info = mPkgInfoMap.get(component.getPackageName());
if (info == null) {
if (!ignorePackages.contains(component.getPackageName())) {
mIconCache.remove(component, user);
itemsToRemove.add(c.getInt(rowIndex));
}
continue;
}
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_IS_DATA_ONLY) != 0) {
// Application is not present
continue;
}
long updateTime = c.getLong(indexLastUpdate);
int version = c.getInt(indexVersion);
LauncherActivityInfo app = componentMap.remove(component);
if (version == info.versionCode && updateTime == info.lastUpdateTime &&
TextUtils.equals(c.getString(systemStateIndex),
mIconCache.mIconProvider.getIconSystemState(info.packageName))) {
continue;
}
if (app == null) {
mIconCache.remove(component, user);
itemsToRemove.add(c.getInt(rowIndex));
} else {
appsToUpdate.add(app);
}
}
} catch (SQLiteException e) {
Log.d(TAG, "Error reading icon cache", e);
// Continue updating whatever we have read so far
}
if (!itemsToRemove.isEmpty()) {
mIconCache.mIconDb.delete(
Utilities.createDbSelectionQuery(IconDB.COLUMN_ROWID, itemsToRemove), null);
}
// Insert remaining apps.
if (!componentMap.isEmpty() || !appsToUpdate.isEmpty()) {
Stack<LauncherActivityInfo> appsToAdd = new Stack<>();
appsToAdd.addAll(componentMap.values());
new SerializedIconUpdateTask(userSerial, user, appsToAdd, appsToUpdate).scheduleNext();
}
}
/**
* A runnable that updates invalid icons and adds missing icons in the DB for the provided
* LauncherActivityInfo list. Items are updated/added one at a time, so that the
* worker thread doesn't get blocked.
*/
private class SerializedIconUpdateTask implements Runnable {
private final long mUserSerial;
private final UserHandle mUserHandle;
private final Stack<LauncherActivityInfo> mAppsToAdd;
private final Stack<LauncherActivityInfo> mAppsToUpdate;
private final HashSet<String> mUpdatedPackages = new HashSet<>();
SerializedIconUpdateTask(long userSerial, UserHandle userHandle,
Stack<LauncherActivityInfo> appsToAdd, Stack<LauncherActivityInfo> appsToUpdate) {
mUserHandle = userHandle;
mUserSerial = userSerial;
mAppsToAdd = appsToAdd;
mAppsToUpdate = appsToUpdate;
}
@Override
public void run() {
if (!mAppsToUpdate.isEmpty()) {
LauncherActivityInfo app = mAppsToUpdate.pop();
String pkg = app.getComponentName().getPackageName();
PackageInfo info = mPkgInfoMap.get(pkg);
mIconCache.addIconToDBAndMemCache(
app, info, mUserSerial, true /*replace existing*/);
mUpdatedPackages.add(pkg);
if (mAppsToUpdate.isEmpty() && !mUpdatedPackages.isEmpty()) {
// No more app to update. Notify model.
LauncherAppState.getInstance(mIconCache.mContext).getModel()
.onPackageIconsUpdated(mUpdatedPackages, mUserHandle);
}
// Let it run one more time.
scheduleNext();
} else if (!mAppsToAdd.isEmpty()) {
LauncherActivityInfo app = mAppsToAdd.pop();
PackageInfo info = mPkgInfoMap.get(app.getComponentName().getPackageName());
// We do not check the mPkgInfoMap when generating the mAppsToAdd. Although every
// app should have package info, this is not guaranteed by the api
if (info != null) {
mIconCache.addIconToDBAndMemCache(
app, info, mUserSerial, false /*replace existing*/);
}
if (!mAppsToAdd.isEmpty()) {
scheduleNext();
}
}
}
public void scheduleNext() {
mIconCache.mWorkerHandler.postAtTime(this, ICON_UPDATE_TOKEN,
SystemClock.uptimeMillis() + 1);
}
}
}
@@ -20,7 +20,7 @@ import android.os.UserHandle;
import com.android.launcher3.AllAppsList;
import com.android.launcher3.AppInfo;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.CallbackTask;
@@ -32,7 +32,7 @@ import android.util.Log;
import android.util.LongSparseArray;
import com.android.launcher3.AppInfo;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
@@ -43,7 +43,8 @@ import android.util.MutableInt;
import com.android.launcher3.AllAppsList;
import com.android.launcher3.AppInfo;
import com.android.launcher3.FolderInfo;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCacheUpdateHandler;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InstallShortcutReceiver;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
@@ -182,7 +183,7 @@ public class LoaderTask implements Runnable {
// second step
TraceHelper.partitionSection(TAG, "step 2.1: loading all apps");
loadAllApps();
List<List<LauncherActivityInfo>> activityListPerUser = loadAllApps();
TraceHelper.partitionSection(TAG, "step 2.2: Binding all apps");
verifyNotStopped();
@@ -190,7 +191,9 @@ public class LoaderTask implements Runnable {
verifyNotStopped();
TraceHelper.partitionSection(TAG, "step 2.3: Update icon cache");
updateIconCache();
IconCacheUpdateHandler updateHandler = mIconCache.getUpdateHandler();
setIgnorePackages(updateHandler);
updateIconCacheForApps(updateHandler, activityListPerUser);
// Take a break
TraceHelper.partitionSection(TAG, "step 2 completed, wait for idle");
@@ -774,7 +777,7 @@ public class LoaderTask implements Runnable {
}
}
private void updateIconCache() {
private void setIgnorePackages(IconCacheUpdateHandler updateHandler) {
// Ignore packages which have a promise icon.
HashSet<String> packagesToIgnore = new HashSet<>();
synchronized (mBgDataModel) {
@@ -792,12 +795,20 @@ public class LoaderTask implements Runnable {
}
}
}
mIconCache.updateDbIcons(packagesToIgnore);
updateHandler.setPackagesToIgnore(Process.myUserHandle(), packagesToIgnore);
}
private void loadAllApps() {
final List<UserHandle> profiles = mUserManager.getUserProfiles();
private void updateIconCacheForApps(IconCacheUpdateHandler updateHandler,
List<List<LauncherActivityInfo>> activityListPerUser) {
int userCount = activityListPerUser.size();
for (int i = 0; i < userCount; i++) {
updateHandler.updateIcons(activityListPerUser.get(i));
}
}
private List<List<LauncherActivityInfo>> loadAllApps() {
final List<UserHandle> profiles = mUserManager.getUserProfiles();
List<List<LauncherActivityInfo>> activityListPerUser = new ArrayList<>();
// Clear the list of apps
mBgAllAppsList.clear();
for (UserHandle user : profiles) {
@@ -806,7 +817,7 @@ public class LoaderTask implements Runnable {
// Fail if we don't have any apps
// TODO: Fix this. Only fail for the current user.
if (apps == null || apps.isEmpty()) {
return;
return activityListPerUser;
}
boolean quietMode = mUserManager.isQuietModeEnabled(user);
// Create the ApplicationInfos
@@ -815,6 +826,7 @@ public class LoaderTask implements Runnable {
// This builds the icon bitmaps.
mBgAllAppsList.add(new AppInfo(app, user, quietMode), app);
}
activityListPerUser.add(apps);
}
if (FeatureFlags.LAUNCHER3_PROMISE_APPS_IN_ALL_APPS) {
@@ -827,6 +839,7 @@ public class LoaderTask implements Runnable {
}
mBgAllAppsList.added = new ArrayList<>();
return activityListPerUser;
}
private void loadDeepShortcuts() {
@@ -24,7 +24,7 @@ import android.util.Log;
import com.android.launcher3.AllAppsList;
import com.android.launcher3.AppInfo;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InstallShortcutReceiver;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
@@ -11,7 +11,7 @@ import android.os.UserHandle;
import android.util.Log;
import com.android.launcher3.AppFilter;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
@@ -184,17 +184,10 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource,
return null;
}
PopupDataProvider popupDataProvider = launcher.getPopupDataProvider();
List<String> shortcutIds = popupDataProvider.getShortcutIdsForItem(itemInfo);
List<NotificationKeyData> notificationKeys = popupDataProvider
.getNotificationKeysForItem(itemInfo);
List<SystemShortcut> systemShortcuts = popupDataProvider
.getEnabledSystemShortcutsForItem(itemInfo);
final PopupContainerWithArrow container =
(PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
R.layout.popup_container, launcher.getDragLayer(), false);
container.populateAndShow(icon, shortcutIds, notificationKeys, systemShortcuts);
container.populateAndShow(icon, itemInfo, SystemShortcutFactory.INSTANCE.get(launcher));
return container;
}
@@ -219,6 +212,15 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource,
}
}
protected void populateAndShow(
BubbleTextView icon, ItemInfo item, SystemShortcutFactory factory) {
PopupDataProvider popupDataProvider = mLauncher.getPopupDataProvider();
populateAndShow(icon,
popupDataProvider.getShortcutIdsForItem(item),
popupDataProvider.getNotificationKeysForItem(item),
factory.getEnabledShortcuts(mLauncher, item));
}
@TargetApi(Build.VERSION_CODES.P)
protected void populateAndShow(final BubbleTextView originalIcon, final List<String> shortcutIds,
final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) {
@@ -50,13 +50,6 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
private static final boolean LOGD = false;
private static final String TAG = "PopupDataProvider";
/** Note that these are in order of priority. */
private static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] {
new SystemShortcut.AppInfo(),
new SystemShortcut.Widgets(),
new SystemShortcut.Install()
};
private final Launcher mLauncher;
/** Maps launcher activity components to their list of shortcut ids. */
@@ -192,16 +185,6 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
: notificationListener.getNotificationsForKeys(notificationKeys);
}
public @NonNull List<SystemShortcut> getEnabledSystemShortcutsForItem(ItemInfo info) {
List<SystemShortcut> systemShortcuts = new ArrayList<>();
for (SystemShortcut systemShortcut : SYSTEM_SHORTCUTS) {
if (systemShortcut.getOnClickListener(mLauncher, info) != null) {
systemShortcuts.add(systemShortcut);
}
}
return systemShortcuts;
}
public void cancelNotification(String notificationKey) {
NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
if (notificationListener == null) {
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2018 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.popup;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.ResourceBasedOverride;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
public class SystemShortcutFactory implements ResourceBasedOverride {
public static final MainThreadInitializedObject<SystemShortcutFactory> INSTANCE =
new MainThreadInitializedObject<>(c -> Overrides.getObject(
SystemShortcutFactory.class, c, R.string.system_shortcut_factory_class));
/** Note that these are in order of priority. */
private final SystemShortcut[] mAllShortcuts;
@SuppressWarnings("unused")
public SystemShortcutFactory() {
this(new SystemShortcut.AppInfo(),
new SystemShortcut.Widgets(), new SystemShortcut.Install());
}
protected SystemShortcutFactory(SystemShortcut... shortcuts) {
mAllShortcuts = shortcuts;
}
public @NonNull List<SystemShortcut> getEnabledShortcuts(Launcher launcher, ItemInfo info) {
List<SystemShortcut> systemShortcuts = new ArrayList<>();
for (SystemShortcut systemShortcut : mAllShortcuts) {
if (systemShortcut.getOnClickListener(launcher, info) != null) {
systemShortcuts.add(systemShortcut);
}
}
return systemShortcuts;
}
}
@@ -56,7 +56,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
private final Activity mActivity;
private final SharedPreferences mPrefs;
private final boolean mIgnoreAutoRotateSettings;
private boolean mIgnoreAutoRotateSettings;
private boolean mAutoRotateEnabled;
/**
@@ -110,6 +110,13 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
}
}
// Used by tests only.
public void forceAllowRotationForTesting(boolean allowRotation) {
mIgnoreAutoRotateSettings =
allowRotation || mActivity.getResources().getBoolean(R.bool.allow_rotation);
notifyChange();
}
public void initialize() {
if (!mInitialized) {
mInitialized = true;
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 The Android Open Source Project
* Copyright (C) 2018 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.
@@ -0,0 +1,274 @@
/*
* Copyright (C) 2018 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.touch;
import android.graphics.PointF;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseLongArray;
import android.view.MotionEvent;
import android.view.MotionEvent.PointerCoords;
import android.view.MotionEvent.PointerProperties;
import com.android.launcher3.Utilities.Consumer;
/**
* To minimize the size of the MotionEvent, historic events are not copied and passed via the
* listener.
*/
public class TouchEventTranslator {
private static final String TAG = "TouchEventTranslator";
private static final boolean DEBUG = false;
private class DownState {
long timeStamp;
float downY;
public DownState(long timeStamp, float downY) {
this.timeStamp = timeStamp;
this.downY = downY;
}
};
private final DownState ZERO = new DownState(0, 0f);
private final Consumer<MotionEvent> mListener;
private final SparseArray<DownState> mDownEvents;
private final SparseArray<PointF> mFingers;
private final SparseArray<Pair<PointerProperties[], PointerCoords[]>> mCache;
public TouchEventTranslator(Consumer<MotionEvent> listener) {
mDownEvents = new SparseArray<>();
mFingers = new SparseArray<>();
mCache = new SparseArray<>();
mListener = listener;
}
public void reset() {
mDownEvents.clear();
mFingers.clear();
}
public float getDownY() {
return mDownEvents.get(0).downY;
}
public void setDownParameters(int idx, MotionEvent e) {
DownState ev = new DownState(e.getEventTime(), e.getY(idx));
mDownEvents.append(idx, ev);
}
public void dispatchDownEvents(MotionEvent ev) {
for(int i = 0; i < ev.getPointerCount() && i < mDownEvents.size(); i++) {
int pid = ev.getPointerId(i);
put(pid, ev.getX(i), 0, mDownEvents.get(i).timeStamp, ev);
}
}
public void processMotionEvent(MotionEvent ev) {
if (DEBUG) {
printSamples(TAG + " processMotionEvent", ev);
}
int index = ev.getActionIndex();
float x = ev.getX(index);
float y = ev.getY(index) - mDownEvents.get(index, ZERO).downY;
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:
int pid = ev.getPointerId(index);
if(mFingers.get(pid, null) != null) {
for(int i=0; i < ev.getPointerCount(); i++) {
pid = ev.getPointerId(i);
position(pid, x, y);
}
generateEvent(ev.getAction(), ev);
} else {
put(pid, x, y, ev);
}
break;
case MotionEvent.ACTION_MOVE:
for(int i=0; i < ev.getPointerCount(); i++) {
pid = ev.getPointerId(i);
position(pid, x, y);
}
generateEvent(ev.getAction(), ev);
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
pid = ev.getPointerId(index);
lift(pid, index, x, y, ev);
break;
case MotionEvent.ACTION_CANCEL:
cancel(ev);
break;
default:
Log.v(TAG, "Didn't process ");
printSamples(TAG, ev);
}
}
private TouchEventTranslator put(int id, float x, float y, MotionEvent ev) {
return put(id, x, y, ev.getEventTime(), ev);
}
private TouchEventTranslator put(int id, float x, float y, long ms, MotionEvent ev) {
checkFingerExistence(id, false);
boolean isInitialDown = (mFingers.size() == 0);
mFingers.put(id, new PointF(x, y));
int n = mFingers.size();
if (mCache.get(n) == null) {
PointerProperties[] properties = new PointerProperties[n];
PointerCoords[] coords = new PointerCoords[n];
for (int i = 0; i < n; i++) {
properties[i] = new PointerProperties();
coords[i] = new PointerCoords();
}
mCache.put(n, new Pair(properties, coords));
}
int action;
if (isInitialDown) {
action = MotionEvent.ACTION_DOWN;
} else {
action = MotionEvent.ACTION_POINTER_DOWN;
// Set the id of the changed pointer.
action |= id << MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
generateEvent(action, ms, ev);
return this;
}
public TouchEventTranslator position(int id, float x, float y) {
checkFingerExistence(id, true);
mFingers.get(id).set(x, y);
return this;
}
private TouchEventTranslator lift(int id, int index, MotionEvent ev) {
checkFingerExistence(id, true);
boolean isFinalUp = (mFingers.size() == 1);
int action;
if (isFinalUp) {
action = MotionEvent.ACTION_UP;
} else {
action = MotionEvent.ACTION_POINTER_UP;
// Set the id of the changed pointer.
action |= index << MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
generateEvent(action, ev);
mFingers.remove(id);
return this;
}
private TouchEventTranslator lift(int id, int index, float x, float y, MotionEvent ev) {
checkFingerExistence(id, true);
mFingers.get(id).set(x, y);
return lift(id, index, ev);
}
public TouchEventTranslator cancel(MotionEvent ev) {
generateEvent(MotionEvent.ACTION_CANCEL, ev);
mFingers.clear();
return this;
}
private void checkFingerExistence(int id, boolean shouldExist) {
if (shouldExist != (mFingers.get(id, null) != null)) {
throw new IllegalArgumentException(
shouldExist ? "Finger does not exist" : "Finger already exists");
}
}
/**
* Used to debug MotionEvents being sent/received.
*/
public void printSamples(String msg, MotionEvent ev) {
System.out.printf("%s %s", msg, MotionEvent.actionToString(ev.getActionMasked()));
final int pointerCount = ev.getPointerCount();
System.out.printf("#%d/%d", ev.getPointerId(ev.getActionIndex()), pointerCount);
System.out.printf(" t=%d:", ev.getEventTime());
for (int p = 0; p < pointerCount; p++) {
System.out.printf(" id=%d: (%f,%f)",
ev.getPointerId(p), ev.getX(p), ev.getY(p));
}
System.out.println();
}
private void generateEvent(int action, MotionEvent ev) {
generateEvent(action, ev.getEventTime(), ev);
}
private void generateEvent(int action, long ms, MotionEvent ev) {
Pair<PointerProperties[], PointerCoords[]> state = getFingerState();
MotionEvent event = MotionEvent.obtain(
mDownEvents.get(0).timeStamp,
ms,
action,
state.first.length,
state.first,
state.second,
ev.getMetaState(),
ev.getButtonState() /* buttonState */,
ev.getXPrecision() /* xPrecision */,
ev.getYPrecision() /* yPrecision */,
ev.getDeviceId(),
ev.getEdgeFlags(),
ev.getSource(),
ev.getFlags() /* flags */);
if (DEBUG) {
printSamples(TAG + " generateEvent", event);
}
mListener.accept(event);
event.recycle();
}
/**
* Returns the description of the fingers' state expected by MotionEvent.
*/
private Pair<PointerProperties[], PointerCoords[]> getFingerState() {
int nFingers = mFingers.size();
Pair<PointerProperties[], PointerCoords[]> result = mCache.get(nFingers);
PointerProperties[] properties = result.first;
PointerCoords[] coordinates = result.second;
int index = 0;
for (int i = 0; i < mFingers.size(); i++) {
int id = mFingers.keyAt(i);
PointF location = mFingers.get(id);
PointerProperties property = properties[i];
property.id = id;
property.toolType = MotionEvent.TOOL_TYPE_FINGER;
properties[index] = property;
PointerCoords coordinate = coordinates[i];
coordinate.x = location.x;
coordinate.y = location.y;
coordinate.pressure = 1.0f;
coordinates[index] = coordinate;
index++;
}
return mCache.get(nFingers);
}
}
@@ -17,6 +17,7 @@ package com.android.launcher3.touch;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_POINTER_UP;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.ViewConfiguration.getLongPressTimeout;
@@ -29,6 +30,7 @@ import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.CellLayout;
@@ -60,12 +62,16 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
private final Launcher mLauncher;
private final Workspace mWorkspace;
private final PointF mTouchDownPoint = new PointF();
private final float mTouchSlop;
private int mLongPressState = STATE_CANCELLED;
public WorkspaceTouchListener(Launcher launcher, Workspace workspace) {
mLauncher = launcher;
mWorkspace = workspace;
// Use twice the touch slop as we are looking for long press which is more
// likely to cause movement.
mTouchSlop = 2 * ViewConfiguration.get(launcher).getScaledTouchSlop();
}
@Override
@@ -116,6 +122,9 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
mWorkspace.onTouchEvent(ev);
if (mWorkspace.isHandlingTouch()) {
cancelLongPress();
} else if (action == ACTION_MOVE && PointF.length(
mTouchDownPoint.x - ev.getX(), mTouchDownPoint.y - ev.getY()) > mTouchSlop) {
cancelLongPress();
}
result = true;
+7 -21
View File
@@ -1,30 +1,16 @@
package com.android.launcher3.util;
public abstract class FlagOp {
public interface FlagOp {
public static FlagOp NO_OP = new FlagOp() {};
FlagOp NO_OP = i -> i;
private FlagOp() {}
int apply(int flags);
public int apply(int flags) {
return flags;
static FlagOp addFlag(int flag) {
return i -> i + flag;
}
public static FlagOp addFlag(final int flag) {
return new FlagOp() {
@Override
public int apply(int flags) {
return flags | flag;
}
};
}
public static FlagOp removeFlag(final int flag) {
return new FlagOp() {
@Override
public int apply(int flags) {
return flags & ~flag;
}
};
static FlagOp removeFlag(int flag) {
return i -> i & ~flag;
}
}
@@ -21,6 +21,7 @@ import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Property;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -42,6 +43,32 @@ import java.util.ArrayList;
public abstract class BaseDragLayer<T extends Context & ActivityContext>
extends InsettableFrameLayout {
public static final Property<LayoutParams, Integer> LAYOUT_X =
new Property<LayoutParams, Integer>(Integer.TYPE, "x") {
@Override
public Integer get(LayoutParams lp) {
return lp.x;
}
@Override
public void set(LayoutParams lp, Integer x) {
lp.x = x;
}
};
public static final Property<LayoutParams, Integer> LAYOUT_Y =
new Property<LayoutParams, Integer>(Integer.TYPE, "y") {
@Override
public Integer get(LayoutParams lp) {
return lp.y;
}
@Override
public void set(LayoutParams lp, Integer y) {
lp.y = y;
}
};
protected final int[] mTmpXY = new int[2];
protected final Rect mHitRect = new Rect();
@@ -307,38 +334,6 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext>
public LayoutParams(ViewGroup.LayoutParams lp) {
super(lp);
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return width;
}
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return height;
}
public void setX(int x) {
this.x = x;
}
public int getX() {
return x;
}
public void setY(int y) {
this.y = y;
}
public int getY() {
return y;
}
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.widget;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import android.content.Context;
@@ -31,13 +33,16 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.graphics.ColorScrim;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.AbstractSlideInView;
import com.android.launcher3.views.BaseDragLayer;
import androidx.core.graphics.ColorUtils;
/**
* Base class for various widgets popup
@@ -49,11 +54,11 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
/* Touch handling related member variables. */
private Toast mWidgetInstructionToast;
protected final ColorScrim mColorScrim;
protected final View mColorScrim;
public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mColorScrim = ColorScrim.createExtractedColorScrim(this);
mColorScrim = createColorScrim(context);
}
@Override
@@ -80,9 +85,14 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
return true;
}
protected void attachToContainer() {
getPopupContainer().addView(mColorScrim);
getPopupContainer().addView(this);
}
protected void setTranslationShift(float translationShift) {
super.setTranslationShift(translationShift);
mColorScrim.setProgress(1 - mTranslationShift);
mColorScrim.setAlpha(1 - mTranslationShift);
}
private boolean beginDraggingWidget(WidgetCell v) {
@@ -115,6 +125,7 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
protected void onCloseComplete() {
super.onCloseComplete();
getPopupContainer().removeView(mColorScrim);
clearNavBarColor();
}
@@ -148,4 +159,19 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
protected SystemUiController getSystemUiController() {
return mLauncher.getSystemUiController();
}
private static View createColorScrim(Context context) {
View view = new View(context);
view.forceHasOverlappingRendering(false);
WallpaperColorInfo colors = WallpaperColorInfo.getInstance(context);
int alpha = context.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
view.setBackgroundColor(ColorUtils.setAlphaComponent(colors.getSecondaryColor(), alpha));
BaseDragLayer.LayoutParams lp = new BaseDragLayer.LayoutParams(MATCH_PARENT, MATCH_PARENT);
lp.ignoreInsets = true;
view.setLayoutParams(lp);
return view;
}
}
@@ -33,8 +33,8 @@ import android.view.View.OnClickListener;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.IconCache;
import com.android.launcher3.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.R;
@@ -70,8 +70,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
R.string.widgets_bottom_sheet_title, mOriginalItemInfo.title));
onWidgetsBound();
getPopupContainer().addView(this);
attachToContainer();
mIsOpen = false;
animateOpen();
}
@@ -18,7 +18,7 @@ package com.android.launcher3.widget;
import android.util.Log;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.widget.WidgetsListAdapter.WidgetListRowEntryComparator;
@@ -220,8 +220,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
public static WidgetsFullSheet show(Launcher launcher, boolean animate) {
WidgetsFullSheet sheet = (WidgetsFullSheet) launcher.getLayoutInflater()
.inflate(R.layout.widgets_full_sheet, launcher.getDragLayer(), false);
sheet.attachToContainer();
sheet.mIsOpen = true;
sheet.getPopupContainer().addView(sheet);
sheet.open(animate);
return sheet;
}
@@ -23,7 +23,7 @@ import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.R;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.model.WidgetItem;
@@ -24,7 +24,7 @@ import androidx.test.rule.provider.ProviderTestRule;
import com.android.launcher3.AllAppsList;
import com.android.launcher3.AppFilter;
import com.android.launcher3.AppInfo;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
@@ -10,7 +10,7 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
@@ -52,10 +52,10 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.testcomponent.AppWidgetNoConfig;
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.LauncherActivityRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -78,22 +78,31 @@ public abstract class AbstractLauncherUiTest {
public static final long DEFAULT_WORKER_TIMEOUT_SECS = 5;
protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
protected UiDevice mDevice;
protected LauncherInstrumentation mLauncher;
protected final UiDevice mDevice;
protected final LauncherInstrumentation mLauncher;
protected Context mTargetContext;
protected String mTargetPackage;
private static final String TAG = "AbstractLauncherUiTest";
protected AbstractLauncherUiTest() {
mDevice = UiDevice.getInstance(getInstrumentation());
mLauncher = new LauncherInstrumentation(getInstrumentation());
}
@Rule
public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(getInstrumentation());
mLauncher = new LauncherInstrumentation(getInstrumentation());
mTargetContext = InstrumentationRegistry.getTargetContext();
mTargetPackage = mTargetContext.getPackageName();
mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 0");
}
@After
public void tearDown() throws Exception {
mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 1");
}
protected void lockRotation(boolean naturalOrientation) throws RemoteException {
@@ -278,12 +287,7 @@ public abstract class AbstractLauncherUiTest {
// flakiness.
protected boolean waitForLauncherCondition(
Function<Launcher, Boolean> condition, long timeout) {
return Wait.atMost(new Condition() {
@Override
public boolean isTrue() {
return getFromLauncher(condition);
}
}, timeout);
return Wait.atMost(() -> getFromLauncher(condition), timeout);
}
/**
@@ -103,6 +103,8 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
if (mSessionId > -1) {
mTargetContext.getPackageManager().getPackageInstaller().abandonSession(mSessionId);
}
super.tearDown();
}
@Test
@@ -29,7 +29,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import android.view.LayoutInflater;
import com.android.launcher3.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.WidgetPreviewLoader;
@@ -42,6 +42,7 @@ public final class AppIcon {
/**
* Clicks the icon to launch its app.
*/
@Deprecated
public Background launch() {
LauncherInstrumentation.log("AppIcon.launch before click");
LauncherInstrumentation.assertTrue(
@@ -50,6 +51,20 @@ public final class AppIcon {
return new Background(mLauncher);
}
/**
* Clicks the icon to launch its app.
*/
public Background launch(String packageName) {
LauncherInstrumentation.log("AppIcon.launch before click");
LauncherInstrumentation.assertTrue(
"Launching an app didn't open a new window: " + mIcon.getText(),
mIcon.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS));
LauncherInstrumentation.assertTrue(
"App didn't start: " + packageName, mLauncher.getDevice().wait(Until.hasObject(
By.pkg(packageName).depth(0)), LauncherInstrumentation.WAIT_TIME_MS));
return new Background(mLauncher);
}
UiObject2 getIcon() {
return mIcon;
}
@@ -25,6 +25,7 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.provider.Settings;
import android.util.Log;
import android.view.Surface;
import android.view.accessibility.AccessibilityEvent;
import androidx.annotation.NonNull;
@@ -92,6 +93,7 @@ public final class LauncherInstrumentation {
private final boolean mSwipeUpEnabled;
private Boolean mSwipeUpEnabledOverride = null;
private final Instrumentation mInstrumentation;
private int mExpectedRotation = Surface.ROTATION_0;
/**
* Constructs the root of TAPL hierarchy. You get all other objects from it.
@@ -109,7 +111,7 @@ public final class LauncherInstrumentation {
assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness());
}
// Used only by tests.
// Used only by TaplTests.
public void overrideSwipeUpEnabled(Boolean swipeUpEnabledOverride) {
mSwipeUpEnabledOverride = swipeUpEnabledOverride;
}
@@ -144,14 +146,30 @@ public final class LauncherInstrumentation {
fail(message + ". " + "Actual: " + actual);
}
static public void assertEquals(String message, int expected, int actual) {
if (expected != actual) {
fail(message + " expected: " + expected + " but was: " + actual);
}
}
static void assertNotEquals(String message, int unexpected, int actual) {
if (unexpected == actual) {
failEquals(message, actual);
}
}
public void setExpectedRotation(int expectedRotation) {
mExpectedRotation = expectedRotation;
}
private UiObject2 verifyContainerType(ContainerType containerType) {
assertEquals("Unexpected display rotation",
mExpectedRotation, mDevice.getDisplayRotation());
assertTrue("Presence of recents button doesn't match isSwipeUpEnabled()",
isSwipeUpEnabled() ==
(mDevice.findObject(By.res(SYSTEMUI_PACKAGE, "recent_apps")) == null));
log("verifyContainerType: " + containerType);
switch (containerType) {
case WORKSPACE: {
waitUntilGone(APPS_RES_ID);
@@ -172,7 +190,11 @@ public final class LauncherInstrumentation {
return waitForLauncherObject(APPS_RES_ID);
}
case OVERVIEW: {
waitForLauncherObject(APPS_RES_ID);
if (mDevice.isNaturalOrientation()) {
waitForLauncherObject(APPS_RES_ID);
} else {
waitUntilGone(APPS_RES_ID);
}
waitUntilGone(WORKSPACE_RES_ID);
waitUntilGone(WIDGETS_RES_ID);
return waitForLauncherObject(OVERVIEW_RES_ID);
@@ -225,7 +247,10 @@ public final class LauncherInstrumentation {
// otherwise waitForIdle may return immediately in case when there was a big enough pause in
// accessibility events prior to pressing Home.
executeAndWaitForEvent(
() -> getSystemUiObject("home").click(),
() -> {
log("LauncherInstrumentation.pressHome before clicking");
getSystemUiObject("home").click();
},
event -> true,
"Pressing Home didn't produce any events");
mDevice.waitForIdle();