Android Open Source - Gloomy-Dungeons-3D Menu View Helper






From Project

Back to project page Gloomy-Dungeons-3D.

License

The source code is released under:

MIT License

If you think the Android project Gloomy-Dungeons-3D 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 zame.game.views;
/*  ww w . j  av a2  s .  com*/
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import zame.game.Common;
import zame.game.MenuActivity;
import zame.game.R;
import zame.game.ZameApplication;

public class MenuViewHelper {
    private static final int DIALOG_RATE_OFFER = 107;

    public static boolean canExit(MenuActivity activity) {
        return (!showRateOffer(activity));
    }

    @SuppressWarnings("deprecation")
    public static boolean showRateOffer(final MenuActivity activity) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
        int showRateOfferCnt = sp.getInt("RateOfferCnt", 5);

        if (showRateOfferCnt > 0) {
            showRateOfferCnt--;
            SharedPreferences.Editor spEditor = sp.edit();
            spEditor.putInt("RateOfferCnt", showRateOfferCnt);
            spEditor.commit();

            if (showRateOfferCnt <= 0) {
                int rateOfferDlgShownCnt = sp.getInt("RateOfferDlgShownCnt", 0);
                spEditor = sp.edit();
                spEditor.putInt("RateOfferDlgShownCnt", rateOfferDlgShownCnt + 1);
                spEditor.commit();

                ZameApplication.trackEvent("Menu", "RateDialog", "", 0);
                ZameApplication.flushEvents();

                activity.showDialog(DIALOG_RATE_OFFER);
                return true;
            }
        }

        return false;
    }

    public static Dialog onCreateDialog(final MenuActivity activity, final MenuView.Data data, int id) {
        switch (id) {
            case DIALOG_RATE_OFFER: {
                AlertDialog.Builder resDialog = new AlertDialog.Builder(activity)
                    .setIcon(R.drawable.ic_dialog_alert)
                    .setTitle(R.string.dlg_rate_offer)
                    .setPositiveButton(R.string.dlg_yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            if (Common.openMarket(activity, ZameApplication.self.getPackageName())) {
                                ZameApplication.trackEvent("Menu", "RateDialogOk", "", 0);
                                ZameApplication.flushEvents();
                            }

                            activity.finish();
                        }
                    });

                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
                int rateOfferDlgShownCnt = sp.getInt("RateOfferDlgShownCnt", 0);

                DialogInterface.OnClickListener remindMeLaterClickListener = new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        rateOfferRemindMeLater(activity);
                    }
                };

                if (rateOfferDlgShownCnt > 1) {
                    resDialog.setNegativeButton(R.string.dlg_no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ZameApplication.trackEvent("Menu", "RateDialogCancel", "", 0);
                            ZameApplication.flushEvents();
                            activity.finish();
                        }
                    });

                    if (rateOfferDlgShownCnt < 5) {
                        resDialog.setNeutralButton(R.string.dlg_later, remindMeLaterClickListener);
                    }
                } else {
                    resDialog.setNegativeButton(R.string.dlg_later, remindMeLaterClickListener);
                }

                resDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        rateOfferRemindMeLater(activity);
                    }
                });

                return resDialog.create();
            }
        }

        return null;
    }

    private static void rateOfferRemindMeLater(MenuActivity activity) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
        SharedPreferences.Editor spEditor = sp.edit();
        spEditor.putInt("RateOfferCnt", 5);
        spEditor.commit();

        ZameApplication.trackEvent("Menu", "RateDialogLater", "", 0);
        ZameApplication.flushEvents();
        activity.finish();
    }
}




Java Source Code List

zame.game.AppConfig.java
zame.game.AppConfig.java
zame.game.Common.java
zame.game.ConfigZeemote.java
zame.game.ConfigZeemote.java
zame.game.Config.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivity.java
zame.game.GamePreferencesActivity.java
zame.game.GamePreferencesActivity.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivity.java
zame.game.Renderer.java
zame.game.SoundManager.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplication.java
zame.game.ZameGame.java
zame.game.ZameJniRenderer.java
zame.game.engine.Action.java
zame.game.engine.AutoWall.java
zame.game.engine.Controls.java
zame.game.engine.Door.java
zame.game.engine.GameHelper.java
zame.game.engine.GameHelper.java
zame.game.engine.Game.java
zame.game.engine.Labels.java
zame.game.engine.LevelConfig.java
zame.game.engine.LevelRenderer.java
zame.game.engine.Level.java
zame.game.engine.Mark.java
zame.game.engine.Monster.java
zame.game.engine.Overlay.java
zame.game.engine.PortalTracer.java
zame.game.engine.State.java
zame.game.engine.Stats.java
zame.game.engine.TextureLoader.java
zame.game.engine.Weapons.java
zame.game.views.EndLevelView.java
zame.game.views.GameOverView.java
zame.game.views.GameView.java
zame.game.views.IZameView.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuView.java
zame.game.views.PreLevelView.java
zame.game.views.ZameGameView.java
zame.libs.FrameLayout.java
zame.libs.GLSurfaceView21.java
zame.libs.Grid.java
zame.libs.KeyMapPreference.java
zame.libs.LabelMaker.java
zame.libs.ListPreference.java
zame.libs.NumericSprite.java
zame.libs.SeekBarPreference.java
zame.promo.PromoView.java