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

Commit 8a867954 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Replace QSDetail Switch with ViewStub

Most of the time this switch is not needed. In particular right now, no
view is using it so make it lazy.

Bug: 133504338
Test: layout inspector
Test: reenable details and see that Switch appears and works
Change-Id: I4cc338a7bff7f8508c37be3a86798ae1d661aa9b
parent 5605a0fe
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -53,12 +53,12 @@
            android:src="@drawable/ic_settings"
            android:visibility="gone"/>

        <Switch
            android:id="@android:id/toggle"
        <ViewStub
            android:id="@+id/toggle_stub"
            android:inflatedId="@+id/toggle"
            android:layout="@layout/qs_detail_switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:textAppearance="@style/TextAppearance.QS.DetailHeader" />
            android:layout_height="wrap_content"/>

    </LinearLayout>

+23 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2019 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.
  -->

<Switch
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/toggle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:textAppearance="@style/TextAppearance.QS.DetailHeader" />
 No newline at end of file
+10 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.accessibility.AccessibilityEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -58,7 +59,8 @@ public class QSDetail extends LinearLayout {

    protected View mQsDetailHeader;
    protected TextView mQsDetailHeaderTitle;
    protected Switch mQsDetailHeaderSwitch;
    private ViewStub mQsDetailHeaderSwitchStub;
    private Switch mQsDetailHeaderSwitch;
    protected ImageView mQsDetailHeaderProgress;

    protected QSTileHost mHost;
@@ -98,7 +100,7 @@ public class QSDetail extends LinearLayout {

        mQsDetailHeader = findViewById(R.id.qs_detail_header);
        mQsDetailHeaderTitle = (TextView) mQsDetailHeader.findViewById(android.R.id.title);
        mQsDetailHeaderSwitch = (Switch) mQsDetailHeader.findViewById(android.R.id.toggle);
        mQsDetailHeaderSwitchStub = mQsDetailHeader.findViewById(R.id.toggle_stub);
        mQsDetailHeaderProgress = findViewById(R.id.qs_detail_header_progress);

        updateDetailText();
@@ -252,9 +254,12 @@ public class QSDetail extends LinearLayout {
        mQsDetailHeaderTitle.setText(adapter.getTitle());
        final Boolean toggleState = adapter.getToggleState();
        if (toggleState == null) {
            mQsDetailHeaderSwitch.setVisibility(INVISIBLE);
            if (mQsDetailHeaderSwitch != null) mQsDetailHeaderSwitch.setVisibility(INVISIBLE);
            mQsDetailHeader.setClickable(false);
        } else {
            if (mQsDetailHeaderSwitch == null) {
                mQsDetailHeaderSwitch = (Switch) mQsDetailHeaderSwitchStub.inflate();
            }
            mQsDetailHeaderSwitch.setVisibility(VISIBLE);
            handleToggleStateChanged(toggleState, adapter.getToggleEnabled());
            mQsDetailHeader.setClickable(true);
@@ -274,9 +279,9 @@ public class QSDetail extends LinearLayout {
        if (mAnimatingOpen) {
            return;
        }
        mQsDetailHeaderSwitch.setChecked(state);
        if (mQsDetailHeaderSwitch != null) mQsDetailHeaderSwitch.setChecked(state);
        mQsDetailHeader.setEnabled(toggleEnabled);
        mQsDetailHeaderSwitch.setEnabled(toggleEnabled);
        if (mQsDetailHeaderSwitch != null) mQsDetailHeaderSwitch.setEnabled(toggleEnabled);
    }

    private void handleScanStateChanged(boolean state) {