v0.6.3: refactored some android interaction out of the core module

This commit is contained in:
Evan Debenham 2017-12-26 23:06:10 -05:00
parent c290e5fe47
commit e828148ebc
8 changed files with 184 additions and 108 deletions

View File

@ -46,6 +46,7 @@ import com.watabou.input.Touchscreen;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.BitmapCache; import com.watabou.utils.BitmapCache;
import com.watabou.utils.DeviceCompat;
import com.watabou.utils.SystemTime; import com.watabou.utils.SystemTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -133,10 +134,10 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
view = new GLSurfaceView( this ); view = new GLSurfaceView( this );
view.setEGLContextClientVersion( 2 ); view.setEGLContextClientVersion( 2 );
//Versions of android below 4.1 are forced to RGB 565 for performance reasons. //Older devices are forced to RGB 565 for performance reasons.
//Otherwise try to use RGB888 for best quality, but use RGB565 if it is what's available. //Otherwise try to use RGB888 for best quality, but use RGB565 if it is what's available.
view.setEGLConfigChooser( new ScreenConfigChooser( view.setEGLConfigChooser( new ScreenConfigChooser(
Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN, DeviceCompat.legacyDevice(),
false )); false ));
view.setRenderer( this ); view.setRenderer( this );

View File

@ -21,9 +21,11 @@
package com.watabou.noosa.audio; package com.watabou.noosa.audio;
import android.app.Activity;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Build;
import android.telephony.PhoneStateListener; import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
@ -158,4 +160,13 @@ public enum Music implements MediaPlayer.OnPreparedListener, MediaPlayer.OnError
super.onCallStateChanged(state, incomingNumber); super.onCallStateChanged(state, incomingNumber);
} }
}; };
public static void setMuteListener(){
//versions lower than this require READ_PHONE_STATE permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
TelephonyManager mgr =
(TelephonyManager) Game.instance.getSystemService(Activity.TELEPHONY_SERVICE);
mgr.listen(Music.callMute, PhoneStateListener.LISTEN_CALL_STATE);
}
}
} }

View File

