summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2013-10-22 16:57:01 -0700
committerMark Wei <markwei@google.com>2013-10-22 17:06:30 -0700
commita23358fbfd62c7aa1c84bfa8395b4dc427a71ce6 (patch)
tree5fe5ce44556e0d8dc267c168c6266651ff8a0222 /sample
parent333647f2886289a23a09a84365aa42d328ec54dc (diff)
downloadbitmap-a23358fbfd62c7aa1c84bfa8395b4dc427a71ce6.tar.gz
Add BasicImageView to unbind on detach for clients with long-lived caches.
Change visibility of mBitmap back to private. Expose through getter. Bug: 11337575 Change-Id: I511976388cc3b6962434416d9e7a632e6d8a1b72
Diffstat (limited to 'sample')
-rw-r--r--sample/res/layout/activity_main.xml4
-rw-r--r--sample/res/values/dimens.xml22
-rw-r--r--sample/src/com/example/bitmapsample/BitmapView.java26
-rw-r--r--sample/src/com/example/bitmapsample/MainActivity.java8
4 files changed, 8 insertions, 52 deletions
diff --git a/sample/res/layout/activity_main.xml b/sample/res/layout/activity_main.xml
index f182664..1b29402 100644
--- a/sample/res/layout/activity_main.xml
+++ b/sample/res/layout/activity_main.xml
@@ -18,10 +18,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
diff --git a/sample/res/values/dimens.xml b/sample/res/values/dimens.xml
deleted file mode 100644
index f009504..0000000
--- a/sample/res/values/dimens.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 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.
--->
-
-<resources>
-
- <!-- Default screen margins, per the Android Design guidelines. -->
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
-</resources>
diff --git a/sample/src/com/example/bitmapsample/BitmapView.java b/sample/src/com/example/bitmapsample/BitmapView.java
index 37904f4..d8de0c9 100644
--- a/sample/src/com/example/bitmapsample/BitmapView.java
+++ b/sample/src/com/example/bitmapsample/BitmapView.java
@@ -17,15 +17,11 @@
package com.example.bitmapsample;
import android.content.Context;
-import android.os.Build;
import android.util.AttributeSet;
-import android.view.View;
-import com.android.bitmap.BitmapCache;
-import com.android.bitmap.drawable.BasicBitmapDrawable;
+import com.android.bitmap.view.BasicImageView;
-public class BitmapView extends View {
- private BasicBitmapDrawable mBitmapDrawable;
+public class BitmapView extends BasicImageView {
private float mDensity;
public BitmapView(Context c) {
@@ -44,22 +40,6 @@ public class BitmapView extends View {
@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
- mBitmapDrawable.setDecodeDimensions(w, h);
+ getDrawable().setDecodeDimensions(w, h);
}
-
- public void setImage(String uriString) {
- if (mBitmapDrawable != null) {
- mBitmapDrawable.bind(new BitmapRequestKeyImpl(uriString));
- }
- }
-
- public void initialize(BitmapCache cache) {
- mBitmapDrawable = new BasicBitmapDrawable(getResources(), cache, true /* limitDensity */);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- setBackground(mBitmapDrawable);
- } else {
- setBackgroundDrawable(mBitmapDrawable);
- }
- }
-
} \ No newline at end of file
diff --git a/sample/src/com/example/bitmapsample/MainActivity.java b/sample/src/com/example/bitmapsample/MainActivity.java
index 6db2bc5..f580dd8 100644
--- a/sample/src/com/example/bitmapsample/MainActivity.java
+++ b/sample/src/com/example/bitmapsample/MainActivity.java
@@ -25,7 +25,7 @@ import android.widget.ListView;
import com.android.bitmap.BitmapCache;
import com.android.bitmap.UnrefedBitmapCache;
-import com.android.bitmap.util.Trace;
+import com.android.bitmap.drawable.BasicBitmapDrawable;
public class MainActivity extends Activity {
private ListView mListView;
@@ -91,9 +91,11 @@ public class MainActivity extends Activity {
v = (BitmapView) convertView;
} else {
v = new BitmapView(MainActivity.this);
- v.initialize(mCache);
+ final BasicBitmapDrawable drawable = new BasicBitmapDrawable(getResources(), mCache,
+ true /* limit density */);
+ v.setDrawable(drawable);
}
- v.setImage(mItems[position]);
+ v.getDrawable().bind(new BitmapRequestKeyImpl(mItems[position]));
return v;
}
}