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

Commit b435250e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move UsageGraph from SettingsLib to Settings."

parents bde482c7 d49b6b99
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
<!--
    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.
-->
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall" />
+0 −20
Original line number Diff line number Diff line
<!--
    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.
-->
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall" />
+0 −99
Original line number Diff line number Diff line
<!--
    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.
-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/graph_label_group"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:clipChildren="false"
        android:clipToPadding="false">

        <LinearLayout
            android:id="@+id/label_group"
            android:layout_width="@dimen/usage_graph_labels_width"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <include android:id="@+id/label_top"
                layout="@layout/usage_side_label" />

            <Space
                android:id="@+id/space1"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <include android:id="@+id/label_middle"
                layout="@layout/usage_side_label" />

            <Space
                android:id="@+id/space2"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <include android:id="@+id/label_bottom"
                layout="@layout/usage_side_label" />

        </LinearLayout>

        <com.android.settingslib.graph.UsageGraph
            android:id="@+id/usage_graph"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginTop="@dimen/usage_graph_margin_top_bottom"
            android:layout_marginBottom="@dimen/usage_graph_margin_top_bottom" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_label_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Space
            android:id="@+id/bottom_label_space"
            android:layout_width="@dimen/usage_graph_labels_width"
            android:layout_height="wrap_content"/>
        <com.android.settingslib.graph.BottomLabelLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:layoutDirection="ltr">
            <include android:id="@+id/label_start"
                     layout="@layout/usage_side_label" />

            <Space
                android:id="@+id/spacer"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <include android:id="@+id/label_end"
                     layout="@layout/usage_side_label" />
        </com.android.settingslib.graph.BottomLabelLayout>
    </LinearLayout>

</LinearLayout>
+0 −8
Original line number Diff line number Diff line
@@ -46,14 +46,6 @@
    <attr name="wifi_signal" format="reference" />
    <attr name="wifi_friction" format="reference" />

    <declare-styleable name="UsageView">
        <attr name="android:colorAccent" />
        <attr name="sideLabels" format="reference" />
        <attr name="bottomLabels" format="reference" />
        <attr name="textColor" format="color" />
        <attr name="android:gravity" />
    </declare-styleable>

    <attr name="footerPreferenceStyle" format="reference" />

</resources>
+0 −97
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.settingslib.graph;

import android.annotation.Nullable;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;

import com.android.settingslib.R;

/**
 * An extension of LinearLayout that automatically switches to vertical
 * orientation when it can't fit its child views horizontally.
 *
 * Main logic in this class comes from {@link android.support.v7.widget.ButtonBarLayout}.
 * Compared with {@link android.support.v7.widget.ButtonBarLayout}, this layout won't reverse
 * children's order and won't update the minimum height
 */
public class BottomLabelLayout extends LinearLayout {
    private static final String TAG = "BottomLabelLayout";

    public BottomLabelLayout(Context context,
            @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        final boolean isStacked = isStacked();
        boolean needsRemeasure = false;

        // If we're not stacked, make sure the measure spec is AT_MOST rather
        // than EXACTLY. This ensures that we'll still get TOO_SMALL so that we
        // know to stack the buttons.
        final int initialWidthMeasureSpec;
        if (!isStacked && MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY) {
            initialWidthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.AT_MOST);

            // We'll need to remeasure again to fill excess space.
            needsRemeasure = true;
        } else {
            initialWidthMeasureSpec = widthMeasureSpec;
        }

        super.onMeasure(initialWidthMeasureSpec, heightMeasureSpec);
        if (!isStacked) {
            final int measuredWidth = getMeasuredWidthAndState();
            final int measuredWidthState = measuredWidth & View.MEASURED_STATE_MASK;

            if (measuredWidthState == View.MEASURED_STATE_TOO_SMALL) {
                setStacked(true);
                // Measure again in the new orientation.
                needsRemeasure = true;
            }
        }

        if (needsRemeasure) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }

    }

    @VisibleForTesting
    void setStacked(boolean stacked) {
        setOrientation(stacked ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
        setGravity(stacked ? Gravity.START : Gravity.BOTTOM);

        final View spacer = findViewById(R.id.spacer);
        if (spacer != null) {
            spacer.setVisibility(stacked ? View.GONE : View.VISIBLE);
        }
    }

    private boolean isStacked() {
        return getOrientation() == LinearLayout.VERTICAL;
    }
}
Loading