1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-11-13 19:08:20 -05:00

Add (almost) everything for the ImageViewer activity

Still needs gesture recognition
This commit is contained in:
DjBushido 2014-03-24 14:41:32 -04:00
parent 00f1f80d1a
commit 8a1acefb21
3 changed files with 70 additions and 23 deletions

View File

@ -1,7 +1,9 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
@ -9,43 +11,40 @@
tools:context=".ImageViewerActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
android:id="@+id/imgViewer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
android:layout_gravity="bottom" >
<Button
android:id="@+id/btnPrev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btnPrev"
android:onClick="onClickPrev" />
android:onClick="onClickPrev"
android:text="@string/btnPrev" />
<Button
android:id="@+id/btnBack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btnBack"
android:onClick="onClickBack" />
android:onClick="onClickBack"
android:text="@string/btnBack" />
<Button
android:id="@+id/btnNext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btnNext"
android:onClick="onClickNext" />
android:onClick="onClickNext"
android:text="@string/btnNext" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>

19
HW4/res/values/colors.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="yellow">#FFFF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="red">#FF0000</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="olive">#808000</color>
<color name="purple">#800080</color>
<color name="maroon">#800000</color>
<color name="aqua">#00FFFF</color>
<color name="lime">#00FF00</color>
<color name="teal">#008080</color>
<color name="green">#008000</color>
<color name="blue">#0000FF</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
</resources>

View File

@ -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<String, Void, Bitmap> {
@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);
}
}