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

Commit 1ef75f49 authored by Justin Ghan's avatar Justin Ghan Committed by Android (Google) Code Review
Browse files

Merge "NoWritingToolsSpan" into main

parents 22809a12 e06ef0e3
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -49760,6 +49760,14 @@ package android.text.style {
    method public abstract void updateMeasureState(@NonNull android.text.TextPaint);
  }
  @FlaggedApi("android.view.inputmethod.writing_tools") public final class NoWritingToolsSpan implements android.text.ParcelableSpan {
    ctor public NoWritingToolsSpan();
    method public int describeContents();
    method public int getSpanTypeId();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.text.style.NoWritingToolsSpan> CREATOR;
  }
  public interface ParagraphStyle {
  }
+8 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.text.style.LineBackgroundSpan;
import android.text.style.LineBreakConfigSpan;
import android.text.style.LineHeightSpan;
import android.text.style.LocaleSpan;
import android.text.style.NoWritingToolsSpan;
import android.text.style.ParagraphStyle;
import android.text.style.QuoteSpan;
import android.text.style.RelativeSizeSpan;
@@ -817,7 +818,9 @@ public class TextUtils {
    /** @hide */
    public static final int LINE_BREAK_CONFIG_SPAN = 30;
    /** @hide */
    public static final int LAST_SPAN = LINE_BREAK_CONFIG_SPAN;
    public static final int NO_WRITING_TOOLS_SPAN = 31;
    /** @hide */
    public static final int LAST_SPAN = NO_WRITING_TOOLS_SPAN;

    /**
     * Flatten a CharSequence and whatever styles can be copied across processes
@@ -1025,6 +1028,10 @@ public class TextUtils {
                    span = LineBreakConfigSpan.CREATOR.createFromParcel(p);
                    break;

                case NO_WRITING_TOOLS_SPAN:
                    span = NoWritingToolsSpan.CREATOR.createFromParcel(p);
                    break;

                default:
                    throw new RuntimeException("bogus span encoding " + kind);
                }
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 android.text.style;

import static android.view.inputmethod.Flags.FLAG_WRITING_TOOLS;

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

/**
 * A span that signals to IMEs that writing tools should not modify the text.
 *
 * <p>For example, a text field may contain a mix of user input text and quoted text. The app
 * can apply {@code NoWritingToolsSpan} to the quoted text so that the IME knows that writing
 * tools should only rewrite the user input text, and not modify the quoted text.
 */
@FlaggedApi(FLAG_WRITING_TOOLS)
public final class NoWritingToolsSpan implements ParcelableSpan {

    /**
     * Creates a {@link NoWritingToolsSpan}.
     */
    public NoWritingToolsSpan() {
    }

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

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

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

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

    /** @hide */
    @Override
    public void writeToParcelInternal(@NonNull Parcel dest, int flags) {
    }

    @Override
    public String toString() {
        return "NoWritingToolsSpan{}";
    }

    @NonNull
    public static final Creator<NoWritingToolsSpan> CREATOR = new Creator<>() {

        @Override
        public NoWritingToolsSpan createFromParcel(Parcel source) {
            return new NoWritingToolsSpan();
        }

        @Override
        public NoWritingToolsSpan[] newArray(int size) {
            return new NoWritingToolsSpan[size];
        }
    };
}