2010년 7월 28일 수요일

장보기 어플을...

장보기 어플에 구매된 리스트의 상세 정보를 넣고 히스토리를 관리한다면...
구매한 항목에 대한 트렌드를 확인할 수 있지 않을까?
내가 언제 구매했고 구매금액은 얼마이고... 등등...
그러면 구매 패턴을 확인할 수 있으니... 경제활동에 도움이 되지 않을까?
그럼 이제... 그래프 기능 구현을 함 해볼까~~~~

장보기 어플 초성검색 기능

장보기 어플의 항목등록을 위해 자바로 구현된 초성검색 로직이다.

public static String getInitialConsonant(String str) {
int value = 0;
int initial, consonant = 0;
String[] arr_consonant =
new String[] {"ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ"
,"ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ"
,"ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"};
String result = "";

for(int i = 0 ; i < str.length(); i++) { value = str.subSequence(i, i+1).hashCode() - 0xAC00; consonant = value % 28; initial = (int)(((value - consonant) / 28) / 21); if(initial > 0) result += arr_consonant[initial];
else result += str.substring(i, i+1);
}

return result;
}

장보기 어플 개발된 화면

1. 우선 장보기 항목을 위한 초성검색 기능이다. 장보기 항목을 가장 빠르게 입력할 수 있는 방법은 초성검색을 지원하는 검색 기능일 것으로 생각했다. 그래서 AutoCompleteTextView를 활용하여 초성검색 입력 기능을 넣었다.
2. 다음은 추가된 장보기 항목이다. 구매된 항목을 클릭하면 구매된 리스트로 표시가 된다. 쉽게 구매항목과 아직 구매되지 않은 항목을 확인할 수 있어야 할 것 같았다.
 
3. 그리고 추가된 항목을 삭제하는 기능이다. 해당 항목을 길게 클릭하면 삭제를 위한 팝업이 뜬다. 삭제를 하기 위해서 "삭제"버튼을 클릭한다.
 
4. 리스트 아래 부분의 두개의 버튼은 새로고침버튼과 항목 일괄 삭제 버튼이다.

장보기 어플 개발 배경

장을 보러 가기전에 항상 품목 리스트를 만들고 간다.
나야 항상 마누라 심부름으로 가는 거니...
마누라가 필요한 물품을 줄줄이 이야기 한다.
그럼 나는 핸드폰 메모장에 열심히 적는다. 아니면 종이에 적는다.
하도 귀찮아서 마누라 보고 써서 달라고 하니 마누라는 투덜거린다...(몇개 안되는 걸 못 외우냐고...)
외워 보기도 했는데... 이상하게 장을 보러가면 구경하느라 가끔 하나씩 빼먹는다... ㅋㅋ

그래서 항상 장보기 어플을 만들어 봐야지 하는 생각을 가지고 있었다.
쉽게 등록할 수 있고 산것과 안 산것을 쉽게 확인할 수 있는 그런 간단한 어플을....

2010년 7월 22일 목요일

애뮬레이터 한글자판 설정

애뮬레이터에 기본적으로 한글자판이 설치되어 있지 않다.
따라서 한글자판 사용을 위해서는 해당 앱을 설치해야만 가능하다.

1. HangulKeyboard.apk 파일을 다운
2. 아래의명령을 실행한다.
adb install 다운로드경로\HangulKeyboard.apk
3. 이클립스에서 가상장치를 구동시킨다.
4. 구동시칸 가상장치의 첫화면(메인)에서
메뉴버튼 >> 설정 >> 언어 및 키보드 를 클릭한다.
5. Android키보드와 한글 접촉식 키보드 를 선택한다.

2010년 7월 13일 화요일

TTS(Text To Speech) 사용하기

음... 반복이의 단어들을 자동으로 읽어주기 위해서 TTS 기능을 추가했다.
약간의 에러가 있어서 해매기는 했지만 지금은 잘 작동이 된다. (음... ㅋㅋ)

TTS 사용을 위한 Sample 코드와 에러를 해결했던 나의 Know-how를 적어 본다.

