Skip to content

Commit 70d3aa7

Browse files
committed
Revert WallpaperManagerCompatVL.java
1 parent d73786f commit 70d3aa7

1 file changed

Lines changed: 7 additions & 72 deletions

File tree

src/com/android/home/compat/WallpaperManagerCompatVL.java

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
import android.graphics.BitmapFactory;
3333
import android.graphics.BitmapRegionDecoder;
3434
import android.graphics.Canvas;
35-
import android.graphics.Color;
3635
import android.graphics.Rect;
3736
import android.graphics.drawable.Drawable;
3837
import android.os.Handler;
3938
import android.os.HandlerThread;
4039
import android.os.ParcelFileDescriptor;
4140
import android.support.annotation.Nullable;
42-
import android.support.v4.graphics.ColorUtils;
4341
import android.support.v7.graphics.Palette;
4442
import android.util.Log;
4543
import android.util.Pair;
@@ -141,16 +139,6 @@ private void handleResult(String result) {
141139

142140
private static final int getWallpaperId(Context context) {
143141
if (!Utilities.ATLEAST_NOUGAT) {
144-
Drawable wallpaper = WallpaperManager.getInstance(context).getDrawable();
145-
if (wallpaper != null) {
146-
Bitmap bm = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
147-
Canvas cv = new Canvas(bm);
148-
wallpaper.setBounds(0, 0, cv.getWidth(), cv.getHeight());
149-
wallpaper.draw(cv);
150-
int c = bm.getPixel(0, 0);
151-
bm.recycle();
152-
return c;
153-
}
154142
return -1;
155143
}
156144
return context.getSystemService(WallpaperManager.class).getWallpaperId(FLAG_SYSTEM);
@@ -167,13 +155,12 @@ private static Pair<Integer, WallpaperColorsCompat> parseValue(String value) {
167155
return Pair.create(wallpaperId, null);
168156
}
169157

170-
int hints = parts.length > 2 ? Integer.parseInt(parts[2]) : 0;
171-
int primary = parts.length > 3 ? Integer.parseInt(parts[3]) : 0;
172-
int secondary = parts.length > 4 ? Integer.parseInt(parts[4]) : 0;
173-
int tertiary = parts.length > 5 ? Integer.parseInt(parts[5]) : 0;
158+
int primary = parts.length > 2 ? Integer.parseInt(parts[2]) : 0;
159+
int secondary = parts.length > 3 ? Integer.parseInt(parts[3]) : 0;
160+
int tertiary = parts.length > 4 ? Integer.parseInt(parts[4]) : 0;
174161

175162
return Pair.create(wallpaperId, new WallpaperColorsCompat(primary, secondary, tertiary,
176-
hints));
163+
0 /* hints */));
177164
}
178165

179166
/**
@@ -182,14 +169,6 @@ private static Pair<Integer, WallpaperColorsCompat> parseValue(String value) {
182169
public static class ColorExtractionService extends JobService implements Runnable {
183170
private static final int MAX_WALLPAPER_EXTRACTION_AREA = 112 * 112;
184171

185-
// Decides when dark theme is optimal for this wallpaper
186-
private static final float DARK_THEME_MEAN_LUMINANCE = 0.25f;
187-
// Minimum mean luminosity that an image needs to have to support dark text
188-
private static final float BRIGHT_IMAGE_MEAN_LUMINANCE = 0.75f;
189-
// We also check if the image has dark pixels in it,
190-
// to avoid bright images with some dark spots.
191-
private static final float DARK_PIXEL_LUMINANCE = 0.45f;
192-
private static final float MAX_DARK_AREA = 0.05f;
193172
private HandlerThread mWorkerThread;
194173
private Handler mWorkerHandler;
195174

@@ -282,11 +261,10 @@ public void run() {
282261

283262
if (bitmap != null) {
284263
Palette palette = Palette.from(bitmap).generate();
285-
int hints = calculateDarkHints(bitmap);
286264
bitmap.recycle();
287265

288266
StringBuilder builder = new StringBuilder(value);
289-
List<Pair<Integer, Integer>> colorsToOccurrences = new ArrayList<>();
267+
List<Pair<Integer,Integer>> colorsToOccurrences = new ArrayList<>();
290268
for (Palette.Swatch swatch : palette.getSwatches()) {
291269
colorsToOccurrences.add(new Pair(swatch.getRgb(), swatch.getPopulation()));
292270
}
@@ -298,8 +276,7 @@ public int compare(Pair<Integer, Integer> a, Pair<Integer, Integer> b) {
298276
}
299277
});
300278

301-
for (int i = 0; i < Math.min(3, colorsToOccurrences.size()); i++) {
302-
builder.append(',').append(hints);
279+
for (int i=0; i < Math.min(3, colorsToOccurrences.size()); i++) {
303280
builder.append(',').append(colorsToOccurrences.get(i).first);
304281
}
305282

@@ -311,47 +288,5 @@ public int compare(Pair<Integer, Integer> a, Pair<Integer, Integer> b) {
311288
.setPackage(getPackageName())
312289
.putExtra(KEY_COLORS, value));
313290
}
314-
315-
316-
/**
317-
* Checks if image is bright and clean enough to support light text.
318-
*
319-
* @param source What to read.
320-
* @return Whether image supports dark text or not.
321-
*/
322-
private static int calculateDarkHints(Bitmap source) {
323-
if (source == null) {
324-
return 0;
325-
}
326-
int[] pixels = new int[source.getWidth() * source.getHeight()];
327-
double totalLuminance = 0;
328-
final int maxDarkPixels = (int) (pixels.length * MAX_DARK_AREA);
329-
int darkPixels = 0;
330-
source.getPixels(pixels, 0 /* offset */, source.getWidth(), 0 /* x */, 0 /* y */,
331-
source.getWidth(), source.getHeight());
332-
// This bitmap was already resized to fit the maximum allowed area.
333-
// Let's just loop through the pixels, no sweat!
334-
float[] tmpHsl = new float[3];
335-
for (int i = 0; i < pixels.length; i++) {
336-
ColorUtils.colorToHSL(pixels[i], tmpHsl);
337-
final float luminance = tmpHsl[2];
338-
final int alpha = Color.alpha(pixels[i]);
339-
// Make sure we don't have a dark pixel mass that will
340-
// make text illegible.
341-
if (luminance < DARK_PIXEL_LUMINANCE && alpha != 0) {
342-
darkPixels++;
343-
}
344-
totalLuminance += luminance;
345-
}
346-
int hints = 0;
347-
double meanLuminance = totalLuminance / pixels.length;
348-
if (meanLuminance > BRIGHT_IMAGE_MEAN_LUMINANCE && darkPixels < maxDarkPixels) {
349-
hints |= WallpaperColorsCompat.HINT_SUPPORTS_DARK_TEXT;
350-
}
351-
if (meanLuminance < DARK_THEME_MEAN_LUMINANCE) {
352-
hints |= WallpaperColorsCompat.HINT_SUPPORTS_DARK_THEME;
353-
}
354-
return hints;
355-
}
356-
}
357291
}
292+
}

0 commit comments

Comments
 (0)