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">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:id="@android:id/background">
|
<item android:id="@android:id/background">
|
||||||
<shape android:shape="rectangle"
|
<shape android:shape="rectangle"
|
||||||
android:tint="?android:attr/colorControlActivated">
|
android:tint="@*android:color/config_progress_background_tint">
|
||||||
<corners android:radius="5dp" />
|
<corners android:radius="@*android:dimen/config_progressBarCornerRadius" />
|
||||||
<size android:height="10dp" />
|
<size android:height="10dp" />
|
||||||
<solid android:color="@color/white_disabled" />
|
<solid android:color="@*android:color/white_disabled_material" />
|
||||||
</shape>
|
</shape>
|
||||||
</item>
|
</item>r
|
||||||
<item android:id="@android:id/secondaryProgress">
|
<item android:id="@android:id/secondaryProgress">
|
||||||
<scale android:scaleWidth="100%">
|
<scale android:scaleWidth="100%">
|
||||||
<shape android:shape="rectangle"
|
<shape android:shape="rectangle"
|
||||||
android:tint="?android:attr/colorControlActivated">
|
android:tint="?android:attr/colorControlActivated">
|
||||||
<corners android:radius="5dp" />
|
<corners android:radius="@*android:dimen/config_progressBarCornerRadius" />
|
||||||
<size android:height="10dp" />
|
<size android:height="10dp" />
|
||||||
<solid android:color="@color/white_disabled" />
|
<solid android:color="@*android:color/white_disabled_material" />
|
||||||
</shape>
|
</shape>
|
||||||
</scale>
|
</scale>
|
||||||
</item>
|
</item>
|
||||||
@@ -36,9 +36,9 @@
|
|||||||
<scale android:scaleWidth="100%">
|
<scale android:scaleWidth="100%">
|
||||||
<shape android:shape="rectangle"
|
<shape android:shape="rectangle"
|
||||||
android:tint="?android:attr/colorControlActivated">
|
android:tint="?android:attr/colorControlActivated">
|
||||||
<corners android:radius="5dp" />
|
<corners android:radius="@*android:dimen/config_progressBarCornerRadius" />
|
||||||
<size android:height="10dp" />
|
<size android:height="10dp" />
|
||||||
<solid android:color="@android:color/black" />
|
<solid android:color="@android:color/white" />
|
||||||
</shape>
|
</shape>
|
||||||
</scale>
|
</scale>
|
||||||
</item>
|
</item>
|
@@ -22,7 +22,7 @@
|
|||||||
android:thickness="@dimen/ring_progress_bar_thickness"
|
android:thickness="@dimen/ring_progress_bar_thickness"
|
||||||
android:useLevel="false"
|
android:useLevel="false"
|
||||||
android:tint="?android:colorControlNormal">
|
android:tint="?android:colorControlNormal">
|
||||||
<solid android:color="@color/white_disabled" />
|
<solid android:color="@*android:color/white_disabled_material" />
|
||||||
</shape>
|
</shape>
|
||||||
</item>
|
</item>
|
||||||
<item android:id="@android:id/progress">
|
<item android:id="@android:id/progress">
|
||||||
|
@@ -68,8 +68,8 @@
|
|||||||
android:id="@+id/determinateBar"
|
android:id="@+id/determinateBar"
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="10dp"
|
android:layout_height="wrap_content"
|
||||||
android:progressDrawable="@drawable/data_usage_progress"/>
|
android:progressDrawable="@drawable/color_bar_progress"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/label_bar"
|
android:id="@+id/label_bar"
|
||||||
|
@@ -36,11 +36,12 @@
|
|||||||
android:gravity="left|center_vertical"
|
android:gravity="left|center_vertical"
|
||||||
android:text="@string/running_processes_header_title" />
|
android:text="@string/running_processes_header_title" />
|
||||||
|
|
||||||
<view class="com.android.settings.widget.LinearColorBar"
|
<ProgressBar
|
||||||
android:id="@+id/color_bar"
|
android:id="@+id/color_bar"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="16sp"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal" />
|
android:progressDrawable="@drawable/color_bar_progress"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@@ -42,11 +42,12 @@
|
|||||||
android:paddingBottom="5dp"
|
android:paddingBottom="5dp"
|
||||||
android:maxLines="10" />
|
android:maxLines="10" />
|
||||||
|
|
||||||
<com.android.settings.widget.LinearColorBar
|
<ProgressBar
|
||||||
android:id="@+id/color_bar"
|
android:id="@+id/color_bar"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="28dp"
|
android:layout_height="wrap_content"
|
||||||
/>
|
android:progressDrawable="@drawable/color_bar_progress"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/label_bar"
|
android:id="@+id/label_bar"
|
||||||
|
@@ -20,10 +20,9 @@ import android.support.v7.preference.PreferenceViewHolder;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
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.
|
* 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 mAmount;
|
||||||
private String mUnits;
|
private String mUnits;
|
||||||
|
|
||||||
private int mLeft, mMiddle, mRight;
|
|
||||||
private boolean mColorsSet = false;
|
|
||||||
private boolean mChartEnabled = true;
|
private boolean mChartEnabled = true;
|
||||||
private float mLeftRatio, mMiddleRatio, mRightRatio;
|
private float mLeftRatio, mMiddleRatio, mRightRatio;
|
||||||
private String mStartLabel;
|
private String mStartLabel;
|
||||||
@@ -81,26 +78,17 @@ public class SummaryPreference extends Preference {
|
|||||||
notifyChanged();
|
notifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColors(int left, int middle, int right) {
|
|
||||||
mLeft = left;
|
|
||||||
mMiddle = middle;
|
|
||||||
mRight = right;
|
|
||||||
mColorsSet = true;
|
|
||||||
notifyChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(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) {
|
if (mChartEnabled) {
|
||||||
colorBar.setVisibility(View.VISIBLE);
|
colorBar.setVisibility(View.VISIBLE);
|
||||||
colorBar.setRatios(mLeftRatio, mMiddleRatio, mRightRatio);
|
int progress = (int) (mLeftRatio * 100);
|
||||||
if (mColorsSet) {
|
colorBar.setProgress(progress);
|
||||||
colorBar.setColors(mLeft, mMiddle, mRight);
|
colorBar.setSecondaryProgress(progress + (int) (mMiddleRatio * 100));
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
colorBar.setVisibility(View.GONE);
|
colorBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,8 @@ import android.app.ActivityManager;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -36,6 +38,7 @@ import android.widget.BaseAdapter;
|
|||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.util.MemInfoReader;
|
import com.android.internal.util.MemInfoReader;
|
||||||
@@ -43,7 +46,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.widget.LinearColorBar;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -75,7 +77,7 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
ListView mListView;
|
ListView mListView;
|
||||||
View mHeader;
|
View mHeader;
|
||||||
ServiceListAdapter mAdapter;
|
ServiceListAdapter mAdapter;
|
||||||
LinearColorBar mColorBar;
|
ProgressBar mColorBar;
|
||||||
TextView mBackgroundProcessPrefix;
|
TextView mBackgroundProcessPrefix;
|
||||||
TextView mAppsProcessPrefix;
|
TextView mAppsProcessPrefix;
|
||||||
TextView mForegroundProcessPrefix;
|
TextView mForegroundProcessPrefix;
|
||||||
@@ -385,9 +387,9 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
Formatter.formatShortFileSize(getContext(), highRam));
|
Formatter.formatShortFileSize(getContext(), highRam));
|
||||||
mForegroundProcessText.setText(getResources().getString(
|
mForegroundProcessText.setText(getResources().getString(
|
||||||
R.string.running_processes_header_ram, sizeStr));
|
R.string.running_processes_header_ram, sizeStr));
|
||||||
mColorBar.setRatios(highRam/(float)totalRam,
|
int progress = (int) ((highRam/(float) totalRam) * 100);
|
||||||
medRam/(float)totalRam,
|
mColorBar.setProgress(progress);
|
||||||
lowRam/(float)totalRam);
|
mColorBar.setSecondaryProgress(progress + (int) ((medRam/(float) totalRam) * 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,17 +448,22 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
mListView.setAdapter(mAdapter);
|
mListView.setAdapter(mAdapter);
|
||||||
mHeader = inflater.inflate(R.layout.running_processes_header, null);
|
mHeader = inflater.inflate(R.layout.running_processes_header, null);
|
||||||
mListView.addHeaderView(mHeader, null, false /* set as not selectable */);
|
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();
|
final Context context = getContext();
|
||||||
mColorBar.setColors(context.getColor(R.color.running_processes_system_ram),
|
mColorBar.setProgressTintList(
|
||||||
Utils.getColorAccent(context),
|
ColorStateList.valueOf(context.getColor(R.color.running_processes_system_ram)));
|
||||||
context.getColor(R.color.running_processes_free_ram));
|
mColorBar.setSecondaryProgressTintList(
|
||||||
mBackgroundProcessPrefix = (TextView)mHeader.findViewById(R.id.freeSizePrefix);
|
ColorStateList.valueOf(Utils.getColorAccent(context)));
|
||||||
mAppsProcessPrefix = (TextView)mHeader.findViewById(R.id.appsSizePrefix);
|
mColorBar.setSecondaryProgressTintMode(PorterDuff.Mode.SRC);
|
||||||
mForegroundProcessPrefix = (TextView)mHeader.findViewById(R.id.systemSizePrefix);
|
mColorBar.setProgressBackgroundTintList(
|
||||||
mBackgroundProcessText = (TextView)mHeader.findViewById(R.id.freeSize);
|
ColorStateList.valueOf(context.getColor(R.color.running_processes_free_ram)));
|
||||||
mAppsProcessText = (TextView)mHeader.findViewById(R.id.appsSize);
|
mColorBar.setProgressBackgroundTintMode(PorterDuff.Mode.SRC);
|
||||||
mForegroundProcessText = (TextView)mHeader.findViewById(R.id.systemSize);
|
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();
|
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||||
mAm.getMemoryInfo(memInfo);
|
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 android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(shadows = SettingsShadowResourcesImpl.class)
|
||||||
public class SummaryPreferenceTest {
|
public class SummaryPreferenceTest {
|
||||||
|
|
||||||
private PreferenceViewHolder mHolder;
|
private PreferenceViewHolder mHolder;
|
||||||
|
@@ -36,6 +36,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
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.ShadowUtils;
|
||||||
import com.android.settings.testutils.shadow.ShadowVibrator;
|
import com.android.settings.testutils.shadow.ShadowVibrator;
|
||||||
import com.android.settings.wrapper.FingerprintManagerWrapper;
|
import com.android.settings.wrapper.FingerprintManagerWrapper;
|
||||||
@@ -54,7 +55,10 @@ import org.robolectric.shadow.api.Shadow;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowUtils.class, ShadowVibrator.class})
|
@Config(shadows = {
|
||||||
|
SettingsShadowResourcesImpl.class,
|
||||||
|
ShadowUtils.class,
|
||||||
|
ShadowVibrator.class})
|
||||||
public class FingerprintEnrollEnrollingTest {
|
public class FingerprintEnrollEnrollingTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@@ -52,6 +52,11 @@ public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
|
|||||||
id = R.drawable.ic_expand_more_inverse;
|
id = R.drawable.ic_expand_more_inverse;
|
||||||
} else if (id == R.drawable.selectable_card_grey) {
|
} else if (id == R.drawable.selectable_card_grey) {
|
||||||
id = R.drawable.ic_expand_more_inverse;
|
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);
|
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 android.view.View.MeasureSpec;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -29,6 +30,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@org.robolectric.annotation.Config(shadows = SettingsShadowResourcesImpl.class)
|
||||||
public class RingProgressBarTest {
|
public class RingProgressBarTest {
|
||||||
|
|
||||||
private Context mContext = RuntimeEnvironment.application;
|
private Context mContext = RuntimeEnvironment.application;
|
||||||
|
Reference in New Issue
Block a user