'Android'에 해당되는 글 58건

  1. 2012.12.24 [android] layout center
  2. 2012.12.22 [android] gesture 제스쳐
  3. 2012.10.31 [Android] 가로로 움직이는 스크롤뷰, HorizontalScrollView
  4. 2012.10.31 [Android] ImageView, Color Filter
  5. 2012.10.30 [Android] Re-installation failed due to different application signatures.
  6. 2012.10.29 [Android] Color Filter, Canvas
  7. 2012.10.09 [Android] 기본브라우저에서 어플 실행시키기
  8. 2012.09.26 [Android] Drawalble Bitmap recycle
  9. 2012.09.24 [Android] Manifest
  10. 2012.09.21 [Android] crash report 구글 문서로 받기 : Acra
  11. 2012.09.18 [Android] Manifest의 정보 읽기
  12. 2012.09.18 [Android] AlertDialog tip
  13. 2012.09.14 [Android] File 직렬화, ArrayList -> File
  14. 2012.09.10 [Android] Layout Rounding
  15. 2012.09.10 [Android] TextView
  16. 2012.08.30 [Android] View Capture, setDrawingCacheEnabled, getDrawingCache
  17. 2012.08.30 [Android] ProgressDialog, progress
  18. 2012.08.23 [Android] Bitmap copy
  19. 2012.08.23 [Android] No Launcher activity found!
  20. 2012.08.22 [Android] ProgressBar ProgressDialog의 사용에 대해서
  21. 2012.08.21 [Android] Menu Button Event
  22. 2012.08.21 [Android] Canvas methods
  23. 2012.08.20 [Android] Image round처리. 모서리 둥글게.
  24. 2012.08.20 [Android] Mask Image 합성
  25. 2012.08.17 [Android] UI 갱신, Error : Only the original thread that created...
  26. 2012.08.16 [Android] ASyncTask
  27. 2012.08.15 [Android] Canvas Animation
  28. 2012.08.13 [Android] MotionEvent, 마우스 이벤트
  29. 2012.08.10 [Android] 동영상 관련, VideoView 2
  30. 2012.08.09 [Android] 현재 사용 메모리, 숫자 1000단위 콤마

[android] layout center

Android 2012. 12. 24. 00:42


ImageView in FrameLayout



ImageView iv = new ImageView(MainActivity.this);

iv.setImageDrawable(MainActivity.this.getResources().getDrawable(drawable.arrow));

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

lp.width = 100;

lp.height = 30;

iv.setLayoutParams(lp);


float frame_center_x = frame.getWidth() /2;

float frame_center_y = frame.getHeight() /2;

iv.setX(frame_center_x - iv.getLayoutParams().width/2);

iv.setY(frame_center_y -  iv.getLayoutParams().height/2);


frame.addView(iv);





Posted by tenn
,

[android] gesture 제스쳐

Android 2012. 12. 22. 13:41




Posted by tenn
,

HorizontalScrollView sv = new HorizontalScrollView(this);


LinearLayout ll = new LinearLayout(this);

ll.setOrientation(LinearLayout.HORIZONTAL);

Posted by tenn
,

Gray Scale


ColorMatrix matrix = new ColorMatrix();

matrix.setSaturation(0);

ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix);

iv.setColorFilter(cf);


or


ColorMatrix matrix = new ColorMatrix(

new float[] { -1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255,0, 0, 0, 1, 0 });

ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix);

iv.setColorFilter(cf);





캔버스에서컬러필터지정


Posted by tenn
,


다른 개발환경에서 설치한 혹은 서명key가 다른 동일한 어플리케이션이 설치되어 있을 때의 에러이다.

설치되어 있는 어플을 언인스톨 해주면 된다.

Posted by tenn
,

public void onDraw(Canvas canvas) 에서





Sepia



Paint paint = new Paint();

paint.setAntiAlias(true);


