Removing some Launcher3 dependencies from BaseIconCache
Change-Id: Ic80ed4a5cd2fc414cd6c27096d798e7f0b8efc72
This commit is contained in:
1 parent
066ace1b88
commit
e62d2bb165
9 files changed
+86
-55
No files matched your search
@@ -15,10 +15,18 @@
|
||||
*/
|
||||
package com.android.launcher3.icons;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
|
||||
public class GraphicsUtils {
|
||||
|
||||
private static final String TAG = "GraphicsUtils";
|
||||
|
||||
/**
|
||||
* Set the alpha component of {@code color} to be {@code alpha}. Unlike the support lib version,
|
||||
* it bounds the alpha in valid range instead of throwing an exception to allow for safer
|
||||
@@ -33,4 +41,23 @@ public class GraphicsUtils {
|
||||
}
|
||||
return (color & 0x00ffffff) | (alpha << 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses the bitmap to a byte array for serialization.
|
||||
*/
|
||||
public static byte[] flattenBitmap(Bitmap bitmap) {
|
||||
// Try go guesstimate how much space the icon will take when serialized
|
||||
// to avoid unnecessary allocations/copies during the write (4 bytes per pixel).
|
||||
int size = bitmap.getWidth() * bitmap.getHeight() * 4;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
|
||||
try {
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||
out.flush();
|
||||
out.close();
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Could not write bitmap");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user