Skip to content

Commit ddc1538

Browse files
committed
Changes
1 parent d9ddc60 commit ddc1538

16 files changed

Lines changed: 499 additions & 144 deletions

File tree

main/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
</activity>
2929
<activity
3030
android:name=".EditorActivity"
31-
android:exported="false" />
31+
android:exported="false"
32+
android:windowSoftInputMode="adjustResize" />
3233
<activity
3334
android:name=".SettingsActivity"
3435
android:exported="false" />
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
[{
2+
"Flexbox container": {
3+
"prefix": "flex",
4+
"body": [
5+
"display: flex;",
6+
"flex-direction: ${1:row};",
7+
"justify-content: ${2:flex-start};",
8+
"align-items: ${3:stretch};",
9+
"flex-wrap: ${4:nowrap};",
10+
"gap: ${5:0};",
11+
"${0}"
12+
],
13+
"description": "Flexbox container properties"
14+
},
15+
"Grid container": {
16+
"prefix": "grid",
17+
"body": [
18+
"display: grid;",
19+
"grid-template-columns: ${1:1fr};",
20+
"grid-template-rows: ${2:auto};",
21+
"gap: ${3:1rem};",
22+
"align-items: ${4:stretch};",
23+
"justify-items: ${5:stretch};",
24+
"${0}"
25+
],
26+
"description": "CSS Grid container"
27+
},
28+
"Centering block": {
29+
"prefix": "center",
30+
"body": [
31+
"display: ${1:block};",
32+
"margin: ${2:0 auto};",
33+
"max-width: ${3:1200px};",
34+
"width: ${4:100%};",
35+
"${0}"
36+
],
37+
"description": "Center a block element"
38+
},
39+
"Position absolute": {
40+
"prefix": "abs",
41+
"body": [
42+
"position: absolute;",
43+
"top: ${1:0};",
44+
"left: ${2:0};",
45+
"right: ${3:0};",
46+
"bottom: ${4:0};",
47+
"${0}"
48+
],
49+
"description": "Absolute positioning"
50+
},
51+
"Media query": {
52+
"prefix": "media",
53+
"body": [
54+
"@media (${1:max-width}: ${2:768px}) {",
55+
" ${0}",
56+
"}"
57+
],
58+
"description": "Media query"
59+
},
60+
"Animation": {
61+
"prefix": "anim",
62+
"body": [
63+
"animation: ${1:name} ${2:1s} ${3:ease} ${4:0s} ${5:1} ${6:normal} ${7:none} ${8:running};",
64+
"${0}"
65+
],
66+
"description": "Animation shorthand"
67+
},
68+
"Transition": {
69+
"prefix": "trans",
70+
"body": [
71+
"transition: ${1:all} ${2:0.3s} ${3:ease};",
72+
"${0}"
73+
],
74+
"description": "Transition shorthand"
75+
},
76+
"Box shadow": {
77+
"prefix": "shadow",
78+
"body": [
79+
"box-shadow: ${1:0} ${2:2px} ${3:4px} rgba(0, 0, 0, ${4:0.1});",
80+
"${0}"
81+
],
82+
"description": "Box shadow"
83+
},
84+
"Border radius": {
85+
"prefix": "radius",
86+
"body": [
87+
"border-radius: ${1:4px};",
88+
"${0}"
89+
],
90+
"description": "Border radius"
91+
},
92+
"Pseudo-classes": {
93+
"prefix": "pseudo",
94+
"body": [
95+
"&:${1|hover,focus,active,visited,first-child,last-child,nth-child(2)|} {",
96+
" ${0}",
97+
"}"
98+
],
99+
"description": "CSS pseudo-classes"
100+
},
101+
"Keyframes": {
102+
"prefix": "keyframes",
103+
"body": [
104+
"@keyframes ${1:name} {",
105+
" from {",
106+
" ${2}",
107+
" }",
108+
" to {",
109+
" ${3}",
110+
" }",
111+
"}",
112+
"${0}"
113+
],
114+
"description": "CSS keyframes animation"
115+
},
116+
"Custom properties": {
117+
"prefix": "vars",
118+
"body": [
119+
"--${1:variable-name}: ${2:value};",
120+
"${0}"
121+
],
122+
"description": "CSS custom properties (variables)"
123+
}
124+
}]

main/src/main/assets/textmate/languages/html/html-snippets.json renamed to main/src/main/assets/textmate/languages/html/html.snippets.json