ColorMatrix cm = new ColorMatrix(

new float[] { 0.3930000066757202f, 0.7689999938011169f,

0.1889999955892563f, 0, 0, 0.3490000069141388f,

0.6859999895095825f, 0.1679999977350235f, 0, 0,

0.2720000147819519f, 0.5339999794960022f,

0.1309999972581863f, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 });



paint.setColorFilter(new ColorMatrixColorFilter(cm));

canvas.drawBitmap( ... );





Gray Scale



cm = new ColorMatrix(


new float[] { 0.299f, 0.587f, 0.114f, 0, 0, 0.299f, 0.587f, 0.114f,

0, 0, 0.299f, 0.587f, 0.114f, 0, 0, 0, 0, 0, 1, 0 });





Reverse



cm = new ColorMatrix(


new float[] { -1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255,

0, 0, 0, 1, 0 });




Adjust Contrast


ColorMatrix cm = new ColorMatrix(); float contrast = 2;
cm.set(new float[] {

contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, 1, 0 });

paint.setColorFilter(new ColorMatrixColorFilter(cm)); 




Adjust Brightness


ColorMatrix cm = new ColorMatrix(); float brightness = -25;
cm.set(new float[] {

1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });

paint.setColorFilter(new ColorMatrixColorFilter(cm)); 




Adjust saturation


ColorMatrix cm = new ColorMatrix(); cm.setSaturation(.5f);
paint.setColorFilter(new ColorMatrixColorFilter(cm));

1보다 큰 값을 넘겨주면 채도가 늘어난다. 영(0)1 사이의 값이라면 채도는 줄어든다.








Posted by tenn
,

< 인텐트필터 개념 참조 >




어플리케이션을 실행시킬 html 페이지의 링크


<a href = "testapp://test"> 실행 </a>





Manifest의 실행시키고 싶은 액티비티에 intent-filter 추가



           <intent-filter>

                <action android:name="android.intent.action.VIEW" />


                <category android:name="android.intent.category.LAUNCHER" />

                <category android:name="android.intent.category.BROWSABLE" />

                <category android:name="android.intent.category.DEFAULT" />


                <data

                    android:host="test"

                    android:scheme="testapp" />

            </intent-filter>





시작 액티비티 실행시키기



            <intent-filter>   메인액티비티 인텐트 필터

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

            <intent-filter>

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />

                <category android:name="android.intent.category.DEFAULT" />

                <data

                    android:host="test"

                    android:scheme="testapp" />

            </intent-filter>





Posted by tenn
,



Bitmap recycle의 타이밍.


같은 액티비티 안에서 recycle한 Bitmap을 참조하려고 하면 예외가 발생한다.


Bitmap a = ((BitmapDrawable) getResources().getDrawable(R.drawalbe.xxx1))

Bitmap b = ((BitmapDrawable) getResources().getDrawable(R.drawalbe.xxx1))


// a와 b 어느쪽을 recycle해도 다른 쪽 변수가 영향을 받는다.





Activity1

onCreate 

resource1으로 비트맵 생성

ImageView에 표시

onDestroy

resource1 recycle


Activity2

onCreate

resource1으로 비트맵 생성 (사용가능)







BitmapFactory -> drawable -> Bitmap 은 같은  resource id라도 새로운 인스턴스가 생성되나.

Context -> resource -> drawable -> Bitmap은 캐쉬에서 읽어오기 때문에 같은 인스턴스가 된다.




http://blog.naver.com/PostView.nhn?blogId=prokyhsigma&logNo=120148185960






Posted by tenn
,

[Android] Manifest

Android 2012. 9. 24. 12:59



// 전화기능?

<uses-feature android:name="android.hardware.telephony" android:required="false" />




<안드로이드 매니페스트파일 설정>


Posted by tenn
,





<ref1 : 日本語 > 


<ref2 : 한국어>

Posted by tenn
,

debuggable


(getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)  

