【发布时间】:2014-08-13 18:52:05
【问题描述】:
我正在运行一个用于谷歌眼镜的模拟器,如图所示,通过显示设置、主显示甚至我的活动(我假装是一个交互式静态卡片),它工作得非常完美。
http://mobilevangelist.com/2014/01/02/gdk-and-the-android-emulator/
我发现运动手势是使用 onKeyUp 或 onKeyDown 事件捕获的,但两者都不起作用我不明白为什么。
这是我的代码。
public class LiveCardMenuActivity extends Activity {
private TextView textView;
@Override //isn't catching a thing, even with onKeyDown (mouse taps or slides in the emulator)
public boolean onKeyUp(int keycode, KeyEvent event){
Log.d("tag","keyUp");
if(keycode == KeyEvent.KEYCODE_DPAD_CENTER){
Log.d("tag","keypadcenter");
textView.setText("tap");
}else if(keycode == KeyEvent.KEYCODE_BACK){
Log.d("tag","swipedown");
textView.setText("down");
}
return true;
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
setContentView(R.layout.live_card);
//does successfully, I can see the layout in the emulator
//and I can swipe it to the left (returning to the main display successfully)
textView = (TextView) findViewById(R.id.textView);
Log.d("tag","attached to window");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.live_card, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_stop:
// Stop the service which will unpublish the live card.
stopService(new Intent(this, LiveCardService.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onOptionsMenuClosed(Menu menu) {
super.onOptionsMenuClosed(menu);
// Nothing else to do, finish the Activity.
finish();
}
}
有人可以帮我解决这个问题吗?特维姆!
【问题讨论】:
标签: java android google-glass gesture