Created
February 16, 2015 15:32
-
-
Save akisute/ae05a2661b5615af80a3 to your computer and use it in GitHub Desktop.
MotionEvent testing on Android Watch https://twitter.com/akisutesama/status/567344923343458305
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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