Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fba1e39 authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Change battery icon to the side of bt icon" into oc-mr1-dev am:...

Merge "Merge "Change battery icon to the side of bt icon" into oc-mr1-dev am: a57aea0d am: d5d97667"
parents 85a5609e c57a9334
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -61,10 +61,13 @@
    <fraction name="battery_button_height_fraction">10.5%</fraction>

    <!-- Ratio between height of button part and height of total -->
    <fraction name="bt_battery_button_height_fraction">7.5%</fraction>
    <fraction name="bt_battery_button_height_fraction">7.8%</fraction>

    <!-- Ratio between width and height -->
    <fraction name="bt_battery_ratio_fraction">45%</fraction>
    <fraction name="bt_battery_ratio_fraction">35%</fraction>

    <!-- Ratio of height between battery icon and bluetooth icon -->
    <fraction name="bt_battery_scale_fraction">75%</fraction>

    <!-- Fraction value to smooth the edges of the battery icon. The path will be inset by this
         fraction of a pixel.-->
+4 −1
Original line number Diff line number Diff line
@@ -292,6 +292,7 @@ public class BatteryMeterDrawableBase extends Drawable {
    @Override
    public void draw(Canvas c) {
        final int level = mLevel;
        final Rect bounds = getBounds();

        if (level == -1) return;

@@ -300,8 +301,10 @@ public class BatteryMeterDrawableBase extends Drawable {
        final int width = (int) (getAspectRatio() * mHeight);
        final int px = (mWidth - width) / 2;
        final int buttonHeight = Math.round(height * mButtonHeightFraction);
        final int left = mPadding.left + bounds.left;
        final int top = bounds.bottom - mPadding.bottom - height;

        mFrame.set(mPadding.left, mPadding.top, width + mPadding.left, height + mPadding.top);
        mFrame.set(left, top, width + left, height + top);
        mFrame.offset(px, 0);

        // button-frame: area above the battery body
+33 −41
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
@@ -47,7 +48,7 @@ public class BluetoothDeviceLayerDrawable extends LayerDrawable {

    /**
     * Create the {@link LayerDrawable} that contains bluetooth device icon and battery icon.
     * This is a vertical layout drawable while bluetooth icon at top and battery icon at bottom.
     * This is a horizontal layout drawable while bluetooth icon at start and battery icon at end.
     *
     * @param context      used to get the spec for icon
     * @param resId        represents the bluetooth device drawable
@@ -55,55 +56,44 @@ public class BluetoothDeviceLayerDrawable extends LayerDrawable {
     */
    public static BluetoothDeviceLayerDrawable createLayerDrawable(Context context, int resId,
            int batteryLevel) {
        return createLayerDrawable(context, resId, batteryLevel, 1 /*iconScale*/);
    }

    /**
     * Create the {@link LayerDrawable} that contains bluetooth device icon and battery icon.
     * This is a horizontal layout drawable while bluetooth icon at start and battery icon at end.
     *
     * @param context      used to get the spec for icon
     * @param resId        represents the bluetooth device drawable
     * @param batteryLevel the battery level for bluetooth device
     * @param iconScale    the ratio of height between battery icon and bluetooth icon
     */
    public static BluetoothDeviceLayerDrawable createLayerDrawable(Context context, int resId,
            int batteryLevel, float iconScale) {
        final Drawable deviceDrawable = context.getDrawable(resId);

        final BatteryMeterDrawable batteryDrawable = new BatteryMeterDrawable(context,
                R.color.meter_background_color, batteryLevel);
        final int pad = context.getResources()
                .getDimensionPixelSize(R.dimen.bt_battery_padding);
        batteryDrawable.setPadding(0, pad, 0, pad);
        final int pad = context.getResources().getDimensionPixelSize(R.dimen.bt_battery_padding);
        batteryDrawable.setPadding(pad, pad, pad, pad);

        final BluetoothDeviceLayerDrawable drawable = new BluetoothDeviceLayerDrawable(
                new Drawable[]{deviceDrawable,
                        rotateDrawable(context.getResources(), batteryDrawable)});
        // Set the bluetooth icon at the top
        drawable.setLayerGravity(0 /* index of deviceDrawable */, Gravity.TOP);
        // Set battery icon right below the bluetooth icon
        drawable.setLayerInset(1 /* index of batteryDrawable */, 0,
                deviceDrawable.getIntrinsicHeight(), 0, 0);
                new Drawable[]{deviceDrawable, batteryDrawable});
        // Set the bluetooth icon at the left
        drawable.setLayerGravity(0 /* index of deviceDrawable */, Gravity.START);
        // Set battery icon to the right of the bluetooth icon
        drawable.setLayerInsetStart(1 /* index of batteryDrawable */,
                deviceDrawable.getIntrinsicWidth());
        drawable.setLayerInsetTop(1 /* index of batteryDrawable */,
                (int) (deviceDrawable.getIntrinsicHeight() * (1 - iconScale)));

        drawable.setConstantState(context, resId, batteryLevel);
        drawable.setConstantState(context, resId, batteryLevel, iconScale);

        return drawable;
    }

    /**
     * Rotate the {@code drawable} by 90 degree clockwise and return rotated {@link Drawable}
     */
    private static Drawable rotateDrawable(Resources res, Drawable drawable) {
        // Get the bitmap from drawable
        final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        // Create rotate matrix
        final Matrix matrix = new Matrix();
        matrix.postRotate(
                res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR
                        ? 90 : 270);

        // Create new bitmap with rotate matrix
        final Bitmap rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), matrix, true);
        bitmap.recycle();

        return new BitmapDrawable(res, rotateBitmap);
    }

    public void setConstantState(Context context, int resId, int batteryLevel) {
        mState = new BluetoothDeviceLayerDrawableState(context, resId, batteryLevel);
    public void setConstantState(Context context, int resId, int batteryLevel, float iconScale) {
        mState = new BluetoothDeviceLayerDrawableState(context, resId, batteryLevel, iconScale);
    }

    @Override
@@ -149,17 +139,19 @@ public class BluetoothDeviceLayerDrawable extends LayerDrawable {
        Context context;
        int resId;
        int batteryLevel;
        float iconScale;

        public BluetoothDeviceLayerDrawableState(Context context, int resId,
                int batteryLevel) {
                int batteryLevel, float iconScale) {
            this.context = context;
            this.resId = resId;
            this.batteryLevel = batteryLevel;
            this.iconScale = iconScale;
        }

        @Override
        public Drawable newDrawable() {
            return createLayerDrawable(context, resId, batteryLevel);
            return createLayerDrawable(context, resId, batteryLevel, iconScale);
        }

        @Override
+21 −4
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import org.robolectric.annotation.Config;
public class BluetoothDeviceLayerDrawableTest {
    private static final int RES_ID = R.drawable.ic_bt_cellphone;
    private static final int BATTERY_LEVEL = 15;
    private static final float BATTERY_ICON_SCALE = 0.75f;
    private static final int BATTERY_ICON_PADDING_TOP = 6;
    private static final float TOLERANCE = 0.001f;

    private Context mContext;
@@ -54,9 +56,24 @@ public class BluetoothDeviceLayerDrawableTest {
                mContext, RES_ID, BATTERY_LEVEL);

        assertThat(drawable.getDrawable(0)).isInstanceOf(VectorDrawable.class);
        assertThat(drawable.getDrawable(1)).isInstanceOf(BitmapDrawable.class);
        assertThat(drawable.getLayerInsetTop(1)).isEqualTo(
                drawable.getDrawable(0).getIntrinsicHeight());
        assertThat(drawable.getDrawable(1)).isInstanceOf(
                BluetoothDeviceLayerDrawable.BatteryMeterDrawable.class);
        assertThat(drawable.getLayerInsetStart(1)).isEqualTo(
                drawable.getDrawable(0).getIntrinsicWidth());
        assertThat(drawable.getLayerInsetTop(1)).isEqualTo(0);
    }

    @Test
    public void testCreateLayerDrawable_withIconScale_configCorrect() {
        BluetoothDeviceLayerDrawable drawable = BluetoothDeviceLayerDrawable.createLayerDrawable(
                mContext, RES_ID, BATTERY_LEVEL, BATTERY_ICON_SCALE);

        assertThat(drawable.getDrawable(0)).isInstanceOf(VectorDrawable.class);
        assertThat(drawable.getDrawable(1)).isInstanceOf(
                BluetoothDeviceLayerDrawable.BatteryMeterDrawable.class);
        assertThat(drawable.getLayerInsetStart(1)).isEqualTo(
                drawable.getDrawable(0).getIntrinsicWidth());
        assertThat(drawable.getLayerInsetTop(1)).isEqualTo(BATTERY_ICON_PADDING_TOP);
    }

    @Test
@@ -65,7 +82,7 @@ public class BluetoothDeviceLayerDrawableTest {
                new BluetoothDeviceLayerDrawable.BatteryMeterDrawable(mContext,
                        R.color.meter_background_color, BATTERY_LEVEL);

        assertThat(batteryDrawable.getAspectRatio()).isWithin(TOLERANCE).of(0.45f);
        assertThat(batteryDrawable.getAspectRatio()).isWithin(TOLERANCE).of(0.35f);
        assertThat(batteryDrawable.getRadiusRatio()).isWithin(TOLERANCE).of(0f);
        assertThat(batteryDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
    }
+2 −2
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@ Copyright (C) 2017 The Android Open Source Project
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="64dp"
    android:height="64dp"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0"
    android:tint="?android:attr/colorControlNormal" >
Loading