GVRBaseController getCursorController(GVRContext context) { Log.d(TAG, "Creating Mouse Device"); if (threadStarted == false) { Log.d(TAG, "Starting " + THREAD_NAME); thread.start(); thread.prepareHandler(); threadStarted = true; } GVRMouseController controller = new GVRMouseController(context, GVRCursorType.MOUSE, thread); int id = controller.getId(); controllers.append(id, controller); return controller; }
@Override public boolean dispatchMotionEvent(MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_MOUSE)) { return thread.submitMotionEvent(getId(), event); } else { return false; } }
void removeCursorController(GVRBaseController controller) { int id = controller.getId(); controllers.remove(id); // stop the thread if no more devices are online if (controllers.size() == 0 && threadStarted) { Log.d(TAG, "Stopping " + THREAD_NAME); thread.quitSafely(); thread = new EventHandlerThread(THREAD_NAME); threadStarted = false; } }
void stop() { if (threadStarted) { thread.quitSafely(); } }