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

Commit a036d599 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Updating JavaDocs for more spans."

parents d95e1d6e 6d047494
Loading
Loading
Loading
Loading
+46 −12
Original line number Diff line number Diff line
@@ -16,71 +16,105 @@

package android.text.style;

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

/**
 * A span that changes the size of the text it's attached to.
 * <p>
 * For example, the size of the text can be changed to 55dp like this:
 * <pre>{@code
 * SpannableString string = new SpannableString("Text with absolute size span");
 *string.setSpan(new AbsoluteSizeSpan(55, true), 10, 23, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
 * <img src="{@docRoot}reference/android/images/text/style/absolutesizespan.png" />
 * <figcaption>Text with text size updated.</figcaption>
 */
public class AbsoluteSizeSpan extends MetricAffectingSpan implements ParcelableSpan {

    private final int mSize;
    private boolean mDip;
    private final boolean mDip;

    /**
     * Set the text size to <code>size</code> physical pixels.
     */
    public AbsoluteSizeSpan(int size) {
        mSize = size;
        this(size, false);
    }

    /**
     * Set the text size to <code>size</code> physical pixels,
     * or to <code>size</code> device-independent pixels if
     * <code>dip</code> is true.
     * Set the text size to <code>size</code> physical pixels, or to <code>size</code>
     * device-independent pixels if <code>dip</code> is true.
     */
    public AbsoluteSizeSpan(int size, boolean dip) {
        mSize = size;
        mDip = dip;
    }

