|
5 | 5 | import android.support.annotation.Nullable; |
6 | 6 | import android.support.v7.widget.LinearLayoutManager; |
7 | 7 | import android.support.v7.widget.RecyclerView; |
| 8 | +import android.support.v7.widget.SwitchCompat; |
8 | 9 | import android.support.v7.widget.Toolbar; |
| 10 | +import android.widget.CompoundButton; |
9 | 11 |
|
10 | 12 | import com.duy.ide.editor.editor.R; |
11 | 13 | import com.jecelyin.editor.v2.Preferences; |
12 | 14 | import com.jecelyin.editor.v2.ThemeSupportActivity; |
13 | 15 |
|
14 | 16 | public class EditorThemeActivity extends ThemeSupportActivity { |
| 17 | + private static final String EXTRA_USE_LIGHT_THEME = "EXTRA_USE_LIGHT_THEME"; |
15 | 18 | private RecyclerView mRecyclerView; |
16 | 19 | private ThemeAdapter mThemeAdapter; |
| 20 | + private SwitchCompat mSwitchCompat; |
17 | 21 |
|
18 | 22 | @Override |
19 | 23 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
20 | 24 | super.onCreate(savedInstanceState); |
| 25 | + |
| 26 | + boolean useLightTheme = getIntent().getBooleanExtra(EXTRA_USE_LIGHT_THEME, true); |
| 27 | + if (useLightTheme){ |
| 28 | + setTheme(R.style.LightTheme); |
| 29 | + }else { |
| 30 | + setTheme(R.style.DarkTheme); |
| 31 | + } |
| 32 | + |
21 | 33 | setContentView(R.layout.activity_editor_theme); |
22 | 34 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); |
23 | 35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 36 | + setTitle(""); |
24 | 37 |
|
25 | 38 | ThemeLoader.init(this); |
26 | 39 |
|
27 | 40 | mRecyclerView = findViewById(R.id.recyclerView); |
28 | 41 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); |
29 | 42 | mThemeAdapter = new ThemeAdapter(this); |
30 | 43 | mRecyclerView.setAdapter(mThemeAdapter); |
| 44 | + mSwitchCompat = findViewById(R.id.switch_theme); |
| 45 | + mSwitchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
| 46 | + @Override |
| 47 | + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 48 | + useLightTheme(isChecked); |
| 49 | + } |
| 50 | + }); |
31 | 51 |
|
32 | 52 | Preferences.getInstance(this).registerOnSharedPreferenceChangeListener(this); |
33 | 53 | } |
34 | 54 |
|
| 55 | + private void useLightTheme(boolean useLightTheme) { |
| 56 | + boolean current = getIntent().getBooleanExtra(EXTRA_USE_LIGHT_THEME, true); |
| 57 | + if (current != useLightTheme) { |
| 58 | + getIntent().putExtra(EXTRA_USE_LIGHT_THEME, useLightTheme); |
| 59 | + recreate(); |
| 60 | + } |
| 61 | + } |
| 62 | + |
35 | 63 | @Override |
36 | 64 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
37 | 65 | if (key.equals(getString(R.string.pref_current_theme))) { |
|
0 commit comments