Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 462b5cca authored by Tony Wickham's avatar Tony Wickham
Browse files

Extract color for the hotseat.

- Only considers the bottom fourth of the wallpaper
- Is translucent black or white depending on how dark/light
  the wallpaper is
- Hotseat extends behind the nav bar

Bug: 27230217
Change-Id: Id4ea6ee91b4dd221b4c277d22d5041cab178801d
parent 34a2d31f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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-rc1'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
    }
}
+58 −1
Original line number Diff line number Diff line
@@ -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;
        }
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -496,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);
        }
    }

+0 −1
Original line number Diff line number Diff line
@@ -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;
+14 −0
Original line number Diff line number Diff line
@@ -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.
Loading