19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.text.style; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinirimport android.annotation.IntRange; 20c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinirimport android.annotation.NonNull; 21c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinirimport android.annotation.Nullable; 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.graphics.Canvas; 234037d51b132a85dcfe37a95f9d2d91ad23d162fdAurimas Liutikasimport android.graphics.Paint; 249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.text.TextPaint; 259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic abstract class ReplacementSpan extends MetricAffectingSpan { 279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 28c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir /** 29c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * Returns the width of the span. Extending classes can set the height of the span by updating 30c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * attributes of {@link android.graphics.Paint.FontMetricsInt}. If the span covers the whole 31c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * text, and the height is not set, 32c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * {@link #draw(Canvas, CharSequence, int, int, float, int, int, int, Paint)} will not be 33c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * called for the span. 34c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * 35c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param paint Paint instance. 36c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param text Current text. 37c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param start Start character index for span. 38c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param end End character index for span. 39c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param fm Font metrics, can be null. 40c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @return Width of the span. 41c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir */ 42c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir public abstract int getSize(@NonNull Paint paint, CharSequence text, 43c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir @IntRange(from = 0) int start, @IntRange(from = 0) int end, 44c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir @Nullable Paint.FontMetricsInt fm); 45c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir 46c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir /** 47c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * Draws the span into the canvas. 48c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * 49c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param canvas Canvas into which the span should be rendered. 50c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param text Current text. 51c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param start Start character index for span. 52c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param end End character index for span. 53c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param x Edge of the replacement closest to the leading margin. 54c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param top Top of the line. 55c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param y Baseline. 56c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param bottom Bottom of the line. 57c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir * @param paint Paint instance. 58c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir */ 59c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir public abstract void draw(@NonNull Canvas canvas, CharSequence text, 60c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, 61c7ff969b47842918330e96fa1ce6df2cff2bf27cSiyamed Sinir int top, int y, int bottom, @NonNull Paint paint); 629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This method does nothing, since ReplacementSpans are measured 659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * explicitly instead of affecting Paint properties. 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void updateMeasureState(TextPaint p) { } 689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This method does nothing, since ReplacementSpans are drawn 719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * explicitly instead of affecting Paint properties. 729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void updateDrawState(TextPaint ds) { } 749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 75