summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Utilities.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r--src/com/android/launcher3/Utilities.java152
1 files changed, 1 insertions, 151 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index b8fe02f1e..108898e99 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -24,15 +24,9 @@ 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.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.res.Resources;
@@ -47,7 +41,6 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.Message;
@@ -59,7 +52,6 @@ import android.text.TextUtils;
import android.text.style.TtsSpan;
import android.util.DisplayMetrics;
import android.util.Log;
-import android.util.Pair;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
@@ -68,7 +60,6 @@ import android.view.animation.Interpolator;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.ShortcutConfigActivityInfo;
-import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
import com.android.launcher3.graphics.RotationMode;
import com.android.launcher3.graphics.TintedDrawableSpan;
@@ -79,17 +70,10 @@ import com.android.launcher3.util.IntArray;
import com.android.launcher3.views.Transposable;
import com.android.launcher3.widget.PendingAddShortcutInfo;
-import java.io.Closeable;
-import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
-import java.util.StringTokenizer;
-import java.util.concurrent.Executor;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -122,8 +106,6 @@ public final class Utilities {
public static final boolean ATLEAST_OREO =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
- public static final int SINGLE_FRAME_MS = 16;
-
/**
* Set on a motion event dispatched from the nav bar. See {@link MotionEvent#setEdgeFlags(int)}.
*/
@@ -139,18 +121,6 @@ public final class Utilities {
public static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
public static final String EXTRA_WALLPAPER_FLAVOR = "com.android.launcher3.WALLPAPER_FLAVOR";
- // These values are same as that in {@link AsyncTask}.
- private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
- private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
- private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
- private static final int KEEP_ALIVE = 1;
- /**
- * An {@link Executor} to be used with async task with no limit on the queue size.
- */
- public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
- CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
- TimeUnit.SECONDS, new LinkedBlockingQueue<>());
-
public static boolean IS_RUNNING_IN_TEST_HARNESS =
ActivityManager.isRunningInTestHarness();
@@ -232,7 +202,6 @@ public final class Utilities {
return scale;
}
-
/**
* Inverse of {@link #getDescendantCoordRelativeToAncestor(View, View, float[], boolean)}.
*/
@@ -368,53 +337,6 @@ public final class Utilities {
return min + (value * (max - min));
}
- public static boolean isSystemApp(Context context, Intent intent) {
- PackageManager pm = context.getPackageManager();
- ComponentName cn = intent.getComponent();
- String packageName = null;
- if (cn == null) {
- ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
- if ((info != null) && (info.activityInfo != null)) {
- packageName = info.activityInfo.packageName;
- }
- } else {
- packageName = cn.getPackageName();
- }
- if (packageName != null) {
- try {
- PackageInfo info = pm.getPackageInfo(packageName, 0);
- return (info != null) && (info.applicationInfo != null) &&
- ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
- } catch (NameNotFoundException e) {
- return false;
- }
- } else {
- return false;
- }
- }
-
- /*
- * Finds a system apk which had a broadcast receiver listening to a particular action.
- * @param action intent action used to find the apk
- * @return a pair of apk package name and the resources.
- */
- static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
- final Intent intent = new Intent(action);
- for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
- if (info.activityInfo != null &&
- (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
- final String packageName = info.activityInfo.packageName;
- try {
- final Resources res = pm.getResourcesForApplication(packageName);
- return Pair.create(packageName, res);
- } catch (NameNotFoundException e) {
- Log.w(TAG, "Failed to find resources for " + packageName);
- }
- }
- }
- return null;
- }
-
/**
* Trims the string, removing all whitespace at the beginning and end of the string.
* Non-breaking whitespaces are also removed.
@@ -439,51 +361,10 @@ public final class Utilities {
return (int) Math.ceil(fm.bottom - fm.top);
}
- /**
- * Convenience println with multiple args.
- */
- public static void println(String key, Object... args) {
- StringBuilder b = new StringBuilder();
- b.append(key);
- b.append(": ");
- boolean isFirstArgument = true;
- for (Object arg : args) {
- if (isFirstArgument) {
- isFirstArgument = false;
- } else {
- b.append(", ");
- }
- b.append(arg);
- }
- System.out.println(b.toString());
- }
-
public static boolean isRtl(Resources res) {
return res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
- /**
- * Returns true if the intent is a valid launch intent for a launcher activity of an app.
- * This is used to identify shortcuts which are different from the ones exposed by the
- * applications' manifest file.
- *
- * @param launchIntent The intent that will be launched when the shortcut is clicked.
- */
- public static boolean isLauncherAppTarget(Intent launchIntent) {
- if (launchIntent != null
- && Intent.ACTION_MAIN.equals(launchIntent.getAction())
- && launchIntent.getComponent() != null
- && launchIntent.getCategories() != null
- && launchIntent.getCategories().size() == 1
- && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
- && TextUtils.isEmpty(launchIntent.getDataString())) {
- // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE.
- Bundle extras = launchIntent.getExtras();
- return extras == null || extras.keySet().isEmpty();
- }
- return false;
- }
-
public static float dpiFromPx(int size, DisplayMetrics metrics){
float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;
return (size / densityRatio);
@@ -586,18 +467,6 @@ public final class Utilities {
return context.getSystemService(WallpaperManager.class).isSetWallpaperAllowed();
}
- public static void closeSilently(Closeable c) {
- if (c != null) {
- try {
- c.close();
- } catch (IOException e) {
- if (FeatureFlags.IS_DOGFOOD_BUILD) {
- Log.d(TAG, "Error closing", e);
- }
- }
- }
- }
-
public static boolean isBinderSizeError(Exception e) {
return e.getCause() instanceof TransactionTooLargeException
|| e.getCause() instanceof DeadObjectException;
@@ -700,7 +569,7 @@ public final class Utilities {
LauncherIcons li = LauncherIcons.obtain(appState.getContext());
Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap;
li.recycle();
- float badgeSize = launcher.getResources().getDimension(R.dimen.profile_badge_size);
+ float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
float insetFraction = (iconSize - badgeSize) / iconSize;
return new InsetDrawable(new FastBitmapDrawable(badge),
insetFraction, insetFraction, 0, 0);
@@ -712,25 +581,6 @@ public final class Utilities {
}
}
- public static int[] getIntArrayFromString(String tokenized) {
- StringTokenizer tokenizer = new StringTokenizer(tokenized, ",");
- int[] array = new int[tokenizer.countTokens()];
- int count = 0;
- while (tokenizer.hasMoreTokens()) {
- array[count] = Integer.parseInt(tokenizer.nextToken().trim());
- count++;
- }
- return array;
- }
-
- public static String getStringFromIntArray(int[] array) {
- StringBuilder str = new StringBuilder();
- for (int value : array) {
- str.append(value).append(",");
- }
- return str.toString();
- }
-
public static float squaredHypot(float x, float y) {
return x * x + y * y;
}