Skip to content

Commit

Permalink
Auto-load an example HTML file in editor
Browse files Browse the repository at this point in the history
- Enabled debugging of web contents
- Set editor fields to editable
  • Loading branch information
Alex authored and Alex committed Mar 24, 2015
1 parent dd66e62 commit ced12ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.content.res.AssetManager;
import android.os.Build;
import android.os.Bundle;
import android.text.Spanned;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -97,7 +98,32 @@ public void onConsoleMessage(String message, int lineNumber, String sourceId) {
}
});
String htmlEditor = getHtmlEditor();

mWebView.loadDataWithBaseURL("file:///android_asset/", htmlEditor, "text/html", "utf-8", "");

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
// TODO: Replace postDelay with a callback from JS
mWebView.postDelayed(new Runnable() {
@Override
public void run() {
String htmlFile = "";
try {
htmlFile = getStringFromAsset("example-content.html");
htmlFile = htmlFile.replace("\\", "\\\\");
htmlFile = htmlFile.replace("\"", "\\\"");
htmlFile = htmlFile.replace("'", "\\'");
htmlFile = htmlFile.replace("\r", "\\r");
htmlFile = htmlFile.replace("\n", "\\n");
} catch (IOException e) {
AppLog.e(T.EDITOR, e.getMessage());
}

// Load example file into editor content field
mWebView.loadUrl("JavaScript:ZSSEditor.getField('zss_field_content').setHTML('" + htmlFile + "');");
}
}, 5000);
}

private String getStringFromAsset(String filename) throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions libs/editor-common/assets/android-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,12 @@
</style>
</head>
<body>
<div contenteditable="false" id="zss_field_title" class="field" nostyle>
<div contenteditable="true" id="zss_field_title" class="field" nostyle>
</div>
<div contenteditable="false" id="separatorDiv" >
<hr/>
</div>
<div contenteditable="false" id="zss_field_content" class="field">
<div contenteditable="true" id="zss_field_content" class="field">
</div>
</body>
</html>

0 comments on commit ced12ea

Please sign in to comment.