public interface

AutoSizeableTextView

 androidx.core.widget.AutoSizeableTextView

Subclasses:

EmojiAppCompatTextView, EmojiAppCompatButton, ActionMenuItemView, AppCompatTextView, AppCompatButton, DialogTitle, MotionButton

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.9.0-alpha04'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.9.0-alpha04

Artifact androidx.core:core:1.9.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.widget.AutoSizeableTextView android.support.v4.widget.AutoSizeableTextView

Overview

Interface which allows a android.widget.TextView to receive background auto-sizing calls from TextViewCompat when running on API v26 devices or lower.

When used on a View annotated with AppCompatShadowedAttributes, this interface implies that AppCompat shadows the platform's auto-size attributes. See for more details and a full mapping of attributes.

Summary

Fields
public static final booleanPLATFORM_SUPPORTS_AUTOSIZE

Methods
public intgetAutoSizeMaxTextSize()

public intgetAutoSizeMinTextSize()

public intgetAutoSizeStepGranularity()

public int[]getAutoSizeTextAvailableSizes()

public intgetAutoSizeTextType()

Returns the type of auto-size set for this widget.

public voidsetAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds.

public voidsetAutoSizeTextTypeUniformWithPresetSizes(int[] presetSizes[], int unit)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds.

public voidsetAutoSizeTextTypeWithDefaults(int autoSizeTextType)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds by using the default auto-size configuration.

Fields

public static final boolean PLATFORM_SUPPORTS_AUTOSIZE

Methods

public void setAutoSizeTextTypeWithDefaults(int autoSizeTextType)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds by using the default auto-size configuration.

Parameters:

autoSizeTextType: the type of auto-size. Must be one of TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE or TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM

See also: AutoSizeableTextView.getAutoSizeTextType()

public void setAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds. If all the configuration params are valid the type of auto-size is set to TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM.

Parameters:

autoSizeMinTextSize: the minimum text size available for auto-size
autoSizeMaxTextSize: the maximum text size available for auto-size
autoSizeStepGranularity: the auto-size step granularity. It is used in conjunction with the minimum and maximum text size in order to build the set of text sizes the system uses to choose from when auto-sizing
unit: the desired dimension unit for all sizes above. See for the possible dimension units

See also: AutoSizeableTextView.setAutoSizeTextTypeWithDefaults(int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithPresetSizes(int[], int), AutoSizeableTextView.getAutoSizeMinTextSize(), AutoSizeableTextView.getAutoSizeMaxTextSize(), AutoSizeableTextView.getAutoSizeStepGranularity(), AutoSizeableTextView.getAutoSizeTextAvailableSizes()

public void setAutoSizeTextTypeUniformWithPresetSizes(int[] presetSizes[], int unit)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds. If at least one value from the presetSizes is valid then the type of auto-size is set to TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM.

Parameters:

presetSizes: an int array of sizes in pixels
unit: the desired dimension unit for the preset sizes above. See for the possible dimension units

See also: AutoSizeableTextView.setAutoSizeTextTypeWithDefaults(int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int), AutoSizeableTextView.getAutoSizeMinTextSize(), AutoSizeableTextView.getAutoSizeMaxTextSize(), AutoSizeableTextView.getAutoSizeTextAvailableSizes()

public int getAutoSizeTextType()

Returns the type of auto-size set for this widget.

Returns:

an int corresponding to one of the auto-size types: TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE or TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM

See also: AutoSizeableTextView.setAutoSizeTextTypeWithDefaults(int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithPresetSizes(int[], int)

public int getAutoSizeStepGranularity()

Returns:

the current auto-size step granularity in pixels.

See also: AutoSizeableTextView.setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)

public int getAutoSizeMinTextSize()

Returns:

the current auto-size minimum text size in pixels (the default is 12sp). Note that if auto-size has not been configured this function returns -1.

See also: AutoSizeableTextView.setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithPresetSizes(int[], int)

public int getAutoSizeMaxTextSize()

Returns:

the current auto-size maximum text size in pixels (the default is 112sp). Note that if auto-size has not been configured this function returns -1.

See also: AutoSizeableTextView.setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithPresetSizes(int[], int)

public int[] getAutoSizeTextAvailableSizes()

Returns:

the current auto-size int sizes array (in pixels).

See also: AutoSizeableTextView.setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int), AutoSizeableTextView.setAutoSizeTextTypeUniformWithPresetSizes(int[], int)

Source

