Merge "Use TwoTargetPreference to replace customized layout"

This commit is contained in:
TreeHugger Robot
2019-09-11 08:35:37 +00:00
committed by Android (Google) Code Review
5 changed files with 14 additions and 53 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 B

View File

@@ -1,43 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<!-- Divider -->
<ImageView
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/nav_divider"
android:contentDescription="@null"
/>
<!-- Details button -->
<ImageView
android:id="@+id/deviceDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="8dip"
android:background="?android:attr/selectableItemBackground"
android:src="@drawable/ic_settings_accent"
android:contentDescription="@string/wifi_display_details" />
</LinearLayout>

View File

@@ -67,6 +67,7 @@ import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.TwoTargetPreference;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
@@ -661,7 +662,7 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment implem
}
};
private class RoutePreference extends Preference
private class RoutePreference extends TwoTargetPreference
implements Preference.OnPreferenceClickListener {
private final MediaRouter.RouteInfo mRoute;
@@ -705,27 +706,30 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment implem
implements View.OnClickListener {
private final WifiDisplay mDisplay;
@Override
protected int getSecondTargetResId() {
return R.layout.preference_widget_gear;
}
public WifiDisplayRoutePreference(Context context, MediaRouter.RouteInfo route,
WifiDisplay display) {
super(context, route);
mDisplay = display;
setWidgetLayoutResource(R.layout.wifi_display_preference);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
ImageView deviceDetails = (ImageView) view.findViewById(R.id.deviceDetails);
if (deviceDetails != null) {
deviceDetails.setOnClickListener(this);
final ImageView gear = (ImageView) holder.findViewById(R.id.settings_button);
if (gear != null) {
gear.setOnClickListener(this);
if (!isEnabled()) {
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.disabledAlpha,
value, true);
deviceDetails.setImageAlpha((int) (value.getFloat() * 255));
deviceDetails.setEnabled(true); // always allow button to be pressed
gear.setImageAlpha((int) (value.getFloat() * 255));
gear.setEnabled(true); // always allow button to be pressed
}
}
}