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

Commit 92d9b19e authored by John Spurlock's avatar John Spurlock
Browse files

QS: Add a caret to the dual tile labels.

Also tweak some of the vertical spacing between the tiles
to get closer to the redlines.

Bug:15852139
Change-Id: I251fde261a74335c16b37ba07ab554f6db05d367
parent 824d2fd8
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->

<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/spinner_mtrl_am_alpha"
        android:tint="@color/qs_tile_text"
        android:autoMirrored="true" />
+8 −4
Original line number Diff line number Diff line
@@ -159,14 +159,18 @@
    <!-- For phones, this is close_handle_height + header_height -->
    <dimen name="peek_height">84dp</dimen>

    <dimen name="qs_tile_height">84dp</dimen>
    <dimen name="qs_tile_padding">8dp</dimen>
    <dimen name="qs_tile_height">88dp</dimen>
    <dimen name="qs_tile_icon_size">28dp</dimen>
    <dimen name="qs_tile_text_size">12sp</dimen>
    <dimen name="qs_tile_divider_height">1dp</dimen>
    <dimen name="qs_panel_padding">16dp</dimen>
    <dimen name="qs_dual_tile_height">109dp</dimen>
    <dimen name="qs_dual_tile_padding">12dp</dimen>
    <dimen name="qs_dual_tile_height">104dp</dimen>
    <dimen name="qs_dual_tile_padding_below_divider">4dp</dimen>
    <dimen name="qs_tile_padding_top">16dp</dimen>
    <dimen name="qs_tile_padding_below_icon">12dp</dimen>
    <dimen name="qs_tile_padding_bottom">16dp</dimen>
    <dimen name="qs_tile_spacing">4dp</dimen>
    <dimen name="qs_panel_padding_bottom">8dp</dimen>

    <!-- How far the expanded QS panel peeks from the header in collapsed state. -->
    <dimen name="qs_peek_height">8dp</dimen>
+1 −0
Original line number Diff line number Diff line
@@ -18,5 +18,6 @@
    <dimen name="status_bar_height">@*android:dimen/status_bar_height</dimen>
    <dimen name="navigation_bar_height">@*android:dimen/navigation_bar_height</dimen>
    <drawable name="notification_material_bg">@*android:drawable/notification_material_bg</drawable>
    <drawable name="spinner_mtrl_am_alpha">@*android:drawable/spinner_mtrl_am_alpha</drawable>
</resources>
+154 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.systemui.qs;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.util.Objects;

/**
 * Text displayed over one or two lines, centered horizontally.  A caret is always drawn at the end
 * of the first line, and considered part of the content for centering purposes.
 *
 * Text overflow rules:
 *   First line: break on a word, unless a single word takes up the entire line - in which case
 *               truncate.
 *   Second line: ellipsis if necessary
 */
public class QSDualTileLabel extends FrameLayout {

    private static final String SPACING_TEXT = "  ";

    private final Context mContext;
    private final TextView mFirstLine;
    private final TextView mSecondLine;

    private String mText;

    public QSDualTileLabel(Context context) {
        super(context);
        mContext = context;
        mFirstLine = initTextView();
        mSecondLine = initTextView();
        mSecondLine.setEllipsize(TruncateAt.END);
        addOnLayoutChangeListener(new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right,
                    int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                if ((oldRight - oldLeft) != (right - left)) {
                    updateText();
                }
            }
        });
    }

    public void setFirstLineBackground(Drawable d) {
        mFirstLine.setBackground(d);
        if (d != null) {
            final LayoutParams lp = (LayoutParams) mSecondLine.getLayoutParams();
            lp.topMargin = d.getIntrinsicHeight() * 3 / 4;
            mSecondLine.setLayoutParams(lp);
        }
    }

    private TextView initTextView() {
        final TextView tv = new TextView(mContext);
        tv.setPadding(0, 0, 0, 0);
        tv.setSingleLine(true);
        tv.setClickable(false);
        tv.setBackground(null);
        final LayoutParams lp =
                new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL;
        addView(tv, lp);
        return tv;
    }

    public void setText(CharSequence text) {
        final String newText = text == null ? null : text.toString().trim();
        if (Objects.equals(newText, mText)) return;
        mText = newText;
        updateText();
    }

    public String getText() {
        return mText;
    }

    public void setTextSize(int unit, float size) {
        mFirstLine.setTextSize(unit, size);
        mSecondLine.setTextSize(unit, size);
    }

    public void setTextColor(int color) {
        mFirstLine.setTextColor(color);
        mSecondLine.setTextColor(color);
    }

    public void setTypeface(Typeface tf) {
        mFirstLine.setTypeface(tf);
        mSecondLine.setTypeface(tf);
    }

    private void updateText() {
        if (getWidth() == 0) return;
        if (TextUtils.isEmpty(mText)) {
            mFirstLine.setText(null);
            mSecondLine.setText(null);
            return;
        }
        final float maxWidth = getWidth() - mFirstLine.getBackground().getIntrinsicWidth()
                - getPaddingLeft() - getPaddingRight();
        float width = mFirstLine.getPaint().measureText(mText + SPACING_TEXT);
        if (width <= maxWidth) {
            mFirstLine.setText(mText + SPACING_TEXT);
            mSecondLine.setText(null);
            return;
        }
        final int n = mText.length();
        int lastWordBoundary = -1;
        boolean inWhitespace = false;
        int i = 0;
        for (i = 1; i < n; i++) {
            if (Character.isWhitespace(mText.charAt(i))) {
                if (!inWhitespace) {
                    lastWordBoundary = i;
                }
                inWhitespace = true;
            } else {
                inWhitespace = false;
            }
            width = mFirstLine.getPaint().measureText(mText.substring(0, i) + SPACING_TEXT);
            if (width > maxWidth) {
                break;
            }
        }
        if (lastWordBoundary == -1) {
            lastWordBoundary = i - 1;
        }
        mFirstLine.setText(mText.substring(0, lastWordBoundary) + SPACING_TEXT);
        mSecondLine.setText(mText.substring(lastWordBoundary).trim());
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public class QSPanel extends ViewGroup {
    private int mCellHeight;
    private int mLargeCellWidth;
    private int mLargeCellHeight;
    private int mPanelPaddingBottom;
    private boolean mExpanded;

    private TileRecord mDetailRecord;
@@ -80,6 +81,7 @@ public class QSPanel extends ViewGroup {
        mCellWidth = (int)(mCellHeight * TILE_ASPECT);
        mLargeCellHeight = res.getDimensionPixelSize(R.dimen.qs_dual_tile_height);
        mLargeCellWidth = (int)(mLargeCellHeight * TILE_ASPECT);
        mPanelPaddingBottom = res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom);
        if (mColumns != columns) {
            mColumns = columns;
            postInvalidate();
@@ -204,7 +206,7 @@ public class QSPanel extends ViewGroup {
            final int ch = record.row == 0 ? mLargeCellHeight : mCellHeight;
            record.tileView.measure(exactly(cw), exactly(ch));
        }
        int h = rows == 0 ? 0 : getRowTop(rows);
        int h = rows == 0 ? 0 : (getRowTop(rows) + mPanelPaddingBottom);
        mDetail.measure(exactly(width), unspecified());
        if (mDetail.getVisibility() == VISIBLE && mDetail.getChildCount() > 0) {
            final int dmh = mDetail.getMeasuredHeight();
Loading