옵션 |
|
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 | package me.blog.haj990108.winklick; import java.util.Arrays; ........ public class ActionService extends Service{ ........ private void moveClick(boolean isClick, int x, int y){ if(isClick){ mCursorView.setImageResource(R.drawable.cursor_clicked); Log.d("TAG", "TOUCH.x = "+x+", TOUCH.y = "+y);//잘 되는거 같음 long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis(); MotionEvent down_event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN,x,y,0); MotionEvent up_event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP,x,y,0); dispatchTouchToTestActivity(down_event); dispatchTouchToTestActivity(up_event); down_event.recycle(); up_event.recycle(); }else{ mCursorView.setImageResource(R.drawable.cursor_norm); } } private void dispatchTouchToTestActivity(MotionEvent ev){ //TODO dispatchTouchToTestActivity Activity testActivity = (Activity) TestActivity.mContext; Log.d("TAG","testActivity = "+testActivity); testActivity.dispatchTouchEvent(ev); } } | cs |
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 | package me.blog.haj990108.winklick; import android.app.Activity; .......... public class TestActivity extends Activity implements OnClickListener{ private TextView dialTextView; private String dialNum = ""; public static Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); mContext = this; dialTextView = (TextView)findViewById(R.id.dialTextView); findViewById(R.id.button1).setOnClickListener(this); ............. } @Override public void onClick(View v) { // TODO Auto-generated method stub int view = v.getId(); switch(view){ case R.id.button1 : writeDial("1"); break; ............. } } @Override public boolean dispatchTouchEvent(MotionEvent event) {//작동 잘됨 int action=event.getAction(); switch(action) { case MotionEvent.ACTION_DOWN: //code Toast.makeText(getApplicationContext(), "ACTION_DOWN" , Toast.LENGTH_SHORT).show(); break; default: break; } Log.d("TAG", "event = "+event); return super.dispatchTouchEvent(event); } private void writeDial(String str) { dialNum += str; dialTextView.setText(PhoneNumberUtils.formatNumber(dialNum)); } } | cs |