| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/ExpandablePreferenceGroup.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/ExpandablePreferenceGroup.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/ExpandablePreferenceGroup.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3394df1561352d3869ad7df2009d69f23f5656e6
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/ExpandablePreferenceGroup.java
|
| @@ -0,0 +1,78 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.preferences;
|
| +
|
| +import android.content.Context;
|
| +import android.graphics.drawable.Drawable;
|
| +import android.os.Build;
|
| +import android.preference.PreferenceGroup;
|
| +import android.text.Spannable;
|
| +import android.text.SpannableStringBuilder;
|
| +import android.text.style.ForegroundColorSpan;
|
| +import android.text.style.StyleSpan;
|
| +import android.text.style.TypefaceSpan;
|
| +import android.util.AttributeSet;
|
| +import android.view.View;
|
| +import android.widget.ImageView;
|
| +
|
| +import org.chromium.chrome.R;
|
| +
|
| +import java.util.Locale;
|
| +
|
| +/**
|
| + * A preference category that accepts clicks for toggling on/off.
|
| + */
|
| +public class ExpandablePreferenceGroup extends PreferenceGroup {
|
| + private Drawable mDrawable = null;
|
| + private ImageView mImageView = null;
|
| +
|
| + public ExpandablePreferenceGroup(Context context, AttributeSet attrs) {
|
| + super(context, attrs, android.R.attr.preferenceStyle);
|
| + setWidgetLayoutResource(R.layout.site_list_expandable_header);
|
| + }
|
| +
|
| + /**
|
| + * Set the title for the preference group.
|
| + * @param resourceId The resource id of the text to use.
|
| + * @param count The number of entries the preference group contains.
|
| + */
|
| + public void setGroupTitle(int resourceId, int count) {
|
| + SpannableStringBuilder spannable =
|
| + new SpannableStringBuilder(getContext().getResources().getString(resourceId));
|
| + String prefCount = String.format(Locale.getDefault(), " - %d", count);
|
| + spannable.append(prefCount);
|
| +
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| + spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
|
| + 0,
|
| + spannable.length() - prefCount.length(),
|
| + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
| + } else {
|
| + spannable.setSpan(new TypefaceSpan("sans-serif-medium"),
|
| + 0,
|
| + spannable.length() - prefCount.length(),
|
| + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
| + }
|
| +
|
| + int gray = getContext().getResources().getColor(R.color.expandable_group_dark_gray);
|
| + spannable.setSpan(new ForegroundColorSpan(gray),
|
| + spannable.length() - prefCount.length(),
|
| + spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
| + setTitle(spannable);
|
| + }
|
| +
|
| + @Override
|
| + public void setIcon(int resourceId) {
|
| + mDrawable = getContext().getResources().getDrawable(resourceId);
|
| + if (mImageView != null) mImageView.setImageDrawable(mDrawable);
|
| + }
|
| +
|
| + @Override
|
| + protected void onBindView(View view) {
|
| + super.onBindView(view);
|
| + mImageView = (ImageView) view.findViewById(R.id.expando);
|
| + if (mDrawable != null) mImageView.setImageDrawable(mDrawable);
|
| + }
|
| +}
|
|
|