File renamed without changes.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
[{
2+
"Console log": {
3+
"prefix": "cl",
4+
"body": "console.log('${1:message}', ${2:value});${0}",
5+
"description": "Console log with message"
6+
},
7+
"Function declaration": {
8+
"prefix": "fn",
9+
"body": [
10+
"/**",
11+
" * ${3:Function description}",
12+
" * @param {${4:type}} ${5:param} - ${6:parameter description}",
13+
" * @returns {${7:returnType}} ${8:return description}",
14+
" */",
15+
"function ${1:functionName}(${2:params}) {",
16+
" ${0}",
17+
"}"
18+
],
19+
"description": "Documented function declaration"
20+
},
21+
"Arrow function": {
22+
"prefix": "af",
23+
"body": [
24+
"const ${1:functionName} = (${2:params}) => {",
25+
" ${0}",
26+
"};"
27+
],
28+
"description": "Arrow function"
29+
},
30+
"Async function": {
31+
"prefix": "async",
32+
"body": [
33+
"async function ${1:functionName}(${2:params}) {",
34+
" try {",
35+
" ${0}",
36+
" } catch (error) {",
37+
" console.error('${3:Error in ${1:functionName}}', error);",
38+
" throw error;",
39+
" }",
40+
"}"
41+
],
42+
"description": "Async function with error handling"
43+
},
44+
"Class declaration": {
45+
"prefix": "class",
46+
"body": [
47+
"class ${1:ClassName} {",
48+
" constructor(${2:params}) {",
49+
" ${3}",
50+
" }",
51+
"",
52+
" ${4:methodName}(${5:params}) {",
53+
" ${0}",
54+
" }",
55+
"}"
56+
],
57+
"description": "Class with constructor and method"
58+
},
59+
"Promise": {
60+
"prefix": "prom",
61+
"body": [
62+
"new Promise((resolve, reject) => {",
63+
" ${1:// async operation}",
64+
" ${2:success} ? resolve(${3:result}) : reject(new Error('${4:Error message}'));",
65+
"}).then(${5:result} => {",
66+
" ${0}",
67+
"}).catch(error => {",
68+
" console.error('${6:Promise error}', error);",
69+
"});"
70+
],
71+
"description": "Promise with then/catch"
72+
},
73+
"If statement": {
74+
"prefix": "if",
75+
"body": [
76+
"if (${1:condition}) {",
77+
" ${0}",
78+
"}"
79+
],
80+
"description": "If statement"
81+
},
82+
"For loop": {
83+
"prefix": "for",
84+
"body": [
85+
"for (let ${1:i} = 0; ${1:i} < ${2:array}.length; ${1:i}++) {",
86+
" ${0}",
87+
"}"
88+
],
89+
"description": "For loop"
90+
},
91+
"Import statement": {
92+
"prefix": "imp",
93+
"body": "import { ${1:module} } from '${2:module-path}';${0}",
94+
"description": "ES6 import"
95+
},
96+
"Export default": {
97+
"prefix": "expd",
98+
"body": "export default ${1:value};${0}",
99+
"description": "ES6 export default"
100+
},
101+
"Object literal": {
102+
"prefix": "obj",
103+
"body": [
104+
"const ${1:objectName} = {",
105+
" ${2:key}: ${3:value},",
106+
" ${4:method}(${5:params}) {",
107+
" ${0}",
108+
" }",
109+
"};"
110+
],
111+
"description": "Object with method"
112+
}
113+
}]

