List adapters will now get the imageViews size from the resources if

possible
This commit is contained in:
daniel oeh 2012-08-27 14:27:53 +02:00
parent f1e71f6a3e
commit e98ce73ad2
7 changed files with 51 additions and 37 deletions

View File

@ -8,16 +8,15 @@
<ImageView
android:id="@+id/imgvFeedimage"
android:layout_width="55dip"
android:layout_height="55dip"
android:layout_width="@dimen/thumbnail_length"
android:layout_height="@dimen/thumbnail_length"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="1dip"
android:layout_marginRight="4dip"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:scaleType="fitXY"
android:src="@drawable/default_cover" />
android:scaleType="fitXY" />
<TextView
android:id="@+id/txtvNewEps"

View File

@ -5,8 +5,8 @@
<ImageView
android:id="@+id/imgvFeedimage"
android:layout_width="160dip"
android:layout_height="160dip"
android:layout_width="@dimen/thumbnail_length"
android:layout_height="@dimen/thumbnail_length"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="thumbnail_length">160dp</dimen>
</resources>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="widget_margin">8dp</dimen>
<dimen name="thumbnail_length">55dp</dimen>
</resources>

View File

@ -95,13 +95,12 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
}
holder.image.setTag(feed.getImage());
holder.image.post(new Runnable() {
imageLoader.loadThumbnailBitmap(
feed.getImage(),
holder.image,
(int) convertView.getResources().getDimension(
R.dimen.thumbnail_length));
@Override
public void run() {
imageLoader.loadThumbnailBitmap(feed.getImage(), holder.image);
}
});
return convertView;
}

View File

@ -51,15 +51,8 @@ public class SearchlistAdapter extends ArrayAdapter<SearchResult> {
final Feed feed = (Feed) component;
holder.title.setText(feed.getTitle());
holder.subtitle.setVisibility(View.GONE);
holder.cover.post(new Runnable() {
@Override
public void run() {
FeedImageLoader.getInstance().loadThumbnailBitmap(
feed.getImage(), holder.cover);
}
});
FeedImageLoader.getInstance().loadThumbnailBitmap(feed.getImage(),
holder.cover, (int) convertView.getResources().getDimension(R.dimen.thumbnail_length));
} else if (component.getClass() == FeedItem.class) {
final FeedItem item = (FeedItem) component;
holder.title.setText(item.getTitle());
@ -67,14 +60,12 @@ public class SearchlistAdapter extends ArrayAdapter<SearchResult> {
holder.subtitle.setVisibility(View.VISIBLE);
holder.subtitle.setText(result.getSubtitle());
}
holder.cover.post(new Runnable() {
@Override
public void run() {
FeedImageLoader.getInstance().loadThumbnailBitmap(
item.getFeed().getImage(), holder.cover);
}
});
FeedImageLoader.getInstance().loadThumbnailBitmap(
item.getFeed().getImage(),
holder.cover,
(int) convertView.getResources().getDimension(
R.dimen.thumbnail_length));
}

View File

@ -106,10 +106,20 @@ public class FeedImageLoader {
/**
* Load a bitmap from the cover cache. If the bitmap is not in the cache, it
* will be loaded from the disk. This method should either be called if the
* ImageView's size has already been set or inside a Runnable which is posted
* to the ImageView's message queue.
* ImageView's size has already been set or inside a Runnable which is
* posted to the ImageView's message queue.
*/
public void loadCoverBitmap(FeedImage image, ImageView target) {
loadCoverBitmap(image, target, target.getHeight());
}
/**
* Load a bitmap from the cover cache. If the bitmap is not in the cache, it
* will be loaded from the disk. This method should either be called if the
* ImageView's size has already been set or inside a Runnable which is
* posted to the ImageView's message queue.
*/
public void loadCoverBitmap(FeedImage image, ImageView target, int length) {
if (image != null && image.getFile_url() != null) {
Bitmap bitmap = getBitmapFromCoverCache(image.getFile_url());
if (bitmap != null) {
@ -117,8 +127,7 @@ public class FeedImageLoader {
} else {
target.setImageResource(R.drawable.default_cover);
FeedImageDecodeWorkerTask worker = new FeedImageDecodeWorkerTask(
handler, target, image, target.getHeight(),
IMAGE_TYPE_COVER);
handler, target, image, length, IMAGE_TYPE_COVER);
executor.submit(worker);
}
} else {
@ -127,12 +136,22 @@ public class FeedImageLoader {
}
/**
* Load a bitmap from the thumbnail cache. If the bitmap is not in the cache, it
* will be loaded from the disk. This method should either be called if the
* ImageView's size has already been set or inside a Runnable which is posted
* to the ImageView's message queue.
* Load a bitmap from the thumbnail cache. If the bitmap is not in the
* cache, it will be loaded from the disk. This method should either be
* called if the ImageView's size has already been set or inside a Runnable
* which is posted to the ImageView's message queue.
*/
public void loadThumbnailBitmap(FeedImage image, ImageView target) {
loadThumbnailBitmap(image, target, target.getHeight());
}
/**
* Load a bitmap from the thumbnail cache. If the bitmap is not in the
* cache, it will be loaded from the disk. This method should either be
* called if the ImageView's size has already been set or inside a Runnable
* which is posted to the ImageView's message queue.
*/
public void loadThumbnailBitmap(FeedImage image, ImageView target, int length) {
if (image != null && image.getFile_url() != null) {
Bitmap bitmap = getBitmapFromThumbnailCache(image.getFile_url());
if (bitmap != null) {
@ -140,7 +159,7 @@ public class FeedImageLoader {
} else {
target.setImageResource(R.drawable.default_cover);
FeedImageDecodeWorkerTask worker = new FeedImageDecodeWorkerTask(
handler, target, image, target.getHeight(),
handler, target, image, length,
IMAGE_TYPE_THUMBNAIL);
executor.submit(worker);
}