옵션 |
|
1 2 3 4 5 6 7 8 9 | Activity testActivity = (Activity) TestActivity.mContext; 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); testActivity.dispatchTouchEvent(down_event); testActivity.dispatchTouchEvent(up_event); down_event.recycle(); up_event.recycle(); | cs |
1 2 3 4 5 6 7 8 9 | public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if(event.getAction()== MotionEvent.ACTION_DOWN) { Toast.makeText(getApplicationContext(), "ACTION_DOWN" , Toast.LENGTH_SHORT).show(); } return true; } | 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 61 62 63 64 65 66 67 68 69 | 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); ..... findViewById(R.id.buttonBack).setOnClickListener(this); findViewById(R.id.buttonBack).setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { dialNum = ""; dialTextView.setText(""); return true; } }); } @Override public void onClick(View v) { // TODO Auto-generated method stub int view = v.getId(); switch(view){ case R.id.button1 : writeDial("1"); break; ......... case R.id.buttonBack : Log.d("TAG", dialNum); if(dialNum.length() > 0) dialNum = dialNum.substring(0, dialNum.length() - 1); Log.d("TAG", dialNum); dialTextView.setText(PhoneNumberUtils.formatNumber(dialNum)); break; } } public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if(event.getAction()== MotionEvent.ACTION_DOWN) { Toast.makeText(getApplicationContext(), "ACTION_DOWN" , Toast.LENGTH_SHORT).show(); } return true; } private void writeDial(String str) { dialNum += str; dialTextView.setText(PhoneNumberUtils.formatNumber(dialNum)); Toast.makeText(getApplicationContext(), "Clicked Button"+str , Toast.LENGTH_SHORT).show(); } } | cs |