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

Commit 96a67430 authored by Deepanshu Gupta's avatar Deepanshu Gupta Committed by Android Git Automerger
Browse files

am 2b98abde: am 8f9ebc65: am 3bd5cbb1: Merge "Use right colors for status bar...

am 2b98abde: am 8f9ebc65: am 3bd5cbb1: Merge "Use right colors for status bar and nav bar." into lmp-dev

* commit '2b98abde':
  Use right colors for status bar and nav bar.
parents 5f0252de 2b98abde
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.layoutlib.bridge.bars;

import android.os.Build.VERSION_CODES;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -40,12 +42,12 @@ public class Config {
    private static final int BLACK = 0xFF000000;

    public static boolean showOnScreenNavBar(int platformVersion) {
        return platformVersion == 0 || platformVersion >= ICE_CREAM_SANDWICH;
        return isGreaterOrEqual(platformVersion, ICE_CREAM_SANDWICH);
    }

    public static int getStatusBarColor(int platformVersion) {
        // return white for froyo and earlier; black otherwise.
        return platformVersion == 0 || platformVersion >= GINGERBREAD ? BLACK : WHITE;
        return isGreaterOrEqual(platformVersion, GINGERBREAD) ? BLACK : WHITE;
    }

    public static List<String> getResourceDirs(int platformVersion) {
@@ -98,7 +100,7 @@ public class Config {
    }

    public static int getTimeColor(int platformVersion) {
        if (platformVersion == 0 || platformVersion >= KITKAT ||
        if (isGreaterOrEqual(platformVersion, KITKAT) ||
                platformVersion > FROYO && platformVersion < HONEYCOMB) {
            // Gingerbread and KitKat onwards.
            return WHITE;
@@ -117,4 +119,13 @@ public class Config {
    public static String getWifiIconType(int platformVersion) {
        return platformVersion == 0 ? "xml" : "png";
    }

    /**
     * Compare simulated platform version and code from {@link VERSION_CODES} to check if
     * the simulated platform is greater than or equal to the version code.
     */
    public static boolean isGreaterOrEqual(int platformVersion, int code) {
        // simulated platform version = 0 means that we use the latest.
        return platformVersion == 0 || platformVersion >= code;
    }
}
+34 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.layoutlib.bridge.bars;

import com.android.annotations.NonNull;
import com.android.ide.common.rendering.api.RenderResources;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.rendering.api.StyleResourceValue;
@@ -26,6 +27,7 @@ import com.android.layoutlib.bridge.impl.ParserFactory;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.Density;
import com.android.resources.LayoutDirection;
import com.android.resources.ResourceType;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -47,6 +49,8 @@ import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;

import static android.os.Build.VERSION_CODES.LOLLIPOP;

/**
 * Base "bar" class for the window decor around the the edited layout.
 * This is basically an horizontal layout that loads a given layout on creation (it is read
@@ -63,7 +67,7 @@ abstract class CustomBar extends LinearLayout {

    protected abstract TextView getStyleableTextView();

    protected CustomBar(Context context, int orientation, String layoutPath,
    protected CustomBar(BridgeContext context, int orientation, String layoutPath,
            String name, int simulatedPlatformVersion) throws XmlPullParserException {
        super(context);
        mSimulatedPlatformVersion = simulatedPlatformVersion;
@@ -197,7 +201,7 @@ abstract class CustomBar extends LinearLayout {


                ResourceValue textColor = res.findItemInStyle(textStyle, "textColor",
                        true /*isFrameworkAttr*/);
                        true);
                textColor = res.resolveResValue(textColor);
                if (textColor != null) {
                    ColorStateList stateList = ResourceHelper.getColorStateList(
@@ -210,12 +214,39 @@ abstract class CustomBar extends LinearLayout {
        }
    }

    /**
     * Given a theme attribute name, get the color referenced by it. The theme attribute may be
     * used in a layout like "?attr/foo".
     * <p/>
     * Returns 0 if not found.
     *
     * @throws NumberFormatException if color resolved to an invalid string.
     */
    protected int getThemeAttrColor(@NonNull String attrName, boolean isFramework) {
        if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) {
            return 0;
        }
        assert mContext instanceof BridgeContext;
        BridgeContext context = ((BridgeContext) mContext);
        RenderResources renderResources = context.getRenderResources();
        // From ?attr/foo to @color/bar. This is most likely an ItemResourceValue.
        ResourceValue resource = renderResources.findItemInTheme(attrName, isFramework);
        if (resource != null) {
            // Form @color/bar to the #AARRGGBB
            resource = renderResources.resolveResValue(resource);
        }
        if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) {
            return ResourceHelper.getColor(resource.getValue());
        }
        return 0;
    }

    private ResourceValue getResourceValue(String reference) {
        BridgeContext bridgeContext = (BridgeContext) mContext;
        RenderResources res = bridgeContext.getRenderResources();

        // find the resource
        ResourceValue value = res.findResValue(reference, false /*isFramework*/);
        ResourceValue value = res.findResValue(reference, false);

        // resolve it if needed
        return res.resolveResValue(value);
+7 −3
Original line number Diff line number Diff line
@@ -16,22 +16,26 @@

package com.android.layoutlib.bridge.bars;

import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.resources.Density;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NavigationBar extends CustomBar {

    public NavigationBar(Context context, Density density, int orientation, boolean isRtl,
    /** Navigation bar background color attribute name. */
    private static final String ATTR_COLOR = "navigationBarColor";

    public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
            boolean rtlEnabled, int simulatedPlatformVersion) throws XmlPullParserException {
        super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml",
                simulatedPlatformVersion);

        setBackgroundColor(0xFF000000);
        int color = getThemeAttrColor(ATTR_COLOR, true);
        setBackgroundColor(color == 0 ? 0xFF000000 : color);

        // Cannot access the inside items through id because no R.id values have been
        // created for them.
+7 −9
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.resources.Density;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
@@ -38,20 +37,21 @@ import java.io.InputStream;

public class StatusBar extends CustomBar {

    private final Context mContext;
    private final int mSimulatedPlatformVersion;
    /** Status bar background color attribute name. */
    private static final String ATTR_COLOR = "colorPrimaryDark";

    public StatusBar(Context context, Density density, int direction, boolean RtlEnabled,
    public StatusBar(BridgeContext context, Density density, int direction, boolean RtlEnabled,
            int simulatedPlatformVersion) throws XmlPullParserException {
        // FIXME: if direction is RTL but it's not enabled in application manifest, mirror this bar.
        super(context, LinearLayout.HORIZONTAL, "/bars/status_bar.xml", "status_bar.xml",
                simulatedPlatformVersion);
        mContext = context;
        mSimulatedPlatformVersion = simulatedPlatformVersion;

        // FIXME: use FILL_H?
        setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT);
        setBackgroundColor(Config.getStatusBarColor(simulatedPlatformVersion));
        int color = getThemeAttrColor(ATTR_COLOR, true);
        setBackgroundColor(color == 0 ? Config.getStatusBarColor(simulatedPlatformVersion) : color);

        // Cannot access the inside items through id because no R.id values have been
        // created for them.
@@ -82,10 +82,8 @@ public class StatusBar extends CustomBar {
                try {
                    BridgeXmlBlockParser parser = new BridgeXmlBlockParser(
                            ParserFactory.create(stream, null), (BridgeContext) mContext, true);
                    Drawable drawable = Drawable.createFromXml(mContext.getResources(), parser);
                    if (drawable != null) {
                        imageView.setImageDrawable(drawable);
                    }
                    imageView.setImageDrawable(
                            Drawable.createFromXml(mContext.getResources(), parser));
                } catch (XmlPullParserException e) {
                    Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e,
                            null);
+3 −2
Original line number Diff line number Diff line
@@ -16,9 +16,10 @@

package com.android.layoutlib.bridge.bars;

import com.android.layoutlib.bridge.android.BridgeContext;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.widget.LinearLayout;
import android.widget.TextView;

@@ -26,7 +27,7 @@ public class TitleBar extends CustomBar {

    private TextView mTextView;

    public TitleBar(Context context, String label, int simulatedPlatformVersion)
    public TitleBar(BridgeContext context, String label, int simulatedPlatformVersion)
            throws XmlPullParserException {
        super(context, LinearLayout.HORIZONTAL, "/bars/title_bar.xml", "title_bar.xml",
                simulatedPlatformVersion);