Created
October 24, 2011 13:32
-
-
Save sakurabird/1309032 to your computer and use it in GitHub Desktop.
Untouchable プリファレンス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* プリファレンスの値を読み込む | |
* | |
*/ | |
privatevoid loadSetting() { | |
//自分で定義したプリファレンスファイルを使用することも出来ますが、デフォルトのプリファレンスを利用しています | |
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences( this ); | |
// アプリのバージョン情報 | |
//最初の引数はプリファレンスを取得する際のキー、2番目の引数はプリファレンスが存在しない場合のデフォルト値です。 | |
pref_version = pref.getString( "app_version", "" ); | |
// メニュー設定項目(サウンド・バイブレーション) | |
pref_sound = pref.getString( ( String ) getResources().getText( R.string.pref_key_sound ), "" ); | |
if ( pref_sound == null ) | |
pref_sound = "2"; | |
elseif ( pref_sound.equals( "" ) ) | |
pref_sound = "2"; | |
pref_vibrator = pref.getBoolean( ( String ) getResources().getText( R.string.pref_key_vibrator ), true ); | |
// 近接センサーの閾値 | |
String ps = pref.getString( ( String ) getResources().getText( R.string.pref_key_sensor_sensitivity ), "3.0" ); | |
pref_Sensor_Sensitivity = Float.parseFloat( ps ); | |
} | |
/*** | |
* プリファレンスの値を保存する | |
* | |
*/ | |
privatevoid saveSetting() { | |
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences( this ); | |
SharedPreferences.Editor edt = pref.edit(); | |
// アプリのバージョン情報 | |
pref_version = getVersionNumber( "", this ); | |
edt.putString( "app_version", pref_version ); | |
// メニュー設定項目(サウンド・バイブレーション) | |
edt.putString( ( String ) getResources().getText( R.string.pref_key_sound ), pref_sound ); | |
edt.putBoolean( ( String ) getResources().getText( R.string.pref_key_vibrator ), pref_vibrator ); | |
// 近接センサーの閾値 | |
String ps = Float.toString( pref_Sensor_Sensitivity ); | |
edt.putString( ( String ) getResources().getText( R.string.pref_key_sensor_sensitivity ), ps ); | |
//この命令を実行することで実際に保存される | |
edt.commit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment