Data plans setting peference.
Change-Id: Ieb2aa67ab98140aa90501227345a15ad64cf124c Note: These changes are required for Data balance UI. Bug: 62349208 Test: make RunSettingsRoboTests -j40
This commit is contained in:
79
res/layout/settings_data_plan_summary_preference.xml
Normal file
79
res/layout/settings_data_plan_summary_preference.xml
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 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"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingStart="@dimen/preference_no_icon_padding_start"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- Shows the data plan usage in chart -->
|
||||
<com.android.settings.widget.DonutView
|
||||
android:id="@+id/donut"
|
||||
android:layout_width="72dp"
|
||||
android:layout_height="72dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_gravity="center"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:gravity="end|center_vertical"
|
||||
settings:applyColorAccent="false"
|
||||
settings:showPercentString="false"
|
||||
settings:thickness="6dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/data_plan_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="2dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Shows the data plan usage -->
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="0dp"
|
||||
android:paddingTop="0dp"
|
||||
android:fontFamily="@*android:string/config_headlineFontFamily"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Title"/>
|
||||
|
||||
<!-- Shows the data plan name -->
|
||||
<TextView
|
||||
android:id="@android:id/text1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="5dp"
|
||||
android:maxLines="3"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
|
||||
<!-- Shows the data plan description -->
|
||||
<TextView
|
||||
android:id="@android:id/text2"
|
||||
android:textStyle="italic"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="5"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.DonutView;
|
||||
|
||||
/**
|
||||
* Provides a summary of data plans as preferences on settings page.
|
||||
*/
|
||||
public final class DataPlanSummaryPreference extends Preference {
|
||||
private String mName;
|
||||
private String mDescription;
|
||||
private double mPercentageUsage;
|
||||
private int mUsageTextColor;
|
||||
private int mMeterBackgroundColor;
|
||||
private int mMeterConsumedColor;
|
||||
|
||||
public DataPlanSummaryPreference(Context context) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.settings_data_plan_summary_preference);
|
||||
}
|
||||
|
||||
public DataPlanSummaryPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.settings_data_plan_summary_preference);
|
||||
}
|
||||
|
||||
public void setName(String planName) {
|
||||
mName = planName;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setDescription(String planDescription) {
|
||||
mDescription = planDescription;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setPercentageUsage(double percentageUsage) {
|
||||
mPercentageUsage = percentageUsage;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setUsageTextColor(@ColorRes int planUsageTextColor) {
|
||||
mUsageTextColor = planUsageTextColor;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
|
||||
mMeterBackgroundColor = meterBackgroundColor;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
|
||||
mMeterConsumedColor = meterConsumedColor;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
holder.setDividerAllowedAbove(false);
|
||||
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
|
||||
titleView.setTextColor(mUsageTextColor);
|
||||
((TextView) holder.findViewById(android.R.id.text1)).setText(mName);
|
||||
((TextView) holder.findViewById(android.R.id.text2)).setText(mDescription);
|
||||
DonutView donutView = (DonutView) holder.findViewById(R.id.donut);
|
||||
donutView.setPercentage(mPercentageUsage);
|
||||
donutView.setMeterBackgroundColor(mMeterBackgroundColor);
|
||||
donutView.setMeterConsumedColor(mMeterConsumedColor);
|
||||
}
|
||||
}
|
@@ -48,6 +48,8 @@ public class DonutView extends View {
|
||||
private String mPercentString;
|
||||
private String mFullString;
|
||||
private boolean mShowPercentString = true;
|
||||
private int mMeterBackgroundColor;
|
||||
private int mMeterConsumedColor;
|
||||
|
||||
public DonutView(Context context) {
|
||||
super(context);
|
||||
@@ -55,18 +57,18 @@ public class DonutView extends View {
|
||||
|
||||
public DonutView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
int meterBackgroundColor = context.getColor(R.color.meter_background_color);
|
||||
int meterConsumedColor = Utils.getDefaultColor(mContext, R.color.meter_consumed_color);
|
||||
mMeterBackgroundColor = context.getColor(R.color.meter_background_color);
|
||||
mMeterConsumedColor = Utils.getDefaultColor(mContext, R.color.meter_consumed_color);
|
||||
boolean applyColorAccent = true;
|
||||
Resources resources = context.getResources();
|
||||
mStrokeWidth = resources.getDimension(R.dimen.storage_donut_thickness);
|
||||
|
||||
if (attrs != null) {
|
||||
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.DonutView);
|
||||
meterBackgroundColor = styledAttrs.getColor(R.styleable.DonutView_meterBackgroundColor,
|
||||
meterBackgroundColor);
|
||||
meterConsumedColor = styledAttrs.getColor(R.styleable.DonutView_meterConsumedColor,
|
||||
meterConsumedColor);
|
||||
mMeterBackgroundColor = styledAttrs.getColor(R.styleable.DonutView_meterBackgroundColor,
|
||||
mMeterBackgroundColor);
|
||||
mMeterConsumedColor = styledAttrs.getColor(R.styleable.DonutView_meterConsumedColor,
|
||||
mMeterConsumedColor);
|
||||
applyColorAccent = styledAttrs.getBoolean(R.styleable.DonutView_applyColorAccent,
|
||||
true);
|
||||
mShowPercentString = styledAttrs.getBoolean(R.styleable.DonutView_showPercentString,
|
||||
@@ -81,14 +83,14 @@ public class DonutView extends View {
|
||||
mBackgroundCircle.setStrokeCap(Paint.Cap.BUTT);
|
||||
mBackgroundCircle.setStyle(Paint.Style.STROKE);
|
||||
mBackgroundCircle.setStrokeWidth(mStrokeWidth);
|
||||
mBackgroundCircle.setColor(meterBackgroundColor);
|
||||
mBackgroundCircle.setColor(mMeterBackgroundColor);
|
||||
|
||||
mFilledArc = new Paint();
|
||||
mFilledArc.setAntiAlias(true);
|
||||
mFilledArc.setStrokeCap(Paint.Cap.BUTT);
|
||||
mFilledArc.setStyle(Paint.Style.STROKE);
|
||||
mFilledArc.setStrokeWidth(mStrokeWidth);
|
||||
mFilledArc.setColor(meterConsumedColor);
|
||||
mFilledArc.setColor(mMeterConsumedColor);
|
||||
|
||||
if (applyColorAccent) {
|
||||
final ColorFilter mAccentColorFilter =
|
||||
@@ -179,12 +181,24 @@ public class DonutView extends View {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getMeterBackgroundColor() {
|
||||
return mMeterBackgroundColor;
|
||||
}
|
||||
|
||||
public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
|
||||
mMeterBackgroundColor = meterBackgroundColor;
|
||||
mBackgroundCircle.setColor(meterBackgroundColor);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getMeterConsumedColor() {
|
||||
return mMeterConsumedColor;
|
||||
}
|
||||
|
||||
public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
|
||||
mMeterConsumedColor = meterConsumedColor;
|
||||
mFilledArc.setColor(meterConsumedColor);
|
||||
invalidate();
|
||||
}
|
||||
|
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.DonutView;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
}
|
||||
)
|
||||
public final class DataPlanSummaryPreferenceTest {
|
||||
|
||||
private static final String TEST_PLAN_USAGE = "Test plan usage";
|
||||
private static final String TEST_PLAN_NAME = "Test plan name";
|
||||
private static final String TEST_PLAN_DESCRIPTION = "Test plan description";
|
||||
private static final int PLAN_USAGE_TEXT_COLOR = Color.parseColor("#FF5C94F1");
|
||||
private static final int METER_BACKGROUND_COLOR = Color.parseColor("#FFDBDCDC");
|
||||
private static final int METER_CONSUMED_COLOR = Color.parseColor("#FF5C94F1");
|
||||
|
||||
private DataPlanSummaryPreference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new DataPlanSummaryPreference(context);
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withoutData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getText().toString()).isEmpty();
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText().toString()).isEmpty();
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(TEST_PLAN_USAGE);
|
||||
mPreference.setUsageTextColor(PLAN_USAGE_TEXT_COLOR);
|
||||
mPreference.setName(TEST_PLAN_NAME);
|
||||
mPreference.setDescription(TEST_PLAN_DESCRIPTION);
|
||||
mPreference.setPercentageUsage(0.25D);
|
||||
mPreference.setMeterBackgroundColor(METER_BACKGROUND_COLOR);
|
||||
mPreference.setMeterConsumedColor(METER_CONSUMED_COLOR);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getTextColors().getDefaultColor())
|
||||
.isEqualTo(PLAN_USAGE_TEXT_COLOR);
|
||||
assertThat(planUsageTextView.getText()).isEqualTo(TEST_PLAN_USAGE);
|
||||
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText()).isEqualTo(TEST_PLAN_NAME);
|
||||
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText()).isEqualTo(TEST_PLAN_DESCRIPTION);
|
||||
|
||||
DonutView donutView = (DonutView) mHolder.findViewById(R.id.donut);
|
||||
assertThat(donutView.getMeterBackgroundColor()).isEqualTo(METER_BACKGROUND_COLOR);
|
||||
assertThat(donutView.getMeterConsumedColor()).isEqualTo(METER_CONSUMED_COLOR);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user