OpenFrameWork

오픈프레임워크_Day70

px 2015. 6. 23. 12:47
### : 목차 구분 기호
--- : 목차 내에 항목 구분 기호
@@@ : 태그 용도 
,,, : 같은 목차 내에 구분 기호

목차
1. 이론 및 정보
2. 설정 및 그 밖에
3. 소스코드 또는 실습
4. 과제

###################################
1. 이론 및 정보
-----------------------------------
* Android 메시지 박스 -> Toast 메시지 박스
----------------------------------- 
* 이벤트 처리 방법 3가지

1. 직접 구현
2. 내부 클래스
3. 익명 클래스, 무명 클래스
4. 간편하게 쓰는 방법 - 메서드 만드는 조건이 있음
----------------------------------- 
###################################
2. 설정 및 그 밖에
-----------------------------------
* 안드로이드를 위한 WorkSpace
~\study\AndroidWork
----------------------------------- 
* 안드로이드를 위한 새로운 Eclipse 실행


----------------------------------- 
* 이클립스와 SDK 연결 => ADT 설치

http://developer.android.com/sdk/installing/installing-adt.html

Download the ADT Plugin
의 내용으로 설치함


-----------------------------------
* 이클립스 플러그인 최신으로 업데이트


----------------------------------- 
* 이클립스 플러그인 관리


-----------------------------------
* 설치 내용 확인



만약 다른데서 가져오거나 가져갈때는 아래 부분에서 SDK 위치를 변경해 줘야함 


----------------------------------- 
* 추가 설정




바로위 설정을 하면  



아이콘이 생기고 위 두 아이콘이 아래 두 프로그램을 실행시키는 아이콘
~\study\android-sdk\SDK Manager.exe
~\study\android-sdk\AVD Manager.exe

----------------------------------- 
* 프로젝트 생성 /FirstApp




새 프로젝트 할 때 유의 사항

Application은 화면에 보여질 이름
프로젝트 이름은 내가 개발할 때 이름
반드시 패키지 이름을 넣어야함
패키지 이름은 절대 중복되어서는 안됨
마켓에 올려도 유지보수 할려면 
패키지 이름은 고유한 이름이 되어야함

젤리빈을 최하 버전으로 설정
L Preview -> Lolly Pop 체험 버전









에러
This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in

아래와 같이 버전을 낮춤






위 설정이 맞지 않아서 아래로 변경





에뮬레이터에 내가만든 어플 넣기 
 


----------------------------------- 
* 에뮬에 화면 전환 단축키

Ctrl + F11 
----------------------------------- 
* 에뮬에서 취소
ESC
----------------------------------- 
* 설치한 앱 제거 -> 기존 스마트폰에서 처럼 제거
-----------------------------------  
* 에뮬레이터에 전화 걸기 - 에뮬레이터 디버깅






-----------------------------------  
* 실제 안드로이드 폰에 연결
스마트폰 드라이버가 제대로 연결되어 있으면 실행시 선택 할 수 있음

개인 안드로이드 폰은 "디버깅 모드 허용" 으로 변경
-----------------------------------  
* 에뮬레이터 Intel Atom 문제 해결

에러 메시지
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure Intel HAXM is properly installed and usable.
CPU acceleration status: HAX kernel module is not installed!


아래 프로그램을 실행해서 설치
~\study\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager\intelhaxm-android.exe
----------------------------------- 
* 프로젝트 생성 /SecondApp


 
-----------------------------------  
* 폴더 설명

리소스
/프로젝트명/res


이미지를 저장하는 폴더
/프로젝트명/res/drawable*


전체 틀을 만들어줌
/프로젝트명/res/layout
xml이 디자인을 처리




    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

여기서 "@"는 아래 파일에 hello_world 참조한다는 의미
/프로젝트명/res/values/strings.xml
<string name="hello_world">Hello world!</string>

에뮬레이터에서는 가능하면 XML에 한글을 쓰지 말아라


아래와 같이 변경
/SecondApp/res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello! Mr.Monkey~~" />
</LinearLayout>


