summaryrefslogtreecommitdiff
path: root/src/com/android/bitmap/ResourceRequestKey.java
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2014-01-07 00:41:21 -0800
committerMark Wei <markwei@google.com>2014-01-07 15:49:24 -0800
commitad6ca3f895022ded1a11f3eedc50d70ea90cd4da (patch)
treeb45396307e40fdd31f948c7ce1b78e9c6a47a1be /src/com/android/bitmap/ResourceRequestKey.java
parent5d6521e290594fe0851086b0c27413e9709e437f (diff)
downloadbitmap-ad6ca3f895022ded1a11f3eedc50d70ea90cd4da.tar.gz
Export some useful custom classes that I wrote back into the bitmap library.
Added: - CircularBitmapDrawable: Use this if you want to display circular images with an optional border stroke. This class uses BitmapShaders, the preferred way of masking a bitmap, instead of using a non-rectangular clip region or overlaying views. - StyledCornersBitmapDrawable: Use this if you want the corners of your images to be stylized. You can choose from rounded or flap corners, with an optional border stroke and optional flap color. This class uses a non-rectangular clip region. In the future, this may change to use a BitmapShader. - ResourceRequestKey: Use this if you want a simple RequestKey implementation that loads images from a resource asset. Change-Id: If64440f3389f56f8a5b799a32a2660f3f9a19385
Diffstat (limited to 'src/com/android/bitmap/ResourceRequestKey.java')
-rw-r--r--src/com/android/bitmap/ResourceRequestKey.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/com/android/bitmap/ResourceRequestKey.java b/src/com/android/bitmap/ResourceRequestKey.java
new file mode 100644
index 0000000..7bb64d9
--- /dev/null
+++ b/src/com/android/bitmap/ResourceRequestKey.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 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 com.android.bitmap;
+
+import android.content.res.Resources;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Simple RequestKey for decoding from a resource id.
+ */
+public class ResourceRequestKey implements RequestKey {
+
+ private Resources mResources;
+ private int mResId;
+
+ /**
+ * Create a new request key with the given resource id. A resId of 0 will
+ * return a null request key.
+ */
+ public static ResourceRequestKey from(Resources res, int resId) {
+ if (resId != 0) {
+ return new ResourceRequestKey(res, resId);
+ }
+ return null;
+ }
+
+ private ResourceRequestKey(Resources res, int resId) {
+ mResources = res;
+ mResId = resId;
+ }
+
+ @Override
+ public Cancelable createFileDescriptorFactoryAsync(RequestKey requestKey, Callback callback) {
+ return null;
+ }
+
+ @Override
+ public InputStream createInputStream() throws IOException {
+ return mResources.openRawResource(mResId);
+ }
+
+ @Override
+ public boolean hasOrientationExif() throws IOException {
+ return false;
+ }
+
+ // START AUTO-GENERATED CODE
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ ResourceRequestKey that = (ResourceRequestKey) o;
+
+ if (mResId != that.mResId) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return mResId;
+ }
+
+ // END AUTO-GENERATED CODE
+
+ @Override
+ public String toString() {
+ return String.format("ResourceRequestKey: %d", mResId);
+ }
+}