Skip to content

Commit 2abece9

Browse files
committed
Added menu change theme
1 parent ef0aea2 commit 2abece9

File tree

9 files changed

+38
-9
lines changed

9 files changed

+38
-9
lines changed

app/src/main/java/com/duy/editor/CodeEditorActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import com.duy.common.purchase.InAppPurchaseHelper;
4343
import com.duy.common.purchase.Premium;
4444
import com.duy.ide.editor.SimpleEditorActivity;
45-
import com.duy.ide.editor.theme.ThemeActivity;
45+
import com.duy.ide.editor.theme.EditorThemeActivity;
4646
import com.duy.ide.filemanager.SaveListener;
4747
import com.jecelyin.common.utils.UIUtils;
4848
import com.jecelyin.editor.v2.editor.Document;
@@ -70,7 +70,7 @@ public class CodeEditorActivity extends SimpleEditorActivity {
7070
@Override
7171
protected void onCreate(Bundle savedInstanceState) {
7272
super.onCreate(savedInstanceState);
73-
startActivity(new Intent(this, ThemeActivity.class));
73+
startActivity(new Intent(this, EditorThemeActivity.class));
7474
mPremiumHelper = new InAppPurchaseHelper(this);
7575

7676
final View toggleView = findViewById(R.id.btn_toggle_panel);

editor-view/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2424

2525
<application android:supportsRtl="false">
26-
<activity android:name="com.duy.ide.editor.theme.ThemeActivity" />
26+
<activity android:name="com.duy.ide.editor.theme.EditorThemeActivity" />
2727
</application>
2828
</manifest>

editor-view/src/main/java/com/duy/ide/editor/SimpleEditorActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.duy.ide.editor.dialogs.DialogNewFile;
4949
import com.duy.ide.editor.editor.BuildConfig;
5050
import com.duy.ide.editor.editor.R;
51+
import com.duy.ide.editor.theme.EditorThemeActivity;
5152
import com.duy.ide.filemanager.FileManager;
5253
import com.jecelyin.common.utils.DLog;
5354
import com.jecelyin.common.utils.IOUtils;
@@ -352,7 +353,7 @@ protected void onCreateNavigationMenu(Menu menu) {
352353
SubMenu subMenu = menu.addSubMenu(group.getNameResId());
353354
List<MenuItemInfo> items = menuFactory.getMenuItemsWithoutToolbarMenu(group);
354355
for (MenuItemInfo item : items) {
355-
MenuItem menuItem = subMenu.add(MenuDef.GROUP_TOOLBAR, item.getItemId(), item.getOrder(), item.getTitleResId());
356+
MenuItem menuItem = subMenu.add(MenuDef.GROUP_NAVIGATION, item.getItemId(), item.getOrder(), item.getTitleResId());
356357
menuItem.setIcon(item.getIconResId());
357358
}
358359
}
@@ -436,7 +437,9 @@ public void run() {
436437
StoreUtil.shareThisApp(this);
437438
} else if (id == R.id.action_rate) {
438439
StoreUtil.gotoPlayStore(this, getPackageName());
439-
} else {
440+
} else if (id == R.id.action_editor_color_scheme){
441+
startActivity(new Intent(this, EditorThemeActivity.class));
442+
}else {
440443
commandEnum = MenuFactory.getInstance(this).idToCommandEnum(id);
441444
if (commandEnum != Command.CommandEnum.NONE)
442445
doCommand(new Command(commandEnum));
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package com.duy.ide.editor.theme;
22

3+
import android.content.SharedPreferences;
34
import android.os.Bundle;
45
import android.support.annotation.Nullable;
56
import android.support.v7.widget.LinearLayoutManager;
67
import android.support.v7.widget.RecyclerView;
78
import android.support.v7.widget.Toolbar;
89

910
import com.duy.ide.editor.editor.R;
11+
import com.jecelyin.editor.v2.Preferences;
1012
import com.jecelyin.editor.v2.ThemeSupportActivity;
1113

12-
public class ThemeActivity extends ThemeSupportActivity {
14+
public class EditorThemeActivity extends ThemeSupportActivity {
1315
private RecyclerView mRecyclerView;
1416
private ThemeAdapter mThemeAdapter;
1517

1618
@Override
1719
protected void onCreate(@Nullable Bundle savedInstanceState) {
1820
super.onCreate(savedInstanceState);
19-
setContentView(R.layout.activity_themes);
21+
setContentView(R.layout.activity_editor_theme);
2022
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
2123
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
2224

@@ -26,6 +28,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2628
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
2729
mThemeAdapter = new ThemeAdapter(this);
2830
mRecyclerView.setAdapter(mThemeAdapter);
31+
32+
Preferences.getInstance(this).registerOnSharedPreferenceChangeListener(this);
2933
}
3034

35+
@Override
36+
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
37+
if (key.equals(getString(R.string.pref_current_theme))) {
38+
39+
} else {
40+
super.onSharedPreferenceChanged(sharedPreferences, key);
41+
}
42+
}
43+
44+
@Override
45+
protected void onDestroy() {
46+
super.onDestroy();
47+
Preferences.getInstance(this).unregisterOnSharedPreferenceChangeListener(this);
48+
}
3149
}

editor-view/src/main/java/com/jecelyin/editor/v2/widget/menu/MenuFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ private void initAllMenuItem() {
127127
menuItemInfos.add(new MenuItemInfo(MenuGroup.EDIT, R.id.action_cursor_forward, CURSOR_FORWARD, R.drawable.ic_arrow_forward_white_24dp, R.string.cursor_forward));
128128

129129
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.m_info, DOC_INFO, R.drawable.ic_info_white_24dp, R.string.document_info));
130-
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.action_highlight, NONE, R.drawable.ic_highlight_white_24dp, R.string.highlight_language));
131130
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.action_encoding, NONE, R.drawable.m_encoding, R.string.encoding));
131+
132+
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.action_highlight, NONE, R.drawable.ic_highlight_white_24dp, R.string.highlight_language));
133+
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.action_editor_color_scheme, NONE, R.drawable.ic_color_lens_white_24dp, R.string.editor_theme));
132134
menuItemInfos.add(new MenuItemInfo(MenuGroup.OTHER, R.id.action_editor_setting, NONE, R.drawable.ic_settings_white_24dp, R.string.editor_setting));
133135
menuItemInfos.add(new MenuItemInfo(MenuGroup.OTHER, R.id.action_share, NONE, R.drawable.baseline_share_24, R.string.share_this_app));
134136
menuItemInfos.add(new MenuItemInfo(MenuGroup.OTHER, R.id.action_rate, NONE, R.drawable.baseline_rate_review_24, R.string.rate_this_app));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@
3838
<item name="avpa_view_tag_key" type="id" />
3939
<item name="action_share" type="id">Share</item>
4040
<item name="action_rate" type="id" />
41+
<item name="action_editor_color_scheme" type="id" />
4142
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,5 @@
219219
<string name="cannot_create_new_file">Cannot create file</string>
220220
<string name="not_a_text_file">The file %s seem like is not a text file. Do you want to open it?</string>
221221
<string name="home">Home</string>
222+
<string name="editor_theme">Editor theme [Pro]</string>
222223
</resources>

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

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

3131
<item name="findResultsPath">#0000ff</item>
3232
<item name="findResultsKeyword">#C26509</item>
33+
34+
<item name="android:statusBarColor">#228a96</item>
3335
</style>
3436

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

3741
<style name="DarkToolbarPopupTheme" parent="@style/ThemeOverlay.AppCompat.Dark" />
3842

0 commit comments

Comments
 (0)