버튼을 추가 하기

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello! Mr.Monkey~~" />

    <Button android:text="First Button"
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/btn1"
          />
   
    <Button android:text="Second Button"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btn2"
          />
   
    <Button android:text="Third Button"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btn3"
          />
   
    <Button android:text="Forth Button"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/btn4"
          />
   
</LinearLayout>

이벤트 처리는 JAVA 클래스에서 함

----------------------------------- 
* 참조할 사이트

https://developer.android.com/guide/components/fundamentals.html
http://www.kandroid.org/guide/basics/what-is-android.html 

-----------------------------------  
* 컴퍼넌트 필수 속성

크기를 정해줘야함. 반드시!

android:layout_width="wrap_content"
android:layout_height="wrap_content"
-----------------------------------  
* 리소스와 자바에서 쓸 수 있게 연결 해주는 클래스

/프로젝트명/gen/com/example/secondapp/R.java

컴퍼넌트에 android:id를 주면 생성이 됨
-----------------------------------  
* 리플랙션 -> 실행중에 자바코드를 구체화 시켜주는 것
-----------------------------------  
* Android Java 코드 부분

/프로젝트명/src

Main 클래스
/프로젝트명/src/com/example/패키지명/MainActivity.java
-----------------------------------  
-----------------------------------  
###################################
3. 소스코드 또는 실습 
-----------------------------------
3-1
~\study\AndroidWork 
/SecondApp/res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello! Mr.Monkey~~" />

    <Button android:text="First Button"
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/btn1"
          />
   
    <Button android:text="Second Button"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btn2"
          />
   
    <Button android:text="Third Button"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btn3"
          />
   
    <Button android:text="Forth Button"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:onClick="forthHandler"
          />
   
</LinearLayout>
----------------------------------- 
3-2
~\study\AndroidWork
/SecondApp/src/com/example/secondapp/MainActivity.java

package com.example.secondapp;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends Activity implements OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        // XML에서 만든 디자인을
        // 실제로 보여질 수 있게 만들어주는 메서드
        // setContentView()
        setContentView(R.layout.activity_main);
       
        // XML에 디자인된 버튼을 가져오는 방법
        Button btn1 = (Button)findViewById(R.id.btn1);
        Button btn2 = (Button)findViewById(R.id.btn2);
        Button btn3 = (Button)findViewById(R.id.btn3);
       
        SecondButtonHandler secondListener = new SecondButtonHandler();
       
        // 이벤트를 처리할 수 있는 4가지 방법이 있음
        // 기존에 배운 방식은 3가지
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(secondListener);
        btn3.setOnClickListener(new OnClickListener() {              
               @Override
               public void onClick(View v) {
                    // TODO 세번째 이벤트 처리 방식, 무명 클래스
                    Toast.makeText(getApplicationContext(),
                              "Third Button is pressed",
                              Toast.LENGTH_SHORT).show();
               }
          });
       
    }

     @Override
     public void onClick(View v) {
          // TODO 첫번째 이벤트 처리 방식, 직접 구현
         
          // getApplicationContext()
          // 항상 실행하고자하는 프로그램의 주소값을 리턴
         
          // 반드시 마지막에 .show() 해야함
         
          Toast.makeText(getApplicationContext(),
                    "Frist Button is pressed",
                    Toast.LENGTH_LONG).show();
     }
    
     class SecondButtonHandler implements OnClickListener{
          @Override
          public void onClick(View v) {
               // TODO 두번째 이벤트 처리 방식, 내부클래스
               Toast.makeText(getApplicationContext(),
                         "Second Button is pressed",
                         Toast.LENGTH_SHORT).show();
          }
     }
    
    
     // 반드시 public void, 반드시 매개변수 View가 있어야함
     public void forthHandler(View v){
          // TODO 네번째 이벤트 처리 방식, 간이용 방식, 간단하게 쓸 때
          Toast.makeText(getApplicationContext(),
                    "Forth Button is pressed",
                    Toast.LENGTH_SHORT).show();
     }
}


----------------------------------- 
###################################
4. 과제
-----------------------------------
-----------------------------------
###################################
5. 과제 해결
-----------------------------------
-----------------------------------
###################################
6. 기타
----------------------------------- 
-----------------------------------