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

Commit 64866055 authored by Joel Galenson's avatar Joel Galenson Committed by tmfang
Browse files

Modify the bar chart for new graph design

- Allow passing a custom string as the label for each bar.
- Also allow passing a CharSequence as the bar summary instead of a
resource id.
- Change barchar style for new graph design. ex: color, font size,
margin size

Test: View graph.
Test: atest BarChartInfoTest BarChartPreferenceTest
Change-Id: I6f31ece4fe61811420cf2458219452862e8d04c2
parent c58829cb
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"
    android:gravity="center"
    android:orientation="vertical">

@@ -47,19 +47,19 @@
            <com.android.settingslib.widget.BarView
                android:id="@+id/bar_view1"
                style="@style/BarViewStyle"
                settings:barColor="#FA7B17"/>
                settings:barColor="#A142F4"/>
            <com.android.settingslib.widget.BarView
                android:id="@+id/bar_view2"
                style="@style/BarViewStyle"
                settings:barColor="#F439A0"/>
                settings:barColor="#24C1E0"/>
            <com.android.settingslib.widget.BarView
                android:id="@+id/bar_view3"
                style="@style/BarViewStyle"
                settings:barColor="#A142F4"/>
                settings:barColor="#4285F4"/>
            <com.android.settingslib.widget.BarView
                android:id="@+id/bar_view4"
                style="@style/BarViewStyle"
                settings:barColor="#24C1E0"/>
                settings:barColor="#009688"/>
        </LinearLayout>

        <Button
+3 −4
Original line number Diff line number Diff line
@@ -32,15 +32,13 @@
        android:layout_width="@dimen/settings_bar_view_icon_size"
        android:layout_height="@dimen/settings_bar_view_icon_size"
        android:scaleType="fitCenter"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="12dp"/>
        android:layout_marginTop="12dp"/>

    <TextView
        android:id="@+id/bar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="12dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textAppearance="@style/BarChart.Text.Title"/>
@@ -49,6 +47,7 @@
        android:id="@+id/bar_summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="12dp"
        android:singleLine="true"
        android:ellipsize="marquee"
+3 −3
Original line number Diff line number Diff line
@@ -35,12 +35,12 @@
    </style>

    <style name="BarChart.Text.Title">
        <item name="android:textSize">22sp</item>
        <item name="android:textSize">14sp</item>
    </style>

    <style name="BarChart.Text.Summary"
           parent="@android:style/TextAppearance.Material.Body1">
           parent="@*android:style/TextAppearance.DeviceDefault.Body1">
        <item name="android:textColor">?android:attr/textColorSecondary</item>
        <item name="android:textSize">14sp</item>
        <item name="android:textSize">12sp</item>
    </style>
</resources>
 No newline at end of file
+1 −2
Original line number Diff line number Diff line
@@ -71,8 +71,7 @@ public class BarView extends LinearLayout {
        //Set height of bar view
        mBarView.getLayoutParams().height = barViewInfo.getNormalizedHeight();
        mIcon.setImageDrawable(barViewInfo.getIcon());
        // For now, we use the bar number as title.
        mBarTitle.setText(Integer.toString(barViewInfo.getHeight()));
        mBarTitle.setText(barViewInfo.getTitle());
        mBarSummary.setText(barViewInfo.getSummary());
        mIcon.setContentDescription(barViewInfo.getContentDescription());
    }
+19 −9
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.view.View;

import androidx.annotation.IntRange;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import java.util.Comparator;

@@ -32,8 +31,8 @@ public class BarViewInfo implements Comparable<BarViewInfo> {

    private final Drawable mIcon;
    private View.OnClickListener mClickListener;
    @StringRes
    private int mSummary;
    private CharSequence mTitle;
    private CharSequence mSummary;
    private @Nullable CharSequence mContentDescription;
    // A number indicates this bar's height. The larger number shows a higher bar view.
    private int mHeight;
@@ -45,13 +44,16 @@ public class BarViewInfo implements Comparable<BarViewInfo> {
     *
     * @param icon      The icon of bar view.
     * @param barHeight The height of bar view. Larger number shows a higher bar view.
     * @param summary   The string resource id for summary.
     * @param title     The string for title.  If this is null, use the height of the bar.
     * @param summary   The string for summary.
     * @param contentDescription Optional text that briefly describes the contents of the icon.
     */
    public BarViewInfo(Drawable icon, @IntRange(from = 0) int barHeight, @StringRes int summary,
    public BarViewInfo(Drawable icon, @IntRange(from = 0) int barHeight,
            @Nullable CharSequence title, CharSequence summary,
            @Nullable CharSequence contentDescription) {
        mIcon = icon;
        mHeight = barHeight;
        mTitle = title;
        mSummary = summary;
        mContentDescription = contentDescription;
    }
@@ -74,8 +76,12 @@ public class BarViewInfo implements Comparable<BarViewInfo> {
        mHeight = height;
    }

    void setSummary(@StringRes int resId) {
        mSummary = resId;
    void setTitle(CharSequence title) {
        mTitle = title;
    }

    void setSummary(CharSequence summary) {
        mSummary = summary;
    }

    Drawable getIcon() {
@@ -90,8 +96,12 @@ public class BarViewInfo implements Comparable<BarViewInfo> {
        return mClickListener;
    }

    @StringRes
    int getSummary() {
    @Nullable
    CharSequence getTitle() {
        return mTitle;
    }

    CharSequence getSummary() {
        return mSummary;
    }

Loading