1 / 29

LifecareScienceLAB Android Seminar 4 th class

아주대학교. LifecareScienceLAB Android Seminar 4 th class. Android Software Development 2011/05/11 – p.m. 06:00 – 팔달관 409 호. Review. Activity Intent. Activity LifeCycle. Activity 간의 통신. CommActivity.java Activity. main.xml View. ActEdit.java Activity. sub.xml View.

ivo
Télécharger la présentation

LifecareScienceLAB Android Seminar 4 th class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 아주대학교 LifecareScienceLABAndroid Seminar 4th class Android Software Development 2011/05/11 – p.m. 06:00 – 팔달관 409호

  2. Review • Activity • Intent

  3. Activity LifeCycle

  4. Activity간의 통신 CommActivity.java Activity main.xml View ActEdit.java Activity sub.xml View

  5. Activity간의 통신 CommActivity.java Activity ActEdit.java Activity new intent +Caller, +Callee getIntent TextIn getStringExtra TextIn putExtra +TextIn new intent startActivityForResult putExtra +TextOut onActivityResult setResut getStringExtra TextOut TextOut

  6. Toast • 작은 팝업 대화상자 • 초보자들에게 디버깅용, 학습용으로 아주 용이한 출력 방법 • 변수 값을 수시로 찍어볼 때 등 • Toast.makeText(ToastTest.this, "잠시 나타나는 메시지", Toast.LENGTH_SHORT).show();

  7. Log • 개발자를 위한 디버깅용 메시지 • Eclipse를 통해서만 확인 가능 • LogCat을 이용하여 확인 할 수 있다. • 다양한 메시지 필터 • Log.v : verbose • Log.i : information • Log.w : warning • Log.e : error • Log.d : debugging • Log.x(String tag, String msg) • tag : 사용자 정의 메시지 분류 • msg : 출력할 메시지

  8. Contents List

  9. Option • Database File I/O Preference ANdroid

  10. Option Menu • JAVA로 구현 • XML로구현

  11. JAVA로 구현한 Option • 다음과 같은 순서로 동작한다. • 1. MENU 버튼을 누르면 액티비티의onCreateOptionMenu메서드로메뉴를 생성하고 보여준다. • 2. 아에템을 선택하면 액티비티의 onOptionItemSelected 메서드로 기능을 수행한다. 1 2

  12. JAVA로 구현한 Option • 1. MENU 버튼을 누르면 액티비티의onCreateOptionMenu메서드로 메뉴를 생성하고 보여준다. • booleanonCreateOptionMenu(Menu menu) • menu :빈 메뉴객체, 여기에 add로 항목 추가 • MenuItem add(intgroupId, intitemId, intorder, CharSequencetitle) • groupId : 항목의 그룹을 구성할 때 지정, NONE(0) • itemId : 항목의고유한 ID로 중복되지 않아야 한다. • order : 메뉴의 순서, NONE(0)이면 추가한 순서대로 나타난다. • title : 메뉴항목의 캡션 문자열, inttitleRes로 대체 가능 • SubMenuaddSubMenu(CharSequence title) • 서브메뉴 추가 • 서브메뉴에도 항목 추가 가능 : add

  13. JAVA로 구현한 Option • 1. MENU 버튼을 누르면 액티비티의onCreateOptionMenu메서드로 메뉴를 생성하고 보여준다. • add로 생성된 MenuItem들의 각종 설정을 변경할 수 있다. • MenuItemsetIcon(inticonRes) • MenuItemsetTitle(CharSequence title) • MenuItemsetVisible(boolean visible) • MenuItemsetAlphabeticShortcut(char alphaChar) • MenuItemsetNumericShortcut(char numericChar) • MenuItemsetCheked(booleancheaked) • MenuItemsetEnable(boolean enabled)

  14. JAVA로 구현한 Option • 2. 아에템을 선택하면 액티비티의onOptionItemSelected메서드로기능을 수행한다. • booleanonOptionItemSelected(MenuItem item) • item : 선택된 메뉴에 대한 정보를 담고있다. • 예제에서는 item.getItemId()로 itemId로 선택된 메뉴를 구분한다.

  15. JAVA로 구현한 Option • 실습 • “OptionMenu” Project Load

  16. XML로 구현한 Option • 다음과 같은 순서로 동작한다. • 1. MENU 버튼을 누르면 액티비티의onCreateOptionMenu메서드로생성된 메뉴를 불러오고 보여준다. • 2. 아에템을 선택하면 액티비티의 onOptionItemSelected 메서드로 기능을 수행한다. 1 2

  17. XML로 구현한 Option • [res] – [menu] – [menu.xml] 디렉터리와 파일 생성을 해야 한다. • menu.xml 파일에는 항목들이 미리 설정되어 있어야 한다. • onCreateOptionMenu에서는 getMenuInflater() 메서드로menu.xml 파일을 불러온다. • onOptionItemSelected에서는 menu.xml 파일에 정의된 항목의 ID로 선택된 메뉴를 구분한다.

  18. Database • SD card에서 File I/O를 이용한 파일 관리 • Preference를 이용한 데이터 관리 Database

  19. File I/O • 1. SDcard의 경로를 설정한다. • 2. 파일명을 설정한다. • 3. 파일을 연다. • FileOutputStreamopenFileOutput(String name, int mode) • FileInputStreamopenFileInput(String name) • 4. 작업을 한다. • read() • write() • 5. 파일을 닫는다. • close()

  20. File I/O • SD card의 상태 확인하기 • Environment.getExternalStorageState(); • MEDIA_MOUNTED, MEDIA_UNMOUNTED • 디렉터리 경로 생성 • File dir = new File([SD카드의 경로]+"/dir"); • dir.mkdir(); • 생성된 경로에 파일 생성 • File file = new File([SD카드의 경로]+"/dir/file.txt");

  21. File I/O Stream • 파일에 내용 쓰기 • FileOutputStreamfos = new FileOutputStream(file); • fos.write(저장할 문자열); • 파일로부터 내용 읽기 • FileInputStreamfis = new FileInputStream(file); • byte[] data = new byte[fis.available()]; • while (fis.read(data) != -1) {;} • 사용한 파일 닫기 • fis.close(); • fos.close();

  22. File I/O Buffer • Buffer를 사용한 File I/O • import java.io.BufferedReader; • import java.io.BufferedWriter; • import java.io.File; • import java.io.FileNotFoundException; • import java.io.FileReader; • import java.io.FileWriter; • import java.io.IOException;

  23. File I/O BufferedWriter • BufferedWriter사용 File root = Environment.getExternalStorageDirectory().getAbsoluteFile(); if(root.canWrite()){ File file = new File(root, [경로 + 이름]);W try { FileWriter writer = new FileWriter(file,true); BufferedWriter out = new BufferedWriter(writer); out.write([저장할 문자열]); out.close(); } catch (IOException e) { e.printStackTrace(); } }

  24. File I/O BufferedReader • BufferedReader사용 File root = Environment.getExternalStorageDirectory().getAbsoluteFile(); if(root.canRead()){ File file = new File(root, [경로 + 이름]); FileReader reader; try { reader = new FileReader(file); BufferedReader in = new BufferedReader(reader); String massage = in.readLine(); in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }

  25. Preference • 응용프로그램의 설정 정보를 영구적으로 저장하는 장치이다. • 1MB 미만의 저용량 데이터 저장에 유용하다.

  26. Preference Import • 사용하는 라이브러리 • import android.content.SharedPreferences; • 선호설정 생성 • SharedPreferences.EditorpreEditor; • settingActivity = getSharedPreferences(“str", 0); • 설정 값가져오기 • intsettingActivity.getInt(String key, intdefValue) • String settingActivity.getString(String key, String defValue) • booleansettingActivity.getBoolean(String key, booleandefValue)

  27. Preference Export • 사용하는 라이브러리 • import android.content.SharedPreferences; • 선호설정 생성 • SharedPreferencessettingActivity; • preEditor = settingActivity.edit(); • 설정 값 내보내기 • preEditor.putInt(String key, intValue) • preEditor.putString(String key, String Value) • preEditor.putBoolean(String key, booleanValue) • preEditor.commit() • preEditor.remove() • preEditor.clear()

  28. Team Presentation Software Development

  29. Team Presentation • 구현 1주차 • 서승환/이영권 • 이기영/최성원 • 설계 • 김영식/임동진 • 주제선정 및 분석 • 권만석/정선홍 • 김유성/김재호 • 서우람/유영욱

More Related