Skip to content

Commit e543565

Browse files
committed
preview light theme/dark theme
1 parent 2abece9 commit e543565

File tree

11 files changed

+83
-27
lines changed

11 files changed

+83
-27
lines changed

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<resources>
22

33
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="DefaultTheme">
4+
<style name="AppTheme" parent="LightTheme">
55
</style>
66

77
</resources>

editor-view/src/main/java/com/duy/ide/editor/theme/EditorThemeActivity.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,61 @@
55
import android.support.annotation.Nullable;
66
import android.support.v7.widget.LinearLayoutManager;
77
import android.support.v7.widget.RecyclerView;
8+
import android.support.v7.widget.SwitchCompat;
89
import android.support.v7.widget.Toolbar;
10+
import android.widget.CompoundButton;
911

1012
import com.duy.ide.editor.editor.R;
1113
import com.jecelyin.editor.v2.Preferences;
1214
import com.jecelyin.editor.v2.ThemeSupportActivity;
1315

1416
public class EditorThemeActivity extends ThemeSupportActivity {
17+
private static final String EXTRA_USE_LIGHT_THEME = "EXTRA_USE_LIGHT_THEME";
1518
private RecyclerView mRecyclerView;
1619
private ThemeAdapter mThemeAdapter;
20+
private SwitchCompat mSwitchCompat;
1721

1822
@Override
1923
protected void onCreate(@Nullable Bundle savedInstanceState) {
2024
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+
2133
setContentView(R.layout.activity_editor_theme);
2234
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
2335
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
36+
setTitle("");
2437

2538
ThemeLoader.init(this);
2639

2740
mRecyclerView = findViewById(R.id.recyclerView);
2841
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
2942
mThemeAdapter = new ThemeAdapter(this);
3043
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+
});
3151

3252
Preferences.getInstance(this).registerOnSharedPreferenceChangeListener(this);
3353
}
3454

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+
3563
@Override
3664
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
3765
if (key.equals(getString(R.string.pref_current_theme))) {

editor-view/src/main/java/com/duy/ide/editor/theme/ThemeLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static EditorTheme loadDefault(Context context) {
5252
}
5353

5454
private static void loadTheme(Context context, String theme) {
55-
// if (CACHED.get(theme) != null) {
56-
// return;
57-
// }
55+
if (CACHED.get(theme) != null) {
56+
return;
57+
}
5858
EditorTheme editorTheme = loadFromAsset(context.getAssets(), ASSET_PATH + "/" + theme);
5959
CACHED.put(theme, editorTheme);
6060
}

editor-view/src/main/java/com/jecelyin/editor/v2/Preferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
7373
, "&", "?", "!", "@", "^", "+", "*", "-", "_", "`", "\\t", "\\n"});
7474

7575
public static final int[] THEMES = new int[]{
76-
R.style.DefaultTheme,
76+
R.style.LightTheme,
7777
R.style.DarkTheme
7878
};
7979

editor-view/src/main/res/layout/activity_editor_theme.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,32 @@
44
android:layout_height="match_parent"
55
android:orientation="vertical">
66

7-
<include layout="@layout/appbar" />
7+
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
8+
xmlns:app="http://schemas.android.com/apk/res-auto"
9+
android:id="@+id/appbar"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content">
12+
13+
<android.support.v7.widget.Toolbar
14+
android:id="@+id/toolbar"
15+
android:layout_width="match_parent"
16+
android:layout_height="?attr/actionBarSize"
17+
app:popupTheme="?attr/actionBarPopupTheme"
18+
app:theme="?attr/actionBarTheme">
19+
20+
<android.support.v7.widget.SwitchCompat
21+
android:id="@+id/switch_theme"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:paddingLeft="16dp"
25+
android:paddingRight="16dp"
26+
android:text="@string/light_theme"
27+
android:textAppearance="@style/TextAppearance.AppCompat.Title"
28+
android:textOff="@string/dark_theme"
29+
android:textOn="@string/light_theme" />
30+
</android.support.v7.widget.Toolbar>
31+
32+
</android.support.design.widget.AppBarLayout>
833

934
<android.support.v7.widget.RecyclerView
1035
android:id="@+id/recyclerView"
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
45
android:layout_height="wrap_content"
5-
android:layout_marginTop="4dp"
6-
android:orientation="vertical">
6+
app:cardUseCompatPadding="true">
77

8-
<android.support.v7.widget.AppCompatTextView
9-
android:id="@+id/txt_name"
8+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
109
android:layout_width="match_parent"
1110
android:layout_height="wrap_content"
12-
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
11+
android:layout_marginTop="4dp"
12+
android:orientation="vertical">
1313

14-
<android.core.widget.EditAreaView
15-
android:id="@+id/editor_view"
16-
android:layout_width="match_parent"
17-
android:layout_height="wrap_content">
14+
<android.support.v7.widget.AppCompatTextView
15+
android:id="@+id/txt_name"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
19+
20+
<android.core.widget.EditAreaView
21+
android:id="@+id/editor_view"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content">
1824

19-
</android.core.widget.EditAreaView>
20-
</LinearLayout>
25+
</android.core.widget.EditAreaView>
26+
</LinearLayout>
27+
</android.support.v7.widget.CardView>
2128

editor-view/src/main/res/values-vi/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<string name="reset">Cài lại</string>
127127
<string name="change_theme">Thay đổi chủ đề</string>
128128
<string name="dark_theme">Chủ đề tối</string>
129-
<string name="default_theme">Chủ đề mặc định</string>
129+
<string name="light_theme">Chủ đề sáng</string>
130130
<string name="fullscreen_mode">Chế độ toàn màn hình</string>
131131
<string name="out_of_memory_error">Hết bộ nhớ ứng dụng</string>
132132
<string name="editor_setting">Cài đặt trình soạn thảo</string>

editor-view/src/main/res/values/arrays.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</string-array>
2323

2424
<string-array name="theme_titles">
25-
<item>@string/default_theme</item>
25+
<item>@string/light_theme</item>
2626
<item>@string/dark_theme</item>
2727
</string-array>
2828
<string-array name="theme_values">

editor-view/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<string name="reset">Reset</string>
195195
<string name="change_theme">Change theme</string>
196196
<string name="dark_theme">Dark Theme</string>
197-
<string name="default_theme">Default Theme</string>
197+
<string name="light_theme">Light Theme</string>
198198
<string name="fullscreen_mode">Full screen Mode</string>
199199
<string name="enable_fullscreen_mode_message">Restart the application will enable the full screen mode</string>
200200
<string name="disabled_fullscreen_mode_message">Restart the application will disable the full screen mode</string>

style/src/main/res/values/dark_themes.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@
3030

3131
<item name="findResultsPath">#0000ff</item>
3232
<item name="findResultsKeyword">#C26509</item>
33-
34-
<item name="android:statusBarColor">#228a96</item>
3533
</style>
3634

37-
<style name="DarkToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
38-
<item name="android:background">#293139</item>
39-
</style>
35+
<style name="DarkToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
4036

4137
<style name="DarkToolbarPopupTheme" parent="@style/ThemeOverlay.AppCompat.Dark" />
4238

0 commit comments

Comments
 (0)