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

Commit 58414a48 authored by Florina Muntenescu's avatar Florina Muntenescu
Browse files

Update JavaDocs for Alignment, Clickable, Editable and MetricAffecting

spans.

Test: N/A
Bug: 72092996
Change-Id: I716ed3841d7ac0b1cc2f75021ae0e02d1bf05524
parent cee2094d
Loading
Loading
Loading
Loading
+53 −12
Original line number Diff line number Diff line
@@ -16,49 +16,90 @@

package android.text.style;

import android.annotation.NonNull;
import android.os.Parcel;
import android.text.Layout;
import android.text.ParcelableSpan;
import android.text.TextUtils;

/**
 * Span that allows defining the alignment of text at the paragraph level.
 */
public interface AlignmentSpan extends ParagraphStyle {

    /**
     * Returns the alignment of the text.
     *
     * @return the text alignment
     */
    Layout.Alignment getAlignment();

    /**
     * Default implementation of the {@link AlignmentSpan}.
     * <p>
     * For example, a text written in a left to right language, like English, which is by default
     * aligned to the left, can be aligned opposite to the layout direction like this:
     * <pre>{@code SpannableString string = new SpannableString("Text with opposite alignment");
     *string.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), 0,
     *string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
     * <img src="{@docRoot}reference/android/images/text/style/ltralignmentspan.png" />
     * <figcaption>Align left to right text opposite to the layout direction.</figcaption>
     * <p>
     * A text written in a right to left language, like Hebrew, which is by default aligned to the
     * right, can be aligned opposite to the layout direction like this:
     * <pre>{@code SpannableString string = new SpannableString("טקסט עם יישור הפוך");
     *string.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), 0,
     *string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
     * <img src="{@docRoot}reference/android/images/text/style/rtlalignmentspan.png" />
     * <figcaption>Align right to left text opposite to the layout direction.</figcaption>
     */
    class Standard implements AlignmentSpan, ParcelableSpan {
        public Standard(Layout.Alignment align) {
        private final Layout.Alignment mAlignment;

        /**
         * Constructs a {@link Standard} from an alignment.
         */
        public Standard(@NonNull Layout.Alignment align) {
            mAlignment = align;
        }

        public Standard(Parcel src) {
        /**
         * Constructs a {@link Standard} from a parcel.
         */
        public Standard(@NonNull Parcel src) {
            mAlignment = Layout.Alignment.valueOf(src.readString());
        }

        @Override
        public int getSpanTypeId() {
            return getSpanTypeIdInternal();
        }

        /** @hide */
        @Override
        public int getSpanTypeIdInternal() {
            return TextUtils.ALIGNMENT_SPAN;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public void writeToParcel(Parcel dest, int flags) {
        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            writeToParcelInternal(dest, flags);
        }

        /** @hide */
        public void writeToParcelInternal(Parcel dest, int flags) {
        @Override
        public void writeToParcelInternal(@NonNull Parcel dest, int flags) {
            dest.writeString(mAlignment.name());
        }

        @Override
        public Layout.Alignment getAlignment() {
            return mAlignment;
        }

        private final Layout.Alignment mAlignment;
    }
}
+13 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.text.style;

import android.annotation.NonNull;
import android.text.TextPaint;
import android.view.View;

@@ -24,6 +25,16 @@ import android.view.View;
 * with a movement method of LinkMovementMethod, the affected spans of
 * text can be selected. If selected and clicked, the {@link #onClick} method will
 * be called.
 * <p>
 * The text with a <code>ClickableSpan</code> attached will be underlined and the link color will be
 * used as a text color. The default link color is the theme's accent color or
 * <code>android:textColorLink</code> if this attribute is defined in the theme.
 * For example, considering that we have a <code>CustomClickableSpan</code> that extends
 * <code>ClickableSpan</code>, it can be used like this:
 * <pre>{@code SpannableString string = new SpannableString("Text with clickable text");
 *string.setSpan(new CustomClickableSpan(), 10, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
 * <img src="{@docRoot}reference/android/images/text/style/clickablespan.png" />
 * <figcaption>Text with <code>ClickableSpan</code>.</figcaption>
 */
public abstract class ClickableSpan extends CharacterStyle implements UpdateAppearance {
    private static int sIdCounter = 0;
@@ -33,13 +44,13 @@ public abstract class ClickableSpan extends CharacterStyle implements UpdateAppe
    /**
     * Performs the click action associated with this span.
     */
    public abstract void onClick(View widget);
    public abstract void onClick(@NonNull View widget);

    /**
     * Makes the text underlined and in the link color.
     */
    @Override
    public void updateDrawState(TextPaint ds) {
    public void updateDrawState(@NonNull TextPaint ds) {
        ds.setColor(ds.linkColor);
        ds.setUnderlineText(true);
    }
+4 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.text.style;

import android.annotation.NonNull;
import android.app.PendingIntent;
import android.os.Parcel;
import android.text.ParcelableSpan;
@@ -79,7 +80,7 @@ public class EasyEditSpan implements ParcelableSpan {
    /**
     * Constructor called from {@link TextUtils} to restore the span.
     */
    public EasyEditSpan(Parcel source) {
    public EasyEditSpan(@NonNull Parcel source) {
        mPendingIntent = source.readParcelable(null);
        mDeleteEnabled = (source.readByte() == 1);
    }
@@ -90,12 +91,12 @@ public class EasyEditSpan implements ParcelableSpan {
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        writeToParcelInternal(dest, flags);
    }

    /** @hide */
    public void writeToParcelInternal(Parcel dest, int flags) {
    public void writeToParcelInternal(@NonNull Parcel dest, int flags) {
        dest.writeParcelable(mPendingIntent, 0);
        dest.writeByte((byte) (mDeleteEnabled ? 1 : 0));
    }
+17 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.text.style;

import android.annotation.NonNull;
import android.text.TextPaint;

/**
@@ -26,7 +27,13 @@ public abstract class MetricAffectingSpan
        extends CharacterStyle
        implements UpdateLayout {

    public abstract void updateMeasureState(TextPaint p);
    /**
     * Classes that extend MetricAffectingSpan implement this method to update the text formatting
     * in a way that can change the width or height of characters.
     *
     * @param textPaint the paint used for drawing the text
     */
    public abstract void updateMeasureState(@NonNull TextPaint textPaint);

    /**
     * Returns "this" for most MetricAffectingSpans, but for
@@ -52,7 +59,7 @@ implements UpdateLayout {
        /**
         * Creates a new Passthrough of the specfied MetricAffectingSpan.
         */
        public Passthrough(MetricAffectingSpan cs) {
        Passthrough(@NonNull MetricAffectingSpan cs) {
            mStyle = cs;
        }

@@ -60,7 +67,7 @@ implements UpdateLayout {
         * Passes updateDrawState through to the underlying MetricAffectingSpan.
         */
        @Override
        public void updateDrawState(TextPaint tp) {
        public void updateDrawState(@NonNull TextPaint tp) {
            mStyle.updateDrawState(tp);
        }

@@ -68,7 +75,7 @@ implements UpdateLayout {
         * Passes updateMeasureState through to the underlying MetricAffectingSpan.
         */
        @Override
        public void updateMeasureState(TextPaint tp) {
        public void updateMeasureState(@NonNull TextPaint tp) {
            mStyle.updateMeasureState(tp);
        }

+11.9 KiB
Loading image diff...
Loading