main/src/main/java/org/xedox/webaide/EditorActivity.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class EditorActivity extends BaseActivity {
4141
private View nav;
4242
private TextView navTitle;
4343
private Handler handler = new Handler(Looper.getMainLooper());
44-
44+
4545
@Override
4646
protected void onCreate(Bundle savedInstanceState) {
4747
super.onCreate(savedInstanceState);
@@ -73,21 +73,24 @@ public void handleBackPressed() {
7373
startActivity(intent);
7474
finish();
7575
}
76-
76+
7777
@Override
7878
public boolean onOptionsItemSelected(MenuItem item) {
79-
if(editorManager.onOptionsItemSelected(item)) return true;
80-
if(item.getItemId() == R.id.run) {
81-
Intent intent = new Intent(this, PreviewActivity.class);
82-
intent.putExtra("index.html", project.file("index.html"));
83-
startActivity(intent);
84-
} else if(item.getItemId() == R.id.color_picker) {
79+
if (editorManager.onOptionsItemSelected(item)) return true;
80+
if (item.getItemId() == R.id.run) {
81+
try {
82+
Intent intent = new Intent(this, PreviewActivity.class);
83+
intent.putExtra("index.html", project.file("index.html"));
84+
startActivity(intent);
85+
} catch (Throwable err) {
86+
ErrorDialog.show(getApplicationContext(), err);
87+
}
88+
} else if (item.getItemId() == R.id.color_picker) {
8589
ColorPickerDialog.show(this);
8690
}
8791
return super.onOptionsItemSelected(item);
8892
}
89-
90-
93+
9194
@Override
9295
public boolean onCreateOptionsMenu(Menu menu) {
9396
return onCreateOptionsMenu(R.menu.editor, menu);

main/src/main/java/org/xedox/webaide/PreviewActivity.java

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,76 @@
1212
import android.webkit.WebViewClient;
1313
import android.widget.ProgressBar;
1414
import androidx.appcompat.app.AppCompatActivity;
15+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
1516
import com.google.android.material.appbar.MaterialToolbar;
1617
import java.io.BufferedReader;
1718
import java.io.InputStream;
1819
import java.io.InputStreamReader;
1920
import org.xedox.utils.BaseActivity;
21+
import org.xedox.utils.dialog.ErrorDialog;
2022
import org.xedox.utils.view.WebViewX;
2123

2224
public class PreviewActivity extends BaseActivity {
2325

2426
private MaterialToolbar toolbar;
2527
private WebViewX webView;
2628
private ProgressBar progress;
29+
private SwipeRefreshLayout swipeRefresh;
2730

2831
@Override
2932
protected void onCreate(Bundle savedInstanceState) {
3033
super.onCreate(savedInstanceState);
31-
setContentView(R.layout.activity_preview);
32-
toolbar = findViewById(R.id.toolbar);
33-
webView = findViewById(R.id.web_view);
34-
progress = findViewById(R.id.progress);
35-
setSupportActionBar(toolbar);
36-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
37-
webView.setProgressBar(progress);
38-
webView.addOnPageStartedListener((v, url, ic)-> {
39-
getSupportActionBar().setSubtitle(url);
40-
});
41-
42-
Intent intent = getIntent();
43-
String indexHtml = intent.getStringExtra("index.html");
44-
45-
if (indexHtml != null && !indexHtml.isBlank()) {
46-
webView.loadUrl("file://"+indexHtml);
47-
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
48-
Uri data = intent.getData();
49-
if (data != null) {
50-
loadHtmlFromUri(data);
51-
} else {
52-
webView.loadData("File found'n", "text/html", "UTF-8");
34+
try {
35+
setContentView(R.layout.activity_preview);
36+
toolbar = findViewById(R.id.toolbar);
37+
webView = findViewById(R.id.web_view);
38+
progress = findViewById(R.id.progress);
39+
swipeRefresh = findViewById(R.id.refresh_layout);
40+
setSupportActionBar(toolbar);
41+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
42+
webView.setProgressBar(progress);
43+
webView.addOnPageStartedListener(
44+
(v, url, ic) -> {
45+
46+
String str = url.substring(url.lastIndexOf("/")+1, url.length());
47+
getSupportActionBar().setSubtitle(str);
48+
});
49+
50+
Intent intent = getIntent();
51+
String indexHtml = intent.getStringExtra("index.html");
52+
53+
if (indexHtml != null && !indexHtml.isBlank()) {
54+
webView.loadUrl("file://" + indexHtml);
55+
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
56+
Uri data = intent.getData();
57+
if (data != null) {
58+
loadHtmlFromUri(data);
59+
} else {
60+
webView.loadData("File found'n", "text/html", "UTF-8");
61+
}
5362
}
63+
swipeRefresh.setOnRefreshListener(
64+
() -> {
65+
webView.reload();
66+
swipeRefresh.setRefreshing(false);
67+
});
68+
} catch (Exception err) {
69+
ErrorDialog.show(this, err);
5470
}
5571
}
56-
72+
5773
@Override
5874
public boolean onOptionsItemSelected(MenuItem item) {
5975
int id = item.getItemId();
60-
if(id == android.R.id.home) {
76+
if (id == android.R.id.home) {
6177
finish();
6278
}
6379
return super.onOptionsItemSelected(item);
6480
}
65-
81+
6682
@Override
6783
public void handleBackPressed() {
68-
finish();
84+
finish();
6985
}
7086

7187
private void loadHtmlFromUri(Uri uri) {

0 commit comments

Comments
 (0)