Android App 1 Android App 2 Android App

  • Slides: 93
Download presentation
Android App 1

Android App 1

Android App 2

Android App 2

Android App v 프로젝트 생성(Android Server) v activity_main. xml 파일에 검색을 위한 화면 구현

Android App v 프로젝트 생성(Android Server) v activity_main. xml 파일에 검색을 위한 화면 구현 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout android: layout_width="match_parent" android: layout_height="match_parent" android: orientation="vertical" xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" > 3

Android App v activity_main. xml 파일에 검색을 위한 화면 구현 <Linear. Layout android: layout_width="match_parent"

Android App v activity_main. xml 파일에 검색을 위한 화면 구현 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="horizontal"> <Spinner android: layout_width="0 dp" android: layout_height="wrap_content" android: layout_weight="2" android: id="@+id/searchtype"/> <Edit. Text android: layout_width="0 dp" android: layout_height="wrap_content" android: layout_weight="2" android: hint="검색어를 입력하세요" android: id="@+id/value"/> 4

Android App v activity_main. xml 파일에 검색을 위한 화면 구현 <Button android: layout_width="0 dp"

Android App v activity_main. xml 파일에 검색을 위한 화면 구현 <Button android: layout_width="0 dp" android: layout_height="wrap_content" android: text="검색" android: text. Size="20 dp" android: text. Alignment="center" android: layout_weight="1" android: id="@+id/search"/> <Button android: layout_width="0 dp" android: layout_height="wrap_content" android: text="다음" android: text. Size="20 dp" android: text. Alignment="center" android: layout_weight="1" android: id="@+id/next"/> </Linear. Layout> 5

Android App v activity_main. xml 파일에 검색을 위한 화면 구현 <Scroll. View android: layout_width="match_parent"

Android App v activity_main. xml 파일에 검색을 위한 화면 구현 <Scroll. View android: layout_width="match_parent" android: layout_height="match_parent"> <Text. View android: layout_width="match_parent" android: layout_height="match_parent" android: id="@+id/list"/> </Scroll. View> </Linear. Layout> 6

Android App v res/values 디렉토리에 array. xml 파일을 추가하고 배열을 생성 <? xml version="1.

Android App v res/values 디렉토리에 array. xml 파일을 추가하고 배열을 생성 <? xml version="1. 0" encoding="utf-8"? > <resources> <string-array name="searchtype_array"> <item></item> <item>이름</item> <item>설명</item> <item>이름 또는 설명</item> </string-array> </resources> 7

Android App v Main. Activity. java 파일에 인스턴스 변수 추가 Spinner searchtype; Array. Adapter<Char.

Android App v Main. Activity. java 파일에 인스턴스 변수 추가 Spinner searchtype; Array. Adapter<Char. Sequence> adapter; Text. View list; Edit. Text value; Button next; Button search; Progress. Dialog progress. Dialog; int page. No = 1; int count; String result = ""; 8

Android App v Main. Activity. java 파일의 on. Create 메소드에서 UI 요소 설정하기 searchtype

Android App v Main. Activity. java 파일의 on. Create 메소드에서 UI 요소 설정하기 searchtype = (Spinner)find. View. By. Id(R. id. searchtype); adapter = Array. Adapter. create. From. Resource(this, R. array. searchtype_array, android. R. layout. simple_spinner_item); adapter. set. Drop. Down. View. Resource(android. R. layout. simple_spinner_dropdown_item); searchtype. set. Adapter(adapter); value = (Edit. Text)find. View. By. Id(R. id. value); list = (Text. View) find. View. By. Id(R. id. list); search = (Button)find. View. By. Id(R. id. search); next = (Button)find. View. By. Id(R. id. next); 9

Android App v Main. Acrivity. java 파일에 데이터가 가져오면 출력할 핸들러 생성 Handler handler

Android App v Main. Acrivity. java 파일에 데이터가 가져오면 출력할 핸들러 생성 Handler handler = new Handler(Looper. get. Main. Looper()) { public void handle. Message(Message msg) { list. set. Text(result); progress. Dialog. dismiss(); } }; 10

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드 클래스 생성 //데이터를 다운로드 받는 스레드 class Thread. Ex extends Thread { //다운로드 받은 문자열을 저장하기 위한 인스턴스 생성 String. Builder sb = new String. Builder(); @Override public void run() { try { //다운로드 받을 주소 생성 int i = searchtype. get. Selected. Item. Position(); String v = value. get. Text(). to. String(); 11

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드 클래스 생성 URL url = null; if(i==0){ url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/list? pageno=" + page. No); }else if(i==1){ url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/list? pageno=" + page. No + "&searchtype=itemname&value=" + v); }else if(i==2){ url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/list? pageno=" + page. No + "&searchtype=description&value=" + v); }else if(i==3){ url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/list? pageno=" + page. No + "&searchtype=both&value=" + v); } 12

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드 클래스 생성 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); //옵션 설정 con. set. Use. Caches(false); con. set. Connect. Timeout(30000); //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream() ) ); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } 13

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드

Android App v Main. Acrivity. java 파일에 데이터를 가져와서 파싱한 후 핸들러를 호출할 스레드 클래스 생성 try { JSONObject object = new JSONObject(sb. to. String()); count = object. get. Int("count"); JSONArray itemlist = object. get. JSONArray("result"); for (int i = 0; i < itemlist. length(); i = i + 1) { JSONArray item = itemlist. get. JSONArray(i); result += item. get. String(0) + "t"; result += item. get. String(1) + "n"; } } } handler. send. Empty. Message(0); } catch (Exception e) { Log. e("파싱에러", e. get. Message()); } 15

Android App v Main. Acrivity. java 파일에서 화면이 출력될 때 마다 호출되는 메소드 재정의

Android App v Main. Acrivity. java 파일에서 화면이 출력될 때 마다 호출되는 메소드 재정의 @Override protected void on. Resume() { super. on. Resume(); progress. Dialog = Progress. Dialog. show(Main. Activity. this, "", "다운로드 중. . . "); new Thread. Ex(). start(); } 16

Android App v Main. Acrivity. java 파일의 on. Create 메소드에 버튼의 이벤트 핸들러를 작성

