Android 안드로이드2014. 7. 28. 09:34


안드로이드 APP에 사운드를 추가해보자.


  • new SoundPool( 5, AudioManager.STREAM_MUSIC, 0 );로 SoundPool 객체를 만든다.
    • AudioManager 상수 중 STREAM_MUSIC은 일반적으로 사용하며 게임 쪽에 유효하다. 
    • AudioManager 상수는 특성이 조금씩 다르다.
      • 예로 STREAM_NOTIFICATION, STREAM_RING, ... 등 몇가지가 더 있는데 STREAM_NOTIFICATION을 사용하면 소리크기를 조정할 수 없다.

  • SoundPool 클래스 설명
    • http://developer.android.com/reference/android/media/SoundPool.html
    • load( int maxStreams, int streamType, int srcQuality )메소드
      1. maxStreams 한 번에 재생가능 스트림 수
      2. streamType; STREAM_NOTIFICATION, STREAM_RING, STREAM_MUSIC, ....
      3. srcQuality; 0을 사용하면 무리 없이 작동한다.
      4. 아래는 원문을 발췌했다.
      • maxStreams the maximum number of simultaneous streams for this SoundPool object
      • streamType the audio stream type as described in AudioManager For example, game applications will normally use STREAM_MUSIC.
      • srcQuality the sample-rate converter quality. Currently has no effect. Use 0 for the default.








Sound 클레스를 만들었다.


import android.content.Context;

import android.media.AudioManager;

import android.media.SoundPool;


public class Sound {

private SoundPool sound_pool; 

private int sound_beep;

Sound() {}


Sound(Context context, int iSoundFile)

sound_pool = new SoundPool( 5, AudioManager.STREAM_MUSIC, 0 );

sound_beep = sound_pool.load( context, iSoundFile, 1 );

public void initSound(Context context, int iSoundFile)

sound_pool = new SoundPool( 5, AudioManager.STREAM_MUSIC, 0 );

sound_beep = sound_pool.load( context, iSoundFile, 1 );

           

public void playSound()

sound_pool.play( sound_beep, 1f, 1f, 0, 0, 1f );

}

// initSound()와 playSound()를 하나로 합침

public void init_playSound(Context context, int iSoundFile)

sound_pool = new SoundPool( 5, AudioManager.STREAM_MUSIC, 0 );

sound_beep = sound_pool.load( context, iSoundFile, 1 );

sound_pool.play( sound_beep, 1f, 1f, 0, 0, 1f );

}

}



[사용 법]

  1. res폴더 하위에 raw폴더를 만들고 btn_main_level_default_click08.wav 사운드 파일을 넣는다.

  1. Sound객체를 만듦.
    1. Sound sndButtonStart;
    2. sndButtonStart = new Sound(this, R.raw.btn_main_level_default_click08);

      1. Sound(Context context, int iSoundFile) 생성자나 initSound(Context context, int iSoundFile) 메소드로 초기화를 한다. 
        • context는 사운드를 최종 호출해서 소리를 재생할 Activity클래스 객체다. 
        • iSoundFile는 R.java에서 참조하는 파일이다.
        • R.raw.btn_main_level_default_click08 를 넣었다.


  1. 사운드를 재생할 줄에서 재생 매소드를 호출
    1. sndButtonStart.playSound();


  2. 주의:
  3. 사운드 폴더는 보통 res하위에 raw를 사용한다.
  4. raw폴더에 soundtest.wa파일을 넣었으면 soundtest.mp3, soundtest.ogg는 사용할 수 없다. 즉 확장자가 다르더라도 파일명이 같으면 않된다.
  5. 리소스 파일 아래에 넣어놓는 파일은 소문자와 언더바'_' 만이 유효하다. 재생이 안되거나 예기치 못한 에러를 접하게 된다.


Posted by 코드버무려
Android 안드로이드2014. 7. 28. 08:55

 FILL_PARENT와 MATCH_PARENT 는 무엇이 다를까?



/**

 * Special value for the height or width requested by a View.

 * FILL_PARENT means that the view wants to be as big as its parent,

 * minus the parent's padding, if any. This value is deprecated

 * starting in API Level 8 and replaced by {@link #MATCH_PARENT}.

 */

 @SuppressWarnings({"UnusedDeclaration"})

 @Deprecated

 public static final int FILL_PARENT = -1;



/**

 * Special value for the height or width requested by a View.

 * MATCH_PARENT means that the view wants to be as big as its parent,

 * minus the parent's padding, if any. Introduced in API Level 8.

 */

 public static final int MATCH_PARENT = -1;


 

FILL_PARENT와 MATCH_PARENT는 정의된 값이 -1로 같다.

FILL_PARENT는 API8 부터 deprecated가 된다. 하위 호환을 위해 FILL_PARENT가 남았있는 것이고 가독성과 일관성이 있는 MATCH_PARENT 가 앞으로 사용될 예정이다.

Posted by 코드버무려
Android 안드로이드2014. 7. 27. 22:48



