Android Open Source - BulletsForever Settings






From Project

Back to project page BulletsForever.

License

The source code is released under:

GNU General Public License

If you think the Android project BulletsForever 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.bulletsforever.bullets;
//  w  w w. j av a  2  s. c  om
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.view.Display;

/**
 * This is for keeping track of app settings, drawn from SharedPreferences
 * This should be called by every Activity's onCreate()
 * Use MenuSettings to manipulate preferences
 */
public class Settings {

  private static Resources res;
  private static SharedPreferences prefs;
  private static HashMap<Integer, String> settings;
  public static int screenWidth, screenHeight;
  public static int screenXMin, screenXMax, screenYMin, screenYMax;
  
  // Manually keep this updated with settings.xml
  private static int[][] keys = {
    {R.string.bgmusic,        R.string.bgmusicDefault},
    {R.string.playerHealth,      R.string.playerHealthDefault},
    {R.string.refreshDelay,      R.string.refreshDelayDefault},
    {R.string.fpsUpdateFrequency,  R.string.fpsUpdateFrequencyDefault},
    {R.string.debugHitboxes,    R.string.debugHitboxesDefault}
  };
  
  // Reload all the settings, call this at the beginning of onCreate() in Activities
  public static void reload(Context c) {
    res = c.getResources();
    prefs = PreferenceManager.getDefaultSharedPreferences(c);
    settings = new HashMap<Integer, String>();
    for (int i = 0; i < keys.length; i++) {
      int setting = keys[i][0];
      int defaultValue = keys[i][1];
      String value = prefs.getString(res.getString(setting), res.getString(defaultValue));
      settings.put(setting, value);
    }
  }
  
  // Call this to figure out the drawable screen dimensions.
  // This is also useful for initial setup before the onDraw section
  public static void setScreenDimensions(Activity a) {
    Display display = a.getWindow().getWindowManager().getDefaultDisplay();
    screenWidth = display.getWidth();
    screenHeight = display.getHeight();
    int margin = (screenWidth < screenHeight) ? (screenWidth / 3) : (screenHeight / 3);
    screenXMin = -margin;
    screenXMax = screenWidth + margin;
    screenYMin = -margin;
    screenYMax = screenHeight + margin;
  }
  
  // Retrieve settings
  public static float getFloat(Integer setting) {
    return Float.parseFloat(settings.get(setting));
  }
  public static int getInt(Integer setting) {
    return Integer.parseInt(settings.get(setting));
  }
  public static boolean getBoolean(Integer setting) {
    return settings.get(setting).equals("1");
  }
  public static String getString(Integer setting) {
    return settings.get(setting);
  }
  
}




Java Source Code List

com.bulletsforever.bullets.AudioMusicPlayer.java
com.bulletsforever.bullets.AudioSoundPool.java
com.bulletsforever.bullets.DrawBitmapLoader.java
com.bulletsforever.bullets.DrawKeyHandler.java
com.bulletsforever.bullets.DrawObjectBackground.java
com.bulletsforever.bullets.DrawObjectBoss.java
com.bulletsforever.bullets.DrawObjectBullet.java
com.bulletsforever.bullets.DrawObjectDynamicArm.java
com.bulletsforever.bullets.DrawObjectDynamicBoss.java
com.bulletsforever.bullets.DrawObjectHUD.java
com.bulletsforever.bullets.DrawObjectPlayer.java
com.bulletsforever.bullets.DrawObject.java
com.bulletsforever.bullets.DrawRefreshHandler.java
com.bulletsforever.bullets.DrawTouchHandler.java
com.bulletsforever.bullets.DrawWorld.java
com.bulletsforever.bullets.GameMain.java
com.bulletsforever.bullets.GameScore.java
com.bulletsforever.bullets.MenuHome.java
com.bulletsforever.bullets.MenuSettings.java
com.bulletsforever.bullets.Settings.java
com.bulletsforever.bullets.ToolsFPSCounter.java
com.bulletsforever.bullets.ToolsRandomizer.java
com.bulletsforever.bullets.ToolsScoreboard.java
com.bulletsforever.bullets.ToolsTracker.java
com.bulletsforever.bullets.ToolsVibrator.java