Android Open Source - game_guess_lib Guess Game Updater






From Project

Back to project page game_guess_lib.

License

The source code is released under:

MIT License

If you think the Android project game_guess_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wkmf.guess.lib.service;
/*  ww  w  . jav  a2  s.  co m*/
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.NotificationCompat;

import com.wkmf.guess.lib.R;
import com.wkmf.guess.lib.common.api.GuessApi;
import com.wkmf.guess.lib.common.api.GuessRestApi;
import com.wkmf.guess.lib.data.GuessGameBDDHandler;
import com.wkmf.guess.lib.structure.GuessConfig;
import com.wkmf.guess.lib.structure.GuessGame;
import com.wkmf.lib.curl.CurlListener;

import java.util.Random;

/**
 * Created by ernestofndz on 07/03/14.
 */
public class GuessGameUpdater extends BroadcastReceiver implements CurlListener {

    private GuessGame guessGame = null;
    private Context context;
    private NotificationManager notificationManager;
    private NotificationCompat.Builder notificationBuilder;

    @Override
    public void onReceive(Context context, Intent intent) {
        this.context = context;
        // recuperamos el objeto desde bdd
        guessGame = new GuessGameBDDHandler(context, GuessConfig.BDD).getGuessGame();
        if (guessGame != null) {
            // hacemos la peticin al servidor
            new GuessRestApi(context, this, false).getLevels(guessGame.getAppId());
        }
    }

    @Override
    public void callback(String result) {
        // recibimos la respuesta
        final GuessGame guessGameNew = new GuessGame(guessGame.getAppId(), GuessApi.toLevels(result));
        // comparamos con actual
        if (guessGameNew.getLevels().size() > guessGame.getLevels().size()) {
            // tenemos niveles nuevos, los recuperamos e insertamos en bdd
            for (int i = guessGame.getLevels().size(); i < guessGameNew.getLevels().size(); i++) {
                guessGame.getLevels().add(guessGameNew.getLevels().get(i));
            }
            // insertamos en bdd
            new GuessGameBDDHandler(context, GuessConfig.BDD).update(guessGame);
            // damos aviso al usuario de que tiene ms niveles disponibles
            notifyUser();
        }
    }

    private void notifyUser() {
        // inicializamos el sistema de notificaciones
        this.notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // builder de la notificacion
        this.notificationBuilder = new NotificationCompat.Builder(context);
        // generamos notificacion aleatoria
        int notif_id = new Random(System.currentTimeMillis()).nextInt();
        // inicializamos la notificacin
        long[] vibraPattern = {0, 500, 250, 500};
        this.notificationBuilder
                .setContentTitle(context.getString(R.string.notification_title))
                .setContentText(context.getString(R.string.notification_subtitle))
                .setVibrate(vibraPattern)
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.ic_launcher);
        // notificamos al usuario
        if (Build.VERSION.SDK_INT < 16) {
            /*build notification for HoneyComb to ICS*/
            notificationManager.notify(notif_id, this.notificationBuilder.getNotification());
        }
        if (Build.VERSION.SDK_INT > 15) {
            /*Notification for Jellybean and above*/
            notificationManager.notify(notif_id, this.notificationBuilder.build());
        }
    }
}




Java Source Code List

com.android.vending.billing.util.Base64DecoderException.java
com.android.vending.billing.util.Base64.java
com.android.vending.billing.util.IabException.java
com.android.vending.billing.util.IabHelper.java
com.android.vending.billing.util.IabResult.java
com.android.vending.billing.util.Inventory.java
com.android.vending.billing.util.Purchase.java
com.android.vending.billing.util.Security.java
com.android.vending.billing.util.SkuDetails.java
com.wkmf.guess.lib.common.Constants.java
com.wkmf.guess.lib.common.ads.GuessGameAdsListener.java
com.wkmf.guess.lib.common.ads.GuessGameAds.java
com.wkmf.guess.lib.common.api.GuessApi.java
com.wkmf.guess.lib.common.api.GuessRestApi.java
com.wkmf.guess.lib.common.async.DownloadTask.java
com.wkmf.guess.lib.common.dialog.DialogElement.java
com.wkmf.guess.lib.common.dialog.DialogModalListAdapter.java
com.wkmf.guess.lib.common.dialog.DialogModal.java
com.wkmf.guess.lib.data.GuessGameBDDHandler.java
com.wkmf.guess.lib.data.GuessSQL.java
com.wkmf.guess.lib.impl.GuessGameBaseApp.java
com.wkmf.guess.lib.impl.GuessGameImageDownload.java
com.wkmf.guess.lib.impl.GuessGameInterface.java
com.wkmf.guess.lib.purchase.items.GuessGameItems.java
com.wkmf.guess.lib.screen.GuessLevelScreen.java
com.wkmf.guess.lib.screen.GuessMainScreen.java
com.wkmf.guess.lib.screen.GuessQuestionScreen.java
com.wkmf.guess.lib.screen.adapter.LevelsAdapter.java
com.wkmf.guess.lib.screen.adapter.QuestionsAdapter.java
com.wkmf.guess.lib.service.GuessGameService.java
com.wkmf.guess.lib.service.GuessGameUpdater.java
com.wkmf.guess.lib.service.ServiceStarter.java
com.wkmf.guess.lib.structure.GuessConfig.java
com.wkmf.guess.lib.structure.GuessDrawable.java
com.wkmf.guess.lib.structure.GuessGame.java
com.wkmf.guess.lib.structure.GuessLevelType.java
com.wkmf.guess.lib.structure.GuessLevel.java
com.wkmf.guess.lib.structure.GuessQuestion.java