Merge "Cleaning Utilities.java" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-11-17 02:39:38 +00:00
committed by Android (Google) Code Review
12 changed files with 110 additions and 269 deletions
@@ -18,8 +18,6 @@ package com.android.launcher3.model;
import static android.content.ContentResolver.SCHEME_CONTENT;
import static com.android.launcher3.Utilities.newContentObserver;
import android.annotation.TargetApi;
import android.app.RemoteAction;
import android.content.ContentProviderClient;
@@ -46,10 +46,7 @@ import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_S
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED;
import android.app.ActivityTaskManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Region;
import android.inputmethodservice.InputMethodService;
import android.net.Uri;
@@ -63,12 +60,12 @@ import android.view.MotionEvent;
import androidx.annotation.BinderThread;
import androidx.annotation.NonNull;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.quickstep.TopTaskTracker.CachedTaskInfo;
import com.android.quickstep.util.NavBarPosition;
import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -114,15 +111,12 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
private boolean mIsUserUnlocked;
private final ArrayList<Runnable> mUserUnlockedActions = new ArrayList<>();
private final BroadcastReceiver mUserUnlockedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_USER_UNLOCKED.equals(intent.getAction())) {
mIsUserUnlocked = true;
notifyUserUnlocked();
}
private final SimpleBroadcastReceiver mUserUnlockedReceiver = new SimpleBroadcastReceiver(i -> {
if (ACTION_USER_UNLOCKED.equals(i.getAction())) {
mIsUserUnlocked = true;
notifyUserUnlocked();
}
};
});
private int mGestureBlockingTaskId = -1;
private @NonNull Region mExclusionRegion = new Region();
@@ -153,10 +147,9 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
mIsUserUnlocked = context.getSystemService(UserManager.class)
.isUserUnlocked(Process.myUserHandle());
if (!mIsUserUnlocked) {
mContext.registerReceiver(mUserUnlockedReceiver,
new IntentFilter(ACTION_USER_UNLOCKED));
mUserUnlockedReceiver.register(mContext, ACTION_USER_UNLOCKED);
}
runOnDestroy(() -> Utilities.unregisterReceiverSafely(mContext, mUserUnlockedReceiver));
runOnDestroy(() -> mUserUnlockedReceiver.unregisterReceiverSafely(mContext));
// Register for exclusion updates
mExclusionListener = new SystemGestureExclusionListenerCompat(mDisplayId) {
@@ -347,7 +340,7 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
action.run();
}
mUserUnlockedActions.clear();
Utilities.unregisterReceiverSafely(mContext, mUserUnlockedReceiver);
mUserUnlockedReceiver.unregisterReceiverSafely(mContext);
}
/**
@@ -18,7 +18,6 @@ package com.android.quickstep.util;
import static com.android.launcher3.LauncherAnimUtils.HOTSEAT_SCALE_PROPERTY_FACTORY;
import static com.android.launcher3.LauncherAnimUtils.SCALE_INDEX_UNFOLD_ANIMATION;
import static com.android.launcher3.LauncherAnimUtils.WORKSPACE_SCALE_PROPERTY_FACTORY;
import static com.android.launcher3.Utilities.comp;
import android.annotation.Nullable;
import android.util.FloatProperty;
@@ -135,7 +134,7 @@ public class LauncherUnfoldAnimationController {
@Override
public void onTransitionProgress(float progress) {
if (mQsbInsettable != null) {
float insetPercentage = comp(progress) * MAX_WIDTH_INSET_FRACTION;
float insetPercentage = (1 - progress) * MAX_WIDTH_INSET_FRACTION;
mQsbInsettable.setHorizontalInsets(insetPercentage);
}
}
@@ -20,7 +20,6 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.widget.Toast.LENGTH_SHORT;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.Utilities.comp;
import static com.android.launcher3.Utilities.getDescendantCoordRelativeToAncestor;
import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
@@ -501,7 +500,7 @@ public class TaskView extends FrameLayout implements Reusable {
return;
}
mModalness = modalness;
mIconView.setAlpha(comp(modalness));
mIconView.setAlpha(1 - modalness);
mDigitalWellBeingToast.updateBannerOffset(modalness,
mCurrentFullscreenParams.mCurrentDrawnInsets.top
+ mCurrentFullscreenParams.mCurrentDrawnInsets.bottom);
@@ -607,15 +607,16 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
* Get the icon bounds on the view depending on the layout type.
*/
public void getIconBounds(int iconSize, Rect outBounds) {
Utilities.setRectToViewCenter(this, iconSize, outBounds);
outBounds.set(0, 0, iconSize, iconSize);
if (mLayoutHorizontal) {
int top = (getHeight() - iconSize) / 2;
if (mIsRtl) {
outBounds.offsetTo(getWidth() - iconSize - getPaddingRight(), outBounds.top);
outBounds.offsetTo(getWidth() - iconSize - getPaddingRight(), top);
} else {
outBounds.offsetTo(getPaddingLeft(), outBounds.top);
outBounds.offsetTo(getPaddingLeft(), top);
}
} else {
outBounds.offsetTo(outBounds.left, getPaddingTop());
outBounds.offset((getWidth() - iconSize) / 2, getPaddingTop());
}
}
@@ -308,8 +308,7 @@ public class InvariantDeviceProfile {
}
public static String getCurrentGridName(Context context) {
return Utilities.isGridOptionsEnabled(context)
? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
return Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null);
}
private String initGrid(Context context, String gridName) {
@@ -384,10 +383,6 @@ public class InvariantDeviceProfile {
allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
allAppsIconSize = displayOption.allAppsIconSizes;
allAppsIconTextSize = displayOption.allAppsIconTextSizes;
if (!Utilities.isGridOptionsEnabled(context)) {
allAppsIconSize = iconSize;
allAppsIconTextSize = iconTextSize;
}
if (devicePaddingId != 0) {
devicePaddings = new DevicePaddings(context, devicePaddingId);
+31 -223
View File
@@ -26,20 +26,13 @@ import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.app.Person;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
@@ -51,7 +44,6 @@ import android.graphics.RectF;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.DeadObjectException;
@@ -71,15 +63,12 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import androidx.annotation.ChecksSdkIntAtLeast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils;
import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
import com.android.launcher3.graphics.GridCustomizationsProvider;
import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.icons.ShortcutCachingLogic;
import com.android.launcher3.icons.ThemedIconDrawable;
@@ -91,7 +80,6 @@ import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.testing.shared.ResourceUtils;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
@@ -100,10 +88,8 @@ import com.android.launcher3.widget.PendingAddShortcutInfo;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -117,8 +103,6 @@ public final class Utilities {
private static final Pattern sTrimPattern =
Pattern.compile("^[\\s|\\p{javaSpaceChar}]*(.*)[\\s|\\p{javaSpaceChar}]*$");
private static final int[] sLoc0 = new int[2];
private static final int[] sLoc1 = new int[2];
private static final Matrix sMatrix = new Matrix();
private static final Matrix sInverseMatrix = new Matrix();
@@ -167,14 +151,6 @@ public final class Utilities {
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
}
// An intent extra to indicate the horizontal scroll of the wallpaper.
public static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
public static final String EXTRA_WALLPAPER_FLAVOR = "com.android.launcher3.WALLPAPER_FLAVOR";
// An intent extra to indicate the launch source by launcher.
public static final String EXTRA_WALLPAPER_LAUNCH_SOURCE =
"com.android.wallpaper.LAUNCH_SOURCE";
public static boolean IS_RUNNING_IN_TEST_HARNESS =
ActivityManager.isRunningInTestHarness();
@@ -186,12 +162,6 @@ public final class Utilities {
return Log.isLoggable(propertyName, Log.VERBOSE);
}
public static boolean existsStyleWallpapers(Context context) {
ResolveInfo ri = context.getPackageManager().resolveActivity(
PackageManagerHelper.getStyleWallpapersIntent(context), 0);
return ri != null;
}
/**
* Given a coordinate relative to the descendant, find the coordinate in a parent view's
* coordinates.
@@ -305,9 +275,9 @@ public final class Utilities {
* Sets {@param out} to be same as {@param in} by rounding individual values
*/
public static void roundArray(float[] in, int[] out) {
for (int i = 0; i < in.length; i++) {
out[i] = Math.round(in[i]);
}
for (int i = 0; i < in.length; i++) {
out[i] = Math.round(in[i]);
}
}
public static void offsetPoints(float[] points, float offsetX, float offsetY) {
@@ -328,80 +298,8 @@ public final class Utilities {
localY < (v.getHeight() + slop);
}
public static int[] getCenterDeltaInScreenSpace(View v0, View v1) {
v0.getLocationInWindow(sLoc0);
v1.getLocationInWindow(sLoc1);
sLoc0[0] += (v0.getMeasuredWidth() * v0.getScaleX()) / 2;
sLoc0[1] += (v0.getMeasuredHeight() * v0.getScaleY()) / 2;
sLoc1[0] += (v1.getMeasuredWidth() * v1.getScaleX()) / 2;
sLoc1[1] += (v1.getMeasuredHeight() * v1.getScaleY()) / 2;
return new int[] {sLoc1[0] - sLoc0[0], sLoc1[1] - sLoc0[1]};
}
/**
* Helper method to set rectOut with rectFSrc.
*/
public static void setRect(RectF rectFSrc, Rect rectOut) {
rectOut.left = (int) rectFSrc.left;
rectOut.top = (int) rectFSrc.top;
rectOut.right = (int) rectFSrc.right;
rectOut.bottom = (int) rectFSrc.bottom;
}
public static void scaleRectFAboutCenter(RectF r, float scale) {
scaleRectFAboutPivot(r, scale, r.centerX(), r.centerY());
}
public static void scaleRectFAboutPivot(RectF r, float scale, float px, float py) {
if (scale != 1.0f) {
r.offset(-px, -py);
r.left = r.left * scale;
r.top = r.top * scale ;
r.right = r.right * scale;
r.bottom = r.bottom * scale;
r.offset(px, py);
}
}
public static void scaleRectAboutCenter(Rect r, float scale) {
if (scale != 1.0f) {
int cx = r.centerX();
int cy = r.centerY();
r.offset(-cx, -cy);
scaleRect(r, scale);
r.offset(cx, cy);
}
}
public static void scaleRect(Rect r, float scale) {
if (scale != 1.0f) {
r.left = (int) (r.left * scale + 0.5f);
r.top = (int) (r.top * scale + 0.5f);
r.right = (int) (r.right * scale + 0.5f);
r.bottom = (int) (r.bottom * scale + 0.5f);
}
}
public static void insetRect(Rect r, Rect insets) {
r.left = Math.min(r.right, r.left + insets.left);
r.top = Math.min(r.bottom, r.top + insets.top);
r.right = Math.max(r.left, r.right - insets.right);
r.bottom = Math.max(r.top, r.bottom - insets.bottom);
}
public static float shrinkRect(Rect r, float scaleX, float scaleY) {
float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
if (scale < 1.0f) {
int deltaX = (int) (r.width() * (scaleX - scale) * 0.5f);
r.left += deltaX;
r.right -= deltaX;
int deltaY = (int) (r.height() * (scaleY - scale) * 0.5f);
r.top += deltaY;
r.bottom -= deltaY;
}
return scale;
scaleRectFAboutCenter(r, scale, scale);
}
/**
@@ -419,6 +317,33 @@ public final class Utilities {
r.offset(px, py);
}
public static void scaleRectAboutCenter(Rect r, float scale) {
if (scale != 1.0f) {
int cx = r.centerX();
int cy = r.centerY();
r.offset(-cx, -cy);
r.left = (int) (r.left * scale + 0.5f);
r.top = (int) (r.top * scale + 0.5f);
r.right = (int) (r.right * scale + 0.5f);
r.bottom = (int) (r.bottom * scale + 0.5f);
r.offset(cx, cy);
}
}
public static float shrinkRect(Rect r, float scaleX, float scaleY) {
float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
if (scale < 1.0f) {
int deltaX = (int) (r.width() * (scaleX - scale) * 0.5f);
r.left += deltaX;
r.right -= deltaX;
int deltaY = (int) (r.height() * (scaleY - scale) * 0.5f);
r.top += deltaY;
r.bottom -= deltaY;
}
return scale;
}
/**
* Maps t from one range to another range.
* @param t The value to map.
@@ -453,30 +378,6 @@ public final class Utilities {
return min + (value * (max - min));
}
/**
* Bounds parameter to the range [0, 1]
*/
public static float saturate(float a) {
return boundToRange(a, 0, 1.0f);
}
/**
* Returns the compliment (1 - a) of the parameter.
*/
public static float comp(float a) {
return 1 - a;
}
/**
* Returns the "probabilistic or" of a and b. (a + b - ab).
* Useful beyond probability, can be used to combine two unit progresses for example.
*/
public static float or(float a, float b) {
float satA = saturate(a);
float satB = saturate(b);
return satA + satB - (satA * satB);
}
/**
* Trims the string, removing all whitespace at the beginning and end of the string.
* Non-breaking whitespaces are also removed.
@@ -536,7 +437,6 @@ public final class Utilities {
return ResourceUtils.roundPxValueFromFloat(value);
}
public static String createDbSelectionQuery(String columnName, IntArray values) {
return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, values.toConcatString());
}
@@ -559,18 +459,6 @@ public final class Utilities {
return defaultValue;
}
/**
* Using the view's bounds and icon size, calculate where the icon bounds will
* be if it was positioned at the center of the view.
*/
public static void setRectToViewCenter(View iconView, int iconSize, Rect outBounds) {
int top = (iconView.getHeight() - iconSize) / 2;
int left = (iconView.getWidth() - iconSize) / 2;
int right = left + iconSize;
int bottom = top + iconSize;
outBounds.set(left, top, right, bottom);
}
/**
* Ensures that a value is within given bounds. Specifically:
* If value is less than lowerBound, return lowerBound; else if value is greater than upperBound,
@@ -646,42 +534,6 @@ public final class Utilities {
|| e.getCause() instanceof DeadObjectException;
}
public static boolean isGridOptionsEnabled(Context context) {
return isComponentEnabled(context.getPackageManager(),
context.getPackageName(),
GridCustomizationsProvider.class.getName());
}
private static boolean isComponentEnabled(PackageManager pm, String pkgName, String clsName) {
ComponentName componentName = new ComponentName(pkgName, clsName);
int componentEnabledSetting = pm.getComponentEnabledSetting(componentName);
switch (componentEnabledSetting) {
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
return false;
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
default:
// We need to get the application info to get the component's default state
try {
PackageInfo packageInfo = pm.getPackageInfo(pkgName,
PackageManager.GET_PROVIDERS | PackageManager.GET_DISABLED_COMPONENTS);
if (packageInfo.providers != null) {
return Arrays.stream(packageInfo.providers).anyMatch(
pi -> pi.name.equals(clsName) && pi.isEnabled());
}
// the component is not declared in the AndroidManifest
return false;
} catch (PackageManager.NameNotFoundException e) {
// the package isn't installed on the device
return false;
}
}
}
/**
* Utility method to post a runnable on the handler, skipping the synchronization barriers.
*/
@@ -691,12 +543,6 @@ public final class Utilities {
handler.sendMessage(msg);
}
public static void unregisterReceiverSafely(Context context, BroadcastReceiver receiver) {
try {
context.unregisterReceiver(receiver);
} catch (IllegalArgumentException e) {}
}
/**
* Returns the full drawable for info without any flattening or pre-processing.
*
@@ -794,14 +640,6 @@ public final class Utilities {
}
}
/**
* @return true is the extra is either null or is of type {@param type}
*/
public static boolean isValidExtraType(Intent intent, String key, Class type) {
Object extra = intent.getParcelableExtra(key);
return extra == null || type.isInstance(extra);
}
public static float squaredHypot(float x, float y) {
return x * x + y * y;
}
@@ -811,18 +649,6 @@ public final class Utilities {
return slop * slop;
}
/**
* Helper method to create a content provider
*/
public static ContentObserver newContentObserver(Handler handler, Consumer<Uri> command) {
return new ContentObserver(handler) {
@Override
public void onChange(boolean selfChange, Uri uri) {
command.accept(uri);
}
};
}
/**
* Rotates `inOutBounds` by `delta` 90-degree increments. Rotation is visually CCW. Parent
* sizes represent the "space" that will rotate carrying inOutBounds along with it to determine
@@ -871,16 +697,6 @@ public final class Utilities {
ColorUtils.blendARGB(0, color, tintAmount));
}
/**
* Sets start margin on the provided {@param view} to be {@param margin}.
* Assumes {@param view} is a child of {@link LinearLayout}
*/
public static void setStartMarginForView(View view, int margin) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) view.getLayoutParams();
lp.setMarginStart(margin);
view.setLayoutParams(lp);
}
public static Rect getViewBounds(@NonNull View v) {
int[] pos = new int[2];
v.getLocationOnScreen(pos);
@@ -921,12 +737,4 @@ public final class Utilities {
}
return options;
}
public static boolean bothNull(@Nullable Object a, @Nullable Object b) {
return a == null && b == null;
}
public static boolean bothNonNull(@Nullable Object a, @Nullable Object b) {
return a != null && b != null;
}
}
@@ -616,11 +616,14 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
public void drawDot(Canvas canvas) {
if (!mForceHideDot && ((mDotInfo != null && mDotInfo.hasDot()) || mDotScale > 0)) {
Rect iconBounds = mDotParams.iconBounds;
// FolderIcon draws the icon to be top-aligned (with padding) & horizontally-centered
int iconSize = mActivity.getDeviceProfile().iconSizePx;
iconBounds.left = (getWidth() - iconSize) / 2;
iconBounds.right = iconBounds.left + iconSize;
iconBounds.top = getPaddingTop();
iconBounds.bottom = iconBounds.top + iconSize;
Utilities.setRectToViewCenter(this, mActivity.getDeviceProfile().iconSizePx,
iconBounds);
iconBounds.offsetTo(iconBounds.left, getPaddingTop());
float iconScale = (float) mBackground.previewSize / iconBounds.width();
float iconScale = (float) mBackground.previewSize / iconSize;
Utilities.scaleRectAboutCenter(iconBounds, iconScale);
// If we are animating to the accepting state, animate the dot out.
@@ -15,8 +15,6 @@
*/
package com.android.launcher3.model;
import static com.android.launcher3.Utilities.isValidExtraType;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
@@ -149,4 +147,12 @@ public class ModelUtils {
info.intent = launchIntent;
return info;
}
/**
* @return true if the extra is either null or is of type {@param type}
*/
private static boolean isValidExtraType(Intent intent, String key, Class type) {
Object extra = intent.getParcelableExtra(key);
return extra == null || type.isInstance(extra);
}
}
@@ -15,10 +15,15 @@
*/
package com.android.launcher3.util;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.WorkerThread;
import java.util.function.Consumer;
/**
* Utility class to define an object which does most of it's processing on a
* dedicated background thread.
@@ -43,4 +48,16 @@ public abstract class BgObjectWithLooper {
*/
@WorkerThread
protected abstract void onInitialized(Looper looper);
/**
* Helper method to create a content provider
*/
protected static ContentObserver newContentObserver(Handler handler, Consumer<Uri> command) {
return new ContentObserver(handler) {
@Override
public void onChange(boolean selfChange, Uri uri) {
command.accept(uri);
}
};
}
}
@@ -52,4 +52,15 @@ public class SimpleBroadcastReceiver extends BroadcastReceiver {
}
context.registerReceiver(this, filter, flags);
}
/**
* Unregisters the receiver ignoring any errors
*/
public void unregisterReceiverSafely(Context context) {
try {
context.unregisterReceiver(this);
} catch (IllegalArgumentException e) {
// It was probably never registered or already unregistered. Ignore.
}
}
}
@@ -15,9 +15,6 @@
*/
package com.android.launcher3.views;
import static com.android.launcher3.Utilities.EXTRA_WALLPAPER_FLAVOR;
import static com.android.launcher3.Utilities.EXTRA_WALLPAPER_LAUNCH_SOURCE;
import static com.android.launcher3.Utilities.EXTRA_WALLPAPER_OFFSET;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.IGNORE;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS;
@@ -51,6 +48,7 @@ import com.android.launcher3.popup.ArrowPopup;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import java.util.ArrayList;
@@ -62,6 +60,13 @@ import java.util.List;
public class OptionsPopupView extends ArrowPopup<Launcher>
implements OnClickListener, OnLongClickListener {
// An intent extra to indicate the horizontal scroll of the wallpaper.
private static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
private static final String EXTRA_WALLPAPER_FLAVOR = "com.android.launcher3.WALLPAPER_FLAVOR";
// An intent extra to indicate the launch source by launcher.
private static final String EXTRA_WALLPAPER_LAUNCH_SOURCE =
"com.android.wallpaper.LAUNCH_SOURCE";
private final ArrayMap<View, OptionItem> mItemMap = new ArrayMap<>();
private RectF mTargetRect;
private boolean mShouldAddArrow;
@@ -180,10 +185,11 @@ public class OptionsPopupView extends ArrowPopup<Launcher>
*/
public static ArrayList<OptionItem> getOptions(Launcher launcher) {
ArrayList<OptionItem> options = new ArrayList<>();
int resString = Utilities.existsStyleWallpapers(launcher) ?
R.string.styles_wallpaper_button_text : R.string.wallpaper_button_text;
int resDrawable = Utilities.existsStyleWallpapers(launcher) ?
R.drawable.ic_palette : R.drawable.ic_wallpaper;
boolean styleWallpaperExists = styleWallpapersExists(launcher);
int resString = styleWallpaperExists
? R.string.styles_wallpaper_button_text : R.string.wallpaper_button_text;
int resDrawable = styleWallpaperExists
? R.drawable.ic_palette : R.drawable.ic_wallpaper;
options.add(new OptionItem(launcher,
resString,
resDrawable,
@@ -251,7 +257,7 @@ public class OptionsPopupView extends ArrowPopup<Launcher>
.putExtra(EXTRA_WALLPAPER_OFFSET,
launcher.getWorkspace().getWallpaperOffsetForCenterPage())
.putExtra(EXTRA_WALLPAPER_LAUNCH_SOURCE, "app_launched_launcher");
if (!Utilities.existsStyleWallpapers(launcher)) {
if (!styleWallpapersExists(launcher)) {
intent.putExtra(EXTRA_WALLPAPER_FLAVOR, "wallpaper_only");
} else {
intent.putExtra(EXTRA_WALLPAPER_FLAVOR, "focus_wallpaper");
@@ -299,4 +305,9 @@ public class OptionsPopupView extends ArrowPopup<Launcher>
this.clickListener = clickListener;
}
}
private static boolean styleWallpapersExists(Context context) {
return context.getPackageManager().resolveActivity(
PackageManagerHelper.getStyleWallpapersIntent(context), 0) != null;
}
}