Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added buttons to control nulling tags and urls

  • Loading branch information...
commit 25d1cc2ff33b5b5516d75f326d92de7a963a1dc3 1 parent fa748c2
@ouchadam ouchadam authored
View
26 demo/res/layout/single_table_base_list_activity.xml
@@ -4,12 +4,32 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
-<!-- added by dwa012 -->
+ <LinearLayout
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:orientation="horizontal">
<Button
android:id="@+id/refresh_button"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="refresh" />
+ android:layout_weight="1"
+ android:text="Refresh" />
+
+ <Button
+ android:id="@+id/null_tag_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" />
+
+ </LinearLayout>
<ListView
android:id="@android:id/android:list"
View
17 demo/src/com/novoda/imageloader/demo/activity/BigImages.java
@@ -4,8 +4,6 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;
import com.novoda.imageloader.core.ImageManager;
@@ -46,18 +44,7 @@ public void onCreate(Bundle savedInstanceState) {
imageTagFactory = ImageTagFactory.getInstance(this, R.drawable.bg_img_loading);
imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
setAdapter();
- initButton();
- }
-
- private void initButton() {
- Button button = (Button) this.findViewById(R.id.refresh_button);
- button.setOnClickListener(new OnClickListener(){
-
- @Override
- public void onClick(View v) {
- refreshData();
- }
- });
+ initButtons();
}
@Override
@@ -84,7 +71,7 @@ protected ViewBinder getViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
+ ((ImageView) view).setTag(getTag(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
View
19 demo/src/com/novoda/imageloader/demo/activity/ImageLongList.java
@@ -3,11 +3,8 @@
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
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;
@@ -49,19 +46,7 @@ public void onCreate(Bundle savedInstanceState) {
imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
imageTagFactory.setSaveThumbnail(true);
setAdapter();
-
- //added by dwa012
- Button button = (Button) this.findViewById(R.id.refresh_button);
- button.setOnClickListener(new OnClickListener(){
-
- @Override
- public void onClick(View v) {
- refreshData();
-
-
- }
-
- });
+ initButtons();
}
/**
@@ -75,7 +60,7 @@ protected ViewBinder getViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
+ ((ImageView) view).setTag(getTag(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
View
23 demo/src/com/novoda/imageloader/demo/activity/LongSmallImageList.java
@@ -3,8 +3,6 @@
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;
import com.novoda.imageloader.core.ImageManager;
@@ -16,13 +14,15 @@
/**
* Very similar to imageLongList example.
*/
-public class LongSmallImageList extends SingleTableBaseListActivity implements OnClickListener {
+public class LongSmallImageList extends SingleTableBaseListActivity {
private static final int SIZE = 80;
private ImageManager imageManager;
private ImageTagFactory imageTagFactory;
-
+ private boolean null_tag;
+ private boolean null_url;
+
@Override
protected String getTableName() {
return LongSmallImageList.class.getSimpleName().toLowerCase();
@@ -41,7 +41,7 @@ public void onCreate(Bundle savedInstanceState) {
imageManager = DemoApplication.getImageLoader();
imageTagFactory = createImageTagFactory();
setAdapter();
- initRefreshButton();
+ initButtons();
}
private ImageTagFactory createImageTagFactory() {
@@ -54,16 +54,6 @@ private ImageTagFactory createImageTagFactory() {
return imageTagFactory;
}
- private void initRefreshButton() {
- Button button = (Button) this.findViewById(R.id.refresh_button);
- button.setOnClickListener(this);
- }
-
- @Override
- public void onClick(View v) {
- refreshData();
- }
-
/**
* Generally you will have a binder where you have to set the image.
* This is an example of using the imageManager to load
@@ -74,11 +64,12 @@ protected ViewBinder getViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
+ ((ImageView) view).setTag(getTag(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
};
}
+
}
View
50 demo/src/com/novoda/imageloader/demo/activity/base/SingleTableBaseListActivity.java
@@ -3,15 +3,22 @@
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
+import android.view.View;
+import android.widget.Button;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorAdapter.ViewBinder;
+import com.novoda.imageloader.core.model.ImageTag;
+import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.demo.R;
-public abstract class SingleTableBaseListActivity extends ListActivity {
+public abstract class SingleTableBaseListActivity extends ListActivity implements View.OnClickListener {
@blundell Owner

Free yourself from the oppressive constraints of ListActivity, all it does it wrap about 3 little methods for you, if you use them pull them in an extend Activity. Will give you more future flexibility. Uh oh did I just say 'future proof' :octocat:

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/app/ListActivity.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
private static final String[] FROM = new String[] { "url" };
private static final int[] TO = new int[] { R.id.list_item_image };
-
+
+ private boolean null_tag;
+ private boolean null_url;
+
private SimpleCursorAdapter adapter;
protected int getImageItem() {
@@ -44,4 +51,43 @@ protected void refreshData(){
adapter.notifyDataSetChanged();
}
+ protected void initButtons() {
+ Button button = (Button) this.findViewById(R.id.refresh_button);
+ button.setOnClickListener(this);
+ button = (Button) this.findViewById(R.id.null_tag_button);
+ button.setOnClickListener(this);
+ button = (Button) this.findViewById(R.id.null_url_button);
+ button.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ switch(v.getId()) {
+ case R.id.refresh_button:
+ null_tag = false;
+ null_url = false;
+ refreshData();
+ break;
+ case R.id.null_tag_button:
+ null_tag = !null_tag;
+ refreshData();
+ break;
+ case R.id.null_url_button:
+ null_url = !null_url;
+ refreshData();
+ break;
+ }
+ }
+
+ protected ImageTag getTag(ImageTagFactory imageTagFactory, String url) {
+ if (null_tag) {
+ return null;
+ }
+ if (null_url) {
+ return imageTagFactory.build(null);
+ }
+ return imageTagFactory.build(url);
+ }
+
+
}
@blundell

Free yourself from the oppressive constraints of ListActivity, all it does it wrap about 3 little methods for you, if you use them pull them in an extend Activity. Will give you more future flexibility. Uh oh did I just say 'future proof' :octocat:

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/app/ListActivity.java

Please sign in to comment.
Something went wrong with that request. Please try again.