Skip to content

Instantly share code, notes, and snippets.

@akisute
Created February 16, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akisute/ae05a2661b5615af80a3 to your computer and use it in GitHub Desktop.
Save akisute/ae05a2661b5615af80a3 to your computer and use it in GitHub Desktop.
MotionEvent testing on Android Watch https://twitter.com/akisutesama/status/567344923343458305
public class MainActivity extends Activity {
@InjectView(R.id.container)
View mContainerView;
@InjectView(R.id.text)
TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Object activity = this;
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
ButterKnife.inject(activity, stub);
mContainerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mTextView.setText("Down");
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
mTextView.setText("Up");
break;
case MotionEvent.ACTION_CANCEL:
mTextView.setText("Cancel");
break;
}
return true;
}
});
}
});
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onResume() {
super.onResume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment