Skip to content

Commit

Permalink
refactoring the demo app -
Browse files Browse the repository at this point in the history
renaming methods to be clearer in what they do
broke down the setviewvalue into clear methods
renaming of base activity and its layout xml
  • Loading branch information
Adam committed Jan 17, 2013
1 parent 8ffb180 commit 4920d7f
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Refresh" />
android:text="Notify Dataset" />

<Button
android:id="@+id/null_tag_button"
android:id="@+id/cache_mode_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Null Tag" />

<Button
android:id="@+id/null_url_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Null URL" />
android:text="Use Cache only" />

</LinearLayout>

Expand Down
60 changes: 29 additions & 31 deletions demo/src/com/novoda/imageloader/demo/activity/BigImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,21 @@
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;

import com.novoda.imageloader.core.ImageManager;
import com.novoda.imageloader.core.OnImageLoadedListener;
import com.novoda.imageloader.core.model.ImageTag;
import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.demo.DemoApplication;
import com.novoda.imageloader.demo.R;
import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
import com.novoda.imageloader.demo.activity.base.ImageLoaderBaseListActivity;

import java.util.Locale;

/**
* This is an example using really big images and see how the image loader can keep up with the memory limitations of android.
*/
public class BigImages extends SingleTableBaseListActivity implements OnImageLoadedListener {
public class BigImages extends ImageLoaderBaseListActivity implements OnImageLoadedListener {

private final static String TAG = DemoApplication.class.getSimpleName().toLowerCase(Locale.UK);

/**
* TODO Generally we can keep an instance of the image loader and the imageTagFactory.
*/
private ImageManager imageManager;
private ImageTagFactory imageTagFactory;
private static final String TAG = DemoApplication.class.getSimpleName().toLowerCase(Locale.UK);

@Override
protected String getTableName() {
Expand All @@ -38,15 +31,11 @@ protected String getTableName() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_table_base_list_activity);

/**
* TODO Need to prepare imageLoader and imageTagFactory
* TODO Need to prepare imageLoader and imageTagFactory, generally we keep and instance of ImageManager and ImageTagFactory
*/
initImageLoader();

setAdapter();
initButtons();
}

private void initImageLoader() {
Expand Down Expand Up @@ -74,20 +63,29 @@ public void onImageLoaded(ImageView imageView) {
Log.i(TAG, "ImageView URL : " + ((ImageTag) imageView.getTag()).getUrl());
}

/**
* TODO Generally you will have a binder where you have to set the image. This is an example of using the imageManager to load
*/
@Override
protected ViewBinder getViewBinder() {
return new ViewBinder() {

@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
((ImageView) view).setTag(buildTagWithButtonOptions(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
};
}
/**
* TODO Generally you will have a binder where you have to set the tag and load the image.
*/
@Override
protected ViewBinder getViewBinder() {
return new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
setImageTag((ImageView) view, url);
loadImage((ImageView) view);
return true;
}

};
}

private void setImageTag(ImageView view, String url) {
view.setTag(imageTagFactory.build(url, this));
}

private void loadImage(ImageView view) {
imageManager.getLoader().load(view);
}

}
53 changes: 25 additions & 28 deletions demo/src/com/novoda/imageloader/demo/activity/ImageLongList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,21 @@
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;

import com.novoda.imageloader.core.ImageManager;
import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.demo.DemoApplication;
import com.novoda.imageloader.demo.R;
import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
import com.novoda.imageloader.demo.activity.base.ImageLoaderBaseListActivity;

import java.util.Locale;

/**
* Example of setting a specific image size. Not that you can ask the imageLoader to store the small image as files. In this way you don't need to scale images
* every time
*/
public class ImageLongList extends SingleTableBaseListActivity {
public class ImageLongList extends ImageLoaderBaseListActivity {

private static final int SIZE = 400;

/**
* TODO Generally we can keep an instance of the image loader and the imageTagFactory.
*/
private ImageManager imageManager;
private ImageTagFactory imageTagFactory;

@Override
protected String getTableName() {
return ImageLongList.class.getSimpleName().toLowerCase(Locale.UK);
Expand All @@ -36,15 +29,11 @@ protected String getTableName() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_table_base_list_activity);

/**
* TODO Need to prepare imageLoader and imageTagFactory
* TODO Need to prepare imageLoader and imageTagFactory, generally we keep and instance of ImageManager and ImageTagFactory
*/
initImageLoader();

setAdapter();
initButtons();
}

private void initImageLoader() {
Expand All @@ -56,20 +45,28 @@ private void initImageLoader() {
}

/**
* TODO Generally you will have a binder where you have to set the image. This is an example of using the imageManager to load
*/
@Override
protected ViewBinder getViewBinder() {
return new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
((ImageView) view).setTag(buildTagWithButtonOptions(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
* TODO Generally you will have a binder where you have to set the tag and load the image.
*/
@Override
protected ViewBinder getViewBinder() {
return new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
setImageTag((ImageView) view, url);
loadImage((ImageView) view);
return true;
}

};
}
};
}

private void setImageTag(ImageView view, String url) {
view.setTag(imageTagFactory.build(url, this));
}

private void loadImage(ImageView view) {
imageManager.getLoader().load(view);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,37 @@
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;

import com.novoda.imageloader.core.ImageManager;
import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.demo.DemoApplication;
import com.novoda.imageloader.demo.R;
import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
import com.novoda.imageloader.demo.activity.base.ImageLoaderBaseListActivity;

import java.util.Locale;

/**
* Very similar to imageLongList example.
*/
public class LongSmallImageList extends SingleTableBaseListActivity {
public class LongSmallImageList extends ImageLoaderBaseListActivity {

private static final int SIZE = 80;

/**
* TODO Generally we can keep an instance of the image loader and the imageTagFactory.
*/
private ImageManager imageManager;
private ImageTagFactory imageTagFactory;

@Override
protected String getTableName() {
return LongSmallImageList.class.getSimpleName().toLowerCase(Locale.UK);
}

@Override
protected int getImageItem() {
protected int getImageItemLayout() {
return R.layout.small_image_item;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_table_base_list_activity);

/**
* TODO Need to prepare imageLoader and imageTagFactory
* TODO Need to prepare imageLoader and imageTagFactory, generally we keep and instance of ImageManager and ImageTagFactory
*/
initImageLoader();

setAdapter();
initButtons();
}

private void initImageLoader() {
Expand All @@ -68,20 +56,28 @@ private ImageTagFactory createImageTagFactory() {
}

/**
* Generally you will have a binder where you have to set the image. This is an example of using the imageManager to load
* TODO Generally you will have a binder where you have to set the tag and load the image.
*/
@Override
protected ViewBinder getViewBinder() {
return new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
((ImageView) view).setTag(buildTagWithButtonOptions(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
setImageTag((ImageView) view, url);
loadImage((ImageView) view);
return true;
}

};
}

private void setImageTag(ImageView view, String url) {
view.setTag(imageTagFactory.build(url, this));
}

private void loadImage(ImageView view) {
imageManager.getLoader().load(view);
}

}
Loading

0 comments on commit 4920d7f

Please sign in to comment.