diff options
Diffstat (limited to 'demokit/app/src/com/google/android/DemoKit/BaseActivity.java')
-rw-r--r-- | demokit/app/src/com/google/android/DemoKit/BaseActivity.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/demokit/app/src/com/google/android/DemoKit/BaseActivity.java b/demokit/app/src/com/google/android/DemoKit/BaseActivity.java new file mode 100644 index 0000000..249ad52 --- /dev/null +++ b/demokit/app/src/com/google/android/DemoKit/BaseActivity.java @@ -0,0 +1,93 @@ +package com.google.android.DemoKit; + +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +public class BaseActivity extends DemoKitActivity { + + private InputController mInputController; + + public BaseActivity() { + super(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (mAccessory != null) { + showControls(); + } else { + hideControls(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.add("Simulate"); + menu.add("Quit"); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getTitle() == "Simulate") { + showControls(); + } else if (item.getTitle() == "Quit") { + finish(); + System.exit(0); + } + return true; + } + + protected void enableControls(boolean enable) { + if (enable) { + showControls(); + } else { + hideControls(); + } + } + + protected void hideControls() { + setContentView(R.layout.no_device); + mInputController = null; + } + + protected void showControls() { + setContentView(R.layout.main); + + mInputController = new InputController(this); + mInputController.accessoryAttached(); + } + + protected void handleJoyMessage(JoyMsg j) { + if (mInputController != null) { + mInputController.joystickMoved(j.getX(), j.getY()); + } + } + + protected void handleLightMessage(LightMsg l) { + if (mInputController != null) { + mInputController.setLightValue(l.getLight()); + } + } + + protected void handleTemperatureMessage(TemperatureMsg t) { + if (mInputController != null) { + mInputController.setTemperature(t.getTemperature()); + } + } + + protected void handleSwitchMessage(SwitchMsg o) { + if (mInputController != null) { + byte sw = o.getSw(); + if (sw >= 0 && sw < 4) { + mInputController.switchStateChanged(sw, o.getState() != 0); + } else if (sw == 4) { + mInputController + .joystickButtonSwitchStateChanged(o.getState() != 0); + } + } + } + +}
\ No newline at end of file |