public class

ExtensionDeviceState

extends java.lang.Object

 java.lang.Object

↳androidx.window.extensions.ExtensionDeviceState

Gradle dependencies

compile group: 'androidx.window', name: 'window-extensions', version: '1.0.0-alpha01'

  • groupId: androidx.window
  • artifactId: window-extensions
  • version: 1.0.0-alpha01

Artifact androidx.window:window-extensions:1.0.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Information about the current state of the device.

Currently only includes the description of the state for foldable devices.

Summary

Fields
public static final intPOSTURE_CLOSED

public static final intPOSTURE_FLIPPED

public static final intPOSTURE_HALF_OPENED

public static final intPOSTURE_OPENED

public static final intPOSTURE_UNKNOWN

Constructors
publicExtensionDeviceState(int posture)

Methods
public booleanequals(java.lang.Object obj)

public intgetPosture()

Get the current posture of the foldable device.

public inthashCode()

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

Fields

public static final int POSTURE_UNKNOWN

public static final int POSTURE_CLOSED

public static final int POSTURE_HALF_OPENED

public static final int POSTURE_OPENED

public static final int POSTURE_FLIPPED

Constructors

public ExtensionDeviceState(int posture)

Methods

public int getPosture()

Get the current posture of the foldable device.

public boolean equals(java.lang.Object obj)

public int hashCode()

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.window.extensions;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;

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

/**
 * Information about the current state of the device.
 * <p>Currently only includes the description of the state for foldable devices.
 */
public class ExtensionDeviceState {

    /**
     * The current posture of the foldable device.
     */
    @Posture
    private final int mPosture;

    public static final int POSTURE_UNKNOWN = 0;
    public static final int POSTURE_CLOSED = 1;
    public static final int POSTURE_HALF_OPENED = 2;
    public static final int POSTURE_OPENED = 3;
    public static final int POSTURE_FLIPPED = 4;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            POSTURE_UNKNOWN,
            POSTURE_CLOSED,
            POSTURE_HALF_OPENED,
            POSTURE_OPENED,
            POSTURE_FLIPPED
    })
    @interface Posture{}

    public ExtensionDeviceState(@Posture int posture) {
        mPosture = posture;
    }

    /**
     * Get the current posture of the foldable device.
     */
    @Posture
    public int getPosture() {
        return mPosture;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ExtensionDeviceState)) {
            return false;
        }
        final ExtensionDeviceState
                other = (ExtensionDeviceState) obj;
        return other.mPosture == mPosture;
    }

    @Override
    public int hashCode() {
        return mPosture;
    }
}