Component는 안드로이드 플랫폼에서 어플리케이션을 실행시킨다.

Component에는 액티비티(Activity), 서비스(Service), 브로드캐스트 리시버(Broadcast Receiver), 컨텐트 프로바이더(Content Provider)와 같이 4가지가 있다. 다시말하면 이들로 컴포턴트를 구현한다.


Posted by 코드버무려
Android 안드로이드2014. 7. 27. 07:19
  1. Intent 활용 예제 ExIntentActivity.java 파일
  2. Activity 하나를 열어 입력한 값을 찍는다.
  3. 똑같은 Activity를 반복해 호출함.
  4. Log.i()는 정보 information를 LogCat에 찍는다.
  5. Log.i()를 사용하려면 import android.util.*; 또는 import android.util.Log가 필요하다.




package soo.intent.ex.test;


import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.*;

import android.util.*;


public class ExIntentActivity extends Activity {

//int iLogFlow = 0;

    EditText et1, et2;

    Button b;

    Intent i1, i2;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        et1 = (EditText)findViewById(R.id.EditText01);

        et1.requestFocus();

        et2 = (EditText)findViewById(R.id.EditText02);

        b = (Button)findViewById(R.id.Button01);

        

        Log.i("ExIntentActivity", " b4 onClick");   // Log찍기

    

        i2 = new Intent(this, ExIntentActivity.class);

        b.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

Log.i("ExIntentActivity", "onClick()");   // Log찍기

i2.putExtra("key", et1.getText().toString());

ExIntentActivity.this.startActivity(i2);

Log.i("ExIntentActivity", "onClick() a4 startActivity");   // Log찍기

et1.setText("입력한 값: "+ et1.getText().toString() + "<====이 줄은 순식간에 사라짐");

ExIntentActivity.this.finish();//onDestroy()호출

}

});

        

        

        i1 = getIntent();

        getData();

    }

    void getData(){

    Log.i("ExIntentActivity", "getData()");   // Log찍기

   

    String value = i1.getStringExtra("key");

    if(value != null) et2.setText(value);

    }

}


=====================

아래는 main.xml파일


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >


    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_margin="20px"

        android:text="매인 Main Activity" 

        android:gravity="center"

        android:textSize="40px"/>

    

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="wrap_content">

        <EditText 

            android:id="@+id/EditText01"

            android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:maxLines="1"/>

        <Button 

            android:id="@+id/Button01"

            android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="전송"/>

    </LinearLayout>

    

    <EditText 

        android:id="@+id/EditText02"

        android:layout_width="fill_parent"

        android:layout_height="match_parent"

        android:editable="false"

        android:hint="여기에 전송결과 뿌려짐!!"/>

</LinearLayout>

Posted by 코드버무려
HTML+CSS+BLOG2014. 7. 25. 22:15



  1. 블로그에 소스 코드를 보기 좋게 표현할 방법을 찾아 보았습니다.
  2. http://alexgorbatchev.com/SyntaxHighlighter/download/
  3. 에서 SyntaxHighlighter 3.0.83를 다운받아 임시 폴더에 압축을 풉니다.
  4. 티스토리 (Tistory) > HTML/CSS 편집 > 파일업로드 > 하단 +추가 버튼을 클릭합니다.
  5. 다운받은 syntaxhighlighter_3.0.83 폴더에서 아래와 같이 업로드를 합니다.
    1. scripts 폴더에 있는 모든 파일을 업로드 합니다.
    2. styles 폴더에서 shCore.css, shCoreMidnight.css, shThemeMidnight.css를 업로드합니다.
  6. HTML/CSS 편집 > skin.html 에서 </head> 바로 위에 아래 줄을 추가합니다.
    1. <link rel="stylesheet" type="text/css" href="./images/shCoreMidnight.css">
  7. HTML/CSS 편집 > skin.html 에서 </body> 바로 위에 아래 줄 모두를 추가합니다.
    1. <script type="text/javascript" src="./images/shCore.js"></script>
    2. <script type="text/javascript" src="./images/shAutoloader.js"></script>
    3. <script type="text/javascript" src="./images/shBrushCpp.js"></script>
    4. <script type="text/javascript" src="./images/shBrushCSharp.js"></script>
    5. <script type="text/javascript" src="./images/shBrushCss.js"></script>
    6. <script type="text/javascript" src="./images/shBrushJava.js"></script>
    7. <script type="text/javascript" src="./images/shBrushJScript.js"></script>
    8. <script type="text/javascript" src="./images/shBrushSql.js"></script>
    9. <script type="text/javascript" src="./images/shBrushXml.js"></script>
    1. <script type="text/javascript">SyntaxHighlighter.all(); </script>
    2. 설치 작업이 모두 끝났습니다.
    3. HTML모드에서 글쓰기를 선택하고       
    4. <pre class="brush: 원하는 brush Name">
    5. 소스 코드 입력
    6. </pre>
    7. 를 적용합니다.

 

Posted by 코드버무려