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

Commit b2771453 authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

SysUI: Pass themed resources on to NavBarEditor

This fixes an issue where additional buttons in the nav bar would
pick up the SystemUI theme instead of the one assigned to the
navigation bar.  This patch esnures that the correct resources are
used when updating the buttons.

Change-Id: Ic187e702355bec1b85353229e2c3a92a6eb6b8e1
TICKET: CYNGNOS-1620
parent 12245b83
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.UserHandle;
@@ -90,6 +91,8 @@ public class NavbarEditor implements View.OnTouchListener {
    // just to avoid reallocations
    private static final int[] sLocation = new int[2];

    private Resources mResources;

    /**
     * Longpress runnable to assign buttons in edit mode
     */
@@ -151,11 +154,12 @@ public class NavbarEditor implements View.OnTouchListener {

    private static final String DEFAULT_SETTING_STRING = "empty|back|home|recent|empty|menu0";

    public NavbarEditor (View parent, boolean orientation, boolean isRtl) {
    public NavbarEditor (View parent, boolean orientation, boolean isRtl, Resources res) {
        mContext = parent.getContext();
        mParent = parent;
        mVertical = orientation;
        mRtl = isRtl;
        mResources = res;

        mButtonViews = new ArrayList<KeyButtonView>();

@@ -277,7 +281,8 @@ public class NavbarEditor implements View.OnTouchListener {
            if (!mLongPressed && !view.getTag().equals(NAVBAR_HOME) &&
                    !view.getTag().equals(NAVBAR_RECENT) && !view.getTag().equals(NAVBAR_BACK)) {
                final boolean isSmallButton = ArrayUtils.contains(SMALL_BUTTON_IDS, view.getId());
                final ButtonAdapter list = new ButtonAdapter(mContext, mButtonViews, isSmallButton);
                final ButtonAdapter list = new ButtonAdapter(mContext, mButtonViews, isSmallButton,
                        getResources());

                AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
                        .setTitle(mContext.getString(R.string.navbar_dialog_title))
@@ -388,7 +393,7 @@ public class NavbarEditor implements View.OnTouchListener {
                }
            }

            buttonView.setInfo(button, mVertical, isSmallButton);
            buttonView.setInfo(button, mVertical, isSmallButton, getResources());
            if (button != NAVBAR_EMPTY && !isSmallButton) {
                visibleCount++;
            }
@@ -462,6 +467,14 @@ public class NavbarEditor implements View.OnTouchListener {
        }
    }

    private Resources getResources() {
        return mResources != null ? mResources : mContext.getResources();
    }

    public void updateResources(Resources res) {
        mResources = res;
    }

    /**
     * Class to store info about supported buttons
     */
@@ -501,9 +514,10 @@ public class NavbarEditor implements View.OnTouchListener {

    private static class ButtonAdapter extends ArrayAdapter<ButtonInfo> {
        private ArrayList<ButtonInfo> mTakenItems;
        private Resources mResources;

        public ButtonAdapter(Context context,
                ArrayList<KeyButtonView> buttons, boolean smallButtons) {
                ArrayList<KeyButtonView> buttons, boolean smallButtons, Resources resources) {
            super(context, R.layout.navigation_bar_edit_menu_item, R.id.key_text,
                    buildItems(smallButtons));

@@ -514,6 +528,7 @@ public class NavbarEditor implements View.OnTouchListener {
                    mTakenItems.add(info);
                }
            }
            mResources = resources;
        }

        private static List<ButtonInfo> buildItems(boolean smallButtons) {
@@ -545,7 +560,7 @@ public class NavbarEditor implements View.OnTouchListener {
            text.setEnabled(enabled);

            ImageView icon = (ImageView) view.findViewById(R.id.key_icon);
            icon.setImageResource(info.portResource);
            icon.setImageDrawable(mResources.getDrawable(info.portResource));
            icon.setColorFilter(new PorterDuffColorFilter(
                    text.getCurrentTextColor(), PorterDuff.Mode.SRC_IN));

+11 −8
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ public class NavigationBarView extends LinearLayout {
        mDisplay = ((WindowManager)context.getSystemService(
                Context.WINDOW_SERVICE)).getDefaultDisplay();

        final Resources res = getContext().getResources();
        final Resources res = getResources();
        mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size);
        mVertical = false;
        mShowMenu = false;
@@ -325,6 +325,9 @@ public class NavigationBarView extends LinearLayout {
                updateLightsOutResources(container);
            }
        }
        if (mEditBar != null) {
            mEditBar.updateResources(res);
        }
    }

    private void updateLightsOutResources(ViewGroup container) {
@@ -348,7 +351,7 @@ public class NavigationBarView extends LinearLayout {

    @Override
    public void setLayoutDirection(int layoutDirection) {
        getIcons(mThemedResources != null ? mThemedResources : getContext().getResources());
        getIcons(getResources());

        super.setLayoutDirection(layoutDirection);
    }
@@ -606,7 +609,7 @@ public class NavigationBarView extends LinearLayout {
        } else {
            mVertical = getWidth() > 0 && getHeight() > getWidth();
        }
        mEditBar = new NavbarEditor(mCurrentView, mVertical, mIsLayoutRtl);
        mEditBar = new NavbarEditor(mCurrentView, mVertical, mIsLayoutRtl, getResources());
        updateSettings();

        getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener);
@@ -700,7 +703,7 @@ public class NavigationBarView extends LinearLayout {

    private String getResourceName(int resId) {
        if (resId != 0) {
            final android.content.res.Resources res = getContext().getResources();
            final android.content.res.Resources res = getResources();
            try {
                return res.getResourceName(resId);
            } catch (android.content.res.Resources.NotFoundException ex) {
@@ -846,9 +849,9 @@ public class NavigationBarView extends LinearLayout {
        }
    }

    // TODO LINK TO THIS ONCE THEMES GOES IN
    protected void updateResources() {
        getIcons(mContext.getResources());
    @Override
    public Resources getResources() {
        return mThemedResources != null ? mThemedResources : getContext().getResources();
    }

    public class NavBarReceiver extends BroadcastReceiver {
+5 −0
Original line number Diff line number Diff line
@@ -192,6 +192,11 @@ public class KeyButtonView extends ImageView {

    public void setInfo(NavbarEditor.ButtonInfo item, boolean isVertical, boolean isSmall) {
        final Resources res = getResources();
        setInfo(item, isVertical, isSmall, res);
    }

    public void setInfo(NavbarEditor.ButtonInfo item, boolean isVertical, boolean isSmall,
            Resources res) {
        final int keyDrawableResId;

        setTag(item);