OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.ui.resources; |
| 6 |
| 7 /** |
| 8 * A class responsible for loading {@link Resource}s for the {@link ResourceMana
ger}. |
| 9 */ |
| 10 public abstract class ResourceLoader { |
| 11 /** |
| 12 * A callback that specifies when a {@link Resource} has been loaded and can
be exposed to the |
| 13 * CC layer. |
| 14 */ |
| 15 public interface ResourceLoaderCallback { |
| 16 /** |
| 17 * Called when a resource as finished loading. Note that it is up to th
e caller to recycle |
| 18 * any {@link android.graphics.Bitmap}s or clean up any state after maki
ng this call. |
| 19 * @param resType The {@link ResourceType} that loaded the resource. |
| 20 * @param resId The Android id of the loaded resource. |
| 21 * @param resource The {@link Resource} of the resource, or {@code null}
if one could |
| 22 * not be loaded. |
| 23 */ |
| 24 void onResourceLoaded(int resType, int resId, Resource resource); |
| 25 } |
| 26 |
| 27 private final int mResourceType; |
| 28 private final ResourceLoaderCallback mCallback; |
| 29 |
| 30 /** |
| 31 * Creates an instance of a {@link ResourceLoader}. |
| 32 * @param resourceType The resource type category this {@link ResourceLoader
} is loading. |
| 33 * @param callback The {@link ResourceLoaderCallback} to notify when a {
@link Resource} is |
| 34 * loaded. |
| 35 */ |
| 36 public ResourceLoader(int resourceType, ResourceLoaderCallback callback) { |
| 37 mResourceType = resourceType; |
| 38 mCallback = callback; |
| 39 } |
| 40 |
| 41 /** |
| 42 * @return What resource type this {@link ResourceLoader} is responsible for
loading. |
| 43 */ |
| 44 public int getResourceType() { |
| 45 return mResourceType; |
| 46 } |
| 47 |
| 48 /** |
| 49 * Requests that a resource specified by {@code resId} be loaded from this |
| 50 * {@link ResourceLoader}. This may or may not actually load the resource a
nd notify the |
| 51 * {@link ResourceLoaderCallback} depending on the internal behavior of the
particular loader. |
| 52 * @param resId The id of the {@link Resource} to load. |
| 53 */ |
| 54 public abstract void loadResource(int resId); |
| 55 |
| 56 /** |
| 57 * Requests that a resource be pre-loaded. This will typically happen async
hronously. |
| 58 * @param resId The id of the {@link Resource} to load. |
| 59 */ |
| 60 public abstract void preloadResource(int resId); |
| 61 |
| 62 /** |
| 63 * A helper method for subclasses to notify that the {@link Resource} specif
ied by {@code resId} |
| 64 * is done loading. |
| 65 * @param resId The id of the {@link Resource} that loaded or failed. |
| 66 * @param resource The {@link Resource}, or {@code null} if the load failed. |
| 67 */ |
| 68 protected void notifyLoadFinished(int resId, Resource resource) { |
| 69 if (mCallback != null) mCallback.onResourceLoaded(getResourceType(), res
Id, resource); |
| 70 } |
| 71 } |
OLD | NEW |