1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.globalactions; 18 19 import android.content.Context; 20 import android.text.Layout; 21 import android.text.TextUtils; 22 import android.util.AttributeSet; 23 import android.widget.LinearLayout; 24 import android.widget.TextView; 25 26 import com.android.internal.R; 27 28 /** 29 * Layout for GlobalActions items. 30 */ 31 public class GlobalActionsItem extends LinearLayout { GlobalActionsItem(Context context)32 public GlobalActionsItem(Context context) { 33 super(context); 34 } 35 GlobalActionsItem(Context context, AttributeSet attrs)36 public GlobalActionsItem(Context context, AttributeSet attrs) { 37 super(context, attrs); 38 } 39 GlobalActionsItem(Context context, AttributeSet attrs, int defStyleAttr)40 public GlobalActionsItem(Context context, AttributeSet attrs, int defStyleAttr) { 41 super(context, attrs, defStyleAttr); 42 } 43 getTextView()44 private TextView getTextView() { 45 return (TextView) findViewById(R.id.message); 46 } 47 48 /** 49 * Sets this item to marquee or not. 50 */ setMarquee(boolean marquee)51 public void setMarquee(boolean marquee) { 52 TextView text = getTextView(); 53 text.setSingleLine(marquee); 54 text.setEllipsize(marquee ? TextUtils.TruncateAt.MARQUEE : TextUtils.TruncateAt.END); 55 } 56 57 /** 58 * Determines whether the message for this item has been truncated. 59 */ isTruncated()60 public boolean isTruncated() { 61 TextView message = getTextView(); 62 if (message != null) { 63 Layout messageLayout = message.getLayout(); 64 if (messageLayout != null) { 65 if (messageLayout.getLineCount() > 0) { 66 // count the number of ellipses in the last line. 67 int ellipses = messageLayout.getEllipsisCount( 68 messageLayout.getLineCount() - 1); 69 // If ellipses are present, the line was forced to truncate. 70 return ellipses > 0; 71 } 72 } 73 } 74 return false; 75 } 76 } 77