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
This commit is contained in:
Fabian Kozynski
2019-12-02 10:32:00 -05:00
parent 5605a0fe11
commit 8a86795422
3 changed files with 38 additions and 10 deletions

View File

@@ -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>

View File

@@ -0,0 +1,23 @@
<!--
~ 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" />

View File

@@ -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) {