// debuggable가 false일 경우 0


<ref>


Posted by tenn
,

[Android] AlertDialog tip

Android 2012. 9. 18. 15:02



표시 메세지 개행. ¥마크로는 안되고 역슬래시 잘 써야됨.


alertDiag.setMessage("ブラウザで開きます。"+"\n"+"よろしいですか。");


타이틀 표시하지 않기.


alertDiag.setTitle(null);  //타이틀영역자체가 표시 되지 않음.


Posted by tenn
,




HashMap으로는 readObject()에서 예외가 발생.

GetFieldID: unable to find field Ljava/util/HashMap;.loadFactor:F



ArrayList -> file -> ArrayList

<ref>




TextView tv = (TextView)findViewById(R.id.textView2);

try {

ArrayList al = new ArrayList();

al.add("one");

al.add("two");

al.add("three");

ObjectOutputStream os = new ObjectOutputStream(

new BufferedOutputStream(new FileOutputStream(

getFilesDir().getAbsolutePath()+"/a.ser")));


os.writeObject(al);

os.close();



File file = new File(getFilesDir().getAbsolutePath()+"/a.ser");

Log.e(null, "file exist? : "+ file.exists());

ObjectInputStream ois = new ObjectInputStream(

new BufferedInputStream(new FileInputStream(

getFilesDir().getAbsolutePath()+"/a.ser")));


ArrayList al2 = (ArrayList)ois.readObject();


ois.close();

tv.setText(al2.get(1) + " - " + al2.get(2) + " - " + al2.get(0));


} catch (Exception e) {

Log.e(null, e.toString());

}


Posted by tenn
,

[Android] Layout Rounding

Android 2012. 9. 10. 11:17

레이아웃의 모서리를 둥글게


<Ref>



<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android" >


    <corners android:radius="15dp" />


    <solid android:color="#FF000000" />


</shape>



Posted by tenn
,

[Android] TextView

Android 2012. 9. 10. 10:37




TextView tv = new TextView(this);


tv.setTextColor(Color.WHITE);

tv.setText("text text text");

tv.setTextSize(25);


tv.setShadowLayer(1.5f, -1, 1, Color.LTGRAY);  //그림자 효과    


LinearLayout.LayoutParams lp 

= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);


lp.topMargin = 20;   //마진은 LayoutParams


mainLayout.addView(tv, lp);



그림자 효과 


public void setShadowLayer (float radius, float dx, float dy, int color)


dx, dy : 그림자의 위치


This draws a shadow layer below the main layer, with the specified offset and color, and blur radius. If radius is 0, then the shadow layer is removed.



Posted by tenn
,


resultLayout.setDrawingCacheEnabled(true);

Bitmap result = frame.getDrawingCache();   //Bitmap 생성

....   

frame.setDrawingCacheEnabled(false);        //Bitmap이 recycle되어버린다.



Posted by tenn
,

PregressDialog


waitingDialog = new ProgressDialog(this);  // this:Activity

waitingDialog.setTitle("処理中");

waitingDialog.setMessage("少々お待ちください。");

waitingDialog.setCancelable(false);  //터치로 다이얼로그가 사라지지않게.

waitingDialog.show();


Posted by tenn
,

[Android] Bitmap copy

Android 2012. 8. 23. 18:03



xxx.copy(Bitmap.Config.ARGB_8888, true);




Posted by tenn
,

Error : No Launcher activity found!

최초 시작할 액티비티를 바꿀 때, Manifest에 이하의 태그를 추가해 줌.




  <activity android:name=".CameraActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

</activity>


Posted by tenn
,

부드러운 UI 처리에 대한 소고


이동전의 액티비티에서 진행중의 프로그레스를 띄우면, 움직임이 매끄럽지 못하고, 끊어지게 보인다. 


UIThread인 현재 액티비티가 다음의 액티비티에의 처리를 하게 되기 때문의 문제라고 생각된다. 


