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

Commit 4fb12d3f authored by Selim Cinek's avatar Selim Cinek
Browse files

Made the bigtext now nicely float around the image

If there is an image instead of applying the same
margin everywhere, the text now floats around the
image.

Change-Id: I87f9ca9f51fb270b0732a99374544381bd1fc4e0
parent 816c8e47
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3925,6 +3925,8 @@ public class Notification implements Parcelable

            mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template);

            contentView.setBoolean(R.id.big_text, "setHasImage", mBuilder.mN.mLargeIcon != null);

            return contentView;
        }

+8 −2
Original line number Diff line number Diff line
@@ -6828,7 +6828,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        if (mEditor != null) mEditor.prepareCursorControllers();
    }

    private Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth,
    /**
     * @hide
     */
    protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth,
            Layout.Alignment alignment, boolean shouldEllipsize, TruncateAt effectiveEllipsize,
            boolean useSaved) {
        Layout result = null;
@@ -9708,7 +9711,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }

    TextDirectionHeuristic getTextDirectionHeuristic() {
    /**
     * @hide
     */
    protected TextDirectionHeuristic getTextDirectionHeuristic() {
        if (hasPasswordTransformationMethod()) {
            // passwords fields should be LTR
            return TextDirectionHeuristics.LTR;
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.internal.widget;

import android.annotation.Nullable;
import android.content.Context;
import android.text.BoringLayout;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.widget.RemoteViews;
import android.widget.TextView;

/**
 * A TextView that can float around an image on the end.
 *
 * @hide
 */
@RemoteViews.RemoteView
public class ImageFloatingTextView extends TextView {

    private boolean mHasImage;

    public ImageFloatingTextView(Context context) {
        this(context, null);
    }

    public ImageFloatingTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ImageFloatingTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

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

    @Override
    protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth,
            Layout.Alignment alignment, boolean shouldEllipsize,
            TextUtils.TruncateAt effectiveEllipsize, boolean useSaved) {
        CharSequence text = getText() == null ? "" : getText();
        StaticLayout.Builder builder = StaticLayout.Builder.obtain(text, 0, text.length(),
                getPaint(), wantWidth)
                .setAlignment(alignment)
                .setTextDirection(getTextDirectionHeuristic())
                .setLineSpacing(getLineSpacingExtra(), getLineSpacingMultiplier())
                .setIncludePad(getIncludeFontPadding())
                .setBreakStrategy(Layout.BREAK_STRATEGY_HIGH_QUALITY)
                .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
        // we set the endmargin on the first 2 lines. this works just in our case but that's
        // sufficient for now.
        int endMargin = (int) (getResources().getDisplayMetrics().density * 52);
        int[] margins = mHasImage ? new int[] {endMargin, endMargin, 0} : null;
        if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
            builder.setIndents(margins, null);
        } else {
            builder.setIndents(null, margins);
        }

        return builder.build();
    }

    @RemotableViewMethod
    public void setHasImage(boolean hasImage) {
        mHasImage = hasImage;
        // The new layout will be automatically created when the text is
        // set again by the notification.
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@
            android:gravity="top"
            android:layout_weight="1"
            >
            <TextView android:id="@+id/big_text"
            <com.android.internal.widget.ImageFloatingTextView android:id="@+id/big_text"
                android:textAppearance="@style/TextAppearance.Material.Notification"
                android:layout_width="0dp"
                android:layout_height="wrap_content"