Skip to content

Commit ced12ea

Browse files
AlexAlex
authored andcommitted
Auto-load an example HTML file in editor
- Enabled debugging of web contents - Set editor fields to editable
1 parent dd66e62 commit ced12ea

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.SuppressLint;
44
import android.content.res.AssetManager;
5+
import android.os.Build;
56
import android.os.Bundle;
67
import android.text.Spanned;
78
import android.view.LayoutInflater;
@@ -97,7 +98,32 @@ public void onConsoleMessage(String message, int lineNumber, String sourceId) {
9798
}
9899
});
99100
String htmlEditor = getHtmlEditor();
101+
100102
mWebView.loadDataWithBaseURL("file:///android_asset/", htmlEditor, "text/html", "utf-8", "");
103+
104+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
105+
WebView.setWebContentsDebuggingEnabled(true);
106+
}
107+
// TODO: Replace postDelay with a callback from JS
108+
mWebView.postDelayed(new Runnable() {
109+
@Override
110+
public void run() {
111+
String htmlFile = "";
112+
try {
113+
htmlFile = getStringFromAsset("example-content.html");
114+
htmlFile = htmlFile.replace("\\", "\\\\");
115+
htmlFile = htmlFile.replace("\"", "\\\"");
116+
htmlFile = htmlFile.replace("'", "\\'");
117+
htmlFile = htmlFile.replace("\r", "\\r");
118+
htmlFile = htmlFile.replace("\n", "\\n");
119+
} catch (IOException e) {
120+
AppLog.e(T.EDITOR, e.getMessage());
121+
}
122+
123+
// Load example file into editor content field
124+
mWebView.loadUrl("JavaScript:ZSSEditor.getField('zss_field_content').setHTML('" + htmlFile + "');");
125+
}
126+
}, 5000);
101127
}
102128

103129
private String getStringFromAsset(String filename) throws IOException {

libs/editor-common/assets/android-editor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,12 +1108,12 @@
11081108
</style>
11091109
</head>
11101110
<body>
1111-
<div contenteditable="false" id="zss_field_title" class="field" nostyle>
1111+
<div contenteditable="true" id="zss_field_title" class="field" nostyle>
11121112
</div>
11131113
<div contenteditable="false" id="separatorDiv" >
11141114
<hr/>
11151115
</div>
1116-
<div contenteditable="false" id="zss_field_content" class="field">
1116+
<div contenteditable="true" id="zss_field_content" class="field">
11171117
</div>
11181118
</body>
11191119
</html>

0 commit comments

Comments
 (0)