diff --git a/HW4/res/layout/activity_image_viewer.xml b/HW4/res/layout/activity_image_viewer.xml
index e4a7da6..3748216 100644
--- a/HW4/res/layout/activity_image_viewer.xml
+++ b/HW4/res/layout/activity_image_viewer.xml
@@ -1,7 +1,9 @@
-
+ android:id="@+id/imgViewer"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_horizontal"
+ android:scaleType="centerInside" />
+ android:layout_gravity="bottom" >
+ android:onClick="onClickPrev"
+ android:text="@string/btnPrev" />
+ android:onClick="onClickBack"
+ android:text="@string/btnBack" />
+ android:onClick="onClickNext"
+ android:text="@string/btnNext" />
-
+
\ No newline at end of file
diff --git a/HW4/res/values/colors.xml b/HW4/res/values/colors.xml
new file mode 100644
index 0000000..e3e1581
--- /dev/null
+++ b/HW4/res/values/colors.xml
@@ -0,0 +1,19 @@
+
+
+ #FFFFFF
+ #FFFF00
+ #FF00FF
+ #FF0000
+ #C0C0C0
+ #808080
+ #808000
+ #800080
+ #800000
+ #00FFFF
+ #00FF00
+ #008080
+ #008000
+ #0000FF
+ #000080
+ #000000
+
\ No newline at end of file
diff --git a/HW4/src/com/example/hw4/ImageViewerActivity.java b/HW4/src/com/example/hw4/ImageViewerActivity.java
index aa8cf78..a0aeafa 100644
--- a/HW4/src/com/example/hw4/ImageViewerActivity.java
+++ b/HW4/src/com/example/hw4/ImageViewerActivity.java
@@ -1,17 +1,24 @@
package com.example.hw4;
+import java.net.URL;
+
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
+import android.app.ProgressDialog;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
+import android.widget.ImageView;
public class ImageViewerActivity extends Activity {
int urlsId;
String[] urls;
int currentIndex;
+
+ ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -22,6 +29,8 @@ public class ImageViewerActivity extends Activity {
urlsId = extras.getInt("urls");
urls = getResources().getStringArray(urlsId);
currentIndex = extras.getInt("index");
+
+ displayImage(currentIndex);
}
@Override
@@ -44,30 +53,50 @@ public class ImageViewerActivity extends Activity {
}
private void displayPrev() {
- currentIndex -= 1;
+ // Wrapping backwards requires more than just modulo
+ if (currentIndex == 0)
+ currentIndex = urls.length - 1;
+ else
+ currentIndex -= 1;
+
displayImage(currentIndex);
}
private void displayNext() {
- currentIndex += 1;
+ currentIndex = (currentIndex + 1) % urls.length;
displayImage(currentIndex);
}
public void displayImage(int indexToDisplay) {
-
-
+ ImageView view = (ImageView)findViewById(R.id.imgViewer);
+ view.setImageBitmap(null);
+ new ImageDownloader().execute(urls[indexToDisplay]);
+ dialog = new ProgressDialog(this);
+ dialog.setCancelable(false);
+ dialog.show();
}
private class ImageDownloader extends AsyncTask {
@Override
protected Bitmap doInBackground(String... params) {
+ try
+ {
+ URL imageUrl = new URL(params[0]);
+ return BitmapFactory.decodeStream(imageUrl.openStream());
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+
return null;
}
@Override
protected void onPostExecute(Bitmap result) {
- // TODO Auto-generated method stub
- super.onPostExecute(result);
+ dialog.cancel();
+ ImageView view = (ImageView)findViewById(R.id.imgViewer);
+ view.setImageBitmap(result);
}
}