Clean up: use AppPreference for PowerGaugePreference

- And remove the code for customizing app icon size.

Bug: 65182905
Bug: 68426851
Test: robotests
Change-Id: I4e37bbee3636266f7c1a639b8e9faabb78d61110
This commit is contained in:
Fan Zhang
2017-10-29 11:54:10 -07:00
parent 1c3a4de93d
commit fdf96975e3
2 changed files with 6 additions and 11 deletions

View File

@@ -19,15 +19,13 @@ package com.android.settings.fuelgauge;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.widget.AppPreference;
/** /**
* Custom preference for displaying battery usage info as a bar and an icon on * Custom preference for displaying battery usage info as a bar and an icon on
@@ -36,8 +34,7 @@ import com.android.settings.Utils;
* The battery usage info could be usage percentage or usage time. The preference * The battery usage info could be usage percentage or usage time. The preference
* won't show any icon if it is null. * won't show any icon if it is null.
*/ */
public class PowerGaugePreference extends Preference { public class PowerGaugePreference extends AppPreference {
private final int mIconSize;
private BatteryEntry mInfo; private BatteryEntry mInfo;
private CharSequence mContentDescription; private CharSequence mContentDescription;
@@ -64,7 +61,6 @@ public class PowerGaugePreference extends Preference {
setWidgetLayoutResource(R.layout.preference_widget_summary); setWidgetLayoutResource(R.layout.preference_widget_summary);
mInfo = info; mInfo = info;
mContentDescription = contentDescription; mContentDescription = contentDescription;
mIconSize = context.getResources().getDimensionPixelSize(R.dimen.app_icon_size);
mShowAnomalyIcon = false; mShowAnomalyIcon = false;
} }
@@ -107,8 +103,6 @@ public class PowerGaugePreference extends Preference {
@Override @Override
public void onBindViewHolder(PreferenceViewHolder view) { public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view); super.onBindViewHolder(view);
ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
icon.setLayoutParams(new LinearLayout.LayoutParams(mIconSize, mIconSize));
final TextView subtitle = (TextView) view.findViewById(R.id.widget_summary); final TextView subtitle = (TextView) view.findViewById(R.id.widget_summary);
subtitle.setText(mProgress); subtitle.setText(mProgress);

View File

@@ -15,6 +15,8 @@
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable; import android.graphics.drawable.VectorDrawable;
@@ -35,8 +37,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PowerGaugePreferenceTest { public class PowerGaugePreferenceTest {
@@ -53,7 +53,7 @@ public class PowerGaugePreferenceTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mRootView = LayoutInflater.from(mContext).inflate(R.layout.preference, mRootView = LayoutInflater.from(mContext).inflate(R.layout.preference_app,
null); null);
mWidgetView = LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary, mWidgetView = LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary,
null); null);
@@ -61,6 +61,7 @@ public class PowerGaugePreferenceTest {
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(mRootView); mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
mPowerGaugePreference = new PowerGaugePreference(mContext); mPowerGaugePreference = new PowerGaugePreference(mContext);
assertThat(mPowerGaugePreference.getLayoutResource()).isEqualTo(R.layout.preference_app);
} }
@Test @Test