void requestTimer(boolean on) { if (gameWantsTimer && on) return; gameWantsTimer = on; if (on) handler.sendMessageDelayed(handler.obtainMessage(MsgType.TIMER.ordinal()), timerInterval); else handler.removeMessages(MsgType.TIMER.ordinal()); }
void handleMessage(Message msg) { switch (MsgType.values()[msg.what]) { case TIMER: if (progress == null) timerTick(); if (gameWantsTimer) { handler.sendMessageDelayed(handler.obtainMessage(MsgType.TIMER.ordinal()), timerInterval); } break; case DONE: if (resizeOnDone) { resizeEvent(gameView.w, gameView.h); resizeOnDone = false; } // set ActionBar icon to the one for this puzzle if (msg.obj != null && actionBarCompat != null) { int iconId = getResources().getIdentifier((String) msg.obj, "drawable", getPackageName()); homeAsUpNoticeable = actionBarCompat.setIconAsShortcut(iconId > 0 ? iconId : R.drawable.icon); if (menu != null) menu.findItem(R.id.other).setVisible(!homeAsUpNoticeable); } dismissProgress(); if (menu != null) onPrepareOptionsMenu(menu); save(); break; case ABORT: stopNative(); dismissProgress(); startChooser(); if (msg.obj != null) { messageBox(getString(R.string.Error), (String) msg.obj, 2, false); } else { finish(); } break; } }
@Override public void onWindowFocusChanged(boolean f) { if (f && gameWantsTimer && gameRunning && !handler.hasMessages(MsgType.TIMER.ordinal())) handler.sendMessageDelayed(handler.obtainMessage(MsgType.TIMER.ordinal()), timerInterval); }
@Override protected void onPause() { if (gameRunning) handler.removeMessages(MsgType.TIMER.ordinal()); save(); super.onPause(); }