@ -0,0 +1,44 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2017 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.utils;
import android.os.Build;
public class DeviceCompat {
public static boolean supportsFullScreen(){
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
public static boolean legacyDevice(){
return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN;
}
public static boolean supportsGamesServices(){
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}
public static boolean usesISO_8859_1(){
return Build.VERSION.SDK_INT == Build.VERSION_CODES.FROYO;
}
}

View File

@ -19,58 +19,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
*/ */
package com.shatteredpixel.shatteredpixeldungeon; package com.watabou.utils;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.utils.GameMath;
enum Preferences { public class GameSettings {
INSTANCE; private static SharedPreferences prefs;
public static final String KEY_LANDSCAPE = "landscape"; private static SharedPreferences get() {
public static final String KEY_IMMERSIVE = "immersive";
public static final String KEY_POWER_SAVER = "power_saver";
public static final String KEY_SCALE = "scale";
public static final String KEY_MUSIC = "music";
public static final String KEY_MUSIC_VOL = "music_vol";
public static final String KEY_SOUND_FX = "soundfx";
public static final String KEY_SFX_VOL = "sfx_vol";
public static final String KEY_ZOOM = "zoom";
public static final String KEY_LAST_CLASS = "last_class";
public static final String KEY_CHALLENGES = "challenges";
public static final String KEY_QUICKSLOTS = "quickslots";
public static final String KEY_FLIPTOOLBAR = "flipped_ui";
public static final String KEY_FLIPTAGS = "flip_tags";
public static final String KEY_BARMODE = "toolbar_mode";
public static final String KEY_LANG = "language";
public static final String KEY_CLASSICFONT = "classic_font";
public static final String KEY_INTRO = "intro";
public static final String KEY_BRIGHTNESS = "brightness";
public static final String KEY_GRID = "visual_grid";
public static final String KEY_VERSION = "version";
private SharedPreferences prefs;
private SharedPreferences get() {
if (prefs == null) { if (prefs == null) {
prefs = Game.instance.getPreferences( Game.MODE_PRIVATE ); prefs = Game.instance.getPreferences( Game.MODE_PRIVATE );
} }
return prefs; return prefs;
} }
boolean contains( String key ){ public static boolean contains( String key ){
return get().contains( key ); return get().contains( key );
} }
int getInt( String key, int defValue ) { public static int getInt( String key, int defValue ) {
return getInt(key, defValue, Integer.MIN_VALUE, Integer.MAX_VALUE); return getInt(key, defValue, Integer.MIN_VALUE, Integer.MAX_VALUE);
} }
int getInt( String key, int defValue, int min, int max ) { public static int getInt( String key, int defValue, int min, int max ) {
try { try {
int i = get().getInt( key, defValue ); int i = get().getInt( key, defValue );
if (i < min || i > max){ if (i < min || i > max){
@ -81,27 +56,27 @@ enum Preferences {
return i; return i;
} }
} catch (ClassCastException e) { } catch (ClassCastException e) {
ShatteredPixelDungeon.reportException(e); //ShatteredPixelDungeon.reportException(e);
put(key, defValue); put(key, defValue);
return defValue; return defValue;
} }
} }
boolean getBoolean( String key, boolean defValue ) { public static boolean getBoolean( String key, boolean defValue ) {
try { try {
return get().getBoolean(key, defValue); return get().getBoolean(key, defValue);
} catch (ClassCastException e) { } catch (ClassCastException e) {
ShatteredPixelDungeon.reportException(e); //ShatteredPixelDungeon.reportException(e);
put(key, defValue); put(key, defValue);
return defValue; return defValue;
} }
} }
String getString( String key, String defValue ) { public static String getString( String key, String defValue ) {
return getString(key, defValue, Integer.MAX_VALUE); return getString(key, defValue, Integer.MAX_VALUE);
} }
String getString( String key, String defValue, int maxLength ) { public static String getString( String key, String defValue, int maxLength ) {
try { try {
String s = get().getString( key, defValue ); String s = get().getString( key, defValue );
if (s != null && s.length() > maxLength) { if (s != null && s.length() > maxLength) {
@ -111,7 +86,7 @@ enum Preferences {
return s; return s;
} }
} catch (ClassCastException e) { } catch (ClassCastException e) {
ShatteredPixelDungeon.reportException(e); //ShatteredPixelDungeon.reportException(e);
put(key, defValue); put(key, defValue);
return defValue; return defValue;
} }
@ -119,7 +94,7 @@ enum Preferences {
//android 2.3+ supports apply, which is asyncronous, much nicer //android 2.3+ supports apply, which is asyncronous, much nicer
void put( String key, int value ) { public static void put( String key, int value ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
get().edit().putInt(key, value).apply(); get().edit().putInt(key, value).apply();
} else { } else {
@ -127,7 +102,7 @@ enum Preferences {
} }
} }
void put( String key, boolean value ) { public static void put( String key, boolean value ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
get().edit().putBoolean(key, value).apply(); get().edit().putBoolean(key, value).apply();
} else { } else {
@ -135,11 +110,12 @@ enum Preferences {
} }
} }
void put( String key, String value ) { public static void put( String key, String value ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
get().edit().putString(key, value).apply(); get().edit().putString(key, value).apply();
} else { } else {
get().edit().putString(key, value).commit(); get().edit().putString(key, value).commit();
} }
} }
} }

View File

@ -0,0 +1,50 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2017 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.watabou.utils.GameSettings;
public class SPDSettings extends GameSettings {
public static final String KEY_LANDSCAPE = "landscape";
public static final String KEY_IMMERSIVE = "immersive";
public static final String KEY_POWER_SAVER = "power_saver";
public static final String KEY_SCALE = "scale";
public static final String KEY_MUSIC = "music";
public static final String KEY_MUSIC_VOL = "music_vol";
public static final String KEY_SOUND_FX = "soundfx";
public static final String KEY_SFX_VOL = "sfx_vol";
public static final String KEY_ZOOM = "zoom";
public static final String KEY_LAST_CLASS = "last_class";
public static final String KEY_CHALLENGES = "challenges";
public static final String KEY_QUICKSLOTS = "quickslots";
public static final String KEY_FLIPTOOLBAR = "flipped_ui";
public static final String KEY_FLIPTAGS = "flip_tags";
public static final String KEY_BARMODE = "toolbar_mode";
public static final String KEY_LANG = "language";
public static final String KEY_CLASSICFONT = "classic_font";
public static final String KEY_INTRO = "intro";
public static final String KEY_BRIGHTNESS = "brightness";
public static final String KEY_GRID = "visual_grid";
public static final String KEY_VERSION = "version";
}

View File

@ -24,8 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -39,6 +37,7 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat;
import java.util.Locale; import java.util.Locale;
@ -134,8 +133,8 @@ public class ShatteredPixelDungeon extends Game {
updateSystemUI(); updateSystemUI();
if (Preferences.INSTANCE.contains( Preferences.KEY_LANDSCAPE )){ if (SPDSettings.contains( SPDSettings.KEY_LANDSCAPE )){
landscape ( Preferences.INSTANCE.getBoolean( Preferences.KEY_LANDSCAPE, false)); landscape ( SPDSettings.getBoolean( SPDSettings.KEY_LANDSCAPE, false));
} else { } else {
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
@ -153,11 +152,7 @@ public class ShatteredPixelDungeon extends Game {
Sample.INSTANCE.enable( soundFx() ); Sample.INSTANCE.enable( soundFx() );
Sample.INSTANCE.volume( SFXVol()/10f ); Sample.INSTANCE.volume( SFXVol()/10f );
//versions lower than this require READ_PHONE_STATE permission Music.setMuteListener();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
mgr.listen(Music.callMute, PhoneStateListener.LISTEN_CALL_STATE);
}
Sample.INSTANCE.load( Sample.INSTANCE.load(
Assets.SND_CLICK, Assets.SND_CLICK,
@ -238,9 +233,11 @@ public class ShatteredPixelDungeon extends Game {
} }
/* /*
* ---> Prefernces * ---> Settings
*/ */
//TODO migrate some of these to SPDSettings, no reason to clutter up Shattered Pixel Dungeon
public static void landscape( boolean value ) { public static void landscape( boolean value ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Game.instance.setRequestedOrientation(value ? Game.instance.setRequestedOrientation(value ?
@ -251,7 +248,7 @@ public class ShatteredPixelDungeon extends Game {
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} }
Preferences.INSTANCE.put( Preferences.KEY_LANDSCAPE, value ); SPDSettings.put( SPDSettings.KEY_LANDSCAPE, value );
((ShatteredPixelDungeon)instance).updateDisplaySize(); ((ShatteredPixelDungeon)instance).updateDisplaySize();
} }
@ -260,13 +257,11 @@ public class ShatteredPixelDungeon extends Game {
} }
public static void scale( int value ) { public static void scale( int value ) {
Preferences.INSTANCE.put( Preferences.KEY_SCALE, value ); SPDSettings.put( SPDSettings.KEY_SCALE, value );
} }
private static boolean immersiveModeChanged = false;
public static void immerse( boolean value ) { public static void immerse( boolean value ) {
Preferences.INSTANCE.put( Preferences.KEY_IMMERSIVE, value ); SPDSettings.put( SPDSettings.KEY_IMMERSIVE, value );
instance.runOnUiThread( new Runnable() { instance.runOnUiThread( new Runnable() {
@Override @Override
@ -301,7 +296,7 @@ public class ShatteredPixelDungeon extends Game {
//force power saver in this case as all devices must run at at least 2x scale. //force power saver in this case as all devices must run at at least 2x scale.
if (dispWidth < renderWidth*2 || dispHeight < renderHeight*2) if (dispWidth < renderWidth*2 || dispHeight < renderHeight*2)
Preferences.INSTANCE.put( Preferences.KEY_POWER_SAVER, true ); SPDSettings.put( SPDSettings.KEY_POWER_SAVER, true );
if (powerSaver()){ if (powerSaver()){
@ -351,7 +346,7 @@ public class ShatteredPixelDungeon extends Game {
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ if (DeviceCompat.supportsFullScreen()){
if (fullscreen && immersed()) { if (fullscreen && immersed()) {
instance.getWindow().getDecorView().setSystemUiVisibility( instance.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
@ -367,88 +362,88 @@ public class ShatteredPixelDungeon extends Game {
} }
public static boolean immersed() { public static boolean immersed() {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_IMMERSIVE, false ); return SPDSettings.getBoolean( SPDSettings.KEY_IMMERSIVE, false );
} }
public static boolean powerSaver(){ public static boolean powerSaver(){
return Preferences.INSTANCE.getBoolean( Preferences.KEY_POWER_SAVER, false ); return SPDSettings.getBoolean( SPDSettings.KEY_POWER_SAVER, false );
} }
public static void powerSaver( boolean value ){ public static void powerSaver( boolean value ){
Preferences.INSTANCE.put( Preferences.KEY_POWER_SAVER, value ); SPDSettings.put( SPDSettings.KEY_POWER_SAVER, value );
((ShatteredPixelDungeon)instance).updateDisplaySize(); ((ShatteredPixelDungeon)instance).updateDisplaySize();
} }
public static int scale() { public static int scale() {
return Preferences.INSTANCE.getInt( Preferences.KEY_SCALE, 0 ); return SPDSettings.getInt( SPDSettings.KEY_SCALE, 0 );
} }
public static void zoom( int value ) { public static void zoom( int value ) {
Preferences.INSTANCE.put( Preferences.KEY_ZOOM, value ); SPDSettings.put( SPDSettings.KEY_ZOOM, value );
} }
public static int zoom() { public static int zoom() {
return Preferences.INSTANCE.getInt( Preferences.KEY_ZOOM, 0 ); return SPDSettings.getInt( SPDSettings.KEY_ZOOM, 0 );
} }
public static void music( boolean value ) { public static void music( boolean value ) {
Music.INSTANCE.enable( value ); Music.INSTANCE.enable( value );
Preferences.INSTANCE.put( Preferences.KEY_MUSIC, value ); SPDSettings.put( SPDSettings.KEY_MUSIC, value );
} }
public static boolean music() { public static boolean music() {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_MUSIC, true ); return SPDSettings.getBoolean( SPDSettings.KEY_MUSIC, true );
} }
public static void musicVol( int value ){ public static void musicVol( int value ){
Preferences.INSTANCE.put( Preferences.KEY_MUSIC_VOL, value ); SPDSettings.put( SPDSettings.KEY_MUSIC_VOL, value );
} }
public static int musicVol(){ public static int musicVol(){
return Preferences.INSTANCE.getInt( Preferences.KEY_MUSIC_VOL, 10, 0, 10 ); return SPDSettings.getInt( SPDSettings.KEY_MUSIC_VOL, 10, 0, 10 );
} }
public static void soundFx( boolean value ) { public static void soundFx( boolean value ) {
Sample.INSTANCE.enable( value ); Sample.INSTANCE.enable( value );
Preferences.INSTANCE.put( Preferences.KEY_SOUND_FX, value ); SPDSettings.put( SPDSettings.KEY_SOUND_FX, value );
} }
public static boolean soundFx() { public static boolean soundFx() {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_SOUND_FX, true ); return SPDSettings.getBoolean( SPDSettings.KEY_SOUND_FX, true );
} }
public static void SFXVol( int value ) { public static void SFXVol( int value ) {
Preferences.INSTANCE.put( Preferences.KEY_SFX_VOL, value ); SPDSettings.put( SPDSettings.KEY_SFX_VOL, value );
} }
public static int SFXVol() { public static int SFXVol() {
return Preferences.INSTANCE.getInt( Preferences.KEY_SFX_VOL, 10, 0, 10 ); return SPDSettings.getInt( SPDSettings.KEY_SFX_VOL, 10, 0, 10 );
} }
public static void brightness( int value ) { public static void brightness( int value ) {
Preferences.INSTANCE.put( Preferences.KEY_BRIGHTNESS, value ); SPDSettings.put( SPDSettings.KEY_BRIGHTNESS, value );
GameScene.updateFog(); GameScene.updateFog();
} }
public static int brightness() { public static int brightness() {
return Preferences.INSTANCE.getInt( Preferences.KEY_BRIGHTNESS, 0, -2, 2 ); return SPDSettings.getInt( SPDSettings.KEY_BRIGHTNESS, 0, -2, 2 );
} }
public static void visualGrid( int value ){ public static void visualGrid( int value ){
Preferences.INSTANCE.put( Preferences.KEY_GRID, value ); SPDSettings.put( SPDSettings.KEY_GRID, value );
GameScene.updateMap(); GameScene.updateMap();
} }
public static int visualGrid() { public static int visualGrid() {
return Preferences.INSTANCE.getInt( Preferences.KEY_GRID, 0, -1, 3 ); return SPDSettings.getInt( SPDSettings.KEY_GRID, 0, -1, 3 );
} }
public static void language(Languages lang) { public static void language(Languages lang) {
Preferences.INSTANCE.put( Preferences.KEY_LANG, lang.code()); SPDSettings.put( SPDSettings.KEY_LANG, lang.code());
} }
public static Languages language() { public static Languages language() {
String code = Preferences.INSTANCE.getString(Preferences.KEY_LANG, null); String code = SPDSettings.getString(SPDSettings.KEY_LANG, null);
if (code == null){ if (code == null){
return Languages.matchLocale(Locale.getDefault()); return Languages.matchLocale(Locale.getDefault());
} else { } else {
@ -457,7 +452,7 @@ public class ShatteredPixelDungeon extends Game {
} }
public static void classicFont(boolean classic){ public static void classicFont(boolean classic){
Preferences.INSTANCE.put(Preferences.KEY_CLASSICFONT, classic); SPDSettings.put(SPDSettings.KEY_CLASSICFONT, classic);
if (classic) { if (classic) {
RenderedText.setFont("pixelfont.ttf"); RenderedText.setFont("pixelfont.ttf");
} else { } else {
@ -466,68 +461,68 @@ public class ShatteredPixelDungeon extends Game {
} }
public static boolean classicFont(){ public static boolean classicFont(){
return Preferences.INSTANCE.getBoolean(Preferences.KEY_CLASSICFONT, return SPDSettings.getBoolean(SPDSettings.KEY_CLASSICFONT,
(language() != Languages.KOREAN && language() != Languages.CHINESE)); (language() != Languages.KOREAN && language() != Languages.CHINESE));
} }
public static void lastClass( int value ) { public static void lastClass( int value ) {
Preferences.INSTANCE.put( Preferences.KEY_LAST_CLASS, value ); SPDSettings.put( SPDSettings.KEY_LAST_CLASS, value );
} }
public static int lastClass() { public static int lastClass() {
return Preferences.INSTANCE.getInt( Preferences.KEY_LAST_CLASS, 0, 0, 3 ); return SPDSettings.getInt( SPDSettings.KEY_LAST_CLASS, 0, 0, 3 );
} }
public static void challenges( int value ) { public static void challenges( int value ) {
Preferences.INSTANCE.put( Preferences.KEY_CHALLENGES, value ); SPDSettings.put( SPDSettings.KEY_CHALLENGES, value );
} }
public static int challenges() { public static int challenges() {
return Preferences.INSTANCE.getInt( Preferences.KEY_CHALLENGES, 0, 0, Challenges.MAX_VALUE ); return SPDSettings.getInt( SPDSettings.KEY_CHALLENGES, 0, 0, Challenges.MAX_VALUE );
} }
public static void quickSlots( int value ){ Preferences.INSTANCE.put( Preferences.KEY_QUICKSLOTS, value ); } public static void quickSlots( int value ){ SPDSettings.put( SPDSettings.KEY_QUICKSLOTS, value ); }
public static int quickSlots(){ return Preferences.INSTANCE.getInt( Preferences.KEY_QUICKSLOTS, 4, 0, 4); } public static int quickSlots(){ return SPDSettings.getInt( SPDSettings.KEY_QUICKSLOTS, 4, 0, 4); }
public static void flipToolbar( boolean value) { public static void flipToolbar( boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_FLIPTOOLBAR, value ); SPDSettings.put(SPDSettings.KEY_FLIPTOOLBAR, value );
} }
public static boolean flipToolbar(){ return Preferences.INSTANCE.getBoolean(Preferences.KEY_FLIPTOOLBAR, false); } public static boolean flipToolbar(){ return SPDSettings.getBoolean(SPDSettings.KEY_FLIPTOOLBAR, false); }
public static void flipTags( boolean value) { public static void flipTags( boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_FLIPTAGS, value ); SPDSettings.put(SPDSettings.KEY_FLIPTAGS, value );
} }
public static boolean flipTags(){ return Preferences.INSTANCE.getBoolean(Preferences.KEY_FLIPTAGS, false); } public static boolean flipTags(){ return SPDSettings.getBoolean(SPDSettings.KEY_FLIPTAGS, false); }
public static void toolbarMode( String value ) { public static void toolbarMode( String value ) {
Preferences.INSTANCE.put( Preferences.KEY_BARMODE, value ); SPDSettings.put( SPDSettings.KEY_BARMODE, value );
} }
public static String toolbarMode() { public static String toolbarMode() {
return Preferences.INSTANCE.getString(Preferences.KEY_BARMODE, !landscape() ? "SPLIT" : "GROUP"); return SPDSettings.getString(SPDSettings.KEY_BARMODE, !landscape() ? "SPLIT" : "GROUP");
} }
public static void intro( boolean value ) { public static void intro( boolean value ) {
Preferences.INSTANCE.put( Preferences.KEY_INTRO, value ); SPDSettings.put( SPDSettings.KEY_INTRO, value );
} }
public static boolean intro() { public static boolean intro() {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_INTRO, true ); return SPDSettings.getBoolean( SPDSettings.KEY_INTRO, true );
} }
public static void version( int value) { public static void version( int value) {
Preferences.INSTANCE.put( Preferences.KEY_VERSION, value ); SPDSettings.put( SPDSettings.KEY_VERSION, value );
} }
public static int version() { public static int version() {
return Preferences.INSTANCE.getInt( Preferences.KEY_VERSION, 0 ); return SPDSettings.getInt( SPDSettings.KEY_VERSION, 0 );
} }
/* /*
* <--- Preferences * <--- Settings
*/ */
public static void reportException( Throwable tr ) { public static void reportException( Throwable tr ) {

View File

@ -22,6 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.messages; package com.shatteredpixel.shatteredpixeldungeon.messages;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.watabou.utils.DeviceCompat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
@ -87,8 +88,7 @@ public class Messages {
String key = keys.nextElement(); String key = keys.nextElement();
String value = bundle.getString(key); String value = bundle.getString(key);
//android 2.2 doesn't use UTF-8 by default, need to force it. if (DeviceCompat.usesISO_8859_1()) {
if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.FROYO) {
try { try {
value = new String(value.getBytes("ISO-8859-1"), "UTF-8"); value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
} catch (Exception e) { } catch (Exception e) {

View File

@ -21,8 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.windows; package com.shatteredpixel.shatteredpixeldungeon.windows;
import android.os.Build;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@ -37,6 +35,7 @@ import com.watabou.noosa.Group;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat;
public class WndSettings extends WndTabbed { public class WndSettings extends WndTabbed {
@ -287,7 +286,7 @@ public class WndSettings extends WndTabbed {
}; };
chkImmersive.setRect( 0, slots.bottom() + GAP_SML, WIDTH, BTN_HEIGHT ); chkImmersive.setRect( 0, slots.bottom() + GAP_SML, WIDTH, BTN_HEIGHT );
chkImmersive.checked(ShatteredPixelDungeon.immersed()); chkImmersive.checked(ShatteredPixelDungeon.immersed());
chkImmersive.enable(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT); chkImmersive.enable(DeviceCompat.supportsFullScreen());
add(chkImmersive); add(chkImmersive);
CheckBox chkFont = new CheckBox(Messages.get(this, "system_font")){ CheckBox chkFont = new CheckBox(Messages.get(this, "system_font")){