Merge "Eliminate duplicated code in Settings for category headers"

This commit is contained in:
Zoltan Szatmary-Ban
2015-02-09 12:53:31 +00:00
committed by Android (Google) Code Review
5 changed files with 17 additions and 40 deletions

View File

@@ -1835,8 +1835,8 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
final AppItem item = mItems.get(position); final AppItem item = mItems.get(position);
if (getItemViewType(position) == 1) { if (getItemViewType(position) == 1) {
if (convertView == null) { if (convertView == null) {
convertView = inflateCategoryHeader(LayoutInflater.from(parent.getContext()), convertView = Utils.inflateCategoryHeader(LayoutInflater.from(
parent); parent.getContext()), parent);
} }
final TextView title = (TextView) convertView.findViewById(android.R.id.title); final TextView title = (TextView) convertView.findViewById(android.R.id.title);
@@ -2527,14 +2527,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
return view; return view;
} }
private static View inflateCategoryHeader(LayoutInflater inflater, ViewGroup root) {
final TypedArray a = inflater.getContext().obtainStyledAttributes(null,
com.android.internal.R.styleable.Preference,
com.android.internal.R.attr.preferenceCategoryStyle, 0);
final int resId = a.getResourceId(com.android.internal.R.styleable.Preference_layout, 0);
return inflater.inflate(resId, root, false);
}
/** /**
* Test if any networks are currently limited. * Test if any networks are currently limited.
*/ */

View File

@@ -303,7 +303,7 @@ public class DeviceAdminSettings extends ListFragment {
bindView(convertView, (DeviceAdminInfo) o); bindView(convertView, (DeviceAdminInfo) o);
} else { } else {
if (convertView == null) { if (convertView == null) {
convertView = newTitleView(parent); convertView = Utils.inflateCategoryHeader(mInflater, parent);
} }
final TextView title = (TextView) convertView.findViewById(android.R.id.title); final TextView title = (TextView) convertView.findViewById(android.R.id.title);
title.setText((String)o); title.setText((String)o);
@@ -322,15 +322,6 @@ public class DeviceAdminSettings extends ListFragment {
return v; return v;
} }
private View newTitleView(ViewGroup parent) {
final TypedArray a = mInflater.getContext().obtainStyledAttributes(null,
com.android.internal.R.styleable.Preference,
com.android.internal.R.attr.preferenceCategoryStyle, 0);
final int resId = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
return mInflater.inflate(resId, parent, false);
}
private void bindView(View view, DeviceAdminInfo item) { private void bindView(View view, DeviceAdminInfo item) {
final Activity activity = getActivity(); final Activity activity = getActivity();
ViewHolder vh = (ViewHolder) view.getTag(); ViewHolder vh = (ViewHolder) view.getTag();

View File

@@ -209,7 +209,7 @@ public class MasterClear extends Fragment {
.getAuthenticatorTypesAsUser(profileId); .getAuthenticatorTypesAsUser(profileId);
final int M = descs.length; final int M = descs.length;
View titleView = newTitleView(contents, inflater); View titleView = Utils.inflateCategoryHeader(inflater, contents);
final TextView titleText = (TextView) titleView.findViewById(android.R.id.title); final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
titleText.setText(userInfo.isManagedProfile() ? R.string.category_work titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
: R.string.category_personal); : R.string.category_personal);
@@ -275,13 +275,4 @@ public class MasterClear extends Fragment {
establishInitialState(); establishInitialState();
return mContentView; return mContentView;
} }
private View newTitleView(ViewGroup parent, LayoutInflater inflater) {
final TypedArray a = inflater.getContext().obtainStyledAttributes(null,
com.android.internal.R.styleable.Preference,
com.android.internal.R.attr.preferenceCategoryStyle, 0);
final int resId = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
return inflater.inflate(resId, parent, false);
}
} }

View File

@@ -321,7 +321,7 @@ public class TrustedCredentialsSettings extends Fragment {
if (convertView == null) { if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getActivity() LayoutInflater inflater = (LayoutInflater) getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflateCategoryHeader(inflater, parent); convertView = Utils.inflateCategoryHeader(inflater, parent);
} }
final TextView title = (TextView) convertView.findViewById(android.R.id.title); final TextView title = (TextView) convertView.findViewById(android.R.id.title);
@@ -354,15 +354,6 @@ public class TrustedCredentialsSettings extends Fragment {
public int getListViewId(Tab tab) { public int getListViewId(Tab tab) {
return tab.mExpandableList; return tab.mExpandableList;
} }
private View inflateCategoryHeader(LayoutInflater inflater, ViewGroup parent) {
final TypedArray a = inflater.getContext().obtainStyledAttributes(null,
com.android.internal.R.styleable.Preference,
com.android.internal.R.attr.preferenceCategoryStyle, 0);
final int resId = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
return inflater.inflate(resId, parent, false);
}
} }
private class TrustedCertificateAdapter extends BaseAdapter implements private class TrustedCertificateAdapter extends BaseAdapter implements

View File

@@ -37,6 +37,7 @@ import android.content.pm.ResolveInfo;
import android.content.pm.Signature; import android.content.pm.Signature;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.Resources.NotFoundException; import android.content.res.Resources.NotFoundException;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@@ -65,6 +66,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ListView; import android.widget.ListView;
@@ -1058,4 +1060,14 @@ public final class Utils {
return null; return null;
} }
public static View inflateCategoryHeader(LayoutInflater inflater, ViewGroup parent) {
final TypedArray a = inflater.getContext().obtainStyledAttributes(null,
com.android.internal.R.styleable.Preference,
com.android.internal.R.attr.preferenceCategoryStyle, 0);
final int resId = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
a.recycle();
return inflater.inflate(resId, parent, false);
}
} }