Android Open Source - game_guess_lib Guess Main Screen

From Project

Back to project page game_guess_lib.


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.screen;
/*from ww  w  .j  av  a 2s .  co m*/
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.wkmf.guess.lib.R;
import com.wkmf.guess.lib.common.Constants;
import com.wkmf.guess.lib.common.api.GuessApi;
import com.wkmf.guess.lib.common.api.GuessRestApi;
import com.wkmf.guess.lib.impl.GuessGameBaseApp;
import com.wkmf.guess.lib.impl.GuessGameInterface;
import com.wkmf.guess.lib.screen.adapter.LevelsAdapter;
import com.wkmf.guess.lib.service.GuessGameService;
import com.wkmf.guess.lib.structure.GuessConfig;
import com.wkmf.guess.lib.structure.GuessDrawable;
import com.wkmf.guess.lib.structure.GuessGame;
import com.wkmf.lib.curl.CurlListener;

 * Created by ernestofndz on 9/02/14.
public abstract class GuessMainScreen extends GuessGameBaseApp implements GuessGameInterface, CurlListener, GuessGameAdsListener {

    private GuessGameAds guessGameAds;

    // callback de curl al solicitar los niveles
    public void callback(String result) {
        guessGame = new GuessGame(config.getId(), GuessApi.toLevels(result));
        // insertamos en bdd
        new GuessGameBDDHandler(this, GuessConfig.BDD).insert(guessGame);
        // cargamos la pantalla

    public void onAdClosed() {

    protected void onCreate(Bundle savedInstanceState) {
        // inicializamos el contexto
        // configuracion
        config = getConfig();
        // seteamos el theme de la actividad, aunque realmente es a pantalla completa
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // intentamos recuperar los datos
        // iniciamos el servicio si ya no lo est previamente
        if (!GuessGameService.isRunning()) startService(new Intent(this, GuessGameService.class));
        // inicializamos los ads
        this.guessGameAds = new GuessGameAds();
        this.guessGameAds.initAd(getContext(), this);

    // recuperar los datos ya sea desde la bdd o haciendo la peticin al servidor
    protected void getData() {
        GuessGame guessGameBDD = new GuessGameBDDHandler(this, GuessConfig.BDD).getGuessGame();
        // si el resultado es null, significa que tenemos que recuperar los datos
        // del servidor
        if (guessGameBDD == null) {
            // hacemos la peticin via cURL para recuperar los niveles
            new GuessRestApi(this, this, true).getLevels(config.getId());
        } else {
            // asignamos el valor que teniamos almacenado en bdd
            guessGame = guessGameBDD;
            // capturamos un posible NPE
            try {
                // cargamos la pantalla
            } catch (NullPointerException npe) {
                // descargamos de nuevo la info pero antes borramos lo que teniamos en BDD
                new GuessGameBDDHandler(getContext(), GuessConfig.BDD).delete(guessGame);
                new GuessRestApi(this, this, true).getLevels(config.getId());

    // cargamos los datos de la pantalla
    protected void loadScreen() {
        // asignamos el layout
        // imagen de fondo
        ((ImageView) findViewById(;
        // rate us
        ((TextView) findViewById(;
        findViewById( View.OnClickListener() {
            public void onClick(View view) {
                // abrimos enlace al market
                Uri uri = Uri.parse("market://details?id=" + getPackageName());
                Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                try {
                } catch (ActivityNotFoundException anfe) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("" + getPackageName())));
        // cargamos la lista de niveles

    // cargamos la lista de niveles
    private void loadLevels() {
        // grid view
        final GridView levelsLayout = (GridView) findViewById(;
        levelsLayout.setAdapter(new LevelsAdapter(this, config, guessGame.getLevels()));
        // damos funcionalidad al pulsar sobre los elementos
        levelsLayout.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                // enviamos los datos a la siguiente tarea
                Intent toLevel = new Intent(getContext(), GuessLevelScreen.class);
                toLevel.putExtra(Constants.EXTRA_GUESS_LEVEL, i);
                startActivityForResult(toLevel, 0);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    protected void resultOK() {
        // recargamos la pantalla

    public void onBackPressed() {
        if (this.guessGameAds.isAdLoaded()) {
        } else {

Java Source Code List