mirror of
https://github.com/bspeice/itcs4180
synced 2025-04-21 07:11:35 -04:00
Add (almost) everything for the ImageViewer activity
Still needs gesture recognition
This commit is contained in:
parent
00f1f80d1a
commit
8a1acefb21
@ -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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/FrameLayout1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/black"
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
@ -9,43 +11,40 @@
|
|||||||
tools:context=".ImageViewerActivity" >
|
tools:context=".ImageViewerActivity" >
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView1"
|
android:id="@+id/imgViewer"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="fill_parent"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_alignParentLeft="true"
|
android:scaleType="centerInside" />
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentTop="true" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_gravity="bottom" >
|
||||||
android:layout_alignParentLeft="true" >
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnPrev"
|
android:id="@+id/btnPrev"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/btnPrev"
|
android:onClick="onClickPrev"
|
||||||
android:onClick="onClickPrev" />
|
android:text="@string/btnPrev" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnBack"
|
android:id="@+id/btnBack"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/btnBack"
|
android:onClick="onClickBack"
|
||||||
android:onClick="onClickBack" />
|
android:text="@string/btnBack" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnNext"
|
android:id="@+id/btnNext"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/btnNext"
|
android:onClick="onClickNext"
|
||||||
android:onClick="onClickNext" />
|
android:text="@string/btnNext" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</FrameLayout>
|
19
HW4/res/values/colors.xml
Normal file
19
HW4/res/values/colors.xml
Normal 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>
|
@ -1,11 +1,16 @@
|
|||||||
package com.example.hw4;
|
package com.example.hw4;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
public class ImageViewerActivity extends Activity {
|
public class ImageViewerActivity extends Activity {
|
||||||
|
|
||||||
@ -13,6 +18,8 @@ public class ImageViewerActivity extends Activity {
|
|||||||
String[] urls;
|
String[] urls;
|
||||||
int currentIndex;
|
int currentIndex;
|
||||||
|
|
||||||
|
ProgressDialog dialog;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -22,6 +29,8 @@ public class ImageViewerActivity extends Activity {
|
|||||||
urlsId = extras.getInt("urls");
|
urlsId = extras.getInt("urls");
|
||||||
urls = getResources().getStringArray(urlsId);
|
urls = getResources().getStringArray(urlsId);
|
||||||
currentIndex = extras.getInt("index");
|
currentIndex = extras.getInt("index");
|
||||||
|
|
||||||
|
displayImage(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,30 +53,50 @@ public class ImageViewerActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void displayPrev() {
|
private void displayPrev() {
|
||||||
|
// Wrapping backwards requires more than just modulo
|
||||||
|
if (currentIndex == 0)
|
||||||
|
currentIndex = urls.length - 1;
|
||||||
|
else
|
||||||
currentIndex -= 1;
|
currentIndex -= 1;
|
||||||
|
|
||||||
displayImage(currentIndex);
|
displayImage(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayNext() {
|
private void displayNext() {
|
||||||
currentIndex += 1;
|
currentIndex = (currentIndex + 1) % urls.length;
|
||||||
displayImage(currentIndex);
|
displayImage(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayImage(int indexToDisplay) {
|
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> {
|
private class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap doInBackground(String... params) {
|
protected Bitmap doInBackground(String... params) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URL imageUrl = new URL(params[0]);
|
||||||
|
return BitmapFactory.decodeStream(imageUrl.openStream());
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Bitmap result) {
|
protected void onPostExecute(Bitmap result) {
|
||||||
// TODO Auto-generated method stub
|
dialog.cancel();
|
||||||
super.onPostExecute(result);
|
ImageView view = (ImageView)findViewById(R.id.imgViewer);
|
||||||
|
view.setImageBitmap(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user