① INTERNET 퍼미션 설정하고,

② 스레드를 생성해서, 코드 실행. (메인스레드에서 네트워크를 바로 사용할수 없다는 듯?)



//URL 에서 스트림 생성해서 읽기

    URL url = new URL("https://www.google.co.jp/");

           

                BufferedReader in = new BufferedReader(

                new InputStreamReader(url.openStream()));

                String inputLine;

                while ((inputLine = in.readLine()) != null)

                in.close();







Posted by tenn
,

[Android] Animation

Android 2012. 7. 24. 18:26



FadeIn FadeOut



      Animation fadeIn = new AlphaAnimation(0, 1);

            fadeIn.setInterpolator(new DecelerateInterpolator()); 

            fadeIn.setDuration(2000);


            Animation fadeOut = new AlphaAnimation(1, 0);

            fadeOut.setInterpolator(new AccelerateInterpolator()); 

            fadeOut.setStartOffset(2000);

            fadeOut.setDuration(2000);


//두 애니메이션을 묶어주기 위한 AnimationSet

            AnimationSet animation = new AnimationSet(true);

            animation.addAnimation(fadeOut);

            animation.addAnimation(fadeIn);



// 애니메이션 이벤트 핸들링을 위한 리스너

            animation.setAnimationListener(new AnimationListener() {

                public void onAnimationStart(Animation animation) {}

                public void onAnimationRepeat(Animation animation) {}

                public void onAnimationEnd(Animation animation) {

                }

            });

            

            

            fl.setAnimation(animation);    

//애니메이션 줄 대상에 애니메이션 세팅







이동 애니메이션


   TranslateAnimation moveAnim = new TranslateAnimation(0, 0, 100, 0);

//( x move from, x move to, y move from, y move to)

    moveAnim.setDuration(1000);

    moveAnim.setFillAfter(true);    //애니메이션이 끝난 후, 그 위치에






AnimationSet의 Repeat


Thread + Handler를 사용.

AnimationSet의 setRepeatCount가 듣지를 않던데...?



...

new Thread(){

public void run(){

while(frame != null){

alphaAnim.sendEmptyMessage(0);

SystemClock.sleep(4000);

}

}

}.start();

...




public final Handler alphaAnim = new Handler() {

public void handleMessage(Message msg) {

 

           

    Animation fadeOut = new AlphaAnimation(1, 0.2f);

            fadeOut.setInterpolator(new AccelerateInterpolator()); 

            fadeOut.setStartOffset(2000);

            fadeOut.setDuration(2000);


            Animation fadeIn = new AlphaAnimation(0.2f, 1);

            fadeIn.setInterpolator(new DecelerateInterpolator()); 

            fadeIn.setDuration(2000);


            AnimationSet animation = new AnimationSet(true);

            animation.addAnimation(fadeOut);

            animation.addAnimation(fadeIn);

           

            //animation.setRepeatCount(100);

            //animation.setRepeatMode(Animation.RESTART);

           

            tv.startAnimation(animation);

}

};








Posted by tenn
,

[Android] BitmapDrawable

Android 2012. 7. 18. 14:26


leak의 가능성이 있는 BitmapFactory보다는 BitmapDrawable을 쓰는 편이 안전.


BitmapDrawable drawable = 
            (BitmapDrawable) getResources().getDrawable(R.drawable.icon);
Bitmap bitmap = drawable.getBitmap();




BitmapDrawable.getBitmap()  의 결과값은 final 이므로 수정불가.

수정하고 싶을때는 copy로 인스턴스를 얻는다.


Bitmap bitmap = drawable.getBitmap().copy(Config.ARGB_8888true);




Posted by tenn
,