| 1 | /* |
| 2 | * This program is free software: you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation, either version 3 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 | */ |
| 15 | |
| 16 | package info.bpace.munchlife; |
| 17 | |
| 18 | import android.app.Activity; |
| 19 | import android.os.Bundle; |
| 20 | import android.preference.Preference; |
| 21 | import android.preference.PreferenceActivity; |
| 22 | import android.preference.Preference.OnPreferenceChangeListener; |
| 23 | import android.widget.Toast; |
| 24 | |
| 25 | import android.util.Log; |
| 26 | |
| 27 | public class SettingsActivity extends PreferenceActivity |
| 28 | { |
| 29 | OnPreferenceChangeListener levelListener = new OnPreferenceChangeListener() |
| 30 | { |
| 31 | public boolean onPreferenceChange(Preference pref, Object newValue) |
| 32 | { |
| 33 | int value = 0; |
| 34 | try |
| 35 | { |
| 36 | value = Integer.parseInt(newValue.toString()); |
| 37 | } |
| 38 | catch(NumberFormatException error) |
| 39 | { |
| 40 | Log.w(MunchLifeActivity.TAG, |
| 41 | "NumberFormatException: " + error.getMessage()); |
| 42 | } |
| 43 | |
| 44 | if(value > 1 && value <= 100) |
| 45 | { |
| 46 | return true; |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | Toast.makeText(getApplicationContext(), |
| 51 | R.string.maxlevelError, |
| 52 | Toast.LENGTH_SHORT).show(); |
| 53 | return false; |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | @Override |
| 59 | protected void onCreate(Bundle savedInstanceState) |
| 60 | { |
| 61 | super.onCreate(savedInstanceState); |
| 62 | addPreferencesFromResource(R.xml.preferences); |
| 63 | Preference levelPreference; |
| 64 | levelPreference = getPreferenceScreen().findPreference("maxlevelPref"); |
| 65 | levelPreference.setOnPreferenceChangeListener(levelListener); |
| 66 | } |
| 67 | } |