PicKKU 1.0 (Android App) + Source Code

สำหรับ App นี้ประโยชน์ที่สำคัญกว่าเอาไว้ส่องสาวๆ คือ Source Code ที่มีหลาย Functions ที่สามารถนำไปประยุกต์ใช้กับงานของผู้อ่าน เช่น ตรวจสอบการเชื่อมต่อ Internet, QueryString, Imageview, Menu, Activity,Regex บลาๆๆ หาเอาใน Code ละกัน:D

Downloads : http://www.mediafire.com/?w6j7z9igndwiogb

MD5:fb291f3b17e940dc60f0af6ab6d3ff57

Sha1:66f8f3c896e1ec2344727f20d2357ed6a94158a0

 

Review:

 

 

 

Changelog :

0.เพิ่ม Function ตรวจสอบคณะที่ศึกษาอยู่(ยังไม่ 100%)

1.เพิ่ม Function check “-” (ต่อไปนี้จะใส่ – หรือไม่ใส่ก็ได้)

2.เพิ่มเมนู Save รูปไว้บน SDCard

3.เพิ่ม Function ตรวจสถานะการเชื่อมต่อ Internet

4.เพิ่ม Activity + Menu

5.เพิ่ม + แก้ไขอีกหลายอย่างลองดูจาก Code หรือทดสอบจากตัว App เอาละกัน 😀

6.เพิ่ม Presenter คนใหม่เป็นคนที่รหัส น.ศ. == 1 (อาจจะเป็นนักศึกษาคนแรกของ มข. รึป่าว ?)

 

Source Code:

1.)Main.java

// Author: MaYaSeVeN
// Date: 16/4/2011
// Version: PicKKU 1.0
// Tested on: Google Nexus S

package com.PicKKU;

import com.PicKKU.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Main extends Activity {

 static EditText inputUrl;
 static Context context;

 public void onCreate(Bundle getpic) {
  super.onCreate(getpic);
  setContentView(R.layout.main);
  inputUrl = ((EditText) findViewById(R.id.editText1));
  inputUrl.setSingleLine();
  inputUrl.setTextSize(20);

  Button getImageButton = (Button) findViewById(R.id.button1);
  getImageButton.setOnClickListener(new OnClickListener() {

   public void onClick(View view) {

    Main.context = view.getContext();
    if (isConnected() != true) {
     Toast.makeText(Main.this, "Can't connect to the Internet",
       Toast.LENGTH_SHORT).show();
    } else if (inputUrl.getText().toString()
      .matches("(\\d{1,10})|(\\d{9}-\\d)")) {
     Intent i1 = new Intent(context, ShowPic.class);
     startActivityForResult(i1, 0);
    } else {
     Toast.makeText(Main.this, "Wrong student ID",
       Toast.LENGTH_SHORT).show();
    }
   }

  });

 }

 public boolean isConnected() {
  ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  return cm.getActiveNetworkInfo() != null;
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.layout.menu2, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  case R.id.exit:
   super.onDestroy();
   super.finish();
   return true;
  default:
   return super.onOptionsItemSelected(item);
  }
 }
}

 

2.)ShowPic.java

// Author: MaYaSeVeN
// Date: 16/4/2011
// Version: PicKKU 1.0
// Tested on: Google Nexus S

package com.PicKKU;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import com.PicKKU.R;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;

public class ShowPic extends Activity {

 private InputStream is;
 private String link;
 private String id;
 private ImageView imgView;

 public void onCreate(Bundle getpic) {
  super.onCreate(getpic);
  setContentView(R.layout.showpic);
  id = "" + Main.inputUrl.getText();
  link = "http://reg1.kku.ac.th/ephoto/getstudentimage.asp?id=" + id;
  link = checkInput();
  imgView = new ImageView(Main.context);
  imgView = (ImageView) findViewById(R.id.imageView1);
  imgView.setImageDrawable(ImageOperations());
  check_fac(id);

 }

