summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-09-01 12:50:11 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-09-02 12:34:33 -0700
commit10629b077c65b648be6a8603a092322d8a2c2c50 (patch)
tree0542a6a28717bd0e29fe6df63fcddb94fc8ae78e /src/com
parent6677eb7668344ef05637bc48982439ed336c7499 (diff)
downloadandroid_packages_apps_Trebuchet-10629b077c65b648be6a8603a092322d8a2c2c50.tar.gz
android_packages_apps_Trebuchet-10629b077c65b648be6a8603a092322d8a2c2c50.tar.bz2
android_packages_apps_Trebuchet-10629b077c65b648be6a8603a092322d8a2c2c50.zip
Moving some image handling classes to .graphics package
Change-Id: Id6d3d0b9c345a503ff2e09f073eb4b6449e21c7e
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher3/AutoInstallsLayout.java3
-rw-r--r--src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java4
-rw-r--r--src/com/android/launcher3/BubbleTextView.java5
-rw-r--r--src/com/android/launcher3/IconCache.java11
-rw-r--r--src/com/android/launcher3/LauncherClings.java30
-rw-r--r--src/com/android/launcher3/LauncherModel.java9
-rw-r--r--src/com/android/launcher3/LauncherProvider.java7
-rw-r--r--src/com/android/launcher3/ShortcutInfo.java9
-rw-r--r--src/com/android/launcher3/Utilities.java236
-rw-r--r--src/com/android/launcher3/graphics/DragPreviewProvider.java3
-rw-r--r--src/com/android/launcher3/graphics/HolographicOutlineHelper.java (renamed from src/com/android/launcher3/HolographicOutlineHelper.java)12
-rw-r--r--src/com/android/launcher3/graphics/IconNormalizer.java (renamed from src/com/android/launcher3/util/IconNormalizer.java)2
-rw-r--r--src/com/android/launcher3/graphics/LauncherIcons.java258
-rw-r--r--src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java3
-rw-r--r--src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java4
-rw-r--r--src/com/android/launcher3/util/CursorIconInfo.java5
-rw-r--r--src/com/android/launcher3/widget/PendingItemPreviewProvider.java4
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java3
18 files changed, 302 insertions, 306 deletions
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java
index d5309b4f0..8b5a8a863 100644
--- a/src/com/android/launcher3/AutoInstallsLayout.java
+++ b/src/com/android/launcher3/AutoInstallsLayout.java
@@ -38,6 +38,7 @@ import android.util.Patterns;
import com.android.launcher3.LauncherProvider.SqlArguments;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.util.Thunk;
import org.xmlpull.v1.XmlPullParser;
@@ -436,7 +437,7 @@ public class AutoInstallsLayout {
return -1;
}
- ItemInfo.writeBitmap(mValues, Utilities.createIconBitmap(icon, mContext));
+ ItemInfo.writeBitmap(mValues, LauncherIcons.createIconBitmap(icon, mContext));
mValues.put(Favorites.ICON_PACKAGE, mIconRes.getResourcePackageName(iconId));
mValues.put(Favorites.ICON_RESOURCE, mIconRes.getResourceName(iconId));
diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java
index b9e627775..b9b044db9 100644
--- a/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java
+++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java
@@ -25,6 +25,8 @@ import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import com.android.launcher3.graphics.HolographicOutlineHelper;
+
/**
* The fast scroller popup that shows the section name the list will jump to.
*/
@@ -116,7 +118,7 @@ public class BaseRecyclerViewFastScrollPopup {
mBgBounds.bottom = mBgBounds.top + bgHeight;
// Generate a bitmap for a shadow matching these bounds
- mShadow = HolographicOutlineHelper.obtain(
+ mShadow = HolographicOutlineHelper.getInstance(
mRv.getContext()).createMediumDropShadow(mBg, false /* shouldCache */);
} else {
mShadow = null;
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 33b3ad347..5cb2d4f31 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -42,6 +42,7 @@ import android.widget.TextView;
import com.android.launcher3.IconCache.IconLoadRequest;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.HolographicOutlineHelper;
import com.android.launcher3.model.PackageItemInfo;
import java.text.NumberFormat;
@@ -148,7 +149,7 @@ public class BubbleTextView extends TextView
mLongPressHelper = new CheckLongPressHelper(this);
mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
- mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
+ mOutlineHelper = HolographicOutlineHelper.getInstance(getContext());
setAccessibilityDelegate(mLauncher.getAccessibilityDelegate());
}
@@ -326,7 +327,7 @@ public class BubbleTextView extends TextView
void setStayPressed(boolean stayPressed) {
mStayPressed = stayPressed;
if (!stayPressed) {
- HolographicOutlineHelper.obtain(getContext()).recycleShadowBitmap(mPressedBackground);
+ HolographicOutlineHelper.getInstance(getContext()).recycleShadowBitmap(mPressedBackground);
mPressedBackground = null;
} else {
if (mPressedBackground == null) {
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index a49162c8b..9ac484738 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -47,6 +47,7 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.SQLiteCacheHelper;
@@ -187,7 +188,7 @@ public class IconCache {
private Bitmap makeDefaultIcon(UserHandleCompat user) {
Drawable unbadged = getFullResDefaultActivityIcon();
- return Utilities.createBadgedIconBitmap(unbadged, user, mContext);
+ return LauncherIcons.createBadgedIconBitmap(unbadged, user, mContext);
}
/**
@@ -387,7 +388,7 @@ public class IconCache {
}
if (entry == null) {
entry = new CacheEntry();
- entry.icon = Utilities.createBadgedIconBitmap(
+ entry.icon = LauncherIcons.createBadgedIconBitmap(
mIconProvider.getIcon(app, mIconDpi), app.getUser(),
mContext);
}
@@ -555,7 +556,7 @@ public class IconCache {
// Check the DB first.
if (!getEntryFromDB(cacheKey, entry, useLowResIcon) || DEBUG_IGNORE_CACHE) {
if (info != null) {
- entry.icon = Utilities.createBadgedIconBitmap(
+ entry.icon = LauncherIcons.createBadgedIconBitmap(
mIconProvider.getIcon(info, mIconDpi), info.getUser(),
mContext);
} else {
@@ -606,7 +607,7 @@ public class IconCache {
entry.title = title;
}
if (icon != null) {
- entry.icon = Utilities.createIconBitmap(icon, mContext);
+ entry.icon = LauncherIcons.createIconBitmap(icon, mContext);
}
}
@@ -641,7 +642,7 @@ public class IconCache {
// Load the full res icon for the application, but if useLowResIcon is set, then
// only keep the low resolution icon instead of the larger full-sized icon
- Bitmap icon = Utilities.createBadgedIconBitmap(
+ Bitmap icon = LauncherIcons.createBadgedIconBitmap(
appInfo.loadIcon(mPackageManager), user, mContext);
Bitmap lowResIcon = generateLowResIcon(icon, mPackageBgColor);
entry.title = appInfo.loadLabel(mPackageManager);
diff --git a/src/com/android/launcher3/LauncherClings.java b/src/com/android/launcher3/LauncherClings.java
deleted file mode 100644
index c1282b51c..000000000
--- a/src/com/android/launcher3/LauncherClings.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2008 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;
-
-import android.content.Context;
-
-@Deprecated
-public class LauncherClings {
- private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed";
-
- public static void markFirstRunClingDismissed(Context ctx) {
- Utilities.getPrefs(ctx).edit()
- .putBoolean(WORKSPACE_CLING_DISMISSED_KEY, true)
- .apply();
- }
-}
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 68450e7a7..c4987298a 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -57,6 +57,7 @@ import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.GridSizeMigrationTask;
import com.android.launcher3.model.WidgetsModel;
@@ -3159,7 +3160,7 @@ public class LauncherModel extends BroadcastReceiver
// Update shortcuts which use iconResource.
if ((si.iconResource != null)
&& pkgFilter.matches(si.iconResource.packageName)) {
- Bitmap icon = Utilities.createIconBitmap(
+ Bitmap icon = LauncherIcons.createIconBitmap(
si.iconResource.packageName,
si.iconResource.resourceName, context);
if (icon != null) {
@@ -3753,17 +3754,15 @@ public class LauncherModel extends BroadcastReceiver
}
Bitmap icon = null;
- boolean customIcon = false;
ShortcutIconResource iconResource = null;
if (bitmap instanceof Bitmap) {
- icon = Utilities.createIconBitmap((Bitmap) bitmap, context);
- customIcon = true;
+ icon = LauncherIcons.createIconBitmap((Bitmap) bitmap, context);
} else {
Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (extra instanceof ShortcutIconResource) {
iconResource = (ShortcutIconResource) extra;
- icon = Utilities.createIconBitmap(iconResource.packageName,
+ icon = LauncherIcons.createIconBitmap(iconResource.packageName,
iconResource.resourceName, context);
}
}
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index f3d949326..e1ff6dbc1 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -764,12 +764,7 @@ public class LauncherProvider extends ContentProvider {
}
}
case 16: {
- // We use the db version upgrade here to identify users who may not have seen
- // clings yet (because they weren't available), but for whom the clings are now
- // available (tablet users). Because one of the possible cling flows (migration)
- // is very destructive (wipes out workspaces), we want to prevent this from showing
- // until clear data. We do so by marking that the clings have been shown.
- LauncherClings.markFirstRunClingDismissed(mContext);
+ // No-op
}
case 17: {
// No-op
diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java
index 9d7be1693..9b4bfbcad 100644
--- a/src/com/android/launcher3/ShortcutInfo.java
+++ b/src/com/android/launcher3/ShortcutInfo.java
@@ -31,6 +31,7 @@ import com.android.launcher3.compat.LauncherActivityInfoCompat;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
/**
@@ -323,13 +324,13 @@ public class ShortcutInfo extends ItemInfo {
IconCache cache = launcherAppState.getIconCache();
Bitmap unbadgedBitmap = unbadgedDrawable == null
? cache.getDefaultIcon(UserHandleCompat.myUserHandle())
- : Utilities.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
+ : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
setIcon(getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context));
}
protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
IconCache cache, Context context) {
- unbadgedBitmap = Utilities.addShadowToIcon(unbadgedBitmap);
+ unbadgedBitmap = LauncherIcons.addShadowToIcon(unbadgedBitmap);
// Get the app info for the source activity.
AppInfo appInfo = new AppInfo();
appInfo.user = user;
@@ -338,9 +339,9 @@ public class ShortcutInfo extends ItemInfo {
cache.getTitleAndIcon(appInfo, shortcutInfo.getActivityInfo(context), false);
} catch (NullPointerException e) {
// This may happen when we fail to load the activity info. Worst case ignore badging.
- return Utilities.badgeIconForUser(unbadgedBitmap, user, context);
+ return LauncherIcons.badgeIconForUser(unbadgedBitmap, user, context);
}
- return Utilities.badgeWithBitmap(unbadgedBitmap, appInfo.iconBitmap, context);
+ return LauncherIcons.badgeWithBitmap(unbadgedBitmap, appInfo.iconBitmap, context);
}
/** Returns the ShortcutInfo id associated with the deep shortcut. */
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index e34f509da..17afe051a 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -31,19 +31,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
-import android.database.Cursor;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
-import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.PaintDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
@@ -62,11 +54,7 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;
-import com.android.launcher3.compat.UserHandleCompat;
-import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
-import com.android.launcher3.graphics.ShadowGenerator;
-import com.android.launcher3.util.IconNormalizer;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
@@ -90,19 +78,9 @@ public final class Utilities {
private static final String TAG = "Launcher.Utilities";
- private static final Rect sOldBounds = new Rect();
- private static final Canvas sCanvas = new Canvas();
-
private static final Pattern sTrimPattern =
Pattern.compile("^[\\s|\\p{javaSpaceChar}]*(.*)[\\s|\\p{javaSpaceChar}]*$");
- static {
- sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
- Paint.FILTER_BITMAP_FLAG));
- }
- static int sColors[] = { 0xffff0000, 0xff00ff00, 0xff0000ff };
- static int sColorIndex = 0;
-
private static final int[] sLoc0 = new int[2];
private static final int[] sLoc1 = new int[2];
@@ -170,198 +148,6 @@ public final class Utilities {
return false;
}
- public static Bitmap createIconBitmap(Cursor c, int iconIndex, Context context) {
- byte[] data = c.getBlob(iconIndex);
- try {
- return createIconBitmap(BitmapFactory.decodeByteArray(data, 0, data.length), context);
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Returns a bitmap suitable for the all apps view. If the package or the resource do not
- * exist, it returns null.
- */
- public static Bitmap createIconBitmap(String packageName, String resourceName,
- Context context) {
- PackageManager packageManager = context.getPackageManager();
- // the resource
- try {
- Resources resources = packageManager.getResourcesForApplication(packageName);
- if (resources != null) {
- final int id = resources.getIdentifier(resourceName, null, null);
- return createIconBitmap(
- resources.getDrawableForDensity(id, LauncherAppState.getInstance()
- .getInvariantDeviceProfile().fillResIconDpi), context);
- }
- } catch (Exception e) {
- // Icon not found.
- }
- return null;
- }
-
- private static int getIconBitmapSize() {
- return LauncherAppState.getInstance().getInvariantDeviceProfile().iconBitmapSize;
- }
-
- /**
- * Returns a bitmap which is of the appropriate size to be displayed as an icon
- */
- public static Bitmap createIconBitmap(Bitmap icon, Context context) {
- final int iconBitmapSize = getIconBitmapSize();
- if (iconBitmapSize == icon.getWidth() && iconBitmapSize == icon.getHeight()) {
- return icon;
- }
- return createIconBitmap(new BitmapDrawable(context.getResources(), icon), context);
- }
-
- /**
- * Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}.
- * The bitmap is also visually normalized with other icons.
- */
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- public static Bitmap createBadgedIconBitmap(
- Drawable icon, UserHandleCompat user, Context context) {
- float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
- 1 : IconNormalizer.getInstance().getScale(icon, null);
- Bitmap bitmap = createIconBitmap(icon, context, scale);
- return badgeIconForUser(bitmap, user, context);
- }
-
- /**
- * Badges the provided icon with the user badge if required.
- */
- public static Bitmap badgeIconForUser(Bitmap icon, UserHandleCompat user, Context context) {
- if (Utilities.ATLEAST_LOLLIPOP && user != null
- && !UserHandleCompat.myUserHandle().equals(user)) {
- BitmapDrawable drawable = new FixedSizeBitmapDrawable(icon);
- Drawable badged = context.getPackageManager().getUserBadgedIcon(
- drawable, user.getUser());
- if (badged instanceof BitmapDrawable) {
- return ((BitmapDrawable) badged).getBitmap();
- } else {
- return createIconBitmap(badged, context);
- }
- } else {
- return icon;
- }
- }
-
- /**
- * Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually
- * normalized with other icons and has enough spacing to add shadow.
- */
- public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context) {
- RectF iconBounds = new RectF();
- float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
- 1 : IconNormalizer.getInstance().getScale(icon, iconBounds);
- scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds));
- return createIconBitmap(icon, context, scale);
- }
-
- /**
- * Adds a shadow to the provided icon. It assumes that the icon has already been scaled using
- * {@link #createScaledBitmapWithoutShadow(Drawable, Context)}
- */
- public static Bitmap addShadowToIcon(Bitmap icon) {
- return ShadowGenerator.getInstance().recreateIcon(icon);
- }
-
- /**
- * Adds the {@param badge} on top of {@param srcTgt} using the badge dimensions.
- */
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- public static Bitmap badgeWithBitmap(Bitmap srcTgt, Bitmap badge, Context context) {
- int badgeSize = context.getResources().getDimensionPixelSize(R.dimen.profile_badge_size);
- synchronized (sCanvas) {
- sCanvas.setBitmap(srcTgt);
- sCanvas.drawBitmap(badge, new Rect(0, 0, badge.getWidth(), badge.getHeight()),
- new Rect(srcTgt.getWidth() - badgeSize,
- srcTgt.getHeight() - badgeSize, srcTgt.getWidth(), srcTgt.getHeight()),
- new Paint(Paint.FILTER_BITMAP_FLAG));
- sCanvas.setBitmap(null);
- }
- return srcTgt;
- }
-
- /**
- * Returns a bitmap suitable for the all apps view.
- */
- public static Bitmap createIconBitmap(Drawable icon, Context context) {
- return createIconBitmap(icon, context, 1.0f /* scale */);
- }
-
- /**
- * @param scale the scale to apply before drawing {@param icon} on the canvas
- */
- public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) {
- synchronized (sCanvas) {
- final int iconBitmapSize = getIconBitmapSize();
-
- int width = iconBitmapSize;
- int height = iconBitmapSize;
-
- if (icon instanceof PaintDrawable) {
- PaintDrawable painter = (PaintDrawable) icon;
- painter.setIntrinsicWidth(width);
- painter.setIntrinsicHeight(height);
- } else if (icon instanceof BitmapDrawable) {
- // Ensure the bitmap has a density.
- BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
- Bitmap bitmap = bitmapDrawable.getBitmap();
- if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) {
- bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
- }
- }
- int sourceWidth = icon.getIntrinsicWidth();
- int sourceHeight = icon.getIntrinsicHeight();
- if (sourceWidth > 0 && sourceHeight > 0) {
- // Scale the icon proportionally to the icon dimensions
- final float ratio = (float) sourceWidth / sourceHeight;
- if (sourceWidth > sourceHeight) {
- height = (int) (width / ratio);
- } else if (sourceHeight > sourceWidth) {
- width = (int) (height * ratio);
- }
- }
-
- // no intrinsic size --> use default size
- int textureWidth = iconBitmapSize;
- int textureHeight = iconBitmapSize;
-
- final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
- Bitmap.Config.ARGB_8888);
- final Canvas canvas = sCanvas;
- canvas.setBitmap(bitmap);
-
- final int left = (textureWidth-width) / 2;
- final int top = (textureHeight-height) / 2;
-
- @SuppressWarnings("all") // suppress dead code warning
- final boolean debug = false;
- if (debug) {
- // draw a big box for the icon for debugging
- canvas.drawColor(sColors[sColorIndex]);
- if (++sColorIndex >= sColors.length) sColorIndex = 0;
- Paint debugPaint = new Paint();
- debugPaint.setColor(0xffcccc00);
- canvas.drawRect(left, top, left+width, top+height, debugPaint);
- }
-
- sOldBounds.set(icon.getBounds());
- icon.setBounds(left, top, left+width, top+height);
- canvas.save(Canvas.MATRIX_SAVE_FLAG);
- canvas.scale(scale, scale, textureWidth / 2, textureHeight / 2);
- icon.draw(canvas);
- canvas.restore();
- icon.setBounds(sOldBounds);
- canvas.setBitmap(null);
-
- return bitmap;
- }
- }
-
/**
* Given a coordinate relative to the descendant, find the coordinate in a parent view's
* coordinates.
@@ -880,28 +666,6 @@ public final class Utilities {
return c == null || c.isEmpty();
}
- /**
- * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
- * This allows the badging to be done based on the action bitmap size rather than
- * the scaled bitmap size.
- */
- private static class FixedSizeBitmapDrawable extends BitmapDrawable {
-
- public FixedSizeBitmapDrawable(Bitmap bitmap) {
- super(null, bitmap);
- }
-
- @Override
- public int getIntrinsicHeight() {
- return getBitmap().getWidth();
- }
-
- @Override
- public int getIntrinsicWidth() {
- return getBitmap().getWidth();
- }
- }
-
public static int getColorAccent(Context context) {
TypedArray ta = context.obtainStyledAttributes(new int[]{android.R.attr.colorAccent});
int colorAccent = ta.getColor(0, 0);
diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java
index bc91c15be..7ad1e3a43 100644
--- a/src/com/android/launcher3/graphics/DragPreviewProvider.java
+++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java
@@ -24,7 +24,6 @@ import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;
-import com.android.launcher3.HolographicOutlineHelper;
import com.android.launcher3.Launcher;
import com.android.launcher3.PreloadIconDrawable;
import com.android.launcher3.Workspace;
@@ -137,7 +136,7 @@ public class DragPreviewProvider {
mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ALPHA_8);
canvas.setBitmap(b);
drawDragView(canvas);
- HolographicOutlineHelper.obtain(mView.getContext())
+ HolographicOutlineHelper.getInstance(mView.getContext())
.applyExpensiveOutlineWithBlur(b, canvas);
canvas.setBitmap(null);
return b;
diff --git a/src/com/android/launcher3/HolographicOutlineHelper.java b/src/com/android/launcher3/graphics/HolographicOutlineHelper.java
index 9dec7d9e4..0d70bdee1 100644
--- a/src/com/android/launcher3/HolographicOutlineHelper.java
+++ b/src/com/android/launcher3/graphics/HolographicOutlineHelper.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.launcher3;
+package com.android.launcher3.graphics;
import android.content.Context;
import android.content.res.Resources;
@@ -29,6 +29,8 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.SparseArray;
+import com.android.launcher3.BubbleTextView;
+import com.android.launcher3.R;
import com.android.launcher3.config.ProviderConfig;
import java.nio.ByteBuffer;
@@ -72,9 +74,9 @@ public class HolographicOutlineHelper {
mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
}
- public static HolographicOutlineHelper obtain(Context context) {
+ public static HolographicOutlineHelper getInstance(Context context) {
if (sInstance == null) {
- sInstance = new HolographicOutlineHelper(context);
+ sInstance = new HolographicOutlineHelper(context.getApplicationContext());
}
return sInstance;
}
@@ -155,11 +157,11 @@ public class HolographicOutlineHelper {
thickInnerBlur.recycle();
}
- Bitmap createMediumDropShadow(BubbleTextView view) {
+ public Bitmap createMediumDropShadow(BubbleTextView view) {
return createMediumDropShadow(view.getIcon(), view.getScaleX(), view.getScaleY(), true);
}
- Bitmap createMediumDropShadow(Drawable drawable, boolean shouldCache) {
+ public Bitmap createMediumDropShadow(Drawable drawable, boolean shouldCache) {
return createMediumDropShadow(drawable, 1f, 1f, shouldCache);
}
diff --git a/src/com/android/launcher3/util/IconNormalizer.java b/src/com/android/launcher3/graphics/IconNormalizer.java
index 040a1b51a..f90b2d72e 100644
--- a/src/com/android/launcher3/util/IconNormalizer.java
+++ b/src/com/android/launcher3/graphics/IconNormalizer.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.launcher3.util;
+package com.android.launcher3.graphics;
import android.graphics.Bitmap;
import android.graphics.Canvas;
diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java
new file mode 100644
index 000000000..9f3f3571d
--- /dev/null
+++ b/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.graphics;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PaintFlagsDrawFilter;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.PaintDrawable;
+import android.os.Build;
+
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
+import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.config.FeatureFlags;
+
+/**
+ * Helper methods for generating various launcher icons
+ */
+public class LauncherIcons {
+
+ private static final Rect sOldBounds = new Rect();
+ private static final Canvas sCanvas = new Canvas();
+
+ static {
+ sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
+ Paint.FILTER_BITMAP_FLAG));
+ }
+
+
+ public static Bitmap createIconBitmap(Cursor c, int iconIndex, Context context) {
+ byte[] data = c.getBlob(iconIndex);
+ try {
+ return createIconBitmap(BitmapFactory.decodeByteArray(data, 0, data.length), context);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns a bitmap suitable for the all apps view. If the package or the resource do not
+ * exist, it returns null.
+ */
+ public static Bitmap createIconBitmap(String packageName, String resourceName,
+ Context context) {
+ PackageManager packageManager = context.getPackageManager();
+ // the resource
+ try {
+ Resources resources = packageManager.getResourcesForApplication(packageName);
+ if (resources != null) {
+ final int id = resources.getIdentifier(resourceName, null, null);
+ return createIconBitmap(
+ resources.getDrawableForDensity(id, LauncherAppState.getInstance()
+ .getInvariantDeviceProfile().fillResIconDpi), context);
+ }
+ } catch (Exception e) {
+ // Icon not found.
+ }
+ return null;
+ }
+
+ private static int getIconBitmapSize() {
+ return LauncherAppState.getInstance().getInvariantDeviceProfile().iconBitmapSize;
+ }
+
+ /**
+ * Returns a bitmap which is of the appropriate size to be displayed as an icon
+ */
+ public static Bitmap createIconBitmap(Bitmap icon, Context context) {
+ final int iconBitmapSize = getIconBitmapSize();
+ if (iconBitmapSize == icon.getWidth() && iconBitmapSize == icon.getHeight()) {
+ return icon;
+ }
+ return createIconBitmap(new BitmapDrawable(context.getResources(), icon), context);
+ }
+
+ /**
+ * Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}.
+ * The bitmap is also visually normalized with other icons.
+ */
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public static Bitmap createBadgedIconBitmap(
+ Drawable icon, UserHandleCompat user, Context context) {
+ float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
+ 1 : IconNormalizer.getInstance().getScale(icon, null);
+ Bitmap bitmap = createIconBitmap(icon, context, scale);
+ return badgeIconForUser(bitmap, user, context);
+ }
+
+ /**
+ * Badges the provided icon with the user badge if required.
+ */
+ public static Bitmap badgeIconForUser(Bitmap icon, UserHandleCompat user, Context context) {
+ if (Utilities.ATLEAST_LOLLIPOP && user != null
+ && !UserHandleCompat.myUserHandle().equals(user)) {
+ BitmapDrawable drawable = new FixedSizeBitmapDrawable(icon);
+ Drawable badged = context.getPackageManager().getUserBadgedIcon(
+ drawable, user.getUser());
+ if (badged instanceof BitmapDrawable) {
+ return ((BitmapDrawable) badged).getBitmap();
+ } else {
+ return createIconBitmap(badged, context);
+ }
+ } else {
+ return icon;
+ }
+ }
+
+ /**
+ * Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually
+ * normalized with other icons and has enough spacing to add shadow.
+ */
+ public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context) {
+ RectF iconBounds = new RectF();
+ float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
+ 1 : IconNormalizer.getInstance().getScale(icon, iconBounds);
+ scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds));
+ return createIconBitmap(icon, context, scale);
+ }
+
+ /**
+ * Adds a shadow to the provided icon. It assumes that the icon has already been scaled using
+ * {@link #createScaledBitmapWithoutShadow(Drawable, Context)}
+ */
+ public static Bitmap addShadowToIcon(Bitmap icon) {
+ return ShadowGenerator.getInstance().recreateIcon(icon);
+ }
+
+ /**
+ * Adds the {@param badge} on top of {@param srcTgt} using the badge dimensions.
+ */
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public static Bitmap badgeWithBitmap(Bitmap srcTgt, Bitmap badge, Context context) {
+ int badgeSize = context.getResources().getDimensionPixelSize(R.dimen.profile_badge_size);
+ synchronized (sCanvas) {
+ sCanvas.setBitmap(srcTgt);
+ sCanvas.drawBitmap(badge, new Rect(0, 0, badge.getWidth(), badge.getHeight()),
+ new Rect(srcTgt.getWidth() - badgeSize,
+ srcTgt.getHeight() - badgeSize, srcTgt.getWidth(), srcTgt.getHeight()),
+ new Paint(Paint.FILTER_BITMAP_FLAG));
+ sCanvas.setBitmap(null);
+ }
+ return srcTgt;
+ }
+
+ /**
+ * Returns a bitmap suitable for the all apps view.
+ */
+ public static Bitmap createIconBitmap(Drawable icon, Context context) {
+ return createIconBitmap(icon, context, 1.0f /* scale */);
+ }
+
+ /**
+ * @param scale the scale to apply before drawing {@param icon} on the canvas
+ */
+ public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) {
+ synchronized (sCanvas) {
+ final int iconBitmapSize = getIconBitmapSize();
+
+ int width = iconBitmapSize;
+ int height = iconBitmapSize;
+
+ if (icon instanceof PaintDrawable) {
+ PaintDrawable painter = (PaintDrawable) icon;
+ painter.setIntrinsicWidth(width);
+ painter.setIntrinsicHeight(height);
+ } else if (icon instanceof BitmapDrawable) {
+ // Ensure the bitmap has a density.
+ BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
+ Bitmap bitmap = bitmapDrawable.getBitmap();
+ if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) {
+ bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
+ }
+ }
+ int sourceWidth = icon.getIntrinsicWidth();
+ int sourceHeight = icon.getIntrinsicHeight();
+ if (sourceWidth > 0 && sourceHeight > 0) {
+ // Scale the icon proportionally to the icon dimensions
+ final float ratio = (float) sourceWidth / sourceHeight;
+ if (sourceWidth > sourceHeight) {
+ height = (int) (width / ratio);
+ } else if (sourceHeight > sourceWidth) {
+ width = (int) (height * ratio);
+ }
+ }
+
+ // no intrinsic size --> use default size
+ int textureWidth = iconBitmapSize;
+ int textureHeight = iconBitmapSize;
+
+ final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
+ Bitmap.Config.ARGB_8888);
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(bitmap);
+
+ final int left = (textureWidth-width) / 2;
+ final int top = (textureHeight-height) / 2;
+
+ sOldBounds.set(icon.getBounds());
+ icon.setBounds(left, top, left+width, top+height);
+ canvas.save(Canvas.MATRIX_SAVE_FLAG);
+ canvas.scale(scale, scale, textureWidth / 2, textureHeight / 2);
+ icon.draw(canvas);
+ canvas.restore();
+ icon.setBounds(sOldBounds);
+ canvas.setBitmap(null);
+
+ return bitmap;
+ }
+ }
+
+ /**
+ * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
+ * This allows the badging to be done based on the action bitmap size rather than
+ * the scaled bitmap size.
+ */
+ private static class FixedSizeBitmapDrawable extends BitmapDrawable {
+
+ public FixedSizeBitmapDrawable(Bitmap bitmap) {
+ super(null, bitmap);
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return getBitmap().getWidth();
+ }
+
+ @Override
+ public int getIntrinsicWidth() {
+ return getBitmap().getWidth();
+ }
+ }
+}
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
index 3c7ba327b..38fd9510a 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
@@ -63,6 +63,7 @@ import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.graphics.TriangleShape;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -391,7 +392,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
private void showDragView(BubbleTextView originalIcon) {
// TODO: implement support for Drawable DragViews so we don't have to create a bitmap here.
- Bitmap b = Utilities.createIconBitmap(originalIcon.getIcon(), mLauncher);
+ Bitmap b = LauncherIcons.createIconBitmap(originalIcon.getIcon(), mLauncher);
float scale = mLauncher.getDragLayer().getLocationInDragLayer(originalIcon, mTempXY);
int dragLayerX = Math.round(mTempXY[0] - (b.getWidth() - scale * originalIcon.getWidth()) / 2);
int dragLayerY = Math.round(mTempXY[1] - (b.getHeight() - scale * b.getHeight()) / 2
diff --git a/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java b/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java
index 2adb82e2d..fc474f527 100644
--- a/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java
+++ b/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java
@@ -23,7 +23,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
-import com.android.launcher3.HolographicOutlineHelper;
+import com.android.launcher3.graphics.HolographicOutlineHelper;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.DragPreviewProvider;
@@ -44,7 +44,7 @@ public class ShortcutDragPreviewProvider extends DragPreviewProvider {
public Bitmap createDragOutline(Canvas canvas) {
Bitmap b = drawScaledPreview(canvas, Bitmap.Config.ALPHA_8);
- HolographicOutlineHelper.obtain(mView.getContext())
+ HolographicOutlineHelper.getInstance(mView.getContext())
.applyExpensiveOutlineWithBlur(b, canvas);
canvas.setBitmap(null);
return b;
diff --git a/src/com/android/launcher3/util/CursorIconInfo.java b/src/com/android/launcher3/util/CursorIconInfo.java
index 4fefa986e..6603ee765 100644
--- a/src/com/android/launcher3/util/CursorIconInfo.java
+++ b/src/com/android/launcher3/util/CursorIconInfo.java
@@ -25,6 +25,7 @@ import android.text.TextUtils;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
+import com.android.launcher3.graphics.LauncherIcons;
/**
* Utility class to load icon from a cursor.
@@ -59,7 +60,7 @@ public class CursorIconInfo {
info.iconResource = new ShortcutIconResource();
info.iconResource.packageName = packageName;
info.iconResource.resourceName = resourceName;
- icon = Utilities.createIconBitmap(packageName, resourceName, mContext);
+ icon = LauncherIcons.createIconBitmap(packageName, resourceName, mContext);
}
if (icon == null) {
// Failed to load from resource, try loading from DB.
@@ -72,7 +73,7 @@ public class CursorIconInfo {
* Loads the fixed bitmap from the icon if available.
*/
public Bitmap loadIcon(Cursor c) {
- return Utilities.createIconBitmap(c, iconIndex, mContext);
+ return LauncherIcons.createIconBitmap(c, iconIndex, mContext);
}
/**
diff --git a/src/com/android/launcher3/widget/PendingItemPreviewProvider.java b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
index eaa0bb3d5..7c06701e8 100644
--- a/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
+++ b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
@@ -21,7 +21,7 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.View;
-import com.android.launcher3.HolographicOutlineHelper;
+import com.android.launcher3.graphics.HolographicOutlineHelper;
import com.android.launcher3.Launcher;
import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.Workspace;
@@ -67,7 +67,7 @@ public class PendingItemPreviewProvider extends DragPreviewProvider {
// Don't clip alpha values for the drag outline if we're using the default widget preview
boolean clipAlpha = !(mAddInfo instanceof PendingAddWidgetInfo &&
(((PendingAddWidgetInfo) mAddInfo).previewImage == 0));
- HolographicOutlineHelper.obtain(mView.getContext())
+ HolographicOutlineHelper.getInstance(mView.getContext())
.applyExpensiveOutlineWithBlur(b, canvas, clipAlpha);
canvas.setBitmap(null);
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 70b2945f5..656fba601 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -45,6 +45,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.Workspace;
import com.android.launcher3.dragndrop.DragController;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -240,7 +241,7 @@ public class WidgetsContainerView extends BaseContainerView
} else {
PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.activityInfo);
- preview = Utilities.createIconBitmap(icon, mLauncher);
+ preview = LauncherIcons.createIconBitmap(icon, mLauncher);
createItemInfo.spanX = createItemInfo.spanY = 1;
scale = ((float) mLauncher.getDeviceProfile().iconSizePx) / preview.getWidth();
}