

Posted by EHXM. Posted in " 안드로이드/Tech Note "2010/06/10 23:12
수동으로 미디어 스캔을 하는 클래스입니다. 강제 Media Scan Sample Source
import android.content.Context;
import android.media.MediaScannerConnection;
import android.net.Uri;
public class MediaScanner {
private MediaScannerConnection mediaScanConn = null;
private MusicSannerClient client = null;
private String filePath = null;
private String fileType = null;
private String[] filePaths = null;
/**
* Then call the MediaScanner .scanFile("/sdcard/2.mp3");
* */
public MediaScanner(Context context) {
// Create MusicSannerClient
if (client == null) {
client = new MusicSannerClient();
}
if (mediaScanConn == null) {
mediaScanConn = new MediaScannerConnection(context, client);
}
}
class MusicSannerClient implements
MediaScannerConnection.MediaScannerConnectionClient {
public void onMediaScannerConnected() {
if(filePath != null){
mediaScanConn.scanFile(filePath, fileType);
}
if(filePaths != null){
for(String file: filePaths){
mediaScanConn.scanFile(file, fileType);
}
}
filePath = null;
fileType = null;
filePaths = null;
}
public void onScanCompleted(String path, Uri uri) {
// TODO Auto-generated method stub
mediaScanConn.disconnect();
}
}
/**
* Scan file label information
* @param filePath File path eg :/sdcard/MediaPlayer/dahai.mp3
* @param fileType File type eg : audio/mp3 media/* application/ogg
* */
public void scanFile(String filepath,String fileType) {
this.filePath = filepath;
this.fileType = fileType;
// After the connection has been called the onMediaScannerConnected MusicSannerClient () Method
mediaScanConn.connect();
}
/**
* @param filePaths File path
* @param fileType File types
* */
public void scanFile(String[] filePaths,String fileType){
this.filePaths = filePaths;
this.fileType = fileType;
mediaScanConn.connect();
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getFileType() {
return fileType;
}
public void setFileType(String fileType) {
this.fileType = fileType;
}
}
여러분의 커뮤니케이션을 기다리고 있습니다.

Posted by EHXM. Posted in " 안드로이드/Tech Note "2010/06/08 22:16
public class ViewSwitcherExample extends ListActivity
implements OnClickListener {
//sample list items
static final String[] ITEMS = new String[]
{ "List Item 1", "List Item 2",
"List Item 3", "List Item 4",
"List Item 5", "List Item 6",
"List Item 7", "List Item 8",
"List Item 9", "List Item 10" };
//the ViewSwitcher
private ViewSwitcher switcher;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//no window title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//create the ViewSwitcher in the current context
switcher = new ViewSwitcher(this);
//footer Button: see XML1
Button footer = (Button)View.inflate(this, R.layout.btn_loadmore, null);
//progress View: see XML2
View progress = View.inflate(this, R.layout.loading_footer, null);
//add the views (first added will show first)
switcher.addView(footer);
switcher.addView(progress);
//add the ViewSwitcher to the footer
getListView().addFooterView(switcher);
//add items to the ListView
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, ITEMS));
}
@Override /* Load More Button Was Clicked */
public void onClick(View arg0) {
//first view is showing, show the second progress view
switcher.showNext();
//and start background work
new getMoreItems().execute();
}
/** Background Task To Get More Items**/
private class getMoreItems extends AsyncTask {
@Override
protected Object doInBackground(Void… params) {
//code to add more items
//...
try {
Thread.sleep(3000); //only to demonstrate
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override /* Background Task is Done */
protected void onPostExecute(Object result) {
//go back to the first view
switcher.showPrevious();
//update the ListView
}
}
}
여러분의 커뮤니케이션을 기다리고 있습니다.

Posted by EHXM. Posted in " 안드로이드/Tech Note "2010/06/08 19:29
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter
{
public static final String KEY_ROWID = "_id";
public static final String KEY_ISBN = "isbn";
public static final String KEY_TITLE = "title";
public static final String KEY_PUBLISHER = "publisher";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "books";
private static final String DATABASE_TABLE = "titles";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
"create table titles (_id integer primary key autoincrement, "
+ "isbn text not null, title text not null, "
+ "publisher text not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS titles");
onCreate(db);
}
}
//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
//---insert a title into the database---
public long insertTitle(String isbn, String title, String publisher)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ISBN, isbn);
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_PUBLISHER, publisher);
return db.insert(DATABASE_TABLE, null, initialValues);
}
//---deletes a particular title---
public boolean deleteTitle(long rowId)
{
return db.delete(DATABASE_TABLE, KEY_ROWID +
"=" + rowId, null) > 0;
}
//---retrieves all the titles---
public Cursor getAllTitles()
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_ISBN,
KEY_TITLE,
KEY_PUBLISHER},
null,
null,
null,
null,
null);
}
//---retrieves a particular title---
public Cursor getTitle(long rowId) throws SQLException
{
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_ISBN,
KEY_TITLE,
KEY_PUBLISHER
},
KEY_ROWID + "=" + rowId,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
//---updates a title---
public boolean updateTitle(long rowId, String isbn,
String title, String publisher)
{
ContentValues args = new ContentValues();
args.put(KEY_ISBN, isbn);
args.put(KEY_TITLE, title);
args.put(KEY_PUBLISHER, publisher);
return db.update(DATABASE_TABLE, args,
KEY_ROWID + "=" + rowId, null) > 0;
}
}
출처: http://www.devx.com/wireless/Article/40842/1954여러분의 커뮤니케이션을 기다리고 있습니다.

