public final class

SizeFCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.util.SizeFCompat

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

Overview

Immutable class for describing width and height dimensions in some arbitrary unit. Width and height are finite values stored as a floating point representation.

This is a backward-compatible version of .

Summary

Constructors
publicSizeFCompat(float width, float height)

Methods
public booleanequals(java.lang.Object o)

public floatgetHeight()

Get the height of the size (as an arbitrary unit).

public floatgetWidth()

Get the width of the size (as an arbitrary unit).

public inthashCode()

public SizeFtoSizeF()

Converts this SizeFCompat into a .

public static SizeFCompattoSizeFCompat(SizeF size)

Converts this into a SizeFCompat.

public java.lang.StringtoString()

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

Constructors

public SizeFCompat(float width, float height)

Methods

public float getWidth()

Get the width of the size (as an arbitrary unit).

Returns:

width

public float getHeight()

Get the height of the size (as an arbitrary unit).

Returns:

height

public boolean equals(java.lang.Object o)

public int hashCode()

public java.lang.String toString()

public SizeF toSizeF()

Converts this SizeFCompat into a .

public static SizeFCompat toSizeFCompat(SizeF size)

Converts this into a SizeFCompat.

Source

/*
 * Copyright 2021 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.util;

import android.util.SizeF;

import androidx.annotation.DoNotInline;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

/**
 * Immutable class for describing width and height dimensions in some arbitrary unit. Width and
 * height are finite values stored as a floating point representation.
 * <p>
 * This is a backward-compatible version of {@link SizeF}.
 */
public final class SizeFCompat {

    private final float mWidth;
    private final float mHeight;

    public SizeFCompat(float width, float height) {
        mWidth = Preconditions.checkArgumentFinite(width, "width");
        mHeight = Preconditions.checkArgumentFinite(height, "height");
    }

    /**
     * Get the width of the size (as an arbitrary unit).
     * @return width
     */
    public float getWidth() {
        return mWidth;
    }

    /**
     * Get the height of the size (as an arbitrary unit).
     * @return height
     */
    public float getHeight() {
        return mHeight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SizeFCompat)) return false;
        SizeFCompat that = (SizeFCompat) o;
        return that.mWidth == mWidth && that.mHeight == mHeight;
    }

    @Override
    public int hashCode() {
        return Float.floatToIntBits(mWidth) ^ Float.floatToIntBits(mHeight);
    }

    @NonNull
    @Override
    public String toString() {
        return mWidth + "x" + mHeight;
    }

    /** Converts this {@link SizeFCompat} into a {@link SizeF}. */
    @RequiresApi(21)
    @NonNull
    public SizeF toSizeF() {
        return Api21Impl.toSizeF(this);
    }

    /** Converts this {@link SizeF} into a {@link SizeFCompat}. */
    @RequiresApi(21)
    @NonNull
    public static SizeFCompat toSizeFCompat(@NonNull SizeF size) {
        return Api21Impl.toSizeFCompat(size);
    }

    @RequiresApi(21)
    private static final class Api21Impl {
        @DoNotInline
        @NonNull
        static SizeFCompat toSizeFCompat(@NonNull SizeF size) {
            Preconditions.checkNotNull(size);
            return new SizeFCompat(size.getWidth(), size.getHeight());
        }

        @DoNotInline
        @NonNull
        static SizeF toSizeF(@NonNull SizeFCompat size) {
            Preconditions.checkNotNull(size);
            return new SizeF(size.getWidth(), size.getHeight());
        }
    }
}