public final class

WearableNavigationHelper

extends java.lang.Object

 java.lang.Object

↳androidx.wear.utils.WearableNavigationHelper

Gradle dependencies

compile group: 'androidx.wear', name: 'wear', version: '1.4.0-alpha01'

  • groupId: androidx.wear
  • artifactId: wear
  • version: 1.4.0-alpha01

Artifact androidx.wear:wear:1.4.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.wear:wear com.android.support:wear

Overview

Class containing helpers for querying wearable navigation pattern

Summary

Methods
public static booleanisSwipeToDismissEnabled()

Query whether swipe-to-dismiss is enabled on current device.

public static booleanisSwipeToDismissEnabled(Context context)

Query whether swipe-to-dismiss is enabled in current context.

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

Methods

public static boolean isSwipeToDismissEnabled()

Query whether swipe-to-dismiss is enabled on current device.

public static boolean isSwipeToDismissEnabled(Context context)

Query whether swipe-to-dismiss is enabled in current context.

Source

/*
 * Copyright 2020 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.wear.utils;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;

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


/**
 * Class containing helpers for querying wearable navigation pattern
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public final class WearableNavigationHelper {

    private static final String ITEM_NAME = "config_windowSwipeToDismiss";
    private static final String ITEM_TYPE = "bool";
    private static final String PACKAGE_NAME = "android";

    private WearableNavigationHelper() {
    }

    /**
     * Query whether swipe-to-dismiss is enabled on current device.
     */
    public static boolean isSwipeToDismissEnabled() {
        final Resources res = Resources.getSystem(); // system resources
        final int identifier = res.getIdentifier(ITEM_NAME, ITEM_TYPE, PACKAGE_NAME);
        if (identifier != 0) {
            return res.getBoolean(identifier);
        }
        return false;
    }

    /**
     * Query whether swipe-to-dismiss is enabled in current context.
     */
    @SuppressWarnings("deprecation")
    public static boolean isSwipeToDismissEnabled(@NonNull Context context) {
        TypedArray windowAttr =
                context.obtainStyledAttributes(new int[]{android.R.attr.windowSwipeToDismiss});
        boolean enabled = false;
        if (windowAttr.getIndexCount() > 0) {
            enabled = windowAttr.getBoolean(0, true);
        }
        windowAttr.recycle();
        return enabled;
    }
}