태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

안드로이드용 영어 어학기 Smart LC

스마트LC 소개 링크:
http://blog.ehxm.net/123

티스토어 링크:
http://bit.ly/awW3XW

[안드로이드 샘플코드] 미디어 스캐닝 Class

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;
        }

        
}
저작자 표시

관련 TAG로 검색해보세요. : android, CODE, media, mediascan, sample, 안드로이드

¬ COMMENT [0]

여러분의 커뮤니케이션을 기다리고 있습니다.

  1. : 이름
  2. : 홈페이지

  1. : 비밀번호

[안드로이드 샘플코드] ViewSwitcher

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
		}
	}
}
저작자 표시

관련 TAG로 검색해보세요. : android, CODE, sample, viewswitcher, 안드로이드

¬ COMMENT [0]

여러분의 커뮤니케이션을 기다리고 있습니다.

  1. : 이름
  2. : 홈페이지

  1. : 비밀번호

[안드로이드 샘플코드] Database

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
저작자 표시

관련 TAG로 검색해보세요. : android, CODE, Database, sample, 안드로이드

¬ COMMENT [0]

여러분의 커뮤니케이션을 기다리고 있습니다.

  1. : 이름
  2. : 홈페이지

  1. : 비밀번호

[안드로이드] Live Wallpaper 샘플

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로 터치이벤트를 처리해 주는 것 같습니다.

관련 TAG로 검색해보세요. : android, live Wallpaper, sample, 안드로이드

¬ COMMENT [2]

  1. Posted by 정재현2010/08/14 16:50

    WallpaperService 에서 비트맵을 사용할려고
    Drawable을 써서 png 파일을 불러오려는데 인식을 못하드라구요 왜그런걸까요

     수정/삭제  댓글쓰기

    • Favicon of http://blog.ehxm.net BlogIcon EHXM2010/08/14 22:06

      질문이 모호하네요.
      일단 프로젝트에서 drawable 폴더에 그림을 넣고 (파일선택후 이클립스 프로젝트 익스프로러의 drawable 폴더로 드래그),
      이미지를 set 하는 부분에서 R.drawable. 을 치면 나와요

       수정/삭제

여러분의 커뮤니케이션을 기다리고 있습니다.

  1. : 이름
  2. : 홈페이지

  1. : 비밀번호

[안드로이드] 영어 어학기 어플

영어 듣기 공부 많이들 하시나요? 따로 어학기를 장만하시기는 비용이 들죠? 스마트폰에서 MP3 파일을 터치를 이용해서 자유롭게 듣을 수 있는 영어 어학기 어플입니다. 동아리.....

2010년 대한민국 매쉬업 경진대회 후기, 아이디어 전쟁을 다녀와서..

아이디어의 전쟁의 현장이었던 2010년 대한민국 매쉬업 경진대회에 다녀왔습니다. 이번 대회는 지난 2월 6일(토요일), 삼성동 코엑스 컨퍼런스룸 401에서 열렸습니다. 이번.....

2010년 100가지가 넘는 안드로이드폰이 몰려온다!

2010년에 100가지가 넘는 안드로이드 폰 출시가 될 예정입니다. Mobile World Congress keynote에서 Google CEO Eric Schmidt의 연설.....

[안드로이드] 모토로이 체험할 수 있는 곳 (전국)

서울, 안양, 부산, 대구, 광주, 대전에 안드로이드 폰 체험 할 수 있는 곳이 있네요. 저는 코엑스 메가박스 입구에 있는 모토로라 체험 부스에서 우연히 모토로이를 만져보게 되.....

위 3D 갤러리는 http://www.fotoviewr.com/ 사이트의 Fotoviewr 입니다. Flex와 Papervision3D를 이용하여 위와같은 3D 갤러리를 구현해.....

무료 MP3 포멧 변경 툴 - Free MP3 WMA Converter
무료 MP3 포멧 변경 툴 - Free MP3 WMA Converter
무료 MP3 포멧 변경 툴 - Free MP3 WMA Converter
무료 MP3 포멧 변경 툴 - Free MP3 WMA Converter
언톡 2010년 신입생 모집 포스터
Android, LEGO NXT를 이용한 Sudoku Solving Robot 제작
Android, LEGO NXT를 이용한 Sudoku Solving Robot 제작
Android, LEGO NXT를 이용한 Sudoku Solving Robot 제작
Android, LEGO NXT를 이용한 Sudoku Solving Robot 제작

Category

전체보기 (108)
Anycall Dreamers (1)
안드로이드 (39)
Adobe Flash Platform (20)
Algorithm (0)
개발노트 (6)
경험 (33)

글 보관함

2011/02 (3)

2011/01 (1)

2010/09 (1)

2010/08 (1)

2010/07 (2)

Calendar

«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

믹시


Total : 115,868 Today : 224 Yesterday : 155