Skip to content
Browse files

ResourcesFinder as asynctask

  • Loading branch information...
1 parent 1f42594 commit 1f5e8c75e400216bc964d58e3eb674257bf74118 lkong committed Nov 4, 2011
View
BIN bin/classes.dex
Binary file not shown.
View
BIN bin/classes/org/isec/hci/MiniGODS/ImageAdapter.class
Binary file not shown.
View
BIN bin/classes/org/isec/hci/MiniGODS/MiniGODSActivity$1.class
Binary file not shown.
View
BIN bin/classes/org/isec/hci/MiniGODS/MiniGODSActivity.class
Binary file not shown.
View
BIN bin/miniGODS.apk
Binary file not shown.
View
60 src/org/isec/hci/MiniGODS/ImageAdapter.java
@@ -28,25 +28,48 @@
private ArrayList<URL> ImageURLs;
public Hashtable<URL,Bitmap> ImageBMPs;
private ResourcesGrabber resourcesGrabber;
+ public boolean isURLsEmpty()
+ {
+ if (ImageURLs.size()==0)
+ return true;
+ else
+ return false;
+ }
+ public synchronized void addURL(URL url)
+ {
+ ImageURLs.add(url);
+ this.notifyDataSetChanged();
+ }
+ public synchronized void removeURL(int pos)
+ {
+ //ImageBMPs.remove(ImageURLs.get(pos));
+ ImageURLs.remove(pos);
+ this.notifyDataSetChanged();
+ }
+
+ public synchronized void removeURL(URL url)
+ {
+ //if (ResourcesGrabber.imageURLs.contains(url))
+ ImageURLs.remove(url);
+ this.notifyDataSetChanged();
+ }
+
+
public ImageAdapter(Context c) {
mContext = c;
- ImageURLs=new ArrayList<URL>();
- ImageBMPs=new Hashtable<URL,Bitmap>();
-
- try {
- ImageURLs.add(new URL("http://dl.dropbox.com/u/5715087/honeybadger00.jpg"));
- ImageURLs.add(new URL("http://dl.dropbox.com/u/5715087/honeybadger01.jpg"));
- ImageURLs.add(new URL("http://dl.dropbox.com/u/5715087/llama00.jpg"));
- ImageURLs.add(new URL("http://dl.dropbox.com/u/5715087/llama01.jpg"));
- ImageURLs.add(new URL("http://dl.dropbox.com/u/5715087/llama.jpg"));
- } catch (MalformedURLException e) {
+ ResourcesFinder Finder=new ResourcesFinder();
+ Finder.execute();
+ try {
+ ImageURLs=Finder.get();
+ }catch (InterruptedException e) {
+
+ } catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private synchronized Bitmap getBitmap(int pos)
{
-
return ImageBMPs.get(pos);
}
public synchronized void addBitmap(URL url,Bitmap BMP)
@@ -67,6 +90,12 @@ public Object getItem(int position) {
public long getItemId(int position) {
return 0;
}
+
+ @Override
+ public void notifyDataSetChanged() {
+
+ super.notifyDataSetChanged();
+ }
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
@@ -76,13 +105,18 @@ public View getView(int position, View convertView, ViewGroup parent) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
- imageView.setPadding(8, 8, 8, 8);
+
+ imageView.setPadding(5, 5, 5, 5);
} else {
imageView = (ImageView) convertView;
}
+
ResourcesGrabber Grabber=new ResourcesGrabber(mContext);
- Grabber.execute(ImageURLs.get(position));
+ ResourcesFinder Finder=new ResourcesFinder();
+ Finder.execute();
try {
+ ImageURLs=Finder.get();
+ Grabber.execute(ImageURLs.get(position));
imageView.setImageBitmap(Grabber.get());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
View
14 src/org/isec/hci/MiniGODS/MiniGODSActivity.java
@@ -14,21 +14,25 @@
public class MiniGODSActivity extends Activity {
/** Called when the activity is first created. */
- @Override
+ GridView gridview;
+ @Override
public void onCreate(Bundle savedInstanceState) {
Log.d("GODS","Program running Very Nice");
//System.out.println("Program running Very Nice");
super.onCreate(savedInstanceState);
//EditText editText=(EditText) findViewById(R.id.statusBar);
//editText.setText("begin");
setContentView(R.layout.main);
- GridView gridview = (GridView) findViewById(R.id.ItemgridView);
- ImageAdapter imageAdapter=new ImageAdapter(this);
- gridview.setAdapter(imageAdapter);
+ gridview = (GridView) findViewById(R.id.ItemgridView);
+ //ImageAdapter imageAdapter=new ImageAdapter(this);
+ gridview.setAdapter(new ImageAdapter(this));
+ //gridview.
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(MiniGODSActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
- }
+
+ }
+
}

0 comments on commit 1f5e8c7

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