public class

ResolutionCorrector

extends java.lang.Object

 java.lang.Object

↳androidx.camera.camera2.internal.compat.workaround.ResolutionCorrector

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-camera2', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-camera2
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-camera2:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Helper class that overrides user configured resolution with resolution selected based on device quirks.

Summary

Constructors
publicResolutionCorrector()

Constructs new ResolutionCorrector.

Methods
public java.util.List<Size>insertOrPrioritize(SurfaceConfig.ConfigType configType, java.util.List<Size> supportedResolutions)

Returns a new list of resolution with the selected resolution inserted or prioritized.

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

Constructors

public ResolutionCorrector()

Constructs new ResolutionCorrector.

Methods

public java.util.List<Size> insertOrPrioritize(SurfaceConfig.ConfigType configType, java.util.List<Size> supportedResolutions)

Returns a new list of resolution with the selected resolution inserted or prioritized.

If the list contains the selected resolution, move it to be the first element; if it does not contain the selected resolution, insert it as the first element; if there is no device quirk, return the original list.

Parameters:

configType: the config type based on which the supported resolution is calculated.
supportedResolutions: a ordered list of resolutions calculated by CameraX.

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.camera.camera2.internal.compat.workaround;

import android.util.Size;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.camera.camera2.internal.compat.quirk.DeviceQuirks;
import androidx.camera.camera2.internal.compat.quirk.ExtraCroppingQuirk;
import androidx.camera.core.impl.SurfaceConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * Helper class that overrides user configured resolution with resolution selected based on device
 * quirks.
 */
public class ResolutionCorrector {

    @Nullable
    private final ExtraCroppingQuirk mExtraCroppingQuirk;

    /**
     * Constructs new {@link ResolutionCorrector}.
     */
    public ResolutionCorrector() {
        this(DeviceQuirks.get(ExtraCroppingQuirk.class));
    }

    /**
     * Constructs new {@link ResolutionCorrector}.
     */
    @VisibleForTesting
    ResolutionCorrector(@Nullable ExtraCroppingQuirk extraCroppingQuirk) {
        mExtraCroppingQuirk = extraCroppingQuirk;
    }

    /**
     * Returns a new list of resolution with the selected resolution inserted or prioritized.
     *
     * <p> If the list contains the selected resolution, move it to be the first element; if it
     * does not contain the selected resolution, insert it as the first element; if there is no
     * device quirk, return the original list.
     *
     * @param configType           the config type based on which the supported resolution is
     *                             calculated.
     * @param supportedResolutions a ordered list of resolutions calculated by CameraX.
     */
    @NonNull
    public List<Size> insertOrPrioritize(
            @NonNull SurfaceConfig.ConfigType configType,
            @NonNull List<Size> supportedResolutions) {
        if (mExtraCroppingQuirk == null) {
            return supportedResolutions;
        }
        Size selectResolution = mExtraCroppingQuirk.getVerifiedResolution(configType);
        if (selectResolution == null) {
            return supportedResolutions;
        }
        List<Size> newResolutions = new ArrayList<>();
        newResolutions.add(selectResolution);
        for (Size size : supportedResolutions) {
            if (!size.equals(selectResolution)) {
                newResolutions.add(size);
            }
        }
        return newResolutions;
    }
}