 public void check_fac(String id) {
  if (id.length() > 9 && id.length() < 12) {
   if (id.substring(2, 5).equals("304")) {
    Toast.makeText(ShowPic.this, "Faculty of Engineering",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("308")) {
    Toast.makeText(ShowPic.this, "Faculty of HUSO",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("321")) {
    Toast.makeText(ShowPic.this, "Faculty of Management Science",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("506")) {
    Toast.makeText(ShowPic.this, "Faculty of Nursing",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("302")) {
    Toast.makeText(ShowPic.this, "Faculty of Medicine",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("321")) {
    Toast.makeText(ShowPic.this, "Faculty of Science",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("305")) {
    Toast.makeText(ShowPic.this, "Faculty of Education",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("315")) {
    Toast.makeText(ShowPic.this, "Faculty of Pharmacy",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("313")) {
    Toast.makeText(ShowPic.this, "Faculty of Dentist",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("316")) {
    Toast.makeText(ShowPic.this, "Faculty of Technology",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("303")) {
    Toast.makeText(ShowPic.this, "Faculty of Agriculture",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("309")) {
    Toast.makeText(ShowPic.this, "Faculty of Medical Technology",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("327")) {
    Toast.makeText(ShowPic.this, "Faculty of Medical Law",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("322")) {
    Toast.makeText(ShowPic.this, "Faculty of Medical Fine Art",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("329")) {
    Toast.makeText(ShowPic.this, "International College",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("328")) {
    Toast.makeText(ShowPic.this, "College of Local Administration",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("323")) {
    Toast.makeText(ShowPic.this, "Nongkhai Campus",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("311")) {
    Toast.makeText(ShowPic.this, "Faculty of Public Health",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("318")) {
    Toast.makeText(ShowPic.this, "Faculty of Veterinary Science",
      Toast.LENGTH_LONG).show();
   } else if (id.substring(2, 5).equals("320")) {
    Toast.makeText(ShowPic.this, " Faculty of Architecture",
      Toast.LENGTH_LONG).show();
   } else
    ;
  } else
   ;
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.layout.menu, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  case R.id.save:
   savePic();
   Toast.makeText(this, "Save in sdcard", Toast.LENGTH_SHORT).show();
   return true;
  case R.id.exit:
   super.onDestroy();
   super.finish();
   return true;
  default:
   return super.onOptionsItemSelected(item);
  }
 }

 private Drawable ImageOperations() {
  try {
   is = (InputStream) this.fetch(link);

   Drawable draw = Drawable.createFromStream(is, "src");
   return draw;
  } catch (MalformedURLException ev) {
   ev.printStackTrace();
   return null;
  } catch (IOException ev) {
   ev.printStackTrace();
   return null;
  }
 }

 private void savePic() {
  try {
   File SDCardRoot = Environment.getExternalStorageDirectory();
   File file = new File(SDCardRoot, id + ".jpg");
   FileOutputStream fileOutput = new FileOutputStream(file);
   byte[] buffer = new byte[1024];
   int bufferLength = 0;
   is = (InputStream) this.fetch(link);
   while ((bufferLength = is.read(buffer)) > 0) {
    fileOutput.write(buffer, 0, bufferLength);
   }
   fileOutput.close();
  } catch (MalformedURLException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }

 private Object fetch(String address) throws MalformedURLException,
   IOException {
  URL url = new URL(address);
  Object content = url.getContent();
  return content;
 }

 private String checkInput() {
  if (id.length() > 9 && id.length() < 12) {
   if (link.lastIndexOf("-") != 61) {
    char last = link.charAt(61);
    link = link.substring(0, 61);
    link = (link + "-" + last);
   }
  }
  return link;
 }
}

3.)AndroidManifest.xml

4.)main.xml

5.)showpic.xml

6.)menu.xml

7.)menu2.xml

8.)strings.xml

#เขียนโดย MaYaSeVeN 

#Matches By @ptantiku

android, android app, kku, รูป, สาว
Previous Post
How to Metasploit, simple to hack WinXP Sp3 + Win7
Next Post
Local Hack Win7 GET System Privilege [ Tutorial+Tools+Clips ]

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed