

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/04/06 01:40
Canvas.drawLine으로 많은 선을 draw할 경우에는 선을 그리는 계산을 많이 하기 때문에 리소스를 많이 사용하게 된다.
만약 drawLine으로 수직선이나 수평선을 그릴 경우에는 drawRect로 하는게 더 빠르다.
canvas.drawLine(x,y,x,y1,paint) 와 같은 굵기가 1인 y에서 y1으로 수직선을 draw할때는
canvas.drawRect(x,y,x+1,y1,paint) 와 같이 너비가 1인 사각형으로 구현하는 것이 더 좋다.
여러분의 커뮤니케이션을 기다리고 있습니다.

Posted by EHXM. Posted in " 안드로이드/Tech Note "2010/03/03 13:00
안드로이드 액티비티의 방향을 설정하는 방법입니다.
AndroidManifest.xml 파일의 <activity>의 android:screenOrientation속성으로 조절이 가능합니다.
만약 OrientationActivity라는 액티비티를 가로로 설정하려면 다음과 같이 AndroidManifest.xml 파일의 속성을 변경해 줍니다.
<activity android:name=".OrientationActivity"
android:screenOrientation="landscape">android:screenOrientation로 지정할 수 있는 속성은 다음과 같습니다.
"unspecified" |
System에서 디바이스에 따라 방향을 결정 |
"landscape" |
가로방향 |
"portrait" |
세로방향 |
"user" |
사용자 설정 |
"behind" |
이전 액티비티의 스택에 따라 결정 |
"sensor" |
가속 센서의 방향에 따라 결정 |
"nosensor" |
가속 센서를 사용하지 않음. "unspecified"와 비슷 |
여러분의 커뮤니케이션을 기다리고 있습니다.

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