Merge "Keyguard slice layout fixes"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9c3d64e60e
@@ -32,6 +32,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/widget_vertical_padding"
|
||||
android:paddingStart="64dp"
|
||||
android:paddingEnd="64dp"
|
||||
android:theme="@style/TextAppearance.Keyguard"
|
||||
/>
|
||||
<LinearLayout android:id="@+id/row"
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<dimen name="widget_separator_thickness">2dp</dimen>
|
||||
<dimen name="widget_horizontal_padding">8dp</dimen>
|
||||
<dimen name="widget_icon_size">16dp</dimen>
|
||||
<dimen name="widget_icon_padding">4dp</dimen>
|
||||
<dimen name="widget_icon_padding">8dp</dimen>
|
||||
|
||||
<!-- The y translation to apply at the start in appear animations. -->
|
||||
<dimen name="appear_y_translation_start">32dp</dimen>
|
||||
|
||||
@@ -83,13 +83,13 @@
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:maxLines">2</item>
|
||||
<item name="android:fontFamily">@*android:string/config_headlineFontFamilyLight</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Keyguard.Secondary">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textSize">@dimen/widget_label_font_size</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -26,6 +26,9 @@ import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.text.Layout;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextUtils.TruncateAt;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -40,6 +43,7 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.keyguard.KeyguardSliceProvider;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -129,7 +133,20 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
|
||||
android.app.slice.SliceItem.FORMAT_TEXT,
|
||||
new String[]{android.app.slice.Slice.HINT_TITLE},
|
||||
null /* nonHints */);
|
||||
mTitle.setText(mainTitle.getText());
|
||||
CharSequence title = mainTitle.getText();
|
||||
mTitle.setText(title);
|
||||
|
||||
// Check if we're already ellipsizing the text.
|
||||
// We're going to figure out the best possible line break if not.
|
||||
Layout layout = mTitle.getLayout();
|
||||
if (layout != null){
|
||||
final int lineCount = layout.getLineCount();
|
||||
if (lineCount > 0) {
|
||||
if (layout.getEllipsisCount(lineCount - 1) == 0) {
|
||||
mTitle.setText(findBestLineBreak(title));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mClickActions.clear();
|
||||
@@ -195,6 +212,46 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
|
||||
mListener.accept(mHasHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Breaks a string in 2 lines where both have similar character count
|
||||
* but first line is always longer.
|
||||
*
|
||||
* @param charSequence Original text.
|
||||
* @return Optimal string.
|
||||
*/
|
||||
private CharSequence findBestLineBreak(CharSequence charSequence) {
|
||||
if (TextUtils.isEmpty(charSequence)) {
|
||||
return charSequence;
|
||||
}
|
||||
|
||||
String source = charSequence.toString();
|
||||
// Ignore if there is only 1 word,
|
||||
// or if line breaks were manually set.
|
||||
if (source.contains("\n") || !source.contains(" ")) {
|
||||
return source;
|
||||
}
|
||||
|
||||
final String[] words = source.split(" ");
|
||||
final StringBuilder optimalString = new StringBuilder(source.length());
|
||||
int current = 0;
|
||||
while (optimalString.length() < source.length() - optimalString.length()) {
|
||||
optimalString.append(words[current]);
|
||||
if (current < words.length - 1) {
|
||||
optimalString.append(" ");
|
||||
}
|
||||
current++;
|
||||
}
|
||||
optimalString.append("\n");
|
||||
for (int i = current; i < words.length; i++) {
|
||||
optimalString.append(words[i]);
|
||||
if (current < words.length - 1) {
|
||||
optimalString.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
return optimalString.toString();
|
||||
}
|
||||
|
||||
public void setDark(float darkAmount) {
|
||||
mDarkAmount = darkAmount;
|
||||
updateTextColors();
|
||||
@@ -287,6 +344,9 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
|
||||
setPadding(horizontalPadding, 0, horizontalPadding, 0);
|
||||
setCompoundDrawablePadding((int) context.getResources()
|
||||
.getDimension(R.dimen.widget_icon_padding));
|
||||
setMaxWidth(KeyguardSliceView.this.getWidth() / 2);
|
||||
setMaxLines(1);
|
||||
setEllipsize(TruncateAt.END);
|
||||
}
|
||||
|
||||
public void setHasDivider(boolean hasDivider) {
|
||||
|
||||
Reference in New Issue
Block a user