무거운 처리가 있을 경우에는  다음의 액티비티에의 이동후, onCreate, onStart, onResume까지 

최대한 가볍게 하여 화면을 표시시킨후, 프로그레스를 띄우는 것이 낫지 않나싶다. 


무거운 처리는 스레드에 시키는 편이 화면 UI에 영향을 적게 미치지 않을까.




Posted by tenn
,


public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {  

        

    }

    return super.onKeyDown(keyCode, event);

}



Posted by tenn
,

[Android] Canvas methods

Android 2012. 8. 21. 10:56




호 그리기

public void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)

useCenter : true/Arc  false/wedge






Posted by tenn
,



Bitmap resultImage = Bitmap.createBitmap(src.getWidth(), src.getHeight(),  Bitmap.Config.ARGB_8888); 

//src : 대상 비트맵


Canvas roundCanvas = new Canvas(resultImage);

final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight());

final RectF rectF = new RectF(rect);

roundCanvas.drawRoundRect(rectF, 30, 30, paint);

Paint roundPaint = new Paint();

roundPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

roundCanvas.drawBitmap(resultImage, rect, rect, roundPaint);



Posted by tenn
,

대상이미지중 마스크 이미지의 투명하지 않은 영역만을 보여줌



ImageView img = photoContents;


Canvas canvas = new Canvas();

Bitmap mainImage = BitmapFactory.decodeFile(imageFile

.getAbsolutePath());

Bitmap tmpMask = BitmapFactory.decodeResource(context.getResources(),

R.drawable.mask);

Bitmap mask = Bitmap.createScaledBitmap(tmpMask, mainImage.getWidth(), mainImage.getHeight(), true);

tmpMask.recycle();

tmpMask = null;

Bitmap result = Bitmap.createBitmap(mainImage.getWidth(),

mainImage.getHeight(), Bitmap.Config.ARGB_8888);


canvas.setBitmap(result);

Paint paint = new Paint();

paint.setFilterBitmap(false);


canvas.drawBitmap(mainImage, 0, 0, paint);

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));  

// DST_IN,  DST_OUT(mask reverse)

canvas.drawBitmap(mask, 0, 0, paint);

paint.setXfermode(null);


img.setImageBitmap(result);

img.invalidate();



< ref > 


Posted by tenn
,

UI Thread 이외에서 UI를 갱신하려고 하면 CalledFromWrongThreadException:Only the original thread that created a view hierarchy can touch its views. 라는 문구를 보게 된다.


Handler


UI의 권한이 있는 Thread의 핸들러에 메시지를 보낸다.

Thread + Handler 조합으로 연속적인 갱신이 가능.



public final Handler handler = new Handler{

@Override

public void handleMessage(Message msg) {

//UI 갱신

}

}



외부에서

xxx.handler.sendEmptyMessage();



Activity.runOnUiThread


UI 갱신 권한이 있는 스레드의 인스턴스를 얻을수 있다면



AActivity.this.runOnUiThread(

new Runnable(){

public void run(){

AActivity.this.xxxx.setText("xxxx");

}}

);



Handler.post 사용


Handler handler = new Handler();


...


handler.post(

new Runnable(

public void run(){

//UI 갱신

}

)

);




그 외의 방법도 있다고 한다. (미확인)


View.post(Runnable)
View.postDelayed(Runnable, long)


Posted by tenn
,

[Android] ASyncTask

Android 2012. 8. 16. 15:39

Thread의 UI 갱신 제한 → Thread + Handler 로직 (복잡함) → ASyncTask


UI갱신 제한에 대해서는


<예제> 인자가 없는 


액티비티의 Nested Class로 구현함.

UI의 갱신은 onPreExecute와 onPostExecute에서는 가능했으나, 

doInBackground, onProgressUpdate에서는 에러.



