/*
********************* [ P O C K E T C A M P U S ] *****************
* [ LICENCE ] see "licence"-file in the root directory
* [ MAINTAINER ] jonathan.baeriswyl@epfl.ch
* [ STATUS ] used
*
**************************[ C O M M E N T S ]**********************
*
* Dialog that just shows the url picture that was pressed by the user
* It put the picture in a simple ImageView
*
*******************************************************************
*/
package org.pocketcampus.gui.picture;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Calendar;
import org.pocketcampus.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
public class PictureSelectedDialog extends Dialog{
String urlSelectedPic;
public PictureSelectedDialog(Context context, String urlSelectedPicture) {
super(context);
urlSelectedPic = urlSelectedPicture;
// Dialog box will have no title
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.picture_selected_dialog);
setCanceledOnTouchOutside(true);
ImageView myImageView = (ImageView) findViewById(R.id.PictureSelected_ImageView);
TextView myTextDateView = (TextView) findViewById(R.id.PictureSelected_TextOfDateView);
/* Open a new URL and get the InputStream to load data from it. */
URL aURL;
try {
aURL = new URL(urlSelectedPic);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream iStream = conn.getInputStream();
long lastModified = conn.getLastModified();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(lastModified);
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(iStream);
Bitmap myBitmap = BitmapFactory.decodeStream(bis);
myImageView.setImageBitmap(myBitmap);
String taken = context.getResources().getString(R.string.resto_picture_taken);
myTextDateView.setText(taken + cal.get(Calendar.DAY_OF_MONTH)+"/"
+(cal.get(Calendar.MONTH)+1)+"/"
+cal.get(Calendar.YEAR)+"\n"
+"at "+cal.get(Calendar.HOUR_OF_DAY)+":"
+cal.get(Calendar.MINUTE)+":"
+cal.get(Calendar.SECOND));
} catch (IOException e) {
e.printStackTrace();
}
}
}
|