/** * Handles text notification, scoring and game reset. Should be called in response to the answer * button. */ protected void onAnswer() { if (isAnswerCorrect()) { showToastMessage("Right! :D"); Score.onCorrectAnswer(); generateScoreNotification(); } else { showToastMessage("Wrong :("); Score.onWrongAnswer(); } gameReset(); }
/** Notify user when they have a score that's a multiple of ten. */ private void generateScoreNotification() { int suc = Score.getSuccesses(); int mod = suc % 10; if (suc < 0 || mod != 0) return; String title = "MathApp Score"; String text = "MathApp score reached " + suc + " points!"; Intent onTrigger = new Intent(this, ActivityScore.class); PendingIntent pending = PendingIntent.getActivity(this, 0, onTrigger, Intent.FLAG_ACTIVITY_NEW_TASK); int nResID = R.drawable.ic_launcher; String nText = title; long nTime = System.currentTimeMillis(); Notification notification = new Notification(nResID, nText, nTime); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, title, text, pending); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, notification); }
protected void onResume() { super.onResume(); Score.load(); }