/*
 * Copyright (C) 2017 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 androidx.core.widget;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.os.Build;
import android.util.TypedValue;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

/**
 * Interface which allows a {@link android.widget.TextView} to receive background auto-sizing calls
 * from {@link TextViewCompat} when running on API v26 devices or lower.
 * <p>
 * When used on a View annotated with
 * {@link androidx.resourceinspection.annotation.AppCompatShadowedAttributes}, this interface
 * implies that AppCompat shadows the platform's auto-size attributes. See
 * {@link androidx.resourceinspection.processor} for more details and a full mapping of attributes.
 *
 * @hide Internal use only
 */
@RestrictTo(LIBRARY_GROUP_PREFIX)
public interface AutoSizeableTextView {
    /**
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    boolean PLATFORM_SUPPORTS_AUTOSIZE = Build.VERSION.SDK_INT >= 27;

    /**
     * Specify whether this widget should automatically scale the text to try to perfectly fit
     * within the layout bounds by using the default auto-size configuration.
     *
     * @param autoSizeTextType the type of auto-size. Must be one of
     *        {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_NONE} or
     *        {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_UNIFORM}
     *
     * @see #getAutoSizeTextType()
     */
    void setAutoSizeTextTypeWithDefaults(@TextViewCompat.AutoSizeTextType int autoSizeTextType);

    /**
     * Specify whether this widget should automatically scale the text to try to perfectly fit
     * within the layout bounds. If all the configuration params are valid the type of auto-size is
     * set to {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_UNIFORM}.
     *
     * @param autoSizeMinTextSize the minimum text size available for auto-size
     * @param autoSizeMaxTextSize the maximum text size available for auto-size
     * @param autoSizeStepGranularity the auto-size step granularity. It is used in conjunction with
     *                                the minimum and maximum text size in order to build the set of
     *                                text sizes the system uses to choose from when auto-sizing
     * @param unit the desired dimension unit for all sizes above. See {@link TypedValue} for the
     *             possible dimension units
     *
     * @throws IllegalArgumentException if any of the configuration params are invalid.
     *
     * @see #setAutoSizeTextTypeWithDefaults(int)
     * @see #setAutoSizeTextTypeUniformWithPresetSizes(int[], int)
     * @see #getAutoSizeMinTextSize()
     * @see #getAutoSizeMaxTextSize()
     * @see #getAutoSizeStepGranularity()
     * @see #getAutoSizeTextAvailableSizes()
     */
    void setAutoSizeTextTypeUniformWithConfiguration(
            int autoSizeMinTextSize,
            int autoSizeMaxTextSize,
            int autoSizeStepGranularity,
            int unit) throws IllegalArgumentException;

    /**
     * Specify whether this widget should automatically scale the text to try to perfectly fit
     * within the layout bounds. If at least one value from the <code>presetSizes</code> is valid
     * then the type of auto-size is set to {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_UNIFORM}.
     *
     * @param presetSizes an {@code int} array of sizes in pixels
     * @param unit the desired dimension unit for the preset sizes above. See {@link TypedValue} for
     *             the possible dimension units
     *
     * @throws IllegalArgumentException if all of the <code>presetSizes</code> are invalid.
     *_
     * @see #setAutoSizeTextTypeWithDefaults(int)
     * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)
     * @see #getAutoSizeMinTextSize()
     * @see #getAutoSizeMaxTextSize()
     * @see #getAutoSizeTextAvailableSizes()
     */
    void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull int[] presetSizes, int unit)
            throws IllegalArgumentException;

    /**
     * Returns the type of auto-size set for this widget.
     *
     * @return an {@code int} corresponding to one of the auto-size types:
     *         {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_NONE} or
     *         {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_UNIFORM}
     *
     * @see #setAutoSizeTextTypeWithDefaults(int)
     * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)
     * @see #setAutoSizeTextTypeUniformWithPresetSizes(int[], int)
     */
    @TextViewCompat.AutoSizeTextType
    int getAutoSizeTextType();

    /**
     * @return the current auto-size step granularity in pixels.
     *
     * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)
     */
    int getAutoSizeStepGranularity();

    /**
     * @return the current auto-size minimum text size in pixels (the default is 12sp). Note that
     *         if auto-size has not been configured this function returns {@code -1}.
     *
     * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)
     * @see #setAutoSizeTextTypeUniformWithPresetSizes(int[], int)
     */
    int getAutoSizeMinTextSize();

    /**
     * @return the current auto-size maximum text size in pixels (the default is 112sp). Note that
     *         if auto-size has not been configured this function returns {@code -1}.
     *
     * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)
     * @see #setAutoSizeTextTypeUniformWithPresetSizes(int[], int)
     */
    int getAutoSizeMaxTextSize();

    /**
     * @return the current auto-size {@code int} sizes array (in pixels).
     *
     * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)
     * @see #setAutoSizeTextTypeUniformWithPresetSizes(int[], int)
     */
    int[] getAutoSizeTextAvailableSizes();
}