Hacking&Security Workshop

ตอนนี้ MaYaSeVeN ได้ย้าย Blog ไปที่ http://blog.mayaseven.com


Monday, April 4, 2011

GetPic_KKU (Android App Alpha 0.1) + Source Code + App Download + Review

สามารถ Download New Full ver 1.0 + Source Code + Changelog + New Review ได้ที่ http://mayaseven.blogspot.com/2011/04/pickku-10-android-app-source-code.html 


Review :


วิธีใช้ : ใส่รหัส นศ. มหาวิทยาลัยขอนแก่น มี "-" แล้วกดปุ่ม "GET IT !" แล้วรอ สองสามวินาที

Source code :



1.)GetPic_KKU.java
// Author: MaYaSeVeN
// Blog: http://mayaseven.blogspot.com 
// Date: 4/4/2011
// Version: GetPic_KKU Alpha 0.1
// Tested on: Google Nexus S
package com.GetPic_KKU;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import com.piccrawler2.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class GetPic_KKU extends Activity {
 EditText inputUrl;
 OnClickListener getImageBtnOnClick = new OnClickListener() {
  public void onClick(View view) {
   Context context = view.getContext();
   String ed = "http://reg1.kku.ac.th/ephoto/getstudentimage.asp?id="
     + inputUrl.getText();
   Drawable image = ImageOperations(context, ed.toString(),
     "image.jpg");
   ImageView imgView = new ImageView(context);
   imgView = (ImageView) findViewById(R.id.imageView1);
   imgView.setImageDrawable(image);
  }
 };

 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);
  inputUrl = ((EditText) findViewById(R.id.editText1));
  inputUrl.setSingleLine();
  inputUrl.setTextSize(11);
  Button getImageButton = (Button) findViewById(R.id.button1);
  getImageButton.setOnClickListener(getImageBtnOnClick);

 }

 private Drawable ImageOperations(Context ctx, String url,
   String saveFilename) {
  try {
   InputStream is = (InputStream) this.fetch(url);
   Drawable draw = Drawable.createFromStream(is, "src");
   return draw;
  } catch (MalformedURLException ev) {
   ev.printStackTrace();
   return null;
  } catch (IOException ev) {
   ev.printStackTrace();
   return null;
  }
 }

 public Object fetch(String address) throws MalformedURLException,
   IOException {
  URL url = new URL(address);
  Object content = url.getContent();
  return content;
 }
}
2.)main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:text="@string/hello"
    android:layout_height="wrap_content" android:layout_width="wrap_content"/>
<EditText android:text="" android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content"></EditText>
<Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_width="match_parent" android:text="@string/getit"></Button>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_gravity="center" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>
</LinearLayout>

3.)strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Input your student ID</string>
    <string name="app_name">GetPic_KKU Alpha 0.1</string>
    <string name="getit">GET IT !</string>
</resources>
#เขียนโดย MaYaSeVeN http://mayaseven.blogspot.com
#อนุญาติให้ Copy ไปโพสที่ไหนก็ได้แต่ต้องแนบเครดิตด้วยนะครับ