Posted by EHXM. Posted in " 안드로이드/Tech Note "2010/02/09 13:46
Android SDK 2.1 에 Live Wallpaper 샘플이 포함되어 있네요.
아래와 같이 Android 2.1을 선택하고 Samples에서 CubeLiveWallpaper로 프로젝트를 만들어 보세요~
프로젝트를 AVD에서 실행시키고, 바탕화면을 계속 누르고 있으면 Live Wallpaper를 지정할 수 있습니다.
큐브가 배경에서 회전하고 있습니다.
아래는 CubeWallpaper의 뼈대입니다.
WallpaperService 상속받아서 클래스를 구현하고, 실제 동작내용을 내부에서 Engine을 상속받아서
해당 메소드를 구현해 주면 끝이군요.
public class CubeWallpaper1 extends WallpaperService {
private final Handler mHandler = new Handler();
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public Engine onCreateEngine() {
return new CubeEngine();
}
class CubeEngine extends Engine {
private final Runnable mDrawCube = new Runnable() {
public void run() {
}
};
private boolean mVisible;
CubeEngine() {
}
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onVisibilityChanged(boolean visible) {
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
}
@Override
public void onOffsetsChanged(float xOffset, float yOffset,
float xStep, float yStep, int xPixels, int yPixels) {
}
@Override
public void onTouchEvent(MotionEvent event) {
}
}
}
onVisibilityChanged로 월페이퍼가 안보일때의 처리, onOffsetsChanged로 홈스크린에서 옆화면으로 이동했을때의 처리,
onTouchEvent로 터치이벤트를 처리해 주는 것 같습니다.
여러분의 커뮤니케이션을 기다리고 있습니다.

아이디어의 전쟁의 현장이었던 2010년 대한민국 매쉬업 경진대회에 다녀왔습니다. 이번 대회는 지난 2월 6일(토요일), 삼성동 코엑스 컨퍼런스룸 401에서 열렸습니다. 이번.....
2010년에 100가지가 넘는 안드로이드 폰 출시가 될 예정입니다. Mobile World Congress keynote에서 Google CEO Eric Schmidt의 연설.....
서울, 안양, 부산, 대구, 광주, 대전에 안드로이드 폰 체험 할 수 있는 곳이 있네요. 저는 코엑스 메가박스 입구에 있는 모토로라 체험 부스에서 우연히 모토로이를 만져보게 되.....
위 3D 갤러리는 http://www.fotoviewr.com/ 사이트의 Fotoviewr 입니다. Flex와 Papervision3D를 이용하여 위와같은 3D 갤러리를 구현해.....
Total : 115,868 Today : 224 Yesterday : 155