Android App v Main. Acrivity. java 파일의 on. Create 메소드에 버튼의 이벤트 핸들러를 작성 search. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ page. No = 1; result = ""; progress. Dialog = Progress. Dialog. show(Main. Activity. this, "", "다운로드 중. . . "); new Thread. Ex(). start(); } }); 17

Android App v Main. Acrivity. java 파일의 on. Create 메소드에 버튼의 이벤트 핸들러를 작성

Android App v Main. Acrivity. java 파일의 on. Create 메소드에 버튼의 이벤트 핸들러를 작성 next. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ int cnt = 3; if(page. No * cnt >= count){ Toast. make. Text(Main. Activity. this, "더이상의 데이터가 없습니다. ", Toast. LENGTH_LONG). show(); return; } page. No = page. No + 1; progress. Dialog = Progress. Dialog. show(Main. Activity. this, "", "다운로드 중. . . "); new Thread. Ex(). start(); } }); 18

Android App v 실행 가능한 Activity 추가(Detail. Activity) v activity_detail. xml 파일에 검색을 위한

Android App v 실행 가능한 Activity 추가(Detail. Activity) v activity_detail. xml 파일에 검색을 위한 화면 구현 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Detail. Activity" android: orientation="vertical"> <Text. View android: layout_width="match_parent" android: layout_height="wrap_content" android: text. Size="32 dp" android: text. Alignment="center" android: id="@+id/title"/> 19

Android App v activity_detail. xml 파일에 검색을 위한 화면 구현 <Linear. Layout android: layout_width="match_parent"

Android App v activity_detail. xml 파일에 검색을 위한 화면 구현 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content"> <Text. View android: layout_width="0 dp" android: layout_height="wrap_content" android: layout_weight="1" android: text. Size="24 dp" android: text="설명"/> <Text. View android: layout_width="0 dp" android: layout_height="wrap_content" android: layout_weight="3" android: text. Size="32 dp" android: id="@+id/description"/> </Linear. Layout> 20

Android App v activity_detail. xml 파일에 검색을 위한 화면 구현 <Linear. Layout android: layout_width="match_parent"

