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:
Andrew Sapperstein
2018-03-18 15:53:09 -07:00
parent b0f251597c
commit 38bf192ed6
14 changed files with 61 additions and 348 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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;