1. Sample Code (http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html)
 /*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package com.example.android.apis.app;

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.android.apis.R;

import java.util.Locale;
import java.util.Random;

public class TextToSpeechActivity extends Activity implements TextToSpeech.OnInitListener {

private static final String TAG = "TextToSpeechDemo";

private TextToSpeech mTts;
private Button mAgainButton;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView
(R.layout.text_to_speech);

// Initialize text-to-speech. This is an asynchronous operation.
// The OnInitListener (second argument) is called after initialization completes.
mTts
= new TextToSpeech(this,
this // TextToSpeech.OnInitListener
);

// The button is disabled in the layout.
// It will be enabled upon initialization of the TTS engine.
mAgainButton
= (Button) findViewById(R.id.again_button);

mAgainButton
.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sayHello
();
}
});
}

@Override
public void onDestroy() {
// Don't forget to shutdown!
if (mTts != null) {
mTts
.stop();
mTts
.shutdown();
}

super.onDestroy();
}

// Implements TextToSpeech.OnInitListener.
public void onInit(int status) {
// status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
if (status == TextToSpeech.SUCCESS) {
// Set preferred language to US english.
// Note that a language may not be available, and the result will indicate this.
int result = mTts.setLanguage(Locale.US);
// Try this someday for some interesting results.
// int result mTts.setLanguage(Locale.FRANCE);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result
== TextToSpeech.LANG_NOT_SUPPORTED) {
// Lanuage data is missing or the language is not supported.
Log.e(TAG, "Language is not available.");
} else {
// Check the documentation for other possible result codes.
// For example, the language may be available for the locale,
// but not for the specified country and variant.

// The TTS engine has been successfully initialized.
// Allow the user to press the button for the app to speak again.
mAgainButton
.setEnabled(true);
// Greet the user.
sayHello
();
}
} else {
// Initialization failed.
Log.e(TAG, "Could not initialize TextToSpeech.");
}
}

private static final Random RANDOM = new Random();
private static final String[] HELLOS = {
"Hello",
"Salutations",
"Greetings",
"Howdy",
"What's crack-a-lackin?",
"That explains the stench!"
};

private void sayHello() {
// Select a random hello.
int helloLength = HELLOS.length;
String hello = HELLOS[RANDOM.nextInt(helloLength)];
mTts
.speak(hello,
TextToSpeech.QUEUE_FLUSH, // Drop all pending entries in the playback queue.
null);
}

}

2. 에러 처리
에러는 "Language is not supported." 이다.
내가 사용하는 폰의 언어 설정은 한국어로 되어 있다.
당연히 지역도 한국으로 되어 있을 것이다.
하지만 Locale.US를 사용하면 지역과 언어가 en_US 가 된다.
따라서 폰의 언어 설정을 영어로 변경하여야 아무런 에러 없이 실행이 된다.
그럼 한국어 설정에서 영어 설정을 사용하려면????
바로 Locale.US => Locale.ENGLISH로 수정하면 된다.
그러면 한국어 설정에서도 TTS에 영어를 적용할 수 있다.

그럼 여기까지 TTS 활용 방법이였다.

모두들 즐거운 하루되세요.

2010년 7월 6일 화요일

데이터 저장을... 파일? DB? 아니면 다른 방법?

반복이를 위한 데이터를 저장하기 위해서 방식을 어떻게 해야 할지?
일단 DB를 사용해서 데이터를 저장하지만 갑작스럽게 고민이 된다.
파일을 이용하여 SD카드를 활용하는 것이 좋은지?
아니면 계속 DB를 활용하는 것이 좋은 것인지?
아니면 다른 방법이 있을지?

DB를 활용하면 저장된 데이터를 활용하는데 편하다.
하지만 SD카드를 활용할 수 없어서 데이터가 증가하면...
안드로이드 2.2에서는 어플을 SD카드에 설치를 할 수 있어서 용량 문제가 없지만,
아직은 어플의 영역에 많은 데이터를 저장하면... 좋지 않을 것 같다는 생각이 있다.

그럼 파일을 사용해야 할까?
활용하기는 어렵지만 SD카드를 활용하여 데이터를 관리할 수 있고,
추가 데이터에 대해서 DB에 업로드할 필요없이 컨텐츠파일만 변경하면 되므로
활용하기도 편할 것 같다.

지금 생각나는 장단점은 여기까지이다.

더 고민해야 할 듯... ^^