public class

AndroidResourceAccessor

extends java.lang.Object

implements ResourceAccessors.AndroidImageResourceByResIdAccessor

 java.lang.Object

↳androidx.wear.tiles.renderer.AndroidResourceAccessor

Gradle dependencies

compile group: 'androidx.wear', name: 'wear-tiles-renderer', version: '1.0.0-alpha01'

  • groupId: androidx.wear
  • artifactId: wear-tiles-renderer
  • version: 1.0.0-alpha01

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

Overview

Resource accessor for Android resources.

Summary

Constructors
publicAndroidResourceAccessor(Resources androidResources)

Constructor.

Methods
public <any>getDrawable(AndroidImageResourceByResId resource)

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

Constructors

public AndroidResourceAccessor(Resources androidResources)

Constructor.

Parameters:

androidResources: An Android Resources instance for the tile provider's package. This is normally obtained from PackageManager#getResourcesForApplication.

Methods

public <any> getDrawable(AndroidImageResourceByResId resource)

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.wear.tiles.renderer;

import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.concurrent.futures.ResolvableFuture;
import androidx.wear.tiles.proto.ResourceProto.AndroidImageResourceByResId;

import com.google.common.util.concurrent.ListenableFuture;

/**
 * Resource accessor for Android resources.
 *
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class AndroidResourceAccessor
        implements ResourceAccessors.AndroidImageResourceByResIdAccessor {
    private final Resources mAndroidResources;

    /**
     * Constructor.
     *
     * @param androidResources An Android Resources instance for the tile provider's package. This
     *     is normally obtained from {@code PackageManager#getResourcesForApplication}.
     */
    public AndroidResourceAccessor(@NonNull Resources androidResources) {
        this.mAndroidResources = androidResources;
    }

    @Override
    @NonNull
    public ListenableFuture<Drawable> getDrawable(@NonNull AndroidImageResourceByResId resource) {
        ResolvableFuture<Drawable> future = ResolvableFuture.create();
        try {
            future.set(mAndroidResources.getDrawable(resource.getResourceId(), null));
        } catch (NotFoundException e) {
            future.setException(e);
        }

        return future;
    }
}