1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text.style; 18 19 import static android.view.inputmethod.Flags.FLAG_WRITING_TOOLS; 20 21 import android.annotation.FlaggedApi; 22 import android.annotation.NonNull; 23 import android.os.Parcel; 24 import android.text.ParcelableSpan; 25 import android.text.TextUtils; 26 27 /** 28 * A span that signals to IMEs that writing tools should not modify the text. 29 * 30 * <p>For example, a text field may contain a mix of user input text and quoted text. The app 31 * can apply {@code NoWritingToolsSpan} to the quoted text so that the IME knows that writing 32 * tools should only rewrite the user input text, and not modify the quoted text. 33 */ 34 @FlaggedApi(FLAG_WRITING_TOOLS) 35 @android.ravenwood.annotation.RavenwoodKeepWholeClass 36 public final class NoWritingToolsSpan implements ParcelableSpan { 37 38 /** 39 * Creates a {@link NoWritingToolsSpan}. 40 */ NoWritingToolsSpan()41 public NoWritingToolsSpan() { 42 } 43 44 @Override getSpanTypeId()45 public int getSpanTypeId() { 46 return getSpanTypeIdInternal(); 47 } 48 49 /** @hide */ 50 @Override getSpanTypeIdInternal()51 public int getSpanTypeIdInternal() { 52 return TextUtils.NO_WRITING_TOOLS_SPAN; 53 } 54 55 @Override describeContents()56 public int describeContents() { 57 return 0; 58 } 59 60 @Override writeToParcel(@onNull Parcel dest, int flags)61 public void writeToParcel(@NonNull Parcel dest, int flags) { 62 writeToParcelInternal(dest, flags); 63 } 64 65 /** @hide */ 66 @Override writeToParcelInternal(@onNull Parcel dest, int flags)67 public void writeToParcelInternal(@NonNull Parcel dest, int flags) { 68 } 69 70 @Override toString()71 public String toString() { 72 return "NoWritingToolsSpan{}"; 73 } 74 75 @NonNull 76 public static final Creator<NoWritingToolsSpan> CREATOR = new Creator<>() { 77 78 @Override 79 public NoWritingToolsSpan createFromParcel(Parcel source) { 80 return new NoWritingToolsSpan(); 81 } 82 83 @Override 84 public NoWritingToolsSpan[] newArray(int size) { 85 return new NoWritingToolsSpan[size]; 86 } 87 }; 88 } 89