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

Commit e950f669 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Use marquee for action items with super-long strings." into rvc-dev am: 5677226b

Change-Id: I80fdb6eeb80634577f48ca3267ac6f1bb3f37452
parents 7377b050 5677226b
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -14,9 +14,7 @@
     limitations under the License.
-->

<!-- RelativeLayouts have an issue enforcing minimum heights, so just
     work around this for now with LinearLayouts. -->
<LinearLayout
<com.android.systemui.globalactions.GlobalActionsItem
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_weight="1"
@@ -42,7 +40,7 @@
            android:id="@*android:id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:ellipsize="end"
            android:marqueeRepeatLimit="marquee_forever"
            android:maxLines="2"
            android:textSize="12sp"
@@ -51,4 +49,4 @@
            android:breakStrategy="high_quality"
            android:hyphenationFrequency="full"
            android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</com.android.systemui.globalactions.GlobalActionsItem>
+26 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.HardwareBgDrawable;
@@ -78,6 +79,31 @@ public class GlobalActionsFlatLayout extends GlobalActionsLayout {
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        boolean anyTruncated = false;
        ViewGroup listView = getListView();
        // Check to see if any of the GlobalActionsItems have had their messages truncated
        for (int i = 0; i < listView.getChildCount(); i++) {
            View child = listView.getChildAt(i);
            if (child instanceof GlobalActionsItem) {
                GlobalActionsItem item = (GlobalActionsItem) child;
                anyTruncated = anyTruncated || item.isTruncated();
            }
        }
        // If any of the items have been truncated, set the all to single-line marquee
        if (anyTruncated) {
            for (int i = 0; i < listView.getChildCount(); i++) {
                View child = listView.getChildAt(i);
                if (child instanceof GlobalActionsItem) {
                    GlobalActionsItem item = (GlobalActionsItem) child;
                    item.setMarquee(true);
                }
            }
        }
    }

    @VisibleForTesting
    protected float getGridItemSize() {
        return getContext().getResources().getDimension(R.dimen.global_actions_grid_item_height);
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.globalactions;

import android.content.Context;
import android.text.Layout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.internal.R;

/**
 * Layout for GlobalActions items.
 */
public class GlobalActionsItem extends LinearLayout {
    public GlobalActionsItem(Context context) {
        super(context);
    }

    public GlobalActionsItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public GlobalActionsItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private TextView getTextView() {
        return (TextView) findViewById(R.id.message);
    }

    /**
     * Sets this item to marquee or not.
     */
    public void setMarquee(boolean marquee) {
        TextView text = getTextView();
        text.setSingleLine(marquee);
        text.setEllipsize(marquee ? TextUtils.TruncateAt.MARQUEE : TextUtils.TruncateAt.END);
    }

    /**
     * Determines whether the message for this item has been truncated.
     */
    public boolean isTruncated() {
        TextView message = getTextView();
        if (message != null) {
            Layout messageLayout = message.getLayout();
            if (messageLayout != null) {
                if (messageLayout.getLineCount() > 0) {
                    // count the number of ellipses in the last line.
                    int ellipses = messageLayout.getEllipsisCount(
                            messageLayout.getLineCount() - 1);
                    // If ellipses are present, the line was forced to truncate.
                    return ellipses > 0;
                }
            }
        }
        return false;
    }
}