mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 19:38:21 +00:00
Update drop target button alignment across devices.
Fix: 229789612 Fix: 231711806 Fix: 231706480 Fix: 232063941 Fix: 232283628 Test: manual. Change-Id: I75d649b953ad1607dbba87a8f758884ff938b6dc
This commit is contained in:
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -49,6 +50,8 @@ public abstract class ButtonDropTarget extends TextView
|
||||
private static final int[] sTempCords = new int[2];
|
||||
private static final int DRAG_VIEW_DROP_DURATION = 285;
|
||||
private static final float DRAG_VIEW_HOVER_OVER_OPACITY = 0.65f;
|
||||
private static final int MAX_LINES_TEXT_MULTI_LINE = 2;
|
||||
private static final int MAX_LINES_TEXT_SINGLE_LINE = 1;
|
||||
|
||||
public static final int TOOLTIP_DEFAULT = 0;
|
||||
public static final int TOOLTIP_LEFT = 1;
|
||||
@@ -72,6 +75,8 @@ public abstract class ButtonDropTarget extends TextView
|
||||
protected CharSequence mText;
|
||||
protected Drawable mDrawable;
|
||||
private boolean mTextVisible = true;
|
||||
private boolean mIconVisible = true;
|
||||
private boolean mTextMultiLine = true;
|
||||
|
||||
private PopupWindow mToolTip;
|
||||
private int mToolTipLocation;
|
||||
@@ -109,8 +114,7 @@ public abstract class ButtonDropTarget extends TextView
|
||||
// drawableLeft and drawableStart.
|
||||
mDrawable = getContext().getDrawable(resId).mutate();
|
||||
mDrawable.setTintList(getTextColors());
|
||||
centerIcon();
|
||||
setCompoundDrawablesRelative(mDrawable, null, null, null);
|
||||
updateIconVisibility();
|
||||
}
|
||||
|
||||
public void setDropTargetBar(DropTargetBar dropTargetBar) {
|
||||
@@ -306,13 +310,49 @@ public abstract class ButtonDropTarget extends TextView
|
||||
if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) {
|
||||
mTextVisible = isVisible;
|
||||
setText(newText);
|
||||
centerIcon();
|
||||
setCompoundDrawablesRelative(mDrawable, null, null, null);
|
||||
int drawablePadding = mTextVisible ? mDrawablePadding : 0;
|
||||
setCompoundDrawablePadding(drawablePadding);
|
||||
updateIconVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display button text over multiple lines when isMultiLine is true, single line otherwise.
|
||||
*/
|
||||
public void setTextMultiLine(boolean isMultiLine) {
|
||||
if (mTextMultiLine != isMultiLine) {
|
||||
mTextMultiLine = isMultiLine;
|
||||
setSingleLine(!isMultiLine);
|
||||
setMaxLines(isMultiLine ? MAX_LINES_TEXT_MULTI_LINE : MAX_LINES_TEXT_SINGLE_LINE);
|
||||
int inputType = InputType.TYPE_CLASS_TEXT;
|
||||
if (isMultiLine) {
|
||||
inputType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
|
||||
}
|
||||
setInputType(inputType);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isTextMultiLine() {
|
||||
return mTextMultiLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the button icon visible when isVisible is true, hides it otherwise.
|
||||
*/
|
||||
public void setIconVisible(boolean isVisible) {
|
||||
if (mIconVisible != isVisible) {
|
||||
mIconVisible = isVisible;
|
||||
updateIconVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateIconVisibility() {
|
||||
if (mIconVisible) {
|
||||
centerIcon();
|
||||
}
|
||||
setCompoundDrawablesRelative(mIconVisible ? mDrawable : null, null, null, null);
|
||||
setCompoundDrawablePadding(mIconVisible && mTextVisible ? mDrawablePadding : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
@@ -324,40 +364,6 @@ public abstract class ButtonDropTarget extends TextView
|
||||
hideTooltip();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reduce the size of the text until it fits or reaches a minimum.
|
||||
*
|
||||
* The minimum size is defined by {@code R.dimen.button_drop_target_min_text_size} and
|
||||
* it diminishes by intervals defined by
|
||||
* {@code R.dimen.button_drop_target_resize_text_increment}
|
||||
* This functionality is very similar to the option
|
||||
* {@link TextView#setAutoSizeTextTypeWithDefaults(int)} but can't be used in this view because
|
||||
* the layout width is {@code WRAP_CONTENT}.
|
||||
*
|
||||
* @param availableWidth Available width in the button to fit the text, used in
|
||||
* {@code ButtonDropTarget#isTextTruncated(int)}
|
||||
* @return The biggest text size in SP that makes the text fit or if the text can't fit returns
|
||||
* the min available value
|
||||
*/
|
||||
public float resizeTextToFit(int availableWidth) {
|
||||
float minSize = Utilities.pxToSp(getResources()
|
||||
.getDimensionPixelSize(R.dimen.button_drop_target_min_text_size));
|
||||
float step = Utilities.pxToSp(getResources()
|
||||
.getDimensionPixelSize(R.dimen.button_drop_target_resize_text_increment));
|
||||
float textSize = Utilities.pxToSp(getTextSize());
|
||||
|
||||
while (textSize > minSize) {
|
||||
if (isTextTruncated(availableWidth)) {
|
||||
textSize -= step;
|
||||
setTextSize(textSize);
|
||||
} else {
|
||||
return textSize;
|
||||
}
|
||||
}
|
||||
return minSize;
|
||||
}
|
||||
|
||||
public boolean isTextTruncated(int availableWidth) {
|
||||
availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth()
|
||||
+ getCompoundDrawablePadding());
|
||||
|
||||
Reference in New Issue
Block a user