옵션 |
|
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | public class ActionService extends Service{ private ImageView mCursorView; private WindowManager.LayoutParams mParams; //뷰의 위치 및 크기 private WindowManager mWindowManager; private Thread checkLearn_course; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { super.onCreate(); Log.i("TAG", "Action Service Started"); mCursorView = new ImageView(this); mCursorView.setImageResource(R.xml.cursor); mCursorView.setBackgroundColor(Color.TRANSPARENT); mCursorView.setImageResource(R.drawable.cursor_norm); mParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT,//w WindowManager.LayoutParams.WRAP_CONTENT,//h WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,//_type WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH /*& WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON & WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON */,//_flags PixelFormat.TRANSLUCENT);//_format mParams.gravity = Gravity.CENTER | Gravity.CENTER; mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); checkLearn_course = new Thread(new Runnable() { public void run() { while (!(checkLearn_course.isInterrupted())) { //Interrupt 메소드가 호출되면 중지 switch(항상2인int형변수){ case 0: break; case 1: break; case 2: new Handler(Looper.getMainLooper()).post(new Runnable() { // new Handler and Runnable @Override public void run() { mWindowManager.addView(mCursorView, mParams); mCursorView.setX(mCursorView.getX() + 100); mWindowManager.updateViewLayout(mCursorView, mParams);//윈도우매니져 내 뷰의 위치 업데이트 });//addView는 메인 스레드에서만! checkLearn_course.interrupt(); break; } } } }); checkLearn_course.start(); } @Override public void onDestroy() { Log.i("TAG", "Action Service Ended"); checkLearn_course.interrupt(); if (mWindowManager != null) { //서비즈 종료시 꼭 뷰를 제거하자. if (mCursorView.isShown()) mWindowManager.removeView(mCursorView); } super.onDestroy(); } } | cs |