diff options
Diffstat (limited to 'sample')
17 files changed, 104 insertions, 7 deletions
diff --git a/sample/res/drawable-hdpi/ic_placeholder.png b/sample/res/drawable-hdpi/ic_placeholder.png Binary files differnew file mode 100644 index 0000000..7b05b48 --- /dev/null +++ b/sample/res/drawable-hdpi/ic_placeholder.png diff --git a/sample/res/drawable-hdpi/ic_progress_inner.png b/sample/res/drawable-hdpi/ic_progress_inner.png Binary files differnew file mode 100644 index 0000000..e461e74 --- /dev/null +++ b/sample/res/drawable-hdpi/ic_progress_inner.png diff --git a/sample/res/drawable-hdpi/ic_progress_outer.png b/sample/res/drawable-hdpi/ic_progress_outer.png Binary files differnew file mode 100644 index 0000000..d495aa8 --- /dev/null +++ b/sample/res/drawable-hdpi/ic_progress_outer.png diff --git a/sample/res/drawable-mdpi/ic_placeholder.png b/sample/res/drawable-mdpi/ic_placeholder.png Binary files differnew file mode 100644 index 0000000..752149d --- /dev/null +++ b/sample/res/drawable-mdpi/ic_placeholder.png diff --git a/sample/res/drawable-mdpi/ic_progress_inner.png b/sample/res/drawable-mdpi/ic_progress_inner.png Binary files differnew file mode 100644 index 0000000..0c06981 --- /dev/null +++ b/sample/res/drawable-mdpi/ic_progress_inner.png diff --git a/sample/res/drawable-mdpi/ic_progress_outer.png b/sample/res/drawable-mdpi/ic_progress_outer.png Binary files differnew file mode 100644 index 0000000..46061db --- /dev/null +++ b/sample/res/drawable-mdpi/ic_progress_outer.png diff --git a/sample/res/drawable-xhdpi/ic_placeholder.png b/sample/res/drawable-xhdpi/ic_placeholder.png Binary files differnew file mode 100644 index 0000000..92ed99b --- /dev/null +++ b/sample/res/drawable-xhdpi/ic_placeholder.png diff --git a/sample/res/drawable-xhdpi/ic_progress_inner.png b/sample/res/drawable-xhdpi/ic_progress_inner.png Binary files differnew file mode 100644 index 0000000..273e8e8 --- /dev/null +++ b/sample/res/drawable-xhdpi/ic_progress_inner.png diff --git a/sample/res/drawable-xhdpi/ic_progress_outer.png b/sample/res/drawable-xhdpi/ic_progress_outer.png Binary files differnew file mode 100644 index 0000000..568e9eb --- /dev/null +++ b/sample/res/drawable-xhdpi/ic_progress_outer.png diff --git a/sample/res/drawable-xxhdpi/ic_placeholder.png b/sample/res/drawable-xxhdpi/ic_placeholder.png Binary files differnew file mode 100644 index 0000000..18ac128 --- /dev/null +++ b/sample/res/drawable-xxhdpi/ic_placeholder.png diff --git a/sample/res/drawable-xxhdpi/ic_progress_inner.png b/sample/res/drawable-xxhdpi/ic_progress_inner.png Binary files differnew file mode 100644 index 0000000..c95c1bf --- /dev/null +++ b/sample/res/drawable-xxhdpi/ic_progress_inner.png diff --git a/sample/res/drawable-xxhdpi/ic_progress_outer.png b/sample/res/drawable-xxhdpi/ic_progress_outer.png Binary files differnew file mode 100644 index 0000000..fbf00d3 --- /dev/null +++ b/sample/res/drawable-xxhdpi/ic_progress_outer.png diff --git a/sample/res/drawable/progress.xml b/sample/res/drawable/progress.xml new file mode 100644 index 0000000..2db9837 --- /dev/null +++ b/sample/res/drawable/progress.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 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. +--> +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item> + <rotate + android:drawable="@drawable/ic_progress_outer" + android:pivotX="50%" + android:pivotY="50%" + android:fromDegrees="0" + android:toDegrees="1080" /> + </item> + <item> + <rotate + android:drawable="@drawable/ic_progress_inner" + android:pivotX="50%" + android:pivotY="50%" + android:fromDegrees="720" + android:toDegrees="0" /> + </item> +</layer-list>
\ No newline at end of file diff --git a/sample/res/layout/activity_main.xml b/sample/res/layout/activity_main.xml index 1b29402..d80841d 100644 --- a/sample/res/layout/activity_main.xml +++ b/sample/res/layout/activity_main.xml @@ -23,6 +23,8 @@ <ListView android:id="@+id/list" android:layout_width="match_parent" - android:layout_height="match_parent" /> + android:layout_height="match_parent" + android:divider="@android:color/transparent" + android:dividerHeight="0px"/> </RelativeLayout> diff --git a/sample/src/com/example/bitmapsample/BitmapRequestKeyImpl.java b/sample/src/com/example/bitmapsample/BitmapRequestKeyImpl.java index 6c375f1..eeec78f 100644 --- a/sample/src/com/example/bitmapsample/BitmapRequestKeyImpl.java +++ b/sample/src/com/example/bitmapsample/BitmapRequestKeyImpl.java @@ -27,6 +27,8 @@ public class BitmapRequestKeyImpl implements RequestKey { public final String mUriString; public final URL mUrl; + private boolean mSlept; + public BitmapRequestKeyImpl(String uriString) { mUriString = uriString; URL url = null; @@ -36,6 +38,7 @@ public class BitmapRequestKeyImpl implements RequestKey { e.printStackTrace(); } mUrl = url; + mSlept = false; } @Override @@ -70,6 +73,20 @@ public class BitmapRequestKeyImpl implements RequestKey { @Override public InputStream createInputStream() throws IOException { + // Artificially sleep for (deterministically) random amount of time. + if (!mSlept) { + // Character difference between shortest and longest uri. + final long spread = 26; + // Maximum amount of time to sleep. + final long max = 2; + final long duration = (long) ((float) (mUriString.length() % spread) / spread * max + * 1000); + try { + Thread.sleep(duration); + } catch (InterruptedException ignored) { + } + mSlept = true; + } return mUrl.openStream(); } diff --git a/sample/src/com/example/bitmapsample/BitmapView.java b/sample/src/com/example/bitmapsample/BitmapView.java index f192963..0613168 100644 --- a/sample/src/com/example/bitmapsample/BitmapView.java +++ b/sample/src/com/example/bitmapsample/BitmapView.java @@ -17,13 +17,19 @@ package com.example.bitmapsample; import android.content.Context; +import android.graphics.Canvas; import android.util.AttributeSet; +import android.widget.ListView; import com.android.bitmap.drawable.BasicBitmapDrawable; +import com.android.bitmap.drawable.ExtendedBitmapDrawable; import com.android.bitmap.view.BitmapDrawableImageView; public class BitmapView extends BitmapDrawableImageView { - private float mDensity; + private final float mDensity; + + private ListView mListView; + private float mParallaxSpeedMultiplier; public BitmapView(Context c) { this(c, null); @@ -41,6 +47,24 @@ public class BitmapView extends BitmapDrawableImageView { @Override protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { - getBasicBitmapDrawable().setDecodeDimensions(w, h); + ExtendedBitmapDrawable drawable = (ExtendedBitmapDrawable) getBasicBitmapDrawable(); + drawable.setDecodeDimensions(w, (int) (h * mParallaxSpeedMultiplier)); + } + + public void setListView(final ListView listView) { + mListView = listView; + } + + @Override + protected void onDraw(final Canvas canvas) { + ExtendedBitmapDrawable drawable = (ExtendedBitmapDrawable) getBasicBitmapDrawable(); + float fraction = (float) getBottom() / (mListView.getHeight() + getHeight()); + drawable.setParallaxFraction(fraction); + + super.onDraw(canvas); + } + + public void setParallaxSpeedMultiplier(final float parallaxSpeedMultiplier) { + mParallaxSpeedMultiplier = parallaxSpeedMultiplier; } }
\ 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 4ad18e5..96e99ec 100644 --- a/sample/src/com/example/bitmapsample/MainActivity.java +++ b/sample/src/com/example/bitmapsample/MainActivity.java @@ -17,6 +17,8 @@ package com.example.bitmapsample; import android.app.Activity; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -24,19 +26,33 @@ import android.widget.BaseAdapter; import android.widget.ListView; import com.android.bitmap.BitmapCache; +import com.android.bitmap.DecodeAggregator; import com.android.bitmap.UnrefedBitmapCache; -import com.android.bitmap.drawable.BasicBitmapDrawable; +import com.android.bitmap.drawable.ExtendedBitmapDrawable; public class MainActivity extends Activity { + private ListView mListView; + private final BitmapCache mCache = new UnrefedBitmapCache(TARGET_CACHE_SIZE_BYTES, 0.1f, 0); + private final DecodeAggregator mDecodeAggregator = new DecodeAggregator(); + private static Drawable PLACEHOLDER; + private static Drawable PROGRESS; + + private static final float NORMAL_PARALLAX_MULTIPLIER = 1.5f; private static final int TARGET_CACHE_SIZE_BYTES = 5 * 1024 * 1024; - private final BitmapCache mCache = new UnrefedBitmapCache(TARGET_CACHE_SIZE_BYTES, 0.1f, 0); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + if (PLACEHOLDER == null) { + Resources res = getResources(); + PLACEHOLDER = res.getDrawable(R.drawable.ic_placeholder); + PROGRESS = res.getDrawable(R.drawable.progress); + } + mListView = (ListView) findViewById(R.id.list); mListView.setAdapter(new MyAdapter()); } @@ -91,9 +107,13 @@ public class MainActivity extends Activity { v = (BitmapView) convertView; } else { v = new BitmapView(MainActivity.this); - final BasicBitmapDrawable drawable = new BasicBitmapDrawable(getResources(), mCache, - true /* limit density */); + final ExtendedBitmapDrawable drawable = new ExtendedBitmapDrawable(getResources(), + mCache, true /* limit density */, mDecodeAggregator, PLACEHOLDER, PROGRESS); + drawable.setParallaxSpeedMultiplier(NORMAL_PARALLAX_MULTIPLIER); + v.setBasicBitmapDrawable(drawable); + v.setListView(mListView); + v.setParallaxSpeedMultiplier(NORMAL_PARALLAX_MULTIPLIER); } v.getBasicBitmapDrawable().bind(new BitmapRequestKeyImpl(mItems[position])); return v; |