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

Commit 46dbfb47 authored by Jason Monk's avatar Jason Monk
Browse files

Handle density changes in QS

Bug: 26845796
Change-Id: Icc783c9d706382e553df49f699aaf44aac943d18
parent 1f67c874
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -39,8 +39,9 @@
        android:clipToPadding="false"
        android:clipChildren="false">

        <include
            layout="@layout/qs_panel"
        <com.android.systemui.DensityContainer
            android:id="@+id/qs_density_container"
            android:layout="@layout/qs_panel"
            android:layout_width="@dimen/notification_panel_width"
            android:layout_height="wrap_content"
            android:layout_gravity="@integer/notification_panel_layout_gravity" />
+4 −0
Original line number Diff line number Diff line
@@ -93,5 +93,9 @@
        <attr name="defValue" format="boolean" />
        <attr name="metricsAction" format="integer" />
    </declare-styleable>

    <declare-styleable name="DensityContainer">
        <attr name="android:layout" />
    </declare-styleable>
</resources>
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.android.systemui;

import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import java.util.ArrayList;
import java.util.List;

public class DensityContainer extends FrameLayout {

    private final List<InflateListener> mInflateListeners = new ArrayList<>();
    private final int mLayout;
    private int mDensity;

    public DensityContainer(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        mDensity = context.getResources().getConfiguration().densityDpi;

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DensityContainer);
        if (!a.hasValue(R.styleable.DensityContainer_android_layout)) {
            throw new IllegalArgumentException("DensityContainer must contain a layout");
        }
        mLayout = a.getResourceId(R.styleable.DensityContainer_android_layout, 0);
        inflateLayout();
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        int density = newConfig.densityDpi;
        if (density != mDensity) {
            mDensity = density;
            inflateLayout();
        }
    }

    private void inflateLayout() {
        removeAllViews();
        LayoutInflater.from(getContext()).inflate(mLayout, this);
        final int N = mInflateListeners.size();
        for (int i = 0; i < N; i++) {
            mInflateListeners.get(i).onInflated(getChildAt(0));
        }
    }

    public void addInflateListener(InflateListener listener) {
        mInflateListeners.add(listener);
        listener.onInflated(getChildAt(0));
    }

    public interface InflateListener {
        /**
         * Called whenever a new view is inflated.
         */
        void onInflated(View v);
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile.DetailAdapter;
import com.android.systemui.qs.QSTile.Host.Callback;
import com.android.systemui.qs.customize.QSCustomizer;
import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.settings.BrightnessController;
@@ -44,7 +45,7 @@ import java.util.ArrayList;
import java.util.Collection;

/** View that represents the quick settings tile panel. **/
public class QSPanel extends LinearLayout implements Tunable {
public class QSPanel extends LinearLayout implements Tunable, Callback {

    public static final String QS_SHOW_BRIGHTNESS = "qs_show_brightness";

@@ -123,9 +124,15 @@ public class QSPanel extends LinearLayout implements Tunable {
    @Override
    protected void onDetachedFromWindow() {
        TunerService.get(mContext).removeTunable(this);
        mHost.removeCallback(this);
        super.onDetachedFromWindow();
    }

    @Override
    public void onTilesChanged() {
        setTiles(mHost.getTiles());
    }

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (QS_SHOW_BRIGHTNESS.equals(key)) {
@@ -168,6 +175,8 @@ public class QSPanel extends LinearLayout implements Tunable {

    public void setHost(QSTileHost host) {
        mHost = host;
        mHost.addCallback(this);
        setTiles(mHost.getTiles());
        mFooter.setHost(host);
        createCustomizePanel();
    }
+1 −0
Original line number Diff line number Diff line
@@ -390,6 +390,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
        Context getContext();
        Collection<QSTile<?>> getTiles();
        void addCallback(Callback callback);
        void removeCallback(Callback callback);
        BluetoothController getBluetoothController();
        LocationController getLocationController();
        RotationLockController getRotationLockController();
Loading