Skip to content

Commit 9b7757b

Browse files
authored
Merge pull request #3 from Sparkleseditor/editor
Chore : Trying to implement editor Modules and Ui and theme logic
2 parents b4a9b9b + a5a4ae7 commit 9b7757b

8 files changed

Lines changed: 187 additions & 29 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ dependencies {
6262
implementation(platform(libs.editor.bom))
6363
implementation(libs.editor)
6464
implementation(libs.language.textmate)
65+
implementation(libs.language.java)
6566
implementation(libs.transition)
6667
implementation(libs.fragment)
6768
implementation(libs.activity)

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<activity
1717
android:name=".MainActivity"
1818
android:exported="true"
19-
android:theme="@style/Theme.SparklesEditor">
19+
android:theme="@style/Theme.SparklesEditor"
20+
android:windowSoftInputMode="adjustResize">
2021
<intent-filter>
2122
<action android:name="android.intent.action.MAIN" />
2223

app/src/main/java/com/sparkleseditor/fragments/MainFragment.java

Lines changed: 118 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
11
package com.sparkleseditor.fragments;
22

33
import android.annotation.SuppressLint;
4+
import android.graphics.Color;
45
import android.os.Bundle;
56
import android.view.LayoutInflater;
67
import android.view.View;
78
import android.view.ViewGroup;
89

910
import androidx.annotation.NonNull;
11+
import androidx.appcompat.app.ActionBarDrawerToggle;
1012
import androidx.core.view.GravityCompat;
13+
import androidx.core.view.ViewCompat;
14+
import androidx.drawerlayout.widget.DrawerLayout;
1115
import androidx.fragment.app.Fragment;
1216

1317
import com.sparkleseditor.R;
1418
import com.sparkleseditor.components.ExpandableLayout;
1519
import com.sparkleseditor.databinding.FragmentMainBinding;
1620
import com.sparkleseditor.navigation.Navigator;
1721

22+
import io.github.rosemoe.sora.widget.SymbolInputView;
23+
1824
public class MainFragment extends BaseFragment {
1925

2026
private FragmentMainBinding binding;
2127

28+
public static final String[] SYMBOLS = {
29+
"TAB","↵", "{", "}", "(", ")",
30+
",", ".", ";", "\"", "?",
31+
"+", "-", "*", "/", "<",
32+
">", "[", "]", ":"
33+
};
34+
35+
public static final String[] SYMBOL_INSERT_TEXT = {
36+
"\t","\n", "{}", "}", "(", ")",
37+
",", ".", ";", "\"", "?",
38+
"+", "-", "*", "/", "<",
39+
">", "[", "]", ":"
40+
};
41+
2242
@Override
2343
public View onCreateView(
2444
@NonNull LayoutInflater inflater, ViewGroup container,
@@ -34,34 +54,122 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
3454
super.onViewCreated(view, savedInstanceState);
3555
setupToolbar();
3656
setupToolbox();
57+
setupInputView();
58+
setupTabLayoutTemp();
59+
slideXDrawer();
60+
binding.fab.setTranslationY(-12);
61+
62+
63+
}
64+
65+
private void slideXDrawer() {
66+
/*int statusBarHeight =
67+
getResources()
68+
.getDimensionPixelSize(
69+
getResources().getIdentifier("status_bar_height", "dimen", "android"));*/
70+
int navigationBarHeight =
71+
getResources()
72+
.getDimensionPixelSize(
73+
getResources().getIdentifier("navigation_bar_height", "dimen", "android"));
74+
ViewGroup.LayoutParams layoutParams = binding.leftDrawerMenu.getLayoutParams();
75+
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
76+
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
77+
binding.leftDrawerMenu.setLayoutParams(marginLayoutParams);
78+
}
79+
80+
binding.drawer.setScrimColor(Color.TRANSPARENT);
81+
binding.drawer.setDrawerElevation(0f);
82+
binding.drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
83+
84+
float slideX;
85+
@Override
86+
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
87+
int gravity = ((DrawerLayout.LayoutParams) drawerView.getLayoutParams()).gravity;
88+
if (gravity == GravityCompat.START) {
89+
binding.coordinator.setTranslationX(slideOffset * drawerView.getWidth());
90+
binding.drawer.bringChildToFront(drawerView);
91+
binding.drawer.requestLayout();
92+
} else if (gravity == GravityCompat.END) {
93+
binding.coordinator.setTranslationX(-slideOffset * drawerView.getWidth());
94+
binding.drawer.bringChildToFront(drawerView);
95+
binding.drawer.requestLayout();
96+
}
97+
}
98+
99+
@Override
100+
public void onDrawerClosed(@NonNull View drawerView) {
101+
binding.coordinator.setTranslationX(0f);
102+
}
103+
104+
@Override
105+
public void onDrawerStateChanged(int newState) {
106+
if (newState == DrawerLayout.STATE_IDLE) {
107+
if (!binding.drawer.isDrawerOpen(GravityCompat.START) &&
108+
!binding.drawer.isDrawerOpen(GravityCompat.END)) {
109+
binding.coordinator.setTranslationX(0f);
110+
}
111+
}
112+
113+
}
114+
115+
116+
});
117+
118+
binding.toolbar.setNavigationOnClickListener(v ->{
119+
binding.drawer.openDrawer(GravityCompat.START);
120+
});
121+
}
122+
123+
private void setupTabLayoutTemp() {
124+
binding.tabLayout.addTab(binding.tabLayout.newTab().setText("My Tab Title"));
125+
126+
}
127+
128+
129+
private void setupInputView() {
130+
131+
SymbolInputView inputView = binding.inputer;
132+
inputView.bindEditor(binding.editor);
133+
inputView.addSymbols(SYMBOLS, SYMBOL_INSERT_TEXT);
134+
inputView.setBackgroundColor(Color.TRANSPARENT);
37135

38136
}
39137