Android App v activity_detail. xml 파일에 검색을 위한 화면 구현 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content"> <Text. View android: layout_width="0 dp" android: layout_height="wrap_content" android: layout_weight="1" android: text. Size="24 dp" android: text="가격"/> <Text. View android: layout_width="0 dp" android: layout_height="wrap_content" android: layout_weight="3" android: text. Size="32 dp" android: id="@+id/price"/> </Linear. Layout> <Image. View android: layout_width="match_parent" android: layout_height="match_parent" android: id="@+id/img"/> </Linear. Layout> 21

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 import androidx. appcompat.

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 import androidx. appcompat. app. App. Compat. Activity; import import import import import android. app. Progress. Dialog; android. graphics. Bitmap. Factory; android. os. Bundle; android. os. Handler; android. os. Looper; android. os. Message; android. util. Log; android. widget. Image. View; android. widget. Text. View; android. widget. Toast; org. json. JSONObject; java. io. Buffered. Reader; java. io. Input. Stream. Reader; java. net. Http. URLConnection; java. net. URL; java. util. Hash. Map; java. util. Map; 22

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 public class Detail.

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 public class Detail. Activity extends App. Compat. Activity { Progress. Dialog progress. Dialog; String itemid; Map<String, String> map; Text. View title, description, price; Image. View img; String json; 23

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 Handler handler =

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 Handler handler = new Handler(Looper. get. Main. Looper()) { public void handle. Message(Message msg) { if(msg. what == 0) { try { JSONObject result = new JSONObject(json); Boolean r = result. get. Boolean("result"); if(r) { JSONObject item = result. get. JSONObject("item"); title. set. Text(item. get. String("itemname")); description. set. Text(item. get. String("description")); price. set. Text(item. get. String("price")); Img. Thread th = new Img. Thread(item. get. String("pictureurl")); th. start(); }else{ Toast. make. Text(Detail. Activity. this, "데이터 가져오기 실패", Toast. LENGTH_LONG). show(); } } catch (Exception e) { Log. e("파싱에러", e. get. Message()); } progress. Dialog. dismiss(); } 24

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 else if(msg. what

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 else if(msg. what == 1){ Bitmap bit = (Bitmap)msg. obj; if (bit == null) { Toast. make. Text(Detail. Activity. this, "bitmap is null", Toast. LENGTH_LONG). show(); } else { img. set. Image. Bitmap(bit); } }; 25

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 //데이터를 다운로드 받는

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 //데이터를 다운로드 받는 스레드 class Thread. Ex extends Thread { //다운로드 받은 문자열을 저장하기 위한 인스턴스 생성 String. Builder sb = new String. Builder(); @Override public void run() { try { //다운로드 받을 주소 생성 URL url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/detail? itemid=" + itemid); //URL에 연결 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); //옵션 설정 con. set. Use. Caches(false); con. set. Connect. Timeout(30000); 26

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 //문자열을 다운로드 받기

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream())); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } //사용한 스트림과 연결 해제 br. close(); con. disconnect(); json = sb. to. String(); } catch (Exception e) { Log. e("다운로드 실패", e. get. Message()); } handler. send. Empty. Message(0); } } 27

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 class Img. Thread

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 class Img. Thread extends Thread { String filename; Img. Thread(String filename) { this. filename = filename; } public void run() { try { Input. Stream is = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/img/" + filename). open. Stream(); Bitmap bit = Bitmap. Factory. decode. Stream(is); is. close(); Message message = new Message(); message. obj = bit; message. what = 1; handler. send. Message(message); } catch (Exception e) { Log. e("이미지 다운로드 에러", e. get. Message()); } } } 28

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 @Override protected void

Android App v Detail. Activity. java 파일에 상세보기를 위한 코드 구현 @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_detail); itemid = "1"; title = (Text. View)find. View. By. Id(R. id. title); description = (Text. View)find. View. By. Id(R. id. description); price = (Text. View)find. View. By. Id(R. id. price); img = (Image. View)find. View. By. Id(R. id. img); } } progress. Dialog = Progress. Dialog. show(Detail. Activity. this, "", "다운로드 중. . . "); new Thread. Ex(). start(); 29

Android App v 실행 가능한 Activity 추가(Insert. Activity) v activity_insert. xml 파일에 검색을 위한

Android App v 실행 가능한 Activity 추가(Insert. Activity) v activity_insert. xml 파일에 검색을 위한 화면 구현 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Insert. Activity" android: orientation="vertical"> 30

Android App v activity_insert. xml 파일에 검색을 위한 화면 구현 <Edit. Text android: layout_width="match_parent"

Android App v activity_insert. xml 파일에 검색을 위한 화면 구현 <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: hint="제품 이름을 입력하세요" android: id="@+id/itemnameinput"/> <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: hint="제품 가격을 입력하세요" android: id="@+id/priceinput" android: input. Type="number"/> <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: hint="제품 설명을 입력하세요" android: id="@+id/descriptioninput"/> <Button android: layout_width="match_parent" android: layout_height="wrap_content" android: text="삽입" android: id="@+id/insert"/> </Linear. Layout> 31

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 import androidx.

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 import androidx. appcompat. app. App. Compat. Activity; import android. os. Bundle; import android. os. Handler; import android. os. Looper; import android. os. Message; import android. util. Log; import android. view. View; import android. view. inputmethod. Input. Method. Manager; import android. widget. Button; import android. widget. Edit. Text; import android. widget. Toast; import org. json. JSONObject; import java. io. Buffered. Reader; import java. io. Data. Output. Stream; import java. io. File. Input. Stream; import java. io. Input. Stream. Reader; import java. io. Output. Stream. Writer; import java. io. Print. Writer; import java. net. Http. URLConnection; import java. net. URLEncoder; import java. util. UUID; 32

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 public class

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 public class Insert. Activity extends App. Compat. Activity { Button insert; Edit. Text itemnameinput, priceinput, descritpioninput; Handler handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ boolean result = (Boolean)message. obj; if(result == true){ Toast. make. Text(Insert. Activity. this, "삽입 성공", Toast. LENGTH_SHORT). show(); }else{ Toast. make. Text(Insert. Activity. this, "삽입 실", Toast. LENGTH_SHORT). show(); } //키보드 관리 객체 가져오기 Input. Method. Manager imm = (Input. Method. Manager)get. System. Service( INPUT_METHOD_SERVICE); } imm. hide. Soft. Input. From. Window(itemnameinput. get. Window. Token(), 0); imm. hide. Soft. Input. From. Window(priceinput. get. Window. Token(), 0); imm. hide. Soft. Input. From. Window(descritpioninput. get. Window. Token(), 0); 33

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 Handler message.

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 Handler message. Handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Insert. Activity. this, result, Toast. LENGTH_SHORT). show(); } }; 34

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 class Thread.

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 class Thread. Ex extends Thread{ String json; @Override public void run(){ try{ Message error. Message = new Message(); if(itemnameinput. get. Text(). to. String(). trim(). length() == 0){ error. Message. obj = "이름은 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; } if(priceinput. get. Text(). to. String(). trim(). length() == 0){ error. Message. obj = "수량은 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; } if(descritpioninput. get. Text(). to. String(). trim(). length() == 0){ error. Message. obj = "설명은 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; } 35

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 //다운로드 받을

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 //다운로드 받을 주소 생성 URL url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/insert"); //URL에 연결 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); String[] data = {itemnameinput. get. Text(). to. String(), priceinput. get. Text(). to. String(), descritpioninput. get. Text(). to. String() }; String[] data. Name = {"itemname", "price", "description"}; // boundary생성, 여기서는 고정값이지만 되도록이면 실행할때마다 다른값을 할당하자. String line. End = "rn"; String boundary = "androidupload"; con. set. Request. Method("POST"); con. set. Read. Timeout(10000); con. set. Connect. Timeout(10000); con. set. Do. Output(true); con. set. Do. Input(true); con. set. Use. Caches(false); con. set. Request. Property("ENCTYPE", "multipart/form-data"); con. set. Request. Property("Content-Type", "multipart/form-data; boundary="+boundary); 36

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 String delimiter

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 String delimiter = "--" + boundary + line. End; // --androiduploadrn String. Buffer post. Data. Builder = new String. Buffer(); for(int i=0; i<data. length; i++){ post. Data. Builder. append(delimiter); post. Data. Builder. append("Content-Disposition: form-data; name="" + data. Name[i] +"""+line. End+data[i]+line. End); } String file. Name = "ball. png"; // 파일이 존재할 때에만 생성 if(file. Name!=null){ post. Data. Builder. append(delimiter); post. Data. Builder. append("Content-Disposition: form-data; name="" + "pictureurl" + ""; filename="" + file. Name +""" + line. End); } Data. Output. Stream ds = new Data. Output. Stream(con. get. Output. Stream()); ds. write(post. Data. Builder. to. String(). get. Bytes()); 37

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 if(file. Name!=null){

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 if(file. Name!=null){ ds. write. Bytes(line. End); Input. Stream fres = get. Resources(). open. Raw. Resource(R. raw. ball); byte[] buffer = new byte[fres. available()]; int length = -1; while((length=fres. read(buffer)) != -1){ ds. write(buffer, 0, length); } ds. write. Bytes(line. End); ds. write. Bytes("--" + boundary + "--" + line. End); // requestbody end fres. close(); } else { ds. write. Bytes(line. End); ds. write. Bytes("--" + boundary + "--" + line. End); // requestbody end } ds. flush(); ds. close(); 38

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 //문자열을 다운로드

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream())); String. Builder sb = new String. Builder(); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } //사용한 스트림과 연결 해제 br. close(); con. disconnect(); json = sb. to. String(); }catch(Exception e){ Log. e("삽입 예외", e. get. Message()); } 39

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 if(json !=

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 if(json != null){ try{ JSONObject object = new JSONObject(json); boolean result = object. get. Boolean("result"); Message message = new Message(); message. obj = result; handler. send. Message(message); }catch(Exception e){ Log. e("삽입 예외", e. get. Message()); } } 40

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 @Override protected

Android App v Insert. Activity. java 파일에 데이터 삽입을 위한 코드 구현 @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_insert); itemnameinput = (Edit. Text)find. View. By. Id(R. id. itemnameinput); priceinput = (Edit. Text)find. View. By. Id(R. id. priceinput); descritpioninput = (Edit. Text)find. View. By. Id(R. id. descriptioninput); insert = (Button)find. View. By. Id(R. id. insert); insert. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ new Thread. Ex(). start(); } } 41

Android App 42

Android App 42

Android App v 실행 가능한 Activity 생성(Join. Activity) v 화면 디자인 <? xml version="1.

Android App v 실행 가능한 Activity 생성(Join. Activity) v 화면 디자인 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Join. Activity" android: orientation="vertical"> <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: hint="email 입력하세요" android: id="@+id/emailinput"/> <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: input. Type="text. Password" android: hint="비밀번호를 입력하세요" android: id="@+id/pwinput" /> 43

Android App v 화면 디자인 <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: hint="별명을 입력하세요"

Android App v 화면 디자인 <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: hint="별명을 입력하세요" android: id="@+id/nicknameinput"/> <Button android: layout_width="match_parent" android: layout_height="wrap_content" android: text="회원가입" android: id="@+id/join"/> </Linear. Layout> 44

Android App v Join. Activity. java 파일에 작성 import androidx. appcompat. app. App. Compat.

Android App v Join. Activity. java 파일에 작성 import androidx. appcompat. app. App. Compat. Activity; import android. os. Bundle; import android. os. Handler; import android. os. Looper; import android. os. Message; import android. util. Log; import android. view. View; import android. view. inputmethod. Input. Method. Manager; import android. widget. Button; import android. widget. Edit. Text; import android. widget. Toast; import org. json. JSONObject; import java. io. Buffered. Reader; import java. io. Data. Output. Stream; import java. io. Input. Stream. Reader; import java. net. Http. URLConnection; import java. net. URL; import java. util. regex. Matcher; import java. util. regex. Pattern; 45

Android App v Join. Activity. java 파일에 작성 public class Join. Activity extends App.

Android App v Join. Activity. java 파일에 작성 public class Join. Activity extends App. Compat. Activity { Edit. Text email. Input, pw. Input, nickname. Input; Button join; //회원 가입 여부를 출력하는 핸들러 Handler handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Join. Activity. this, result, Toast. LENGTH_SHORT). show(); //키보드 관리 객체 가져오기 Input. Method. Manager imm = (Input. Method. Manager)get. System. Service( INPUT_METHOD_SERVICE); } imm. hide. Soft. Input. From. Window(email. Input. get. Window. Token(), 0); imm. hide. Soft. Input. From. Window(pw. Input. get. Window. Token(), 0); imm. hide. Soft. Input. From. Window(nickname. Input. get. Window. Token(), 0); 46

Android App v Join. Activity. java 파일에 작성 //유효성 검사여부를 출력하는 핸들러 Handler message.

Android App v Join. Activity. java 파일에 작성 //유효성 검사여부를 출력하는 핸들러 Handler message. Handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Join. Activity. this, result, Toast. LENGTH_SHORT). show(); } }; 47

Android App v Join. Activity. java 파일에 작성 //회원가입 요청을 전송하는 스레드 class Thread.

Android App v Join. Activity. java 파일에 작성 //회원가입 요청을 전송하는 스레드 class Thread. Ex extends Thread{ String json; @Override public void run(){ try{ //다운로드 받을 주소 생성 URL url = new URL("http: //172. 20. 10. 2: 9000/mysqlserver/join"); //URL에 연결 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); String[] data = {email. Input. get. Text(). to. String(), pw. Input. get. Text(). to. String(), nickname. Input. get. Text(). to. String() }; String[] data. Name = {"email", "pw", "nickname"}; // boundary생성, 여기서는 고정값이지만 되도록이면 실행할때마다 다른값을 할당하자. String line. End = "rn"; String boundary = "androidjoin"; con. set. Request. Method("POST"); 48

Android App v Join. Activity. java 파일에 작성 con. set. Read. Timeout(10000); con. set.

Android App v Join. Activity. java 파일에 작성 con. set. Read. Timeout(10000); con. set. Connect. Timeout(10000); con. set. Do. Output(true); con. set. Do. Input(true); con. set. Use. Caches(false); con. set. Request. Property("ENCTYPE", "multipart/form-data"); con. set. Request. Property("Content-Type", "multipart/form-data; boundary="+boundary); String delimiter = "--" + boundary + line. End; // --androiduploadrn String. Buffer post. Data. Builder = new String. Buffer(); for(int i=0; i<data. length; i++){ post. Data. Builder. append(delimiter); post. Data. Builder. append("Content-Disposition: form-data; name="" + data. Name[i] +"""+line. End+data[i]+line. End); } String file. Name = "ball. png"; // 파일이 존재할 때에만 생성 if(file. Name!=null){ post. Data. Builder. append(delimiter); post. Data. Builder. append("Content-Disposition: form-data; name="" + "profile" + ""; filename="" + file. Name +""" + line. End); } 49

Android App v Join. Activity. java 파일에 작성 Data. Output. Stream ds = new

Android App v Join. Activity. java 파일에 작성 Data. Output. Stream ds = new Data. Output. Stream(con. get. Output. Stream()); ds. write(post. Data. Builder. to. String(). get. Bytes()); if(file. Name!=null){ ds. write. Bytes(line. End); Input. Stream fres = get. Resources(). open. Raw. Resource(R. raw. ball); byte[] buffer = new byte[fres. available()]; int length = -1; while((length=fres. read(buffer)) != -1){ ds. write(buffer, 0, length); } ds. write. Bytes(line. End); ds. write. Bytes("--" + boundary + "--" + line. End); // requestbody end fres. close(); } else { ds. write. Bytes(line. End); ds. write. Bytes("--" + boundary + "--" + line. End); // requestbody end } ds. flush(); ds. close(); 50

Android App v Join. Activity. java 파일에 작성 //문자열을 다운로드 받기 위한 스트림을 생성

Android App v Join. Activity. java 파일에 작성 //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream())); String. Builder sb = new String. Builder(); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } //사용한 스트림과 연결 해제 br. close(); con. disconnect(); json = sb. to. String(); }catch(Exception e){ Log. e("회원가입 예외", e. get. Message()); } 51

Android App v Join. Activity. java 파일에 작성 if(json != null){ try{ JSONObject object

Android App v Join. Activity. java 파일에 작성 if(json != null){ try{ JSONObject object = new JSONObject(json); Log. e("데이터", object. to. String()); boolean result = object. get. Boolean("result"); Message message = new Message(); if(result == true) { message. obj = "회원가입 성공"; }else{ boolean emailcheck = object. get. Boolean("emailcheck"); if(emailcheck == false){ message. obj = "이메일이 사용 중이므로 회원가입 실패"; }else{ message. obj = "닉네임이 사용 중이이므로 회원가입 실패"; } } handler. send. Message(message); }catch(Exception e){ Log. e("파싱 예외", e. get. Message()); } } 52

Android App v Join. Activity. java 파일에 작성 @Override protected void on. Create(Bundle saved.

Android App v Join. Activity. java 파일에 작성 @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_join); email. Input = (Edit. Text)find. View. By. Id(R. id. emailinput); pw. Input = (Edit. Text)find. View. By. Id(R. id. pwinput); nickname. Input = (Edit. Text)find. View. By. Id(R. id. nicknameinput); join = (Button)find. View. By. Id(R. id. join); join. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ Message error. Message = new Message(); String email = email. Input. get. Text(). to. String(). trim(); String pw = pw. Input. get. Text(). to. String(). trim(); String nickname = nickname. Input. get. Text(). to. String(). trim(); 53

Android App v Join. Activity. java 파일에 작성 if(email. length() == 0){ error. Message.

Android App v Join. Activity. java 파일에 작성 if(email. length() == 0){ error. Message. obj = "email은 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; }else{ String regex = "^[_a-z 0 -9 -]+(. [_a-z 0 -9 -]+)*@(? : \w+\. )+\w+$"; Pattern p = Pattern. compile(regex); Matcher m = p. matcher(email); if(m. matches() == false) { error. Message. obj = "email 형식과 일치하지 않습니다. "; message. Handler. send. Message(error. Message); return; } } 54

Android App v Join. Activity. java 파일에 작성 if(pw. length() == 0){ error. Message.

Android App v Join. Activity. java 파일에 작성 if(pw. length() == 0){ error. Message. obj = "비밀번호는 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; }else{ String regex = "^(? =. *[a-z])(? =. *[A-Z])(? =. *\d)(? =. *[$@$!%*? &])[A-Zaz\d$@$!%*? &]{8, }"; Pattern p = Pattern. compile(regex); Matcher m = p. matcher(pw); if(m. matches() == false) { error. Message. obj = "비밀번호는 영문 대소문자 1개 이상 특수문자 1개 숫자 1개 이상으로 만들어져야 합니다. "; message. Handler. send. Message(error. Message); return; } } 55

Android App v Join. Activity. java 파일에 작성 if(nickname. length() < 2){ error. Message.

Android App v Join. Activity. java 파일에 작성 if(nickname. length() < 2){ error. Message. obj = "별명은 2자 이상이어야 합니다. "; message. Handler. send. Message(error. Message); return; }else{ String regex = "[0 -9]|[a-z]|[A-Z]|[가-힣]"; for(int i = 0; i < nickname. length(); i++) { String ch = nickname. char. At(i) + ""; Pattern p = Pattern. compile(regex); Matcher m = p. matcher(ch); if (m. matches() == false) { error. Message. obj = "별명은 영문 숫자 한글만 사용해야 합니다. "; message. Handler. send. Message(error. Message); return; } } }); } new Thread. Ex(). start(); 56

Android App v 실행 가능한 Activity 생성(Login. Activity) v 화면 디자인 <? xml version="1.

Android App v 실행 가능한 Activity 생성(Login. Activity) v 화면 디자인 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Login. Activity" android: orientation="vertical"> 57

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android:

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android: orientation="horizontal" > <Text. View android: layout_width="wrap_content" android: layout_height="wrap_content" android: text=" 닉네임: " /> <Edit. Text android: id="@+id/nicknameinput" android: layout_width="200 dp" android: layout_height="wrap_content" android: text="" /> </Linear. Layout> 58

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android:

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android: orientation="horizontal" > <Text. View android: layout_width="wrap_content" android: layout_height="wrap_content" android: text=" 비밀번호: " /> <Edit. Text android: id="@+id/pwinput" android: input. Type="text. Password" android: layout_width="200 dp" android: layout_height="wrap_content" android: text="" /> </Linear. Layout> 59

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android:

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android: orientation="horizontal" > <Button android: id="@+id/btnlogin" android: layout_width="wrap_content" android: layout_height="wrap_content" android: gravity="center_horizontal" android: text="LOGIN"/> </Linear. Layout> 60

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android:

Android App v 화면 디자인 <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center_horizontal" android: orientation="horizontal" > <Image. View android: id="@+id/profileimage" android: layout_width="wrap_content" android: layout_height="wrap_content" android: gravity="center_horizontal" /> </Linear. Layout> 61

Android App v Login. Activity. java 파일에 작성 import androidx. appcompat. app. App. Compat.

Android App v Login. Activity. java 파일에 작성 import androidx. appcompat. app. App. Compat. Activity; import android. graphics. Bitmap. Factory; import android. os. Bundle; import android. os. Handler; import android. os. Looper; import android. os. Message; import android. util. Log; import android. view. View; import android. view. inputmethod. Input. Method. Manager; import android. widget. Button; import android. widget. Edit. Text; import android. widget. Image. View; import android. widget. Toast; import org. json. JSONObject; import java. io. Buffered. Reader; import java. io. Data. Output. Stream; import java. io. Input. Stream. Reader; import java. io. Output. Stream. Writer; import java. net. Http. URLConnection; 62

Android App v Login. Activity. java 파일에 작성 import java. net. URL; import java.

Android App v Login. Activity. java 파일에 작성 import java. net. URL; import java. net. URLEncoder; import java. util. regex. Matcher; import java. util. regex. Pattern; public class Login. Activity extends App. Compat. Activity { Edit. Text nicknameinput, pw. Input; Button btnlogin; Image. View profile. Image; String profile. Url; String email, nickname; 63

Android App v Login. Activity. java 파일에 작성 Handler handler = new Handler(Looper. get.

Android App v Login. Activity. java 파일에 작성 Handler handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ boolean result = (Boolean)message. obj; if(result == true){ Toast. make. Text(Login. Activity. this, "로그인 성공", Toast. LENGTH_SHORT). show(); new Image. Thread(). start(); }else{ Toast. make. Text(Login. Activity. this, "로그인 실패", Toast. LENGTH_SHORT). show(); } //키보드 관리 객체 가져오기 Input. Method. Manager imm = (Input. Method. Manager)get. System. Service( INPUT_METHOD_SERVICE); } imm. hide. Soft. Input. From. Window(nicknameinput. get. Window. Token(), 0); imm. hide. Soft. Input. From. Window(pw. Input. get. Window. Token(), 0); 64

Android App v Login. Activity. java 파일에 작성 Handler message. Handler = new Handler(Looper.

Android App v Login. Activity. java 파일에 작성 Handler message. Handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Login. Activity. this, result, Toast. LENGTH_SHORT). show(); } }; Handler image. Handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ Bitmap bit = (Bitmap)message. obj; if (bit == null) { Toast. make. Text(Login. Activity. this, "bitmap is null", Toast. LENGTH_LONG). show(); } else { profile. Image. set. Image. Bitmap(bit); } } }; 65

Android App v Login. Activity. java 파일에 작성 class Thread. Ex extends Thread{ String

Android App v Login. Activity. java 파일에 작성 class Thread. Ex extends Thread{ String json; @Override public void run(){ try{ //다운로드 받을 주소 생성 URL url = new URL("http: //172. 20. 10. 2: 9000/mysqlserver/login"); //URL에 연결 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); con. set. Request. Method("POST"); con. set. Read. Timeout(10000); con. set. Connect. Timeout(10000); con. set. Do. Output(true); con. set. Do. Input(true); con. set. Use. Caches(false); 66

Android App v Login. Activity. java 파일에 작성 // Construct data String data =

Android App v Login. Activity. java 파일에 작성 // Construct data String data = URLEncoder. encode("nickname", "UTF-8") + "=" + URLEncoder. encode(nicknameinput. get. Text(). to. String(). trim(), "UTF-8"); data += "&" + URLEncoder. encode("pw", "UTF-8") + "=" + URLEncoder. encode(pw. Input. get. Text(). to. String(). trim(), "UTF-8"); Output. Stream. Writer wr = new Output. Stream. Writer(con. get. Output. Stream()); wr. write(data); wr. flush(); //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream())); String. Builder sb = new String. Builder(); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } 67

Android App v Login. Activity. java 파일에 작성 //사용한 스트림과 연결 해제 br. close();

Android App v Login. Activity. java 파일에 작성 //사용한 스트림과 연결 해제 br. close(); con. disconnect(); json = sb. to. String(); }catch(Exception e){ Log. e("로그인 예외", e. get. Message()); } 68

Android App v Login. Activity. java 파일에 작성 if(json != null){ try{ JSONObject object

Android App v Login. Activity. java 파일에 작성 if(json != null){ try{ JSONObject object = new JSONObject(json); Log. e("데이터", object. to. String()); boolean result = object. get. Boolean("login"); if(result == true){ profile. Url = object. get. String("profile"); email = object. get. String("email"); nickname = object. get. String("nickname"); } 69

Android App v Login. Activity. java 파일에 작성 try { File. Output. Stream fos

Android App v Login. Activity. java 파일에 작성 try { File. Output. Stream fos = open. File. Output("login. txt", Context. MODE_PRIVATE); String str = nickname + ": " + email + ": " + profile. Url; fos. write(str. get. Bytes()); fos. close(); } catch (Exception e) {} } Message message = new Message(); message. obj = result; handler. send. Message(message); }catch(Exception e){ Log. e("파싱 예외", e. get. Message()); } 70

Android App v Login. Activity. java 파일에 작성 class Image. Thread extends Thread{ public

Android App v Login. Activity. java 파일에 작성 class Image. Thread extends Thread{ public void run() { try { Input. Stream is = new URL("http: //172. 20. 10. 2: 9000/mysqlserver/profile/" + profile. Url). open. Stream(); Bitmap bit = Bitmap. Factory. decode. Stream(is); is. close(); Message message = new Message(); message. obj = bit; image. Handler. send. Message(message); } catch (Exception e) { Log. e("이미지 다운로드 에러", e. get. Message()); } } } 71

Android App v Login. Activity. java 파일에 작성 @Override protected void on. Create(Bundle saved.

Android App v Login. Activity. java 파일에 작성 @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_login); nicknameinput = (Edit. Text)find. View. By. Id(R. id. nicknameinput); pw. Input = (Edit. Text)find. View. By. Id(R. id. pwinput); profile. Image = (Image. View) find. View. By. Id(R. id. profileimage); btnlogin = (Button)find. View. By. Id(R. id. btnlogin); btnlogin. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ Message error. Message = new Message(); String nickname = nicknameinput. get. Text(). to. String(). trim(); String pw = pw. Input. get. Text(). to. String(). trim(); if(nickname. length() < 2){ error. Message. obj = "별명은 2자 이상이어야 합니다. "; message. Handler. send. Message(error. Message); return; } 72

Android App v Login. Activity. java 파일에 작성 else{ String regex = "[0 -9]|[a-z]|[A-Z]|[가-힣]";

Android App v Login. Activity. java 파일에 작성 else{ String regex = "[0 -9]|[a-z]|[A-Z]|[가-힣]"; for(int i = 0; i < nickname. length(); i++) { String ch = nickname. char. At(i) + ""; Pattern p = Pattern. compile(regex); Matcher m = p. matcher(ch); if (m. matches() == false) { error. Message. obj = "별명은 영문 숫자 한글만 사용해야 합니다. "; message. Handler. send. Message(error. Message); return; } } } 73

Android App v Login. Activity. java 파일에 작성 if(pw. length() == 0){ error. Message.

Android App v Login. Activity. java 파일에 작성 if(pw. length() == 0){ error. Message. obj = "비밀번호는 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; }else{ String regex = "^(? =. *[a-z])(? =. *[A-Z])(? =. *\d)(? =. *[$@$!%*? &])[A-Zaz\d$@$!%*? &]{8, }"; Pattern p = Pattern. compile(regex); Matcher m = p. matcher(pw); if(m. matches() == false) { error. Message. obj = "비밀번호는 영문 대소문자 1개 이상 특수문자 1개 숫자 1개 이상으로 만들어져야 합니다. "; message. Handler. send. Message(error. Message); return; } } }); } new Thread. Ex(). start(); 74

Android App v 실행 가능한 Activity 생성(Update. Activity) v 화면 디자인 <? xml version="1.

Android App v 실행 가능한 Activity 생성(Update. Activity) v 화면 디자인 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Update. Activity" android: orientation="vertical"> <Text. View android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center" android: id="@+id/lblemail"/> <Text. View android: layout_width="match_parent" android: layout_height="wrap_content" android: gravity="center" android: id="@+id/lblnickname"/> 75

Android App v 화면 디자인 <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: input. Type="text.

Android App v 화면 디자인 <Edit. Text android: layout_width="match_parent" android: layout_height="wrap_content" android: input. Type="text. Password" android: hint="비밀번호를 입력하세요" android: id="@+id/pwinput" /> <Button android: layout_width="match_parent" android: layout_height="wrap_content" android: text="회원정보수정" android: id="@+id/btnupdate"/> </Linear. Layout> 76

Android App v Update. Activity. java 파일 수정 public class Update. Activity extends App.

Android App v Update. Activity. java 파일 수정 public class Update. Activity extends App. Compat. Activity { Text. View lbl. Email, lbl. Nickname; Edit. Text pw. Input; Button btn. Update; //유효성 검사여부를 출력하는 핸들러 Handler message. Handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Update. Activity. this, result, Toast. LENGTH_SHORT). show(); } }; 77

Android App v Update. Activity. java 파일 수정 //회원 가입 여부를 출력하는 핸들러 Handler

Android App v Update. Activity. java 파일 수정 //회원 가입 여부를 출력하는 핸들러 Handler handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Update. Activity. this, result, Toast. LENGTH_SHORT). show(); //키보드 관리 객체 가져오기 Input. Method. Manager imm = (Input. Method. Manager)get. System. Service( INPUT_METHOD_SERVICE); imm. hide. Soft. Input. From. Window(pw. Input. get. Window. Token(), 0); } }; 78

Android App v Update. Activity. java 파일 수정 //회원가입 요청을 전송하는 스레드 class Thread.

Android App v Update. Activity. java 파일 수정 //회원가입 요청을 전송하는 스레드 class Thread. Ex extends Thread{ String json; @Override public void run(){ try{ //다운로드 받을 주소 생성 URL url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/update"); //URL에 연결 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); String[] data = {lbl. Email. get. Text(). to. String(), pw. Input. get. Text(). to. String(), lbl. Nickname. get. Text(). to. String() }; String[] data. Name = {"email", "pw", "nickname"}; // boundary생성, 여기서는 고정값이지만 되도록이면 실행할때마다 다른값을 할당하자. String line. End = "rn"; String boundary = "androidupdate"; con. set. Request. Method("POST"); 79

Android App v Update. Activity. java 파일 수정 con. set. Read. Timeout(10000); con. set.

Android App v Update. Activity. java 파일 수정 con. set. Read. Timeout(10000); con. set. Connect. Timeout(10000); con. set. Do. Output(true); con. set. Do. Input(true); con. set. Use. Caches(false); con. set. Request. Property("ENCTYPE", "multipart/form-data"); con. set. Request. Property("Content-Type", "multipart/form-data; boundary="+boundary); String delimiter = "--" + boundary + line. End; // --androiduploadrn String. Buffer post. Data. Builder = new String. Buffer(); for(int i=0; i<data. length; i++){ post. Data. Builder. append(delimiter); post. Data. Builder. append("Content-Disposition: form-data; name="" + data. Name[i] +"""+line. End+data[i]+line. End); } String file. Name = "girls. jpg"; // 파일이 존재할 때에만 생성 if(file. Name!=null){ post. Data. Builder. append(delimiter); post. Data. Builder. append("Content-Disposition: form-data; name="" + "profile" + ""; filename="" + file. Name +""" + line. End); } 80

Android App v Update. Activity. java 파일 수정 Data. Output. Stream ds = new

Android App v Update. Activity. java 파일 수정 Data. Output. Stream ds = new Data. Output. Stream(con. get. Output. Stream()); ds. write(post. Data. Builder. to. String(). get. Bytes()); if(file. Name!=null){ ds. write. Bytes(line. End); Input. Stream fres = get. Resources(). open. Raw. Resource(R. raw. girls); byte[] buffer = new byte[fres. available()]; int length = -1; while((length=fres. read(buffer)) != -1){ ds. write(buffer, 0, length); } ds. write. Bytes(line. End); ds. write. Bytes("--" + boundary + "--" + line. End); // requestbody end fres. close(); } else { ds. write. Bytes(line. End); ds. write. Bytes("--" + boundary + "--" + line. End); // requestbody end } ds. flush(); ds. close(); 81

Android App v Update. Activity. java 파일 수정 //문자열을 다운로드 받기 위한 스트림을 생성

Android App v Update. Activity. java 파일 수정 //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream())); String. Builder sb = new String. Builder(); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } //사용한 스트림과 연결 해제 br. close(); con. disconnect(); json = sb. to. String(); }catch(Exception e){ Log. e("회원정보 수정예외", e. get. Message()); } 82

Android App v Update. Activity. java 파일 수정 if(json != null){ try{ JSONObject object

Android App v Update. Activity. java 파일 수정 if(json != null){ try{ JSONObject object = new JSONObject(json); Log. e("데이터", object. to. String()); boolean result = object. get. Boolean("update"); Message message = new Message(); if(result == true) { message. obj = "회원정보 수정 성공"; }else{ message. obj = "회원정보 수정 실패"; } handler. send. Message(message); }catch(Exception e){ Log. e("파싱 예외", e. get. Message()); } } 83

Android App v Update. Activity. java 파일 수정 @Override protected void on. Create(Bundle saved.

Android App v Update. Activity. java 파일 수정 @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_update); lbl. Email = (Text. View)find. View. By. Id(R. id. lblemail); lbl. Nickname = (Text. View)find. View. By. Id(R. id. lblnickname); pw. Input = (Edit. Text)find. View. By. Id(R. id. pwinput); btn. Update = (Button)find. View. By. Id(R. id. btnupdate); try { File. Input. Stream fis = open. File. Input("login. txt"); byte[] data = new byte[fis. available()]; while (fis. read(data) != -1) {; } fis. close(); String msg = new String(data); String [] ar = msg. split(": "); lbl. Nickname. set. Text(ar[0]); lbl. Email. set. Text(ar[1]); } catch (File. Not. Found. Exception e) { Toast. make. Text(this, "로그인 정보가 없어서 수정할 수 없습니다. ", Toast. LENGTH_LONG). show(); } catch (Exception e) {; } 84

Android App v Update. Activity. java 파일 수정 btn. Update. set. On. Click. Listener(new

Android App v Update. Activity. java 파일 수정 btn. Update. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ String pw = pw. Input. get. Text(). to. String(). trim(); Message error. Message = new Message(); if(pw. length() == 0){ error. Message. obj = "비밀번호는 비어있을 수 없습니다. "; message. Handler. send. Message(error. Message); return; }else{ String regex = "^(? =. *[a-z])(? =. *[A-Z])(? =. *\d)(? =. *[$@$!%*? &])[A-Zaz\d$@$!%*? &]{8, }"; Pattern p = Pattern. compile(regex); Matcher m = p. matcher(pw); if(m. matches() == false) { error. Message. obj = "비밀번호는 영문 대소문자 1개 이상 특수문자 1개 숫자 1개 이상으로 만들어져야 합니다. "; message. Handler. send. Message(error. Message); return; } } 85

Android App v Update. Activity. java 파일 수정 new Thread. Ex(). start(); } }

Android App v Update. Activity. java 파일 수정 new Thread. Ex(). start(); } } 86

Android App v 실행 가능한 Activity 생성(Delete. Activity) v 화면 디자인 <? xml version="1.

Android App v 실행 가능한 Activity 생성(Delete. Activity) v 화면 디자인 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Delete. Activity" android: orientation="vertical"> <Button android: layout_width="match_parent" android: layout_height="wrap_content" android: text="회원탈퇴" android: text. Size="32 sp" android: gravity="center" android: id="@+id/btnsecession" /> </Linear. Layout> 87

Android App v Delete. Activity. java 파일 작성 public class Delete. Activity extends App.

Android App v Delete. Activity. java 파일 작성 public class Delete. Activity extends App. Compat. Activity { Button btn. Secession; Handler handler = new Handler(Looper. get. Main. Looper()){ @Override public void handle. Message(Message message){ String result = (String)message. obj; Toast. make. Text(Delete. Activity. this, result, Toast. LENGTH_SHORT). show(); } }; 88

Android App v Delete. Activity. java 파일 작성 class Thread. Ex extends Thread{ String

Android App v Delete. Activity. java 파일 작성 class Thread. Ex extends Thread{ String json; @Override public void run(){ try{ //다운로드 받을 주소 생성 URL url = new URL("http: //172. 30. 1. 24: 9000/mysqlserver/secession"); //URL에 연결 Http. URLConnection con = (Http. URLConnection) url. open. Connection(); con. set. Request. Method("POST"); con. set. Read. Timeout(10000); con. set. Connect. Timeout(10000); con. set. Do. Output(true); con. set. Do. Input(true); con. set. Use. Caches(false); 89

Android App v Delete. Activity. java 파일 작성 File. Input. Stream fis = open.

Android App v Delete. Activity. java 파일 작성 File. Input. Stream fis = open. File. Input("login. txt"); byte[] data = new byte[fis. available()]; while (fis. read(data) != -1) {; } fis. close(); String msg = new String(data); String [] ar = msg. split(": "); String nickname = ar[0]; // Construct data String param = URLEncoder. encode("nickname", "UTF-8") + "=" + URLEncoder. encode(nickname, "UTF-8"); Output. Stream. Writer wr = new Output. Stream. Writer(con. get. Output. Stream()); wr. write(param); wr. flush(); 90

Android App v Delete. Activity. java 파일 작성 //문자열을 다운로드 받기 위한 스트림을 생성

Android App v Delete. Activity. java 파일 작성 //문자열을 다운로드 받기 위한 스트림을 생성 Buffered. Reader br = new Buffered. Reader( new Input. Stream. Reader( con. get. Input. Stream())); String. Builder sb = new String. Builder(); //문자열을 읽어서 저장 while (true) { String line = br. read. Line(); if (line == null) break; sb. append(line + "n"); } //사용한 스트림과 연결 해제 br. close(); con. disconnect(); json = sb. to. String(); }catch(Exception e){ Log. e("탈퇴 예외", e. get. Message()); } 91

Android App v Delete. Activity. java 파일 작성 if(json != null){ try{ JSONObject object

Android App v Delete. Activity. java 파일 작성 if(json != null){ try{ JSONObject object = new JSONObject(json); Log. e("데이터", object. to. String()); boolean result = object. get. Boolean("delete"); Message message = new Message(); if(result == true) { message. obj = "회원 탈퇴 성공"; }else{ message. obj = "회원 탈퇴 실패"; } handler. send. Message(message); }catch(Exception e){ Log. e("파싱 예외", e. get. Message()); } } 92

Android App v Delete. Activity. java 파일 작성 @Override protected void on. Create(Bundle saved.

Android App v Delete. Activity. java 파일 작성 @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_delete); } } btn. Secession = (Button)find. View. By. Id(R. id. btnsecession); btn. Secession. set. On. Click. Listener(new Button. On. Click. Listener(){ public void on. Click(View view){ new Thread. Ex(). start(); } }); 93