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

Commit 54b5fbf0 authored by Clark Scheff's avatar Clark Scheff
Browse files

Support theming navbar separately from SystemUI

This allows using a different theme for the navbar than the theme
applied to the rest of SystemUI.  This will not affect theming until
we have the front end in place that allows users to change this.

Change-Id: I3ad4e8774ac69d1e6e1d83fa5e1ffe59b977d4e9
parent 8a07476d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -45,6 +45,12 @@ import java.util.Map;
public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfig> {
    public static final String TAG = ThemeConfig.class.getCanonicalName();
    public static final String HOLO_DEFAULT = "holo";

    /**
     * Special package name for theming the navbar separate from the rest of SystemUI
     */
    public static final String SYSTEMUI_NAVBAR_PKG = "com.android.systemui.navbar";

    // Key for any app which does not have a specific theme applied
    private static final String KEY_DEFAULT_PKG = "default";
    private static final HoloConfig mHoloConfig = new HoloConfig();
+19 −7
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class NavigationBarView extends LinearLayout {
    private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon;
    private Drawable mRecentIcon;
    private Drawable mRecentLandIcon;
    private Drawable mHomeIcon, mHomeLandIcon;

    private DelegateViewHelper mDelegateHelper;
    private DeadZone mDeadZone;
@@ -120,6 +121,8 @@ public class NavigationBarView extends LinearLayout {
    // performs manual animation in sync with layout transitions
    private final NavTransitionListener mTransitionListener = new NavTransitionListener();

    private Resources mThemedResources;

    private class NavTransitionListener implements TransitionListener {
        private boolean mBackTransitioning;
        private boolean mHomeAppearing;
@@ -362,10 +365,13 @@ public class NavigationBarView extends LinearLayout {
        mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime_land);
        mRecentIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
        mRecentLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land);
        mHomeIcon = res.getDrawable(R.drawable.ic_sysbar_home);
        mHomeLandIcon = res.getDrawable(R.drawable.ic_sysbar_home_land);
    }

    public void updateResources() {
        getIcons(mContext.getResources());
    public void updateResources(Resources res) {
        mThemedResources = res;
        getIcons(mThemedResources);
        for (int i = 0; i < mRotatedViews.length; i++) {
            ViewGroup container = (ViewGroup) mRotatedViews[i];
            if (container != null) {
@@ -382,17 +388,17 @@ public class NavigationBarView extends LinearLayout {
            for (int i = 0; i < nChildren; i++) {
                final View child = midNavButtons.getChildAt(i);
                if (child instanceof KeyButtonView) {
                    ((KeyButtonView) child).updateResources();
                    ((KeyButtonView) child).updateResources(mThemedResources);
                }
            }
        }
        KeyButtonView kbv = (KeyButtonView) findViewById(R.id.one);
        if (kbv != null) {
            kbv.updateResources();
            kbv.updateResources(mThemedResources);
        }
        kbv = (KeyButtonView) findViewById(R.id.six);
        if (kbv != null) {
            kbv.updateResources();
            kbv.updateResources(mThemedResources);
        }
    }

@@ -408,7 +414,8 @@ public class NavigationBarView extends LinearLayout {
                    // ImageView keeps track of the resource ID and if it is the same
                    // it will not update the drawable.
                    iv.setImageDrawable(null);
                    iv.setImageResource(R.drawable.ic_sysbar_lights_out_dot_large);
                    iv.setImageDrawable(mThemedResources.getDrawable(
                            R.drawable.ic_sysbar_lights_out_dot_large));
                }
            }
        }
@@ -416,7 +423,7 @@ public class NavigationBarView extends LinearLayout {

    @Override
    public void setLayoutDirection(int layoutDirection) {
        getIcons(mContext.getResources());
        if (mThemedResources != null) getIcons(mThemedResources);

        super.setLayoutDirection(layoutDirection);
    }
@@ -474,6 +481,7 @@ public class NavigationBarView extends LinearLayout {

        ImageView backView = (ImageView) findButton(NavbarEditor.NAVBAR_BACK);
        ImageView recentView = (ImageView) findButton(NavbarEditor.NAVBAR_RECENT);
        ImageView homeView = (ImageView) findButton(NavbarEditor.NAVBAR_HOME);

        if (backView != null) {
            backView.setImageDrawable(backAlt
@@ -485,6 +493,10 @@ public class NavigationBarView extends LinearLayout {
            recentView.setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon);
        }

        if (homeView != null) {
            homeView.setImageDrawable(mVertical ? mHomeLandIcon : mHomeIcon);
        }

        setDisabledFlags(mDisabledFlags, true);
    }

+17 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.ThemeConfig;
import android.content.res.Resources;
@@ -433,6 +434,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,

        mNavigationBarView.setDisabledFlags(mDisabled);
        mNavigationBarView.setBar(this);
        mNavigationBarView.updateResources(getNavbarThemedResources());
        addNavigationBar();
    }

@@ -678,6 +680,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            if (showNav && !mRecreating) {
                mNavigationBarView =
                    (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);
                mNavigationBarView.updateResources(getNavbarThemedResources());

                mNavigationBarView.setDisabledFlags(mDisabled);
                mNavigationBarView.setBar(this);
@@ -1182,6 +1185,18 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        return lp;
    }

    private Resources getNavbarThemedResources() {
        String pkgName = mCurrentTheme.getOverlayPkgNameForApp(ThemeConfig.SYSTEMUI_NAVBAR_PKG);
        Resources res = null;
        try {
            res = mContext.getPackageManager().getThemedResourcesForApplication(
                    mContext.getPackageName(), pkgName);
        } catch (PackageManager.NameNotFoundException e) {
            res = mContext.getResources();
        }
        return res;
    }

    private void addHeadsUpView() {
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
@@ -3273,7 +3288,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        repositionNavigationBar();
        addHeadsUpView();
        if (mNavigationBarView != null) {
            mNavigationBarView.updateResources();
            mNavigationBarView.updateResources(getNavbarThemedResources());
        }

        // recreate StatusBarIconViews.
@@ -3338,7 +3353,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        // Update the QuickSettings container
        if (mQS != null) mQS.updateResources();
        if (mNavigationBarView != null)  {
            mNavigationBarView.updateResources();
            mNavigationBarView.updateResources(getNavbarThemedResources());
            updateSearchPanel();
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -116,9 +116,9 @@ public class KeyButtonView extends ImageView {
        mPm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    }

    public void updateResources() {
    public void updateResources(Resources res) {
        if (mGlowBgId != 0) {
            mGlowBG = mContext.getResources().getDrawable(mGlowBgId);
            mGlowBG = res.getDrawable(mGlowBgId);
        }
    }