Added images to event list.

This commit is contained in:
Robert Kolner committed 2011-12-05 21:12:26 +01:00
1 parent 69b2a438aa
commit 28001df8c6
3 files changed
+51 -5

No files matched your search

+10 -2
View File
@@ -6,21 +6,29 @@
android:paddingTop="3px"
android:paddingBottom="3px">
<ImageView android:id="@+id/event_list_row_image"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:padding="5px"
android:layout_marginRight="5px" />
<TextView android:id="@+id/event_list_row_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/event_list_row_image"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/event_list_row_date"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toRightOf="@id/event_list_row_image"
android:layout_below="@id/event_list_row_text" />
<TextView android:id="@+id/event_list_row_price"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_below="@id/event_list_row_text"
android:layout_alignParentRight="true" />
</RelativeLayout>
+6 -3
View File
@@ -81,13 +81,16 @@ public class Event implements Serializable {
return Uri.parse("http://studentersamfundet.no/vis.php?ID=" + this.id);
}
public Uri getImageUri() {
public Uri getImageUri(int width) {
if (this.id <= 0) {
return null;
}
String imageUri = "http://studentersamfundet.no/imageResize.php?pic=bilder/program/{image}&maxwidth=480";
return Uri.parse(imageUri.replaceAll("{image}", this.image));
String imageUri = "http://studentersamfundet.no/imageResize.php?pic=bilder/program/{img}&maxwidth={width}";
imageUri = imageUri.replace("{img}", this.image);
imageUri = imageUri.replace("{width}", Integer.toString(width));
return Uri.parse(imageUri);
}
public String getPriceString() {
@@ -1,6 +1,10 @@
package com.studentersamfundet.app.ui;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import org.w3c.dom.NodeList;
@@ -8,6 +12,9 @@ import org.w3c.dom.NodeList;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
@@ -20,6 +27,7 @@ import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
@@ -107,6 +115,33 @@ public class EventListActivity extends BaseDnsActivity {
final Event e = getItem(position);
/* Set images: */
ImageView imageView = (ImageView) row.findViewById(R.id.event_list_row_image);
try {
String urlStr = e.getImageUri(60).toString();
URL ulrn = new URL(urlStr);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp) {
int width = bmp.getWidth();
int height = bmp.getHeight();
float scaleWidth = ((float)60) / width;
float scaleHeight = ((float)60) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resized = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, false);
imageView.setImageBitmap(resized);
}
} catch (MalformedURLException ex1){ /* TODO: Default image */
} catch (IOException ex2) { /* TODO: Default image */ }
/* Set text: */
TextView titleView = (TextView) row.findViewById(R.id.event_list_row_text);
titleView.setText(Html.fromHtml(e.title));