Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file modified bin/TweetView.apk
Binary file not shown.
Binary file modified bin/classes.dex
Binary file not shown.
Binary file modified bin/com/example/Example.class
Binary file not shown.
Binary file modified bin/com/example/ImageManager$BitmapDisplayer.class
Binary file not shown.
Binary file modified bin/com/example/ImageManager$ImageQueue.class
Binary file not shown.
Binary file modified bin/com/example/ImageManager$ImageQueueManager.class
Binary file not shown.
Binary file modified bin/com/example/ImageManager$ImageRef.class
Binary file not shown.
Binary file modified bin/com/example/ImageManager.class
Binary file not shown.
Binary file modified bin/com/example/R$id.class
Binary file not shown.
Binary file modified bin/com/example/R$layout.class
Binary file not shown.
Binary file modified bin/com/example/R$string.class
Binary file not shown.
Binary file modified bin/com/example/TweetItemAdapter$ViewHolder.class
Binary file not shown.
Binary file modified bin/com/example/TweetItemAdapter.class
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
7 changes: 4 additions & 3 deletions gen/com/example/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int ListViewId=0x7f050003;
public static final int ListViewId=0x7f050004;
public static final int avatar=0x7f050000;
public static final int message=0x7f050002;
public static final int username=0x7f050001;
public static final int message=0x7f050003;
public static final int progress_bar=0x7f050001;
public static final int username=0x7f050002;
}
public static final class layout {
public static final int listitem=0x7f030000;
Expand Down
21 changes: 19 additions & 2 deletions res/layout/listitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@
android:paddingTop="5px"
android:paddingLeft="5px">

<ImageView
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent">

<ImageView
android:layout_centerVertical="true"
android:id="@+id/avatar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/icon" />
android:visibility="gone" />
<ProgressBar
android:layout_centerVertical="true"
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="30dip"
android:minWidth="30dip"
android:maxHeight="30dip"
android:minHeight="30dip"
android:layout_marginRight="6dip"
android:indeterminate="true" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
Expand Down
48 changes: 32 additions & 16 deletions src/com/example/ImageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class ImageManager {

Expand Down Expand Up @@ -39,20 +41,25 @@ public ImageManager(Context context) {
cacheDir.mkdirs();
}

public void displayImage(String url, Activity activity, ImageView imageView) {
if(imageMap.containsKey(url))
public void displayImage(String url, Activity activity, ImageView imageView, ProgressBar progressBar) {
if(imageMap.containsKey(url)) {
imageView.setImageBitmap(imageMap.get(url));
progressBar.setVisibility(View.GONE); //ADDED
imageView.setVisibility(View.VISIBLE); //ADDED
}
else {
queueImage(url, activity, imageView);
imageView.setImageResource(R.drawable.icon);
queueImage(url, activity, imageView, progressBar);
//imageView.setImageResource(R.drawable.icon);
imageView.setVisibility(View.GONE); //ADDED
progressBar.setVisibility(View.VISIBLE); //ADDED
}
}

private void queueImage(String url, Activity activity, ImageView imageView) {
private void queueImage(String url, Activity activity, ImageView imageView, ProgressBar progressBar) {
// This ImageView might have been used for other images, so we clear
// the queue of old tasks before starting.
imageQueue.Clean(imageView);
ImageRef p=new ImageRef(url, imageView);
ImageRef p=new ImageRef(url, imageView, progressBar);

synchronized(imageQueue.imageRefs) {
imageQueue.imageRefs.push(p);
Expand Down Expand Up @@ -105,10 +112,12 @@ private void writeFile(Bitmap bmp, File f) {
private class ImageRef {
public String url;
public ImageView imageView;
public ProgressBar progressBar;

public ImageRef(String u, ImageView i) {
url=u;
imageView=i;
public ImageRef(String u, ImageView i, ProgressBar p) {
url = u;
imageView = i;
progressBar = p;
}
}

Expand Down Expand Up @@ -156,7 +165,7 @@ public void run() {
// Make sure we have the right view - thread safety defender
if(tag != null && ((String)tag).equals(imageToLoad.url)) {
BitmapDisplayer bmpDisplayer =
new BitmapDisplayer(bmp, imageToLoad.imageView);
new BitmapDisplayer(bmp, imageToLoad.imageView, imageToLoad.progressBar);

Activity a =
(Activity)imageToLoad.imageView.getContext();
Expand All @@ -176,17 +185,24 @@ public void run() {
private class BitmapDisplayer implements Runnable {
Bitmap bitmap;
ImageView imageView;
ProgressBar progressBar;

public BitmapDisplayer(Bitmap b, ImageView i) {
bitmap=b;
imageView=i;
public BitmapDisplayer(Bitmap b, ImageView i, ProgressBar p) {
bitmap = b;
imageView = i;
progressBar = p;
}

public void run() {
if(bitmap != null)
if(bitmap != null) {
imageView.setImageBitmap(bitmap);
else
imageView.setImageResource(R.drawable.icon);
progressBar.setVisibility(View.GONE); //ADDED
imageView.setVisibility(View.VISIBLE); //ADDED
}
else {
imageView.setVisibility(View.GONE); //ADDED
progressBar.setVisibility(View.VISIBLE); //ADDED
}
}
}
}
5 changes: 4 additions & 1 deletion src/com/example/TweetItemAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class TweetItemAdapter extends ArrayAdapter<Tweet> {
Expand All @@ -31,6 +32,7 @@ public static class ViewHolder{
public TextView username;
public TextView message;
public ImageView image;
public ProgressBar progress; //ADDED
}

@Override
Expand All @@ -45,6 +47,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.username = (TextView) v.findViewById(R.id.username);
holder.message = (TextView) v.findViewById(R.id.message);
holder.image = (ImageView) v.findViewById(R.id.avatar);
holder.progress = (ProgressBar) v.findViewById(R.id.progress_bar); //ADDED
v.setTag(holder);
}
else
Expand All @@ -55,7 +58,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.username.setText(tweet.username);
holder.message.setText(tweet.message);
holder.image.setTag(tweet.image_url);
imageManager.displayImage(tweet.image_url, activity, holder.image);
imageManager.displayImage(tweet.image_url, activity, holder.image, holder.progress); //CHANGED
}
return v;
}
Expand Down