public final class

GrammaticalInflectionManagerCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.app.GrammaticalInflectionManagerCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

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

Androidx artifact mapping:

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

Overview

Helper for accessing features in .

Summary

Fields
public static final intGRAMMATICAL_GENDER_FEMININE

Constant for grammatical gender: to indicate the terms of address the user preferred in an application is feminine.

public static final intGRAMMATICAL_GENDER_MASCULINE

Constant for grammatical gender: to indicate the terms of address the user preferred in an application is masculine.

public static final intGRAMMATICAL_GENDER_NEUTRAL

Constant for grammatical gender: to indicate the terms of address the user preferred in an application is neuter.

public static final intGRAMMATICAL_GENDER_NOT_SPECIFIED

Constant for grammatical gender: to indicate the user has not specified the terms of address for the application.

Methods
public static intgetApplicationGrammaticalGender(Context context)

Returns the current grammatical gender.

public static voidsetRequestedApplicationGrammaticalGender(Context context, int grammaticalGender)

Sets the current grammatical gender.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int GRAMMATICAL_GENDER_NOT_SPECIFIED

Constant for grammatical gender: to indicate the user has not specified the terms of address for the application.

See also:

public static final int GRAMMATICAL_GENDER_NEUTRAL

Constant for grammatical gender: to indicate the terms of address the user preferred in an application is neuter.

See also:

public static final int GRAMMATICAL_GENDER_FEMININE

Constant for grammatical gender: to indicate the terms of address the user preferred in an application is feminine.

See also:

public static final int GRAMMATICAL_GENDER_MASCULINE

Constant for grammatical gender: to indicate the terms of address the user preferred in an application is masculine.

See also:

Methods

public static int getApplicationGrammaticalGender(Context context)

Returns the current grammatical gender. No-op on versions prior to .

Parameters:

context: Context to retrieve service from.

Returns:

the grammatical gender if device API level is greater than 33, otherwise, return 0.

public static void setRequestedApplicationGrammaticalGender(Context context, int grammaticalGender)

Sets the current grammatical gender. No-op on versions prior to .

Parameters:

context: Context to retrieve service from.
grammaticalGender: the terms of address the user preferred in an application.

Source

/*
 * Copyright 2023 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.app;

import android.app.GrammaticalInflectionManager;
import android.content.Context;
import android.os.Build;

import androidx.annotation.AnyThread;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.OptIn;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Helper for accessing features in {@link android.app.GrammaticalInflectionManager}.
 */
public final class GrammaticalInflectionManagerCompat {

    @RestrictTo(RestrictTo.Scope.LIBRARY)
    @IntDef(value = {
            GRAMMATICAL_GENDER_NOT_SPECIFIED,
            GRAMMATICAL_GENDER_NEUTRAL,
            GRAMMATICAL_GENDER_FEMININE,
            GRAMMATICAL_GENDER_MASCULINE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface GrammaticalGender {}

    /**
     * Constant for grammatical gender: to indicate the user has not specified the terms
     * of address for the application.
     *
     * @see android.content.res.Configuration#GRAMMATICAL_GENDER_NOT_SPECIFIED
     */
    public static final int GRAMMATICAL_GENDER_NOT_SPECIFIED = 0;

    /**
     * Constant for grammatical gender: to indicate the terms of address the user
     * preferred in an application is neuter.
     *
     * @see android.content.res.Configuration#GRAMMATICAL_GENDER_NEUTRAL
     */
    public static final int GRAMMATICAL_GENDER_NEUTRAL = 1;

    /**
     * Constant for grammatical gender: to indicate the terms of address the user
     * preferred in an application is feminine.
     *
     * @see android.content.res.Configuration#GRAMMATICAL_GENDER_FEMININE
     */
    public static final int GRAMMATICAL_GENDER_FEMININE = 2;

    /**
     * Constant for grammatical gender: to indicate the terms of address the user
     * preferred in an application is masculine.
     *
     * @see android.content.res.Configuration#GRAMMATICAL_GENDER_MASCULINE
     */
    public static final int GRAMMATICAL_GENDER_MASCULINE = 3;

    private GrammaticalInflectionManagerCompat() {}

   /**
    * Returns the current grammatical gender. No-op on versions prior to
    * {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}.
    *
    * @param context Context to retrieve service from.
    * @return the grammatical gender if device API level is greater than 33, otherwise, return 0.
    */
    @OptIn(markerClass = androidx.core.os.BuildCompat.PrereleaseSdkCheck.class)
    @AnyThread
    public static int getApplicationGrammaticalGender(@NonNull Context context) {
        if (Build.VERSION.SDK_INT >= 34) {
            return Api34Impl.getApplicationGrammaticalGender(context);
        } else {
            return 0;
        }
    }

    /**
     * Sets the current grammatical gender. No-op on versions prior to
     * {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}.
     *
     * @param context Context to retrieve service from.
     * @param grammaticalGender the terms of address the user preferred in an application.
     */
    @OptIn(markerClass = androidx.core.os.BuildCompat.PrereleaseSdkCheck.class)
    @AnyThread
    public static void setRequestedApplicationGrammaticalGender(
            @NonNull Context context, @GrammaticalGender int grammaticalGender) {
        if (Build.VERSION.SDK_INT >= 34) {
            Api34Impl.setRequestedApplicationGrammaticalGender(context, grammaticalGender);
        }
    }

    @RequiresApi(34)
    static class Api34Impl {
        private Api34Impl() {}

        static int getApplicationGrammaticalGender(Context context) {
            return getGrammaticalInflectionManager(context).getApplicationGrammaticalGender();
        }

        static void setRequestedApplicationGrammaticalGender(
                Context context, int grammaticalGender) {
            getGrammaticalInflectionManager(context)
                    .setRequestedApplicationGrammaticalGender(grammaticalGender);
        }

        private static GrammaticalInflectionManager getGrammaticalInflectionManager(
                Context context) {
            return context.getSystemService(GrammaticalInflectionManager.class);
        }
    }
}