    public AbsoluteSizeSpan(Parcel src) {
    /**
     * Creates an {@link AbsoluteSizeSpan} from a parcel.
     */
    public AbsoluteSizeSpan(@NonNull Parcel src) {
        mSize = src.readInt();
        mDip = src.readInt() != 0;
    }

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

    /** @hide */
    @Override
    public int getSpanTypeIdInternal() {
        return TextUtils.ABSOLUTE_SIZE_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.writeInt(mSize);
        dest.writeInt(mDip ? 1 : 0);
    }

    /**
     * Get the text size. This is in physical pixels if {@link #getDip()} returns false or in
     * device-independent pixels if {@link #getDip()} returns true.
     *
     * @return the text size, either in physical pixels or device-independent pixels.
     * @see AbsoluteSizeSpan#AbsoluteSizeSpan(int, boolean)
     */
    public int getSize() {
        return mSize;
    }

    /**
     * Returns whether the size is in device-independent pixels or not, depending on the
     * <code>dip</code> flag passed in {@link #AbsoluteSizeSpan(int, boolean)}
     *
     * @return <code>true</code> if the size is in device-independent pixels, <code>false</code>
     * otherwise
     *
     * @see #AbsoluteSizeSpan(int, boolean)
     */
    public boolean getDip() {
        return mDip;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
    public void updateDrawState(@NonNull TextPaint ds) {
        if (mDip) {
            ds.setTextSize(mSize * ds.density);
        } else {
@@ -89,7 +123,7 @@ public class AbsoluteSizeSpan extends MetricAffectingSpan implements ParcelableS
    }

    @Override
    public void updateMeasureState(TextPaint ds) {
    public void updateMeasureState(@NonNull TextPaint ds) {
        if (mDip) {
            ds.setTextSize(mSize * ds.density);
        } else {
+7 −9
Original line number Diff line number Diff line
@@ -27,11 +27,10 @@ import android.text.TextUtils;
 * Changes the background color of the text to which the span is attached.
 * <p>
 * For example, to set a green background color for a text you would create a {@link
 * android.text.SpannableStringBuilder} based on the text and set the span.
 * android.text.SpannableString} based on the text and set the span.
 * <pre>{@code
 * SpannableString string = new SpannableString("Text with a background color span");
 *string.setSpan(new BackgroundColorSpan(color), 12, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
 * }</pre>
 *string.setSpan(new BackgroundColorSpan(color), 12, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
 * <img src="{@docRoot}reference/android/images/text/style/backgroundcolorspan.png" />
 * <figcaption>Set a background color for the text.</figcaption>
 */
@@ -58,30 +57,29 @@ public class BackgroundColorSpan extends CharacterStyle
        mColor = src.readInt();
    }

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

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

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

    /**
     * Flatten this object into a Parcel.
     *
     * @param dest The Parcel in which the object should be written.
     * @param flags Additional flags about how the object should be written.
     */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        writeToParcelInternal(dest, flags);
    }

    /** @hide */
    @Override
    public void writeToParcelInternal(@NonNull Parcel dest, int flags) {
        dest.writeInt(mColor);
    }
+7 −9
Original line number Diff line number Diff line
@@ -27,11 +27,10 @@ import android.text.TextUtils;
 * Changes the color of the text to which the span is attached.
 * <p>
 * For example, to set a green text color you would create a {@link
 * android.text.SpannableStringBuilder} based on the text and set the span.
 * android.text.SpannableString} based on the text and set the span.
 * <pre>{@code
 * SpannableString string = new SpannableString("Text with a foreground color span");
 *string.setSpan(new ForegroundColorSpan(color), 12, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
 * }</pre>
 *string.setSpan(new ForegroundColorSpan(color), 12, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
 * <img src="{@docRoot}reference/android/images/text/style/foregroundcolorspan.png" />
 * <figcaption>Set a text color.</figcaption>
 */
@@ -59,30 +58,29 @@ public class ForegroundColorSpan extends CharacterStyle
        mColor = src.readInt();
    }

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

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

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

    /**
     * Flatten this object into a Parcel.
     *
     * @param dest  The Parcel in which the object should be written.
     * @param flags Additional flags about how the object should be written.
     */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        writeToParcelInternal(dest, flags);
    }

    /** @hide */
    @Override
    public void writeToParcelInternal(@NonNull Parcel dest, int flags) {
        dest.writeInt(mColor);
    }
+37 −8
Original line number Diff line number Diff line
@@ -16,56 +16,85 @@

package android.text.style;

import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.os.Parcel;
import android.text.ParcelableSpan;
import android.text.TextPaint;
import android.text.TextUtils;

/**
 * Uniformly scales the size of the text to which it's attached by a certain proportion.
 * <p>
 * For example, a <code>RelativeSizeSpan</code> that increases the text size by 50% can be
 * constructed like this:
 * <pre>{@code
 *  SpannableString string = new SpannableString("Text with relative size span");
 *string.setSpan(new RelativeSizeSpan(1.5f), 10, 24, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
 * <img src="{@docRoot}reference/android/images/text/style/relativesizespan.png" />
 * <figcaption>Text increased by 50% with <code>RelativeSizeSpan</code>.</figcaption>
 */
public class RelativeSizeSpan extends MetricAffectingSpan implements ParcelableSpan {

    private final float mProportion;

    public RelativeSizeSpan(float proportion) {
    /**
     * Creates a {@link RelativeSizeSpan} based on a proportion.
     *
     * @param proportion the proportion with which the text is scaled.
     */
    public RelativeSizeSpan(@FloatRange(from = 0) float proportion) {
        mProportion = proportion;
    }

    public RelativeSizeSpan(Parcel src) {
    /**
     * Creates a {@link RelativeSizeSpan} from a parcel.
     */
    public RelativeSizeSpan(@NonNull Parcel src) {
        mProportion = src.readFloat();
    }

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

    /** @hide */
    @Override
    public int getSpanTypeIdInternal() {
        return TextUtils.RELATIVE_SIZE_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.writeFloat(mProportion);
    }

    /**
     * @return the proportion with which the text size is changed.
     */
    public float getSizeChange() {
        return mProportion;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
    public void updateDrawState(@NonNull TextPaint ds) {
        ds.setTextSize(ds.getTextSize() * mProportion);
    }

    @Override
    public void updateMeasureState(TextPaint ds) {
    public void updateMeasureState(@NonNull TextPaint ds) {
        ds.setTextSize(ds.getTextSize() * mProportion);
    }
}
+40 −6
Original line number Diff line number Diff line
@@ -16,45 +16,79 @@

package android.text.style;

import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.os.Parcel;
import android.text.ParcelableSpan;
import android.text.TextPaint;
import android.text.TextUtils;

/**
 * Scales horizontally the size of the text to which it's attached by a certain factor.
 * <p>
 * Values > 1.0 will stretch the text wider. Values < 1.0 will stretch the text narrower.
 * <p>
 * For example, a <code>ScaleXSpan</code> that stretches the text size by 100% can be
 * constructed like this:
 * <pre>{@code
 * SpannableString string = new SpannableString("Text with ScaleX span");
 *string.setSpan(new ScaleXSpan(2f), 10, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
 * <img src="{@docRoot}reference/android/images/text/style/scalexspan.png" />
 * <figcaption>Text scaled by 100% with <code>ScaleXSpan</code>.</figcaption>
 */
public class ScaleXSpan extends MetricAffectingSpan implements ParcelableSpan {

    private final float mProportion;

    public ScaleXSpan(float proportion) {
    /**
     * Creates a {@link ScaleXSpan} based on a proportion. Values > 1.0 will stretch the text wider.
     * Values < 1.0 will stretch the text narrower.
     *
     * @param proportion the horizontal scale factor.
     */
    public ScaleXSpan(@FloatRange(from = 0) float proportion) {
        mProportion = proportion;
    }

    public ScaleXSpan(Parcel src) {
    /**
     * Creates a {@link ScaleXSpan} from a parcel.
     */
    public ScaleXSpan(@NonNull Parcel src) {
        mProportion = src.readFloat();
    }

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

    /** @hide */
    @Override
    public int getSpanTypeIdInternal() {
        return TextUtils.SCALE_X_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.writeFloat(mProportion);
    }

    /**
     * Get the horizontal scale factor for the text.
     *
     * @return the horizontal scale factor.
     */
    public float getScaleX() {
        return mProportion;
    }
Loading