class MyASyncTask extends AsyncTask<Void, Void, Void> {


@Override

protected void onPreExecute() {

super.onPreExecute();

}


@Override

protected Void doInBackground(Void... params) {

SystemClock.sleep(2000);

return null;

}


@Override

protected void onProgressUpdate(Void... unuse) {

super.onProgressUpdate();

}


@Override

protected void onPostExecute(Void unuse){

super.onPostExecute(unuse);

}


}



Posted by tenn
,

[Android] Canvas Animation

Android 2012. 8. 15. 15:56

invalidate를 루프에서 처리하면 onDraw가 불리지 않는다.

핸들러에서 재귀호출을 하면 /일단은/ 가능하다.


public final Handler refreshHandler = new Handler() {

public void handleMessage(Message msg) {



Act3Activity.this.ca.invalidate();

this.sendEmptyMessageDelayed(0, 25);   <-  25 milisecond 후에 재귀 호출

}

};


Posted by tenn
,

싱글터치


ACTION_DOWN   

ACTION_MOVE   

ACTION_UP      

ACTION_CANCEL    :    터치영역을 벗어날때 (버튼을 누른후 버튼영역을 벗어날때)



멀티터치


ACTION_POINTER_1_DOWN    :    먼저닿은 손가락이 떨어진 후 다시 터치할때

(나중에 닿은 손가락은 계속 터치)

ACTION_POINTER_1_UP        :    먼저 닿은 손가락이 떨어질때

ACTION_POINTER_2_DOWN    :    한손가락을 터치한 채로 다른 손가락이 터치될때

ACTION_POINTER_2_UP    :    나중에 터치된 손가락이 떨어질때



Posted by tenn
,

확인단말 : GalaxyNexus, Galaxy S2


Galaxy Nexus에서 좀처럼 동영상을 재생해주지않아서 삽질.


raw리소스의 동영상 파일을 file로 출력한 후, 생성파일을 이용해서 재생.

생성화일의 확장자는 관계없었다. (mp4를 mov로 바꾸어도 재생가능)


a() : 안드로이드에서 제공해주는 ACTION_VIEW 이용.

b() : VideoView + MediaController 이용.



방법1. 갤러리 이용


void a(){


this.filecopy();

String path = getFilesDir().getAbsolutePath()+"/"+FILE_NAME;

Log.e(null, path);

Log.e(null, "file exist? "+ new File(path).exists());


Intent i = new Intent(Intent.ACTION_VIEW);

 


Uri uri = Uri.fromFile(new File(path));

  it.setDataAndType(uri, "video/*");

  startActivity(i);

}


방법2. VideoVIew



void b(){


VideoView vv = (VideoView) findViewById(R.id.videoView1);


MediaController mc = new MediaController(this);

mc.setAnchorView(vv);

this.filecopy();

String path = getFilesDir().getAbsolutePath()+"/"+FILE_NAME;

Log.e(null"xxx : "+path);

Log.e(null"file : "+new File(path).exists());

vv.setMediaController(mc);

//Uri uri = Uri.fromFile(new File(path));

//vv.setVideoURI(uri);  //uri로도 정상동작

vv.setVideoPath(path);

vv.requestFocus();

vv.start();

}




raw Resource -> file


final String FILE_NAME = "a1.mp4";


void filecopy() {


Log.e(null, "filecopy");

InputStream in = this.getResources().openRawResource(R.raw.a14); //raw리소스


int size;

byte[] w = new byte[1024];

OutputStream out = null;

try {

out = this.openFileOutput(FILE_NAME, Context.MODE_WORLD_READABLE);

while (true) {

size = in.read(w);

if (size <= 0)

break;

out.write(w, 0, size);

}

out.close();

in.close();

} catch (Exception e) {

Log.e(null, e.toString());

}


}


Posted by tenn
,


long m = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

DecimalFormat df = new DecimalFormat("#,##0");

Log.v(null, "using mem : "+df.format(m));



Posted by tenn
,