Merge "Changed the way the ellipsizing of text is measured" into pi-dev

am: 497fa8b8ab

Change-Id: I65cf2e2ca592616f68811f80dee92e786a93329c
This commit is contained in:
Selim Cinek
2018-05-03 18:08:32 -07:00
committed by android-build-merger
2 changed files with 31 additions and 32 deletions

View File

@@ -28,8 +28,6 @@ import android.view.RemotableViewMethod;
import android.widget.RemoteViews;
import android.widget.TextView;
import com.android.internal.R;
/**
* A TextView that can float around an image on the end.
*
@@ -44,9 +42,7 @@ public class ImageFloatingTextView extends TextView {
/** Resolved layout direction */
private int mResolvedDirection = LAYOUT_DIRECTION_UNDEFINED;
private int mMaxLinesForHeight = -1;
private boolean mFirstMeasure = true;
private int mLayoutMaxLines = -1;
private boolean mBlockLayouts;
private int mImageEndMargin;
public ImageFloatingTextView(Context context) {
@@ -122,30 +118,31 @@ public class ImageFloatingTextView extends TextView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
// Lets calculate how many lines the given measurement allows us.
int availableHeight = height - mPaddingTop - mPaddingBottom;
int maxLines = availableHeight / getLineHeight();
maxLines = Math.max(1, maxLines);
if (getMaxLines() > 0) {
maxLines = Math.min(getMaxLines(), maxLines);
}
if (maxLines != mMaxLinesForHeight) {
mMaxLinesForHeight = maxLines;
if (getLayout() != null && mMaxLinesForHeight != mLayoutMaxLines) {
// Invalidate layout.
mBlockLayouts = true;
setHint(getHint());
mBlockLayouts = false;
}
int availableHeight = MeasureSpec.getSize(heightMeasureSpec) - mPaddingTop - mPaddingBottom;
if (getLayout() != null && getLayout().getHeight() != availableHeight) {
// We've been measured before and the new size is different than before, lets make sure
// we reset the maximum lines, otherwise we may be cut short
mMaxLinesForHeight = -1;
nullLayouts();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public void requestLayout() {
if (!mBlockLayouts) {
super.requestLayout();
Layout layout = getLayout();
if (layout.getHeight() > availableHeight) {
// With the existing layout, not all of our lines fit on the screen, let's find the
// first one that fits and ellipsize at that one.
int maxLines = layout.getLineCount() - 1;
while (maxLines > 1 && layout.getLineBottom(maxLines - 1) > availableHeight) {
maxLines--;
}
if (getMaxLines() > 0) {
maxLines = Math.min(getMaxLines(), maxLines);
}
// Only if the number of lines is different from the current layout, we recreate it.
if (maxLines != mLayoutMaxLines) {
mMaxLinesForHeight = maxLines;
nullLayouts();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
@@ -157,7 +154,8 @@ public class ImageFloatingTextView extends TextView {
mResolvedDirection = layoutDirection;
if (mIndentLines > 0) {
// Invalidate layout.
setHint(getHint());
nullLayouts();
requestLayout();
}
}
}
@@ -175,7 +173,8 @@ public class ImageFloatingTextView extends TextView {
if (mIndentLines != lines) {
mIndentLines = lines;
// Invalidate layout.
setHint(getHint());
nullLayouts();
requestLayout();
return true;
}
return false;

View File

@@ -24,7 +24,7 @@
>
<include layout="@layout/notification_template_header" />
<LinearLayout
<com.android.internal.widget.RemeasuringLinearLayout
android:id="@+id/notification_action_list_margin_target"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -34,7 +34,7 @@
android:clipToPadding="false"
android:orientation="vertical">
<LinearLayout
<com.android.internal.widget.RemeasuringLinearLayout
android:id="@+id/notification_main_column"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -62,7 +62,7 @@
android:visibility="gone"
android:textAlignment="viewStart"
/>
</LinearLayout>
</com.android.internal.widget.RemeasuringLinearLayout>
<ViewStub android:layout="@layout/notification_material_reply_text"
android:id="@+id/notification_material_reply_container"
@@ -75,6 +75,6 @@
android:layout_marginEnd="@dimen/notification_content_margin_end"
android:layout_marginTop="@dimen/notification_content_margin" />
<include layout="@layout/notification_material_action_list" />
</LinearLayout>
</com.android.internal.widget.RemeasuringLinearLayout>
<include layout="@layout/notification_template_right_icon" />
</FrameLayout>