|
| 1 | +package com.omkarmoghe.pokemap.views.settings; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.content.SharedPreferences; |
| 5 | +import android.support.v7.app.AppCompatActivity; |
| 6 | +import android.os.Bundle; |
| 7 | +import android.view.View; |
| 8 | +import android.widget.RadioButton; |
| 9 | + |
| 10 | +import com.omkarmoghe.pokemap.R; |
| 11 | + |
| 12 | +public class ThemeActivity extends AppCompatActivity { |
| 13 | + |
| 14 | + private SharedPreferences sharedPref; |
| 15 | + private int themeId; |
| 16 | + |
| 17 | + private String PREF_ID; |
| 18 | + private String PREF_ID_NO_ACTION_BAR; |
| 19 | + |
| 20 | + @Override |
| 21 | + protected void onCreate(Bundle savedInstanceState) { |
| 22 | + super.onCreate(savedInstanceState); |
| 23 | + |
| 24 | + PREF_ID = getString(R.string.pref_theme); |
| 25 | + PREF_ID_NO_ACTION_BAR = getString(R.string.pref_theme_no_action_bar); |
| 26 | + |
| 27 | + sharedPref = this.getSharedPreferences(getString(R.string.pref_file_key), Context.MODE_PRIVATE); |
| 28 | + themeId = sharedPref.getInt(getString(R.string.pref_theme), R.style.AppTheme); |
| 29 | + setTheme(themeId); |
| 30 | + |
| 31 | + setTitle("Preset Themes"); |
| 32 | + setContentView(R.layout.activity_theme); |
| 33 | + |
| 34 | + RadioButton r1 = (RadioButton) findViewById(R.id.radioButton1); |
| 35 | + RadioButton r2 = (RadioButton) findViewById(R.id.radioButton2); |
| 36 | + RadioButton r3 = (RadioButton) findViewById(R.id.radioButton3); |
| 37 | + RadioButton r4 = (RadioButton) findViewById(R.id.radioButton4); |
| 38 | + RadioButton r5 = (RadioButton) findViewById(R.id.radioButton5); |
| 39 | + |
| 40 | + switch (themeId) { |
| 41 | + case R.style.AppThemeSquirtle: |
| 42 | + r1.setChecked(true); |
| 43 | + break; |
| 44 | + case R.style.AppThemeCharmander: |
| 45 | + r2.setChecked(true); |
| 46 | + break; |
| 47 | + case R.style.AppThemeBulbasaur: |
| 48 | + r3.setChecked(true); |
| 49 | + break; |
| 50 | + case R.style.AppThemePikachu: |
| 51 | + r4.setChecked(true); |
| 52 | + break; |
| 53 | + case R.style.AppTheme: |
| 54 | + r5.setChecked(true); |
| 55 | + break; |
| 56 | + default: |
| 57 | + break; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + public void onRadioButtonClicked(View v) { |
| 62 | + |
| 63 | + SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.pref_file_key), Context.MODE_PRIVATE); |
| 64 | + SharedPreferences.Editor editor = sharedPref.edit(); |
| 65 | + |
| 66 | + boolean checked = ((RadioButton) v).isChecked(); |
| 67 | + |
| 68 | + |
| 69 | + switch(v.getId()) { |
| 70 | + case R.id.radioButton1: |
| 71 | + if(checked) { |
| 72 | + editor.putInt(PREF_ID, R.style.AppThemeSquirtle); |
| 73 | + editor.putInt(PREF_ID_NO_ACTION_BAR, R.style.AppThemeSquirtle_NoActionBar); |
| 74 | + editor.apply(); |
| 75 | + } |
| 76 | + break; |
| 77 | + case R.id.radioButton2: |
| 78 | + if(checked) { |
| 79 | + editor.putInt(PREF_ID, R.style.AppThemeCharmander); |
| 80 | + editor.putInt(PREF_ID_NO_ACTION_BAR, R.style.AppThemeCharmander_NoActionBar); |
| 81 | + editor.apply(); |
| 82 | + } |
| 83 | + break; |
| 84 | + case R.id.radioButton3: |
| 85 | + if(checked) { |
| 86 | + editor.putInt(PREF_ID, R.style.AppThemeBulbasaur); |
| 87 | + editor.putInt(PREF_ID_NO_ACTION_BAR, R.style.AppThemeBulbasaur_NoActionBar); |
| 88 | + editor.apply(); |
| 89 | + } |
| 90 | + break; |
| 91 | + case R.id.radioButton4: |
| 92 | + if(checked) { |
| 93 | + editor.putInt(PREF_ID, R.style.AppThemePikachu); |
| 94 | + editor.putInt(PREF_ID_NO_ACTION_BAR, R.style.AppThemePikachu_NoActionBar); |
| 95 | + editor.apply(); |
| 96 | + } |
| 97 | + break; |
| 98 | + case R.id.radioButton5: |
| 99 | + if(checked) { |
| 100 | + editor.putInt(PREF_ID, R.style.AppTheme); |
| 101 | + editor.putInt(PREF_ID_NO_ACTION_BAR, R.style.AppTheme_NoActionBar); |
| 102 | + editor.apply(); |
| 103 | + } |
| 104 | + break; |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments