summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.gradle2
-rw-r--r--src/com/android/launcher3/Hotseat.java59
-rw-r--r--src/com/android/launcher3/Launcher.java33
-rw-r--r--src/com/android/launcher3/LauncherAppState.java7
-rw-r--r--src/com/android/launcher3/LauncherAppWidgetHostView.java2
-rw-r--r--src/com/android/launcher3/LauncherModel.java27
-rw-r--r--src/com/android/launcher3/Utilities.java15
-rw-r--r--src/com/android/launcher3/config/FeatureFlags.java12
-rw-r--r--src/com/android/launcher3/config/ProviderConfig.java2
-rw-r--r--src/com/android/launcher3/dynamicui/ColorExtractionService.java14
-rw-r--r--src/com/android/launcher3/dynamicui/ExtractedColors.java86
-rw-r--r--src/com/android/launcher3/dynamicui/ExtractionUtils.java44
-rw-r--r--src/com/android/launcher3/folder/Folder.java9
-rw-r--r--src/com/android/launcher3/logging/FileLog.java216
-rw-r--r--tests/src/com/android/launcher3/logging/FileLogTest.java77
15 files changed, 511 insertions, 94 deletions
diff --git a/build.gradle b/build.gradle
index 4df406363..d777e95c8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.5.0'
+ classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
}
}
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index bb70be697..7e1ecf5af 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -16,8 +16,12 @@
package com.android.launcher3;
+import android.animation.ArgbEvaluator;
+import android.animation.ValueAnimator;
import android.content.Context;
+import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -27,12 +31,13 @@ import android.view.ViewDebug;
import android.widget.FrameLayout;
import android.widget.TextView;
+import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
public class Hotseat extends FrameLayout
- implements UserEventDispatcher.LaunchSourceProvider{
+ implements UserEventDispatcher.LaunchSourceProvider, Insettable {
private CellLayout mContent;
@@ -44,6 +49,14 @@ public class Hotseat extends FrameLayout
@ViewDebug.ExportedProperty(category = "launcher")
private final boolean mHasVerticalHotseat;
+ @ViewDebug.ExportedProperty(category = "launcher")
+ private Rect mInsets = new Rect();
+
+ @ViewDebug.ExportedProperty(category = "launcher")
+ private int mBackgroundColor;
+ @ViewDebug.ExportedProperty(category = "launcher")
+ private ColorDrawable mBackground;
+
public Hotseat(Context context) {
this(context, null);
}
@@ -56,6 +69,8 @@ public class Hotseat extends FrameLayout
super(context, attrs, defStyle);
mLauncher = (Launcher) context;
mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
+ mBackground = new ColorDrawable();
+ setBackground(mBackground);
}
public CellLayout getLayout() {
@@ -166,4 +181,46 @@ public class Hotseat extends FrameLayout
target.gridY = info.cellY;
targetParent.containerType = LauncherLogProto.HOTSEAT;
}
+
+ //Overridden so that the background color extends behind the navigation buttons.
+ @Override
+ public void setInsets(Rect insets) {
+ int rightInset = insets.right - mInsets.right;
+ int bottomInset = insets.bottom - mInsets.bottom;
+ mInsets.set(insets);
+ LayoutParams lp = (LayoutParams) getLayoutParams();
+ if (mHasVerticalHotseat) {
+ setPadding(getPaddingLeft(), getPaddingTop(),
+ getPaddingRight() + rightInset, getPaddingBottom());
+ if (lp.width != LayoutParams.MATCH_PARENT && lp.width != LayoutParams.WRAP_CONTENT) {
+ lp.width += rightInset;
+ }
+ } else {
+ setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
+ getPaddingBottom() + bottomInset);
+ if (lp.height != LayoutParams.MATCH_PARENT && lp.height != LayoutParams.WRAP_CONTENT) {
+ lp.height += bottomInset;
+ }
+ }
+ }
+
+ public void updateColor(ExtractedColors extractedColors, boolean animate) {
+ if (!mHasVerticalHotseat) {
+ int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
+ if (!animate) {
+ setBackgroundColor(color);
+ } else {
+ ValueAnimator animator = ValueAnimator.ofInt(mBackgroundColor, color);
+ animator.setEvaluator(new ArgbEvaluator());
+ animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ mBackground.setColor((Integer) animation.getAnimatedValue());
+ }
+ });
+ animator.start();
+ }
+ mBackgroundColor = color;
+ }
+ }
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b2f96d099..eacf72aa1 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -114,6 +114,7 @@ import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.ViewOnDrawExecutor;
@@ -123,11 +124,9 @@ import com.android.launcher3.widget.WidgetsContainerView;
import java.io.FileDescriptor;
import java.io.PrintWriter;
-import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -307,11 +306,6 @@ public class Launcher extends Activity
private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
- private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
- private static final Date sDateStamp = new Date();
- private static final DateFormat sDateFormat =
- DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
-
// We only want to get the SharedPreferences once since it does an FS stat each time we get
// it from the context.
private SharedPreferences mSharedPrefs;
@@ -502,9 +496,10 @@ public class Launcher extends Activity
}
private void loadExtractedColorsAndColorItems() {
- if (mExtractedColors != null) {
+ // TODO: do this in pre-N as well, once the extraction part is complete.
+ if (mExtractedColors != null && Utilities.isNycOrAbove()) {
mExtractedColors.load(this);
- // TODO: pass mExtractedColors to interested items such as hotseat.
+ mHotseat.updateColor(mExtractedColors, !mPaused);
}
}
@@ -3976,7 +3971,7 @@ public class Launcher extends Activity
// Verify that we own the widget
if (appWidgetInfo == null) {
- Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
+ FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
deleteWidgetInfo(item);
return;
}
@@ -4649,12 +4644,10 @@ public class Launcher extends Activity
}
}
- synchronized (sDumpLogs) {
- writer.println();
- writer.println(prefix + "Debug logs");
- for (String log : sDumpLogs) {
- writer.println(prefix + " " + log);
- }
+ try {
+ FileLog.flushAll(writer);
+ } catch (Exception e) {
+ // Ignore
}
if (mLauncherCallbacks != null) {
@@ -4662,14 +4655,6 @@ public class Launcher extends Activity
}
}
- public static void addDumpLog(String tag, String log) {
- Log.d(tag, log);
- synchronized(sDumpLogs) {
- sDateStamp.setTime(System.currentTimeMillis());
- sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
- }
- }
-
public static CustomAppWidget getCustomAppWidget(String name) {
return sCustomAppWidgets.get(name);
}
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index f84e4b5b4..9d889e09a 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -27,9 +27,9 @@ import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.UserManagerCompat;
-import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.util.ConfigMonitor;
+import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
@@ -79,6 +79,7 @@ public class LauncherAppState {
// is the first component to get created. Initializing application context here ensures
// that LauncherAppState always exists in the main process.
sContext = provider.getContext().getApplicationContext();
+ FileLog.setDir(sContext.getFilesDir());
}
private LauncherAppState() {
@@ -184,8 +185,4 @@ public class LauncherAppState {
public InvariantDeviceProfile getInvariantDeviceProfile() {
return mInvariantDeviceProfile;
}
-
- public static boolean isDogfoodBuild() {
- return FeatureFlags.IS_ALPHA_BUILD || FeatureFlags.IS_DEV_BUILD;
- }
}
diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java
index 570607ec7..28557d0a5 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java
@@ -256,7 +256,7 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc
@Override
public void requestChildFocus(View child, View focused) {
super.requestChildFocus(child, focused);
- dispatchChildFocus(focused != null);
+ dispatchChildFocus(mChildrenFocused && focused != null);
if (focused != null) {
focused.setFocusableInTouchMode(false);
}
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 884685c8a..2fd12fd57 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -60,6 +60,7 @@ import com.android.launcher3.model.GridSizeMigrationTask;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.CursorIconInfo;
+import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.ManagedProfileHeuristic;
@@ -1335,7 +1336,7 @@ public class LauncherModel extends BroadcastReceiver
try {
screenIds.add(sc.getLong(idIndex));
} catch (Exception e) {
- addDumpLog("Invalid screen id: " + e);
+ FileLog.d(TAG, "Invalid screen id", e);
}
}
} finally {
@@ -1813,7 +1814,7 @@ public class LauncherModel extends BroadcastReceiver
if (intent == null) {
// The app is installed but the component is no
// longer available.
- addDumpLog("Invalid component removed: " + cn);
+ FileLog.d(TAG, "Invalid component removed: " + cn);
itemsToRemove.add(id);
continue;
} else {
@@ -1824,7 +1825,7 @@ public class LauncherModel extends BroadcastReceiver
} else if (restored) {
// Package is not yet available but might be
// installed later.
- addDumpLog("package not yet restored: " + cn);
+ FileLog.d(TAG, "package not yet restored: " + cn);
if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) {
// Restore has started once.
@@ -1850,12 +1851,12 @@ public class LauncherModel extends BroadcastReceiver
itemReplaced = true;
} else if (REMOVE_UNRESTORED_ICONS) {
- addDumpLog("Unrestored package removed: " + cn);
+ FileLog.d(TAG, "Unrestored package removed: " + cn);
itemsToRemove.add(id);
continue;
}
} else if (REMOVE_UNRESTORED_ICONS) {
- addDumpLog("Unrestored package removed: " + cn);
+ FileLog.d(TAG, "Unrestored package removed: " + cn);
itemsToRemove.add(id);
continue;
}
@@ -1880,7 +1881,7 @@ public class LauncherModel extends BroadcastReceiver
} else {
// Do not wait for external media load anymore.
// Log the invalid package, and remove it
- addDumpLog("Invalid package removed: " + cn);
+ FileLog.d(TAG, "Invalid package removed: " + cn);
itemsToRemove.add(id);
continue;
}
@@ -1890,7 +1891,7 @@ public class LauncherModel extends BroadcastReceiver
restored = false;
}
} catch (URISyntaxException e) {
- addDumpLog("Invalid uri: " + intentDescription);
+ FileLog.d(TAG, "Invalid uri: " + intentDescription);
itemsToRemove.add(id);
continue;
}
@@ -2073,7 +2074,7 @@ public class LauncherModel extends BroadcastReceiver
final boolean isProviderReady = isValidProvider(provider);
if (!isSafeMode && !customWidget &&
wasProviderReady && !isProviderReady) {
- addDumpLog("Deleting widget that isn't installed anymore: "
+ FileLog.d(TAG, "Deleting widget that isn't installed anymore: "
+ provider);
itemsToRemove.add(id);
} else {
@@ -2115,7 +2116,7 @@ public class LauncherModel extends BroadcastReceiver
appWidgetInfo.restoreStatus |=
LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
} else if (REMOVE_UNRESTORED_ICONS && !isSafeMode) {
- addDumpLog("Unrestored widget removed: " + component);
+ FileLog.d(TAG, "Unrestored widget removed: " + component);
itemsToRemove.add(id);
continue;
}
@@ -2171,9 +2172,7 @@ public class LauncherModel extends BroadcastReceiver
}
}
} finally {
- if (c != null) {
- c.close();
- }
+ Utilities.closeSilently(c);
}
// Break early if we've stopped loading
@@ -3541,8 +3540,4 @@ public class LauncherModel extends BroadcastReceiver
public static Looper getWorkerLooper() {
return sWorkerThread.getLooper();
}
-
- @Thunk static final void addDumpLog(String log) {
- Launcher.addDumpLog(TAG, log);
- }
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 1acbfc12b..c5f601dcd 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -46,7 +46,6 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.os.Build;
-import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.PowerManager;
import android.text.Spannable;
@@ -63,9 +62,11 @@ 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.util.IconNormalizer;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -845,6 +846,18 @@ public final class Utilities {
return true;
}
+ public static void closeSilently(Closeable c) {
+ if (c != null) {
+ try {
+ c.close();
+ } catch (IOException e) {
+ if (ProviderConfig.IS_DOGFOOD_BUILD) {
+ Log.d(TAG, "Error closing", e);
+ }
+ }
+ }
+ }
+
/**
* 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
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 5711a3db7..34c6663e9 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -18,27 +18,15 @@ package com.android.launcher3.config;
/**
* Defines a set of flags used to control various launcher behaviors
- * All the flags must be defined as
- * public static boolean LAUNCHER3_FLAG_NAME = true/false;
- *
- * Use LAUNCHER3_ prefix for prevent namespace conflicts.
*/
public final class FeatureFlags {
private FeatureFlags() {}
- public static boolean IS_DEV_BUILD = false;
- public static boolean IS_ALPHA_BUILD = false;
- public static boolean IS_RELEASE_BUILD = true;
-
// Custom flags go below this
public static boolean LAUNCHER3_DISABLE_ICON_NORMALIZATION = false;
// As opposed to the new spring-loaded workspace.
public static boolean LAUNCHER3_LEGACY_WORKSPACE_DND = false;
public static boolean LAUNCHER3_LEGACY_FOLDER_ICON = false;
- public static boolean LAUNCHER3_LEGACY_LOGGING = false;
public static boolean LAUNCHER3_USE_SYSTEM_DRAG_DRIVER = false;
public static boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = false;
-
- // This flags is only defined to resolve some build issues.
- public static boolean LAUNCHER3_ICON_NORMALIZATION = false;
}
diff --git a/src/com/android/launcher3/config/ProviderConfig.java b/src/com/android/launcher3/config/ProviderConfig.java
index 825b43422..1d964b1b2 100644
--- a/src/com/android/launcher3/config/ProviderConfig.java
+++ b/src/com/android/launcher3/config/ProviderConfig.java
@@ -20,5 +20,5 @@ public class ProviderConfig {
public static final String AUTHORITY = "com.android.launcher3.settings".intern();
- public static boolean IS_DOGFOOD_BUILD = false;
+ public static boolean IS_DOGFOOD_BUILD = true;
}
diff --git a/src/com/android/launcher3/dynamicui/ColorExtractionService.java b/src/com/android/launcher3/dynamicui/ColorExtractionService.java
index 95a62b957..89594f407 100644
--- a/src/com/android/launcher3/dynamicui/ColorExtractionService.java
+++ b/src/com/android/launcher3/dynamicui/ColorExtractionService.java
@@ -32,6 +32,9 @@ import com.android.launcher3.LauncherSettings;
*/
public class ColorExtractionService extends IntentService {
+ /** The fraction of the wallpaper to extract colors for use on the hotseat. */
+ private static final float HOTSEAT_FRACTION = 1f / 4;
+
public ColorExtractionService() {
super("ColorExtractionService");
}
@@ -44,10 +47,21 @@ public class ColorExtractionService extends IntentService {
if (wallpaperManager.getWallpaperInfo() != null) {
// We can't extract colors from live wallpapers, so just use the default color always.
extractedColors.updatePalette(null);
+ extractedColors.updateHotseatPalette(null);
} else {
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
Palette palette = Palette.from(wallpaper).generate();
extractedColors.updatePalette(palette);
+ // We extract colors for the hotseat separately,
+ // since it only considers the lower part of the wallpaper.
+ // TODO(twickham): update Palette library to 23.3.1 or higher,
+ // which fixes a bug with using regions (b/28349435).
+ Palette hotseatPalette = Palette.from(wallpaper)
+ .setRegion(0, (int) (wallpaper.getHeight() * (1f - HOTSEAT_FRACTION)),
+ wallpaper.getWidth(), wallpaper.getHeight())
+ .clearFilters()
+ .generate();
+ extractedColors.updateHotseatPalette(hotseatPalette);
}
// Save the extracted colors and wallpaper id to LauncherProvider.
diff --git a/src/com/android/launcher3/dynamicui/ExtractedColors.java b/src/com/android/launcher3/dynamicui/ExtractedColors.java
index 4d17ff764..e545288a0 100644
--- a/src/com/android/launcher3/dynamicui/ExtractedColors.java
+++ b/src/com/android/launcher3/dynamicui/ExtractedColors.java
@@ -18,6 +18,7 @@ package com.android.launcher3.dynamicui;
import android.content.Context;
import android.graphics.Color;
+import android.support.v4.graphics.ColorUtils;
import android.support.v7.graphics.Palette;
import android.util.Log;
@@ -35,26 +36,30 @@ public class ExtractedColors {
// These color profile indices should NOT be changed, since they are used when saving and
// loading extracted colors. New colors should always be added at the end.
- public static final int DEFAULT_INDEX = 0;
- public static final int VIBRANT_INDEX = 1;
- public static final int VIBRANT_DARK_INDEX = 2;
- public static final int VIBRANT_LIGHT_INDEX = 3;
- public static final int MUTED_INDEX = 4;
- public static final int MUTED_DARK_INDEX = 5;
- public static final int MUTED_LIGHT_INDEX = 6;
-
- public static final int NUM_COLOR_PROFILES = 7;
+ public static final int VERSION_INDEX = 0;
+ public static final int HOTSEAT_INDEX = 1;
+ // public static final int VIBRANT_INDEX = 2;
+ // public static final int VIBRANT_DARK_INDEX = 3;
+ // public static final int VIBRANT_LIGHT_INDEX = 4;
+ // public static final int MUTED_INDEX = 5;
+ // public static final int MUTED_DARK_INDEX = 6;
+ // public static final int MUTED_LIGHT_INDEX = 7;
+
+ public static final int NUM_COLOR_PROFILES = 1;
+ private static final int VERSION = 1;
private static final String COLOR_SEPARATOR = ",";
private int[] mColors;
public ExtractedColors() {
- mColors = new int[NUM_COLOR_PROFILES];
+ // The first entry is reserved for the version number.
+ mColors = new int[NUM_COLOR_PROFILES + 1];
+ mColors[VERSION_INDEX] = VERSION;
}
public void setColorAtIndex(int index, int color) {
- if (index >= 0 && index < mColors.length) {
+ if (index > VERSION_INDEX && index < mColors.length) {
mColors[index] = color;
} else {
Log.e(TAG, "Attempted to set a color at an invalid index " + index);
@@ -89,17 +94,21 @@ public class ExtractedColors {
*/
public void load(Context context) {
String encodedString = Utilities.getPrefs(context).getString(
- ExtractionUtils.EXTRACTED_COLORS_PREFERENCE_KEY, DEFAULT_COLOR + "");
+ ExtractionUtils.EXTRACTED_COLORS_PREFERENCE_KEY, VERSION + "");
decodeFromString(encodedString);
+
+ if (mColors[VERSION_INDEX] != VERSION) {
+ ExtractionUtils.startColorExtractionService(context);
+ }
}
/** @param index must be one of the index values defined at the top of this class. */
- public int getColor(int index) {
- if (index >= 0 && index < mColors.length) {
+ public int getColor(int index, int defaultColor) {
+ if (index > VERSION_INDEX && index < mColors.length) {
return mColors[index];
}
- return DEFAULT_COLOR;
+ return defaultColor;
}
/**
@@ -112,20 +121,39 @@ public class ExtractedColors {
setColorAtIndex(i, ExtractedColors.DEFAULT_COLOR);
}
} else {
- setColorAtIndex(ExtractedColors.DEFAULT_INDEX,
- ExtractedColors.DEFAULT_COLOR);
- setColorAtIndex(ExtractedColors.VIBRANT_INDEX,
- palette.getVibrantColor(ExtractedColors.DEFAULT_COLOR));
- setColorAtIndex(ExtractedColors.VIBRANT_DARK_INDEX,
- palette.getDarkVibrantColor(ExtractedColors.DEFAULT_DARK));
- setColorAtIndex(ExtractedColors.VIBRANT_LIGHT_INDEX,
- palette.getLightVibrantColor(ExtractedColors.DEFAULT_LIGHT));
- setColorAtIndex(ExtractedColors.MUTED_INDEX,
- palette.getMutedColor(ExtractedColors.DEFAULT_COLOR));
- setColorAtIndex(ExtractedColors.MUTED_DARK_INDEX,
- palette.getDarkMutedColor(ExtractedColors.DEFAULT_DARK));
- setColorAtIndex(ExtractedColors.MUTED_LIGHT_INDEX,
- palette.getLightVibrantColor(ExtractedColors.DEFAULT_LIGHT));
+ // We currently don't use any of the colors defined by the Palette API,
+ // but this is how we would add them if we ever need them.
+
+ // setColorAtIndex(ExtractedColors.VIBRANT_INDEX,
+ // palette.getVibrantColor(ExtractedColors.DEFAULT_COLOR));
+ // setColorAtIndex(ExtractedColors.VIBRANT_DARK_INDEX,
+ // palette.getDarkVibrantColor(ExtractedColors.DEFAULT_DARK));
+ // setColorAtIndex(ExtractedColors.VIBRANT_LIGHT_INDEX,
+ // palette.getLightVibrantColor(ExtractedColors.DEFAULT_LIGHT));
+ // setColorAtIndex(ExtractedColors.MUTED_INDEX,
+ // palette.getMutedColor(DEFAULT_COLOR));
+ // setColorAtIndex(ExtractedColors.MUTED_DARK_INDEX,
+ // palette.getDarkMutedColor(ExtractedColors.DEFAULT_DARK));
+ // setColorAtIndex(ExtractedColors.MUTED_LIGHT_INDEX,
+ // palette.getLightVibrantColor(ExtractedColors.DEFAULT_LIGHT));
+ }
+ }
+
+ /**
+ * The hotseat's color is defined as follows:
+ * - 12% black for super light wallpaper
+ * - 18% white for super dark
+ * - 25% white otherwise
+ */
+ public void updateHotseatPalette(Palette hotseatPalette) {
+ int hotseatColor;
+ if (hotseatPalette != null && ExtractionUtils.isSuperLight(hotseatPalette)) {
+ hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
+ } else if (hotseatPalette != null && ExtractionUtils.isSuperDark(hotseatPalette)) {
+ hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
+ } else {
+ hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
}
+ setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
}
}
diff --git a/src/com/android/launcher3/dynamicui/ExtractionUtils.java b/src/com/android/launcher3/dynamicui/ExtractionUtils.java
index 0b28ba6f9..6dc0035ee 100644
--- a/src/com/android/launcher3/dynamicui/ExtractionUtils.java
+++ b/src/com/android/launcher3/dynamicui/ExtractionUtils.java
@@ -20,11 +20,15 @@ import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Color;
+import android.support.v4.graphics.ColorUtils;
+import android.support.v7.graphics.Palette;
import com.android.launcher3.Utilities;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.List;
/**
* Contains helper fields and methods related to extracting colors from the wallpaper.
@@ -34,6 +38,7 @@ public class ExtractionUtils {
public static final String WALLPAPER_ID_PREFERENCE_KEY = "pref_wallpaperId";
private static final int FLAG_SET_SYSTEM = 1 << 0; // TODO: use WallpaperManager.FLAG_SET_SYSTEM
+ private static final float MIN_CONTRAST_RATIO = 2f;
/**
* Extract colors in the :wallpaper-chooser process, if the wallpaper id has changed.
@@ -46,12 +51,17 @@ public class ExtractionUtils {
@Override
public void run() {
if (hasWallpaperIdChanged(context)) {
- context.startService(new Intent(context, ColorExtractionService.class));
+ startColorExtractionService(context);
}
}
});
}
+ /** Starts the {@link ColorExtractionService} without checking the wallpaper id */
+ public static void startColorExtractionService(Context context) {
+ context.startService(new Intent(context, ColorExtractionService.class));
+ }
+
private static boolean hasWallpaperIdChanged(Context context) {
if (!Utilities.isNycOrAbove()) {
// TODO: update an id in sharedprefs in onWallpaperChanged broadcast, and read it here.
@@ -72,4 +82,36 @@ public class ExtractionUtils {
return -1;
}
}
+
+ public static boolean isSuperLight(Palette p) {
+ return !isLegibleOnWallpaper(Color.WHITE, p.getSwatches());
+ }
+
+ public static boolean isSuperDark(Palette p) {
+ return !isLegibleOnWallpaper(Color.BLACK, p.getSwatches());
+ }
+
+ /**
+ * Given a color, returns true if that color is legible on
+ * the given wallpaper color swatches, else returns false.
+ */
+ private static boolean isLegibleOnWallpaper(int color, List<Palette.Swatch> wallpaperSwatches) {
+ int legiblePopulation = 0;
+ int illegiblePopulation = 0;
+ for (Palette.Swatch swatch : wallpaperSwatches) {
+ if (isLegible(color, swatch.getRgb())) {
+ legiblePopulation += swatch.getPopulation();
+ } else {
+ illegiblePopulation += swatch.getPopulation();
+ }
+ }
+ return legiblePopulation > illegiblePopulation;
+ }
+
+ /** @return Whether the foreground color is legible on the background color. */
+ private static boolean isLegible(int foreground, int background) {
+ background = ColorUtils.setAlphaComponent(background, 255);
+ return ColorUtils.calculateContrast(foreground, background) >= MIN_CONTRAST_RATIO;
+ }
+
}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 7dc815529..1ebe8fdfb 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -330,8 +330,13 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
public void startEditingFolderName() {
- mFolderName.setHint("");
- mIsEditingName = true;
+ post(new Runnable() {
+ @Override
+ public void run() {
+ mFolderName.setHint("");
+ mIsEditingName = true;
+ }
+ });
}
public void dismissEditingName() {
diff --git a/src/com/android/launcher3/logging/FileLog.java b/src/com/android/launcher3/logging/FileLog.java
new file mode 100644
index 000000000..68d9b8c92
--- /dev/null
+++ b/src/com/android/launcher3/logging/FileLog.java
@@ -0,0 +1,216 @@
+package com.android.launcher3.logging;
+
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Message;
+import android.util.Log;
+import android.util.Pair;
+
+import com.android.launcher3.LauncherModel;
+import com.android.launcher3.Utilities;
+import com.android.launcher3.config.ProviderConfig;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Wrapper around {@link Log} to allow writing to a file.
+ * This class can safely be called from main thread.
+ *
+ * Note: This should only be used for logging errors which have a persistent effect on user's data,
+ * but whose effect may not be visible immediately.
+ */
+public final class FileLog {
+
+ private static final String FILE_NAME_PREFIX = "log-";
+ private static final DateFormat DATE_FORMAT =
+ DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+
+ private static final long MAX_LOG_FILE_SIZE = 4 << 20; // 4 mb
+
+ private static Handler sHandler = null;
+ private static File sLogsDirectory = null;
+
+ public static void setDir(File logsDir) {
+ sLogsDirectory = logsDir;
+ }
+
+ public static void d(String tag, String msg, Exception e) {
+ Log.d(tag, msg, e);
+ print(tag, msg, e);
+ }
+
+ public static void d(String tag, String msg) {
+ Log.d(tag, msg);
+ print(tag, msg);
+ }
+
+ public static void e(String tag, String msg, Exception e) {
+ Log.e(tag, msg, e);
+ print(tag, msg, e);
+ }
+
+ public static void e(String tag, String msg) {
+ Log.e(tag, msg);
+ print(tag, msg);
+ }
+
+ public static void print(String tag, String msg) {
+ print(tag, msg, null);
+ }
+
+ public static void print(String tag, String msg, Exception e) {
+ if (!ProviderConfig.IS_DOGFOOD_BUILD) {
+ return;
+ }
+ String out = String.format("%s %s %s", DATE_FORMAT.format(new Date()), tag, msg);
+ if (e != null) {
+ out += "\n" + Log.getStackTraceString(e);
+ }
+ Message.obtain(getHandler(), LogWriterCallback.MSG_WRITE, out).sendToTarget();
+ }
+
+ private static Handler getHandler() {
+ synchronized (DATE_FORMAT) {
+ if (sHandler == null) {
+ HandlerThread thread = new HandlerThread("file-logger");
+ thread.start();
+ sHandler = new Handler(thread.getLooper(), new LogWriterCallback());
+ }
+ }
+ return sHandler;
+ }
+
+ /**
+ * Blocks until all the pending logs are written to the disk
+ * @param out if not null, all the persisted logs are copied to the writer.
+ */
+ public static void flushAll(PrintWriter out) throws InterruptedException {
+ if (!ProviderConfig.IS_DOGFOOD_BUILD) {
+ return;
+ }
+ CountDownLatch latch = new CountDownLatch(1);
+ Message.obtain(getHandler(), LogWriterCallback.MSG_FLUSH,
+ Pair.create(out, latch)).sendToTarget();
+
+ latch.await(2, TimeUnit.SECONDS);
+ }
+
+ /**
+ * Writes logs to the file.
+ * Log files are named log-0 for even days of the year and log-1 for odd days of the year.
+ * Logs older than 36 hours are purged.
+ */
+ private static class LogWriterCallback implements Handler.Callback {
+
+ private static final long CLOSE_DELAY = 5000; // 5 seconds
+
+ private static final int MSG_WRITE = 1;
+ private static final int MSG_CLOSE = 2;
+ private static final int MSG_FLUSH = 3;
+
+ private String mCurrentFileName = null;
+ private PrintWriter mCurrentWriter = null;
+
+ private void closeWriter() {
+ Utilities.closeSilently(mCurrentWriter);
+ mCurrentWriter = null;
+ }
+
+ @Override
+ public boolean handleMessage(Message msg) {
+ if (sLogsDirectory == null || !ProviderConfig.IS_DOGFOOD_BUILD) {
+ return true;
+ }
+ switch (msg.what) {
+ case MSG_WRITE: {
+ Calendar cal = Calendar.getInstance();
+ // suffix with 0 or 1 based on the day of the year.
+ String fileName = FILE_NAME_PREFIX + (cal.get(Calendar.DAY_OF_YEAR) & 1);
+
+ if (!fileName.equals(mCurrentFileName)) {
+ closeWriter();
+ }
+
+ try {
+ if (mCurrentWriter == null) {
+ mCurrentFileName = fileName;
+
+ boolean append = false;
+ File logFile = new File(sLogsDirectory, fileName);
+ if (logFile.exists()) {
+ Calendar modifiedTime = Calendar.getInstance();
+ modifiedTime.setTimeInMillis(logFile.lastModified());
+
+ // If the file was modified more that 36 hours ago, purge the file.
+ // We use instead of 24 to account for day-365 followed by day-1
+ modifiedTime.add(Calendar.HOUR, 36);
+ append = cal.before(modifiedTime)
+ && logFile.length() < MAX_LOG_FILE_SIZE;
+ }
+ mCurrentWriter = new PrintWriter(new FileWriter(logFile, append));
+ }
+
+ mCurrentWriter.println((String) msg.obj);
+ mCurrentWriter.flush();
+
+ // Auto close file stream after some time.
+ sHandler.removeMessages(MSG_CLOSE);
+ sHandler.sendEmptyMessageDelayed(MSG_CLOSE, CLOSE_DELAY);
+ } catch (Exception e) {
+ Log.e("FileLog", "Error writing logs to file", e);
+ // Close stream, will try reopening during next log
+ closeWriter();
+ }
+ return true;
+ }
+ case MSG_CLOSE: {
+ closeWriter();
+ return true;
+ }
+ case MSG_FLUSH: {
+ closeWriter();
+ Pair<PrintWriter, CountDownLatch> p =
+ (Pair<PrintWriter, CountDownLatch>) msg.obj;
+
+ if (p.first != null) {
+ dumpFile(p.first, FILE_NAME_PREFIX + 0);
+ dumpFile(p.first, FILE_NAME_PREFIX + 1);
+ }
+ p.second.countDown();
+ return true;
+ }
+ }
+ return true;
+ }
+ }
+
+ private static void dumpFile(PrintWriter out, String fileName) {
+ File logFile = new File(sLogsDirectory, fileName);
+ if (logFile.exists()) {
+
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new FileReader(logFile));
+ out.println();
+ out.println("--- logfile: " + fileName + " ---");
+ String line;
+ while ((line = in.readLine()) != null) {
+ out.println(line);
+ }
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ Utilities.closeSilently(in);
+ }
+ }
+ }
+}
diff --git a/tests/src/com/android/launcher3/logging/FileLogTest.java b/tests/src/com/android/launcher3/logging/FileLogTest.java
new file mode 100644
index 000000000..c24cc3fb7
--- /dev/null
+++ b/tests/src/com/android/launcher3/logging/FileLogTest.java
@@ -0,0 +1,77 @@
+package com.android.launcher3.logging;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Calendar;
+
+/**
+ * Tests for {@link FileLog}
+ */
+@SmallTest
+public class FileLogTest extends AndroidTestCase {
+
+ private File mTempDir;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ int count = 0;
+ do {
+ mTempDir = new File(getContext().getCacheDir(), "log-test-" + (count++));
+ } while(!mTempDir.mkdir());
+
+ FileLog.setDir(mTempDir);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Clear existing logs
+ new File(mTempDir, "log-0").delete();
+ new File(mTempDir, "log-1").delete();
+ mTempDir.delete();
+ super.tearDown();
+ }
+
+ public void testPrintLog() throws Exception {
+ FileLog.print("Testing", "hoolalala");
+ StringWriter writer = new StringWriter();
+ FileLog.flushAll(new PrintWriter(writer));
+ assertTrue(writer.toString().contains("hoolalala"));
+
+ FileLog.print("Testing", "abracadabra", new Exception("cat! cat!"));
+ writer = new StringWriter();
+ FileLog.flushAll(new PrintWriter(writer));
+ assertTrue(writer.toString().contains("abracadabra"));
+ // Exception is also printed
+ assertTrue(writer.toString().contains("cat! cat!"));
+
+ // Old logs still present after flush
+ assertTrue(writer.toString().contains("hoolalala"));
+ }
+
+ public void testOldFileTruncated() throws Exception {
+ FileLog.print("Testing", "hoolalala");
+ StringWriter writer = new StringWriter();
+ FileLog.flushAll(new PrintWriter(writer));
+ assertTrue(writer.toString().contains("hoolalala"));
+
+ Calendar threeDaysAgo = Calendar.getInstance();
+ threeDaysAgo.add(Calendar.HOUR, -72);
+ new File(mTempDir, "log-0").setLastModified(threeDaysAgo.getTimeInMillis());
+ new File(mTempDir, "log-1").setLastModified(threeDaysAgo.getTimeInMillis());
+
+ FileLog.print("Testing", "abracadabra", new Exception("cat! cat!"));
+ writer = new StringWriter();
+ FileLog.flushAll(new PrintWriter(writer));
+ assertTrue(writer.toString().contains("abracadabra"));
+ // Exception is also printed
+ assertTrue(writer.toString().contains("cat! cat!"));
+
+ // Old logs have been truncated
+ assertFalse(writer.toString().contains("hoolalala"));
+ }
+}