Remove LinearColorBar and replace uses with ProgressBar.
We never actually needed it, since progress bar can do everything we want it to. Renamed data_usage_progress to color_bar_progress to reflect its more generic state. Updated color_bar_progress to use proper values. Since we can't seem to use private attrs in settings, use the dimen/color values that are customizable. Updated usages to use regular ProgressBar APIs. Fixes: 74111937 Test: visual inspection and robotests Change-Id: I4f0c59e6cf5c629e3cc3901800d9c4afc95fa495
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="@android:color/white"
|
||||
android:alpha="?android:attr/disabledAlpha" />
|
||||
</selector>
|
@@ -16,19 +16,19 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle"
|
||||
android:tint="?android:attr/colorControlActivated">
|
||||
<corners android:radius="5dp" />
|
||||
android:tint="@*android:color/config_progress_background_tint">
|
||||
<corners android:radius="@*android:dimen/config_progressBarCornerRadius" />
|
||||
<size android:height="10dp" />
|
||||
<solid android:color="@color/white_disabled" />
|
||||
<solid android:color="@*android:color/white_disabled_material" />
|
||||
</shape>
|
||||
</item>
|
||||
</item>r
|
||||
<item android:id="@android:id/secondaryProgress">
|
||||
<scale android:scaleWidth="100%">
|
||||
<shape android:shape="rectangle"
|
||||
android:tint="?android:attr/colorControlActivated">
|
||||
<corners android:radius="5dp" />
|
||||
<corners android:radius="@*android:dimen/config_progressBarCornerRadius" />
|
||||
<size android:height="10dp" />
|
||||
<solid android:color="@color/white_disabled" />
|
||||
<solid android:color="@*android:color/white_disabled_material" />
|
||||
</shape>
|
||||
</scale>
|
||||
</item>
|
||||
@@ -36,9 +36,9 @@
|
||||
<scale android:scaleWidth="100%">
|
||||
<shape android:shape="rectangle"
|
||||
android:tint="?android:attr/colorControlActivated">
|
||||
<corners android:radius="5dp" />
|
||||
<corners android:radius="@*android:dimen/config_progressBarCornerRadius" />
|
||||
<size android:height="10dp" />
|
||||
<solid android:color="@android:color/black" />
|
||||
<solid android:color="@android:color/white" />
|
||||
</shape>
|
||||
</scale>
|
||||
</item>
|
@@ -22,7 +22,7 @@
|
||||
android:thickness="@dimen/ring_progress_bar_thickness"
|
||||
android:useLevel="false"
|
||||
android:tint="?android:colorControlNormal">
|
||||
<solid android:color="@color/white_disabled" />
|
||||
<solid android:color="@*android:color/white_disabled_material" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@android:id/progress">
|
||||
|
@@ -68,8 +68,8 @@
|
||||
android:id="@+id/determinateBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:progressDrawable="@drawable/data_usage_progress"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:progressDrawable="@drawable/color_bar_progress"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/label_bar"
|
||||
|
@@ -36,11 +36,12 @@
|
||||
android:gravity="left|center_vertical"
|
||||
android:text="@string/running_processes_header_title" />
|
||||
|
||||
<view class="com.android.settings.widget.LinearColorBar"
|
||||
<ProgressBar
|
||||
android:id="@+id/color_bar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="16sp"
|
||||
android:orientation="horizontal" />
|
||||
android:layout_height="wrap_content"
|
||||
android:progressDrawable="@drawable/color_bar_progress"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@@ -42,11 +42,12 @@
|
||||
android:paddingBottom="5dp"
|
||||
android:maxLines="10" />
|
||||
|
||||
<com.android.settings.widget.LinearColorBar
|
||||
<ProgressBar
|
||||
android:id="@+id/color_bar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="28dp"
|
||||
/>
|
||||
android:layout_height="wrap_content"
|
||||
android:progressDrawable="@drawable/color_bar_progress"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/label_bar"
|
||||
|
@@ -20,10 +20,9 @@ import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.widget.LinearColorBar;
|
||||
|
||||
/**
|
||||
* Provides a summary of a setting page in a preference. Such as memory or data usage.
|
||||
*/
|
||||
@@ -33,8 +32,6 @@ public class SummaryPreference extends Preference {
|
||||
private String mAmount;
|
||||
private String mUnits;
|
||||
|
||||
private int mLeft, mMiddle, mRight;
|
||||
private boolean mColorsSet = false;
|
||||
private boolean mChartEnabled = true;
|
||||
private float mLeftRatio, mMiddleRatio, mRightRatio;
|
||||
private String mStartLabel;
|
||||
@@ -81,26 +78,17 @@ public class SummaryPreference extends Preference {
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setColors(int left, int middle, int right) {
|
||||
mLeft = left;
|
||||
mMiddle = middle;
|
||||
mRight = right;
|
||||
mColorsSet = true;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
final LinearColorBar colorBar = holder.itemView.findViewById(R.id.color_bar);
|
||||
final ProgressBar colorBar = holder.itemView.findViewById(R.id.color_bar);
|
||||
|
||||
if (mChartEnabled) {
|
||||
colorBar.setVisibility(View.VISIBLE);
|
||||
colorBar.setRatios(mLeftRatio, mMiddleRatio, mRightRatio);
|
||||
if (mColorsSet) {
|
||||
colorBar.setColors(mLeft, mMiddle, mRight);
|
||||
}
|
||||
int progress = (int) (mLeftRatio * 100);
|
||||
colorBar.setProgress(progress);
|
||||
colorBar.setSecondaryProgress(progress + (int) (mMiddleRatio * 100));
|
||||
} else {
|
||||
colorBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import android.app.ActivityManager;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
@@ -36,6 +38,7 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.util.MemInfoReader;
|
||||
@@ -43,7 +46,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.widget.LinearColorBar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -75,7 +77,7 @@ public class RunningProcessesView extends FrameLayout
|
||||
ListView mListView;
|
||||
View mHeader;
|
||||
ServiceListAdapter mAdapter;
|
||||
LinearColorBar mColorBar;
|
||||
ProgressBar mColorBar;
|
||||
TextView mBackgroundProcessPrefix;
|
||||
TextView mAppsProcessPrefix;
|
||||
TextView mForegroundProcessPrefix;
|
||||
@@ -385,9 +387,9 @@ public class RunningProcessesView extends FrameLayout
|
||||
Formatter.formatShortFileSize(getContext(), highRam));
|
||||
mForegroundProcessText.setText(getResources().getString(
|
||||
R.string.running_processes_header_ram, sizeStr));
|
||||
mColorBar.setRatios(highRam/(float)totalRam,
|
||||
medRam/(float)totalRam,
|
||||
lowRam/(float)totalRam);
|
||||
int progress = (int) ((highRam/(float) totalRam) * 100);
|
||||
mColorBar.setProgress(progress);
|
||||
mColorBar.setSecondaryProgress(progress + (int) ((medRam/(float) totalRam) * 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,17 +448,22 @@ public class RunningProcessesView extends FrameLayout
|
||||
mListView.setAdapter(mAdapter);
|
||||
mHeader = inflater.inflate(R.layout.running_processes_header, null);
|
||||
mListView.addHeaderView(mHeader, null, false /* set as not selectable */);
|
||||
mColorBar = (LinearColorBar)mHeader.findViewById(R.id.color_bar);
|
||||
mColorBar = mHeader.findViewById(R.id.color_bar);
|
||||
final Context context = getContext();
|
||||
mColorBar.setColors(context.getColor(R.color.running_processes_system_ram),
|
||||
Utils.getColorAccent(context),
|
||||
context.getColor(R.color.running_processes_free_ram));
|
||||
mBackgroundProcessPrefix = (TextView)mHeader.findViewById(R.id.freeSizePrefix);
|
||||
mAppsProcessPrefix = (TextView)mHeader.findViewById(R.id.appsSizePrefix);
|
||||
mForegroundProcessPrefix = (TextView)mHeader.findViewById(R.id.systemSizePrefix);
|
||||
mBackgroundProcessText = (TextView)mHeader.findViewById(R.id.freeSize);
|
||||
mAppsProcessText = (TextView)mHeader.findViewById(R.id.appsSize);
|
||||
mForegroundProcessText = (TextView)mHeader.findViewById(R.id.systemSize);
|
||||
mColorBar.setProgressTintList(
|
||||
ColorStateList.valueOf(context.getColor(R.color.running_processes_system_ram)));
|
||||
mColorBar.setSecondaryProgressTintList(
|
||||
ColorStateList.valueOf(Utils.getColorAccent(context)));
|
||||
mColorBar.setSecondaryProgressTintMode(PorterDuff.Mode.SRC);
|
||||
mColorBar.setProgressBackgroundTintList(
|
||||
ColorStateList.valueOf(context.getColor(R.color.running_processes_free_ram)));
|
||||
mColorBar.setProgressBackgroundTintMode(PorterDuff.Mode.SRC);
|
||||
mBackgroundProcessPrefix = mHeader.findViewById(R.id.freeSizePrefix);
|
||||
mAppsProcessPrefix = mHeader.findViewById(R.id.appsSizePrefix);
|
||||
mForegroundProcessPrefix = mHeader.findViewById(R.id.systemSizePrefix);
|
||||
mBackgroundProcessText = mHeader.findViewById(R.id.freeSize);
|
||||
mAppsProcessText = mHeader.findViewById(R.id.appsSize);
|
||||
mForegroundProcessText = mHeader.findViewById(R.id.systemSize);
|
||||
|
||||
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||
mAm.getMemoryInfo(memInfo);
|
||||
|
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
/**
|
||||
* @Deprecated Use {@link android.widget.ProgressBar} instead.
|
||||
*/
|
||||
public class LinearColorBar extends LinearLayout {
|
||||
|
||||
static final int RIGHT_COLOR = 0xffced7db;
|
||||
static final int GRAY_COLOR = 0xff555555;
|
||||
static final int WHITE_COLOR = 0xffffffff;
|
||||
|
||||
private float mRedRatio;
|
||||
private float mYellowRatio;
|
||||
private float mGreenRatio;
|
||||
|
||||
private int mLeftColor;
|
||||
private int mMiddleColor;
|
||||
private int mRightColor = RIGHT_COLOR;
|
||||
|
||||
private int mColoredRegions = REGION_RED | REGION_YELLOW | REGION_GREEN;
|
||||
|
||||
final Rect mRect = new Rect();
|
||||
final Paint mPaint = new Paint();
|
||||
|
||||
int mLineWidth;
|
||||
|
||||
int mLastRegion;
|
||||
|
||||
final Paint mColorGradientPaint = new Paint();
|
||||
final Paint mEdgeGradientPaint = new Paint();
|
||||
|
||||
public static final int REGION_RED = 1 << 0;
|
||||
public static final int REGION_YELLOW = 1 << 1;
|
||||
public static final int REGION_GREEN = 1 << 2;
|
||||
|
||||
public LinearColorBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWillNotDraw(false);
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
mColorGradientPaint.setStyle(Paint.Style.FILL);
|
||||
mColorGradientPaint.setAntiAlias(true);
|
||||
mEdgeGradientPaint.setStyle(Paint.Style.STROKE);
|
||||
mLineWidth = getResources().getDisplayMetrics().densityDpi >= DisplayMetrics.DENSITY_HIGH
|
||||
? 2 : 1;
|
||||
mEdgeGradientPaint.setStrokeWidth(mLineWidth);
|
||||
mEdgeGradientPaint.setAntiAlias(true);
|
||||
mLeftColor = mMiddleColor = Utils.getColorAccent(context);
|
||||
}
|
||||
|
||||
public void setRatios(float red, float yellow, float green) {
|
||||
mRedRatio = red;
|
||||
mYellowRatio = yellow;
|
||||
mGreenRatio = green;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setColors(int red, int yellow, int green) {
|
||||
mLeftColor = red;
|
||||
mMiddleColor = yellow;
|
||||
mRightColor = green;
|
||||
updateIndicator();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void updateIndicator() {
|
||||
int off = getPaddingTop() - getPaddingBottom();
|
||||
if (off < 0) off = 0;
|
||||
mRect.top = off;
|
||||
mRect.bottom = getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateIndicator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchSetPressed(boolean pressed) {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private int pickColor(int color, int region) {
|
||||
if (isPressed() && (mLastRegion & region) != 0) {
|
||||
return WHITE_COLOR;
|
||||
}
|
||||
if ((mColoredRegions & region) == 0) {
|
||||
return GRAY_COLOR;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
final int width = getWidth();
|
||||
|
||||
if (!isLayoutRtl()) {
|
||||
drawLtr(canvas, width);
|
||||
} else {
|
||||
drawRtl(canvas, width);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawLtr(Canvas canvas, int width) {
|
||||
int start = 0;
|
||||
int end = start + (int) (width * mRedRatio);
|
||||
int end2 = end + (int) (width * mYellowRatio);
|
||||
|
||||
if (start < end) {
|
||||
mRect.left = start;
|
||||
mRect.right = end;
|
||||
mPaint.setColor(pickColor(mLeftColor, REGION_RED));
|
||||
canvas.drawRect(mRect, mPaint);
|
||||
start = end;
|
||||
}
|
||||
|
||||
end = end2;
|
||||
|
||||
if (start < end) {
|
||||
mRect.left = start;
|
||||
mRect.right = end;
|
||||
mPaint.setColor(pickColor(mMiddleColor, REGION_YELLOW));
|
||||
canvas.drawRect(mRect, mPaint);
|
||||
start = end;
|
||||
}
|
||||
|
||||
end = width;
|
||||
if (start < end) {
|
||||
mRect.left = start;
|
||||
mRect.right = end;
|
||||
mPaint.setColor(pickColor(mRightColor, REGION_GREEN));
|
||||
canvas.drawRect(mRect, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawRtl(Canvas canvas, int width) {
|
||||
int start = width;
|
||||
int end = start - (int) (width * mRedRatio);
|
||||
int end2 = end - (int) (width * mYellowRatio);
|
||||
|
||||
if (start > end) {
|
||||
mRect.left = end;
|
||||
mRect.right = start;
|
||||
mPaint.setColor(pickColor(mLeftColor, REGION_RED));
|
||||
canvas.drawRect(mRect, mPaint);
|
||||
start = end;
|
||||
}
|
||||
|
||||
end = end2;
|
||||
|
||||
if (start > end) {
|
||||
mRect.left = end;
|
||||
mRect.right = start;
|
||||
mPaint.setColor(pickColor(mMiddleColor, REGION_YELLOW));
|
||||
canvas.drawRect(mRect, mPaint);
|
||||
start = end;
|
||||
}
|
||||
|
||||
end = 0;
|
||||
if (start > end) {
|
||||
mRect.left = end;
|
||||
mRect.right = start;
|
||||
mPaint.setColor(pickColor(mRightColor, REGION_GREEN));
|
||||
canvas.drawRect(mRect, mPaint);
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,13 +25,16 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = SettingsShadowResourcesImpl.class)
|
||||
public class SummaryPreferenceTest {
|
||||
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
@@ -36,6 +36,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowVibrator;
|
||||
import com.android.settings.wrapper.FingerprintManagerWrapper;
|
||||
@@ -54,7 +55,10 @@ import org.robolectric.shadow.api.Shadow;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowUtils.class, ShadowVibrator.class})
|
||||
@Config(shadows = {
|
||||
SettingsShadowResourcesImpl.class,
|
||||
ShadowUtils.class,
|
||||
ShadowVibrator.class})
|
||||
public class FingerprintEnrollEnrollingTest {
|
||||
|
||||
@Mock
|
||||
|
@@ -52,6 +52,11 @@ public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
|
||||
id = R.drawable.ic_expand_more_inverse;
|
||||
} else if (id == R.drawable.selectable_card_grey) {
|
||||
id = R.drawable.ic_expand_more_inverse;
|
||||
} else if (id == R.drawable.color_bar_progress
|
||||
|| id == R.drawable.ring_progress) {
|
||||
// color_bar_progress and ring_progress use hidden resources, so just use the regular
|
||||
// progress_horizontal drawable
|
||||
id = android.R.drawable.progress_horizontal;
|
||||
}
|
||||
return super.loadDrawable(wrapper, value, id, density, theme);
|
||||
}
|
||||
|
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowCanvas;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class LinearColorBarTest {
|
||||
|
||||
private static final int HEIGHT = 100;
|
||||
private static final int WIDTH = 100;
|
||||
|
||||
private Context mContext;
|
||||
private LinearColorBar mLinearColorBar;
|
||||
private Canvas mCanvas;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mLinearColorBar = spy(new LinearColorBar(mContext, null /* attrs */));
|
||||
when(mLinearColorBar.getHeight()).thenReturn(HEIGHT);
|
||||
when(mLinearColorBar.getWidth()).thenReturn(WIDTH);
|
||||
mLinearColorBar.setRatios(0.2f, 0.4f, 0.4f);
|
||||
mLinearColorBar.setColors(1, 2, 3);
|
||||
mCanvas = new Canvas();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void draw_ltr_showStartFromLeft() {
|
||||
mLinearColorBar.onDraw(mCanvas);
|
||||
|
||||
final ShadowCanvas shadowCanvas = Shadows.shadowOf(mCanvas);
|
||||
assertThat(shadowCanvas.getRectPaintHistoryCount()).isEqualTo(3);
|
||||
|
||||
// 3 boxes, takes space of 20%, 40%, 40% of the the WIDTH correspondingly.
|
||||
assertThat(shadowCanvas.getDrawnRect(0).left).isWithin(0.01f).of(0);
|
||||
assertThat(shadowCanvas.getDrawnRect(1).left).isWithin(0.01f).of(20);
|
||||
assertThat(shadowCanvas.getDrawnRect(2).left).isWithin(0.01f).of(60);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void draw_rtl_showStartFromRight() {
|
||||
when(mLinearColorBar.isLayoutRtl()).thenReturn(true);
|
||||
|
||||
mLinearColorBar.onDraw(mCanvas);
|
||||
|
||||
final ShadowCanvas shadowCanvas = Shadows.shadowOf(mCanvas);
|
||||
assertThat(shadowCanvas.getRectPaintHistoryCount()).isEqualTo(3);
|
||||
|
||||
// 3 boxes, takes space of 20%, 40%, 40% of the the WIDTH correspondingly.
|
||||
assertThat(shadowCanvas.getDrawnRect(0).right).isWithin(0.01f).of(100);
|
||||
assertThat(shadowCanvas.getDrawnRect(1).right).isWithin(0.01f).of(80);
|
||||
assertThat(shadowCanvas.getDrawnRect(2).right).isWithin(0.01f).of(40);
|
||||
}
|
||||
}
|
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.view.View.MeasureSpec;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -29,6 +30,7 @@ import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@org.robolectric.annotation.Config(shadows = SettingsShadowResourcesImpl.class)
|
||||
public class RingProgressBarTest {
|
||||
|
||||
private Context mContext = RuntimeEnvironment.application;
|
||||
|
Reference in New Issue
Block a user