40138
private void setupToolbox() {
41139
binding.options.setExpansion(false);
42140
binding.options.setDuration(200);
43141
binding.options.setOrientatin(ExpandableLayout.VERTICAL);
142+
binding.settings.setOnClickListener(v->{
143+
Fragment frgSettings = new SettingsFragment();
144+
Navigator.pushTo(
145+
getParentFragmentManager(),
146+
R.id.nav_host,
147+
frgSettings
148+
);
149+
});
44150
}
45151

46152
@SuppressLint("NonConstantResourceId")
47153
private void setupToolbar() {
48154
binding.toolbar.setOnMenuItemClickListener(
49155
item->{
50156
int id = item.getItemId();
51-
if (id == R.id.undo) return true;
52-
if (id == R.id.redo) return true;
157+
if (id == R.id.undo){
158+
if (binding.editor.canUndo()){
159+
binding.editor.undo();
160+
}
161+
return true ;
162+
}
163+
if (id == R.id.redo) {
164+
if (binding.editor.canRedo()) {
165+
binding.editor.redo();
166+
}
167+
}
53168
if (id == R.id.right_drawer) {
54169
binding.drawer.openDrawer(GravityCompat.END);
55170
return true;
56171
}
57-
if (id == R.id.action_settings){
58-
Fragment frgSettings = new SettingsFragment();
59-
Navigator.pushTo(
60-
getParentFragmentManager(),
61-
R.id.nav_host,
62-
frgSettings
63-
);
64-
}
172+
65173
if (id == R.id.toolbar){
66174
if (!binding.options.isExpanded()) {
67175
binding.options.expand();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorOnSurface">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M160,720Q143,720 131.5,708.5Q120,697 120,680Q120,663 131.5,651.5Q143,640 160,640L800,640Q817,640 828.5,651.5Q840,663 840,680Q840,697 828.5,708.5Q817,720 800,720L160,720ZM160,520Q143,520 131.5,508.5Q120,497 120,480Q120,463 131.5,451.5Q143,440 160,440L800,440Q817,440 828.5,451.5Q840,463 840,480Q840,497 828.5,508.5Q817,520 800,520L160,520ZM160,320Q143,320 131.5,308.5Q120,297 120,280Q120,263 131.5,251.5Q143,240 160,240L800,240Q817,240 828.5,251.5Q840,263 840,280Q840,297 828.5,308.5Q817,320 800,320L160,320Z"/>
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorOnSurface">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M320,687L320,273Q320,256 332,244.5Q344,233 360,233Q365,233 370.5,234.5Q376,236 381,239L707,446Q716,452 720.5,461Q725,470 725,480Q725,490 720.5,499Q716,508 707,514L381,721Q376,724 370.5,725.5Q365,727 360,727Q344,727 332,715.5Q320,704 320,687Z"/>
10+
</vector>

app/src/main/res/layout/fragment_main.xml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
xmlns:tools="http://schemas.android.com/tools"
77
android:id="@+id/drawer"
88
android:layout_width="match_parent"
9-
android:layout_height="match_parent">
9+
android:layout_height="match_parent"
10+
android:background="?colorSurface">
1011

1112
<androidx.coordinatorlayout.widget.CoordinatorLayout
1213
android:layout_width="match_parent"
13-
android:layout_height="match_parent">
14+
android:layout_height="match_parent"
15+
android:id="@+id/coordinator">
1416

1517
<com.google.android.material.appbar.AppBarLayout
1618
android:id="@+id/appBarLayout"
@@ -21,12 +23,10 @@
2123
android:id="@+id/toolbar"
2224
android:layout_width="match_parent"
2325
android:layout_height="?attr/actionBarSize"
24-
app:title="@string/app_name"
25-
app:menu="@menu/menu_main" />
26-
<com.google.android.material.divider.MaterialDivider
27-
android:layout_width="match_parent"
28-
android:layout_height="wrap_content"
29-
/>
26+
app:title="Sparkles"
27+
app:menu="@menu/menu_main"
28+
app:navigationIcon="@drawable/ic_menu_rounded_filled_24dp"/>
29+
3030
</com.google.android.material.appbar.AppBarLayout>
3131

3232
<LinearLayout
@@ -91,24 +91,56 @@
9191
<com.google.android.material.tabs.TabLayout
9292
android:id="@+id/tabLayout"
9393
android:layout_width="match_parent"
94+
android:layout_height="wrap_content"
95+
app:tabGravity="start"
96+
app:tabMode="scrollable"/>
97+
98+
<io.github.rosemoe.sora.widget.CodeEditor
99+
android:layout_width="match_parent"
100+
android:layout_height="0dp"
101+
android:id="@+id/editor"
102+
android:layout_weight="1"/>
103+
104+
<HorizontalScrollView
105+
android:layout_width="match_parent"
106+
android:layout_height="wrap_content"
107+
android:id="@+id/scroll"
108+
android:scrollbars="none"
109+
android:background="?colorSurface">
110+
<io.github.rosemoe.sora.widget.SymbolInputView
111+
android:id="@+id/inputer"
112+
android:layout_width="match_parent"
94113
android:layout_height="wrap_content" />
95-
</LinearLayout>
114+
</HorizontalScrollView>
115+
96116

117+
</LinearLayout>
118+
<View
119+
android:layout_width="match_parent"
120+
android:layout_height="?attr/actionBarSize"
121+
android:visibility="invisible"
122+
android:layout_gravity="bottom"
123+
android:id="@+id/view"/>
97124
<com.google.android.material.floatingactionbutton.FloatingActionButton
98125
android:id="@+id/fab"
99126
android:layout_width="wrap_content"
100127
android:layout_height="wrap_content"
101-
android:layout_gravity="bottom|end"
102-
android:layout_margin="16dp"
128+
app:layout_anchor="@id/scroll"
129+
app:layout_anchorGravity="top|end"
130+
android:layout_marginBottom="64dp"
131+
android:layout_marginEnd="16dp"
103132
android:contentDescription="Play"
104-
app:srcCompat="@android:drawable/ic_dialog_email" />
133+
app:srcCompat="@drawable/ic_play_arrow_rounded_filled_24dp" />
134+
135+
105136

106137
</androidx.coordinatorlayout.widget.CoordinatorLayout>
107138

108139
<com.google.android.material.navigation.NavigationView
109140
android:layout_width="wrap_content"
110141
android:layout_height="match_parent"
111-
android:layout_gravity="start" />
142+
android:layout_gravity="start"
143+
android:id="@+id/left_drawer_menu"/>
112144

113145
<com.google.android.material.navigation.NavigationView
114146
android:id="@+id/right_drawer_menu"

app/src/main/res/menu/menu_main.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,5 @@
2828
android:title="right"
2929
app:showAsAction="always" />
3030

31-
<item
32-
android:id="@+id/action_settings"
33-
android:orderInCategory="101"
34-
android:title="@string/action_settings"
35-
app:showAsAction="never" />
3631

3732
</menu>

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ junit = { group = "junit", name = "junit", version.ref = "junit" }
2424
ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
2525
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
2626
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
27+
language-java = { module = "io.github.rosemoe:language-java" }
2728
language-textmate = { module = "io.github.rosemoe:language-textmate" }
2829
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
2930
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

0 commit comments

Comments
 (0)