Use SettingsLib's LayoutPreference

- Remove LayoutPreference in Settings source code.
- Remove unused style, layout
- Replace old imports to com.android.settingslib.widget.LayoutPreference
- Replace old XML tag to com.android.settingslib.widget.LayoutPreference

Test: robotest, manual test
Bug: 120005054
Change-Id: I9ae1ae14a16f443e11ac5d75b6038c7c5e253844
This commit is contained in:
tmfang
2018-11-26 18:41:01 +08:00
parent 9dbb20cc23
commit dce94bb237
67 changed files with 78 additions and 436 deletions

View File

@@ -58,6 +58,7 @@ import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.applications.ApplicationsState.Callbacks;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
import com.android.settingslib.widget.LayoutPreference;
import java.util.Collections;
import java.util.List;

View File

@@ -1,119 +0,0 @@
/*
* Copyright (C) 2015 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.settings.applications;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.Utils;
public class LayoutPreference extends Preference {
private final View.OnClickListener mClickListener = v -> performClick(v);
private boolean mAllowDividerAbove;
private boolean mAllowDividerBelow;
private View mRootView;
public LayoutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0 /* defStyleAttr */);
}
public LayoutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
public LayoutPreference(Context context, int resource) {
this(context, LayoutInflater.from(context).inflate(resource, null, false));
}
public LayoutPreference(Context context, View view) {
super(context);
setView(view);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Preference);
mAllowDividerAbove = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerAbove,
R.styleable.Preference_allowDividerAbove, false);
mAllowDividerBelow = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerBelow,
R.styleable.Preference_allowDividerBelow, false);
a.recycle();
a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.Preference, defStyleAttr, 0);
int layoutResource = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
if (layoutResource == 0) {
throw new IllegalArgumentException("LayoutPreference requires a layout to be defined");
}
a.recycle();
// Need to create view now so that findViewById can be called immediately.
final View view = LayoutInflater.from(getContext())
.inflate(layoutResource, null, false);
setView(view);
}
private void setView(View view) {
setLayoutResource(R.layout.layout_preference_frame);
mRootView = view;
setShouldDisableView(false);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
holder.itemView.setOnClickListener(mClickListener);
final boolean selectable = isSelectable();
holder.itemView.setFocusable(selectable);
holder.itemView.setClickable(selectable);
holder.setDividerAllowedAbove(mAllowDividerAbove);
holder.setDividerAllowedBelow(mAllowDividerBelow);
FrameLayout layout = (FrameLayout) holder.itemView;
layout.removeAllViews();
ViewGroup parent = (ViewGroup) mRootView.getParent();
if (parent != null) {
parent.removeView(mRootView);
}
layout.addView(mRootView);
}
public <T extends View> T findViewById(int id) {
return mRootView.findViewById(id);
}
public void setAllowDividerBelow(boolean allowed) {
mAllowDividerBelow = allowed;
}
public boolean isAllowDividerBelow() {
return mAllowDividerBelow;
}
}

View File

@@ -23,8 +23,6 @@ import android.content.pm.PackageInfo;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils;
@@ -32,6 +30,7 @@ import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.widget.LayoutPreference;
public class AppHeaderViewPreferenceController extends BasePreferenceController
implements AppInfoDashboardFragment.Callback, LifecycleObserver, OnStart {

View File

@@ -34,7 +34,6 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.applications.AppStoreUtil;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -42,6 +41,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
import com.android.settingslib.core.lifecycle.events.OnOptionsItemSelected;
import com.android.settingslib.core.lifecycle.events.OnPrepareOptionsMenu;
import com.android.settingslib.widget.LayoutPreference;
import java.util.List;