diff --git a/InClass3/project.properties b/InClass3/project.properties
index 4ab1256..6759fcc 100644
--- a/InClass3/project.properties
+++ b/InClass3/project.properties
@@ -12,3 +12,4 @@
# Project target.
target=android-19
+android.library.reference.1=../../../workspace/gridlayout_v7
diff --git a/InClass3/res/layout/activity_photo.xml b/InClass3/res/layout/activity_photo.xml
index 2ff3dd9..386c367 100644
--- a/InClass3/res/layout/activity_photo.xml
+++ b/InClass3/res/layout/activity_photo.xml
@@ -1,11 +1,28 @@
-
-
+
+
+
+
+
diff --git a/InClass3/res/values/integers.xml b/InClass3/res/values/integers.xml
new file mode 100644
index 0000000..d2e771d
--- /dev/null
+++ b/InClass3/res/values/integers.xml
@@ -0,0 +1,5 @@
+
+
+ 2
+ 2
+
diff --git a/InClass3/res/values/strings.xml b/InClass3/res/values/strings.xml
index 9ae6218..a802a4e 100644
--- a/InClass3/res/values/strings.xml
+++ b/InClass3/res/values/strings.xml
@@ -10,5 +10,6 @@
http://farm9.staticflickr.com/8441/7882624916_5f62cb318f_z.jpg
UNC Charlotte Photos
UNC Charlotte Photos
+ Exit
diff --git a/InClass3/src/edu/uncc/itcs4180/hw4/PhotoActivity.java b/InClass3/src/edu/uncc/itcs4180/hw4/PhotoActivity.java
index 0c9c8dd..de75b40 100644
--- a/InClass3/src/edu/uncc/itcs4180/hw4/PhotoActivity.java
+++ b/InClass3/src/edu/uncc/itcs4180/hw4/PhotoActivity.java
@@ -1,15 +1,63 @@
package edu.uncc.itcs4180.hw4;
+import java.net.URL;
+import java.util.ArrayList;
+
+import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.view.Menu;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.Button;
+import android.widget.GridView;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
public class PhotoActivity extends Activity {
+ ProgressDialog progress;
+ LinearLayout root;
+ GridView photoGrid;
+ public int[] imageUrlIds = {R.string.uncc_main_image, R.string.football_main_image,
+ R.string.ifest_main_image, R.string.commencement_main_image
+ };
+ ArrayList bitmapList = new ArrayList();
+ int downloadProgress;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
+
+ root = (LinearLayout)findViewById(R.id.LinearLayout1);
+ photoGrid = (GridView)findViewById(R.id.GridView1);
+ downloadProgress = 0;
+
+ //set the progress dialog
+ progress = new ProgressDialog(this);
+ progress.setMessage("Loading...");
+ progress.setCancelable(false);
+ progress.show();
+
+ for(int x : imageUrlIds)//download images
+ {
+ new DownloadPhoto().execute(getString(x));
+ }
+
+ //create exit button
+ Button exit = (Button)findViewById(R.id.ExitButton);
+ exit.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v)
+ {
+ finish();
+ }
+ });
}
@Override
@@ -18,5 +66,90 @@ public class PhotoActivity extends Activity {
getMenuInflater().inflate(R.menu.photo, menu);
return true;
}
+
+ private class DownloadPhoto extends AsyncTask
+ {
+ @Override
+ protected Bitmap doInBackground(String... url)
+ {
+ Bitmap image = null;
+
+ try
+ {
+ URL imageUrl = new URL(url[0]);
+ image = BitmapFactory.decodeStream(imageUrl.openStream());
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ return image;
+ }
+
+ @Override
+ protected void onPostExecute(Bitmap result)
+ {
+ if (result == null)//set failed images to a default image
+ {
+ //set blank image
+ }
+ bitmapList.add(result);
+
+ downloadProgress++;
+ if(downloadProgress>=imageUrlIds.length)
+ {
+ progress.dismiss();
+ photoGrid.setAdapter(new ImageAdapter(photoGrid.getContext()));
+ }
+ }
+ }
+
+ public class ImageAdapter extends BaseAdapter
+ {
+ private Context context;
+
+ public ImageAdapter(Context context)
+ {
+ this.context = context;
+ }
+
+ @Override
+ public int getCount()
+ {
+ return imageUrlIds.length;
+ }
+
+ @Override
+ public Object getItem(int position)
+ {
+ return position;
+ }
+
+ @Override
+ public long getItemId(int position)
+ {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent)
+ {
+ ImageView newImageView = new ImageView(getBaseContext());
+
+ if(convertView == null)
+ {
+ newImageView.setLayoutParams(new GridView.LayoutParams(
+ 140, 140));
+ newImageView.setPadding(5, 5, 5, 5);
+ }
+ else
+ {
+ newImageView = (ImageView) convertView;
+ }
+ newImageView.setImageBitmap(bitmapList.get(position));
+
+ return newImageView;
+ }
+ }
}