11package org .wordpress .android .editor ;
22
33import android .annotation .SuppressLint ;
4- import android .content .res .AssetManager ;
54import android .os .Build ;
65import android .os .Bundle ;
6+ import android .support .annotation .NonNull ;
77import android .text .Spanned ;
88import android .view .LayoutInflater ;
99import android .view .View ;
2323import org .wordpress .android .util .helpers .MediaFile ;
2424import org .wordpress .android .util .helpers .MediaGallery ;
2525
26- import java .io .BufferedReader ;
27- import java .io .IOException ;
28- import java .io .InputStream ;
29- import java .io .InputStreamReader ;
3026import java .util .HashMap ;
3127import java .util .Map ;
3228
@@ -95,7 +91,7 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
9591 });
9692 mWebView .setWebChromeClient (new WebChromeClient () {
9793 @ Override
98- public boolean onConsoleMessage (ConsoleMessage cm ) {
94+ public boolean onConsoleMessage (@ NonNull ConsoleMessage cm ) {
9995 AppLog .d (T .EDITOR , cm .message () + " -- From line " + cm .lineNumber () + " of " + cm .sourceId ());
10096 return true ;
10197 }
@@ -107,7 +103,7 @@ public boolean onJsAlert(WebView view, String url, String message, JsResult resu
107103 }
108104 });
109105
110- String htmlEditor = getHtmlFromFile ("android-editor.html" );
106+ String htmlEditor = Utils . getHtmlFromFile (getActivity (), "android-editor.html" );
111107
112108 mWebView .addJavascriptInterface (new JsCallbackHandler (this ), JS_CALLBACK_HANDLER );
113109
@@ -124,33 +120,6 @@ public void onClick(View v) {
124120 }
125121 }
126122
127- private String getStringFromAsset (String filename ) throws IOException {
128- if (!isAdded ()) {
129- return null ;
130- }
131- AssetManager assetManager = getActivity ().getAssets ();
132- InputStream in = assetManager .open (filename );
133- InputStreamReader is = new InputStreamReader (in );
134- StringBuilder sb = new StringBuilder ();
135- BufferedReader br = new BufferedReader (is );
136- String read = br .readLine ();
137- while (read != null ) {
138- sb .append (read );
139- sb .append ('\n' );
140- read = br .readLine ();
141- }
142- return sb .toString ();
143- }
144-
145- private String getHtmlFromFile (String filename ) {
146- try {
147- return getStringFromAsset (filename );
148- } catch (IOException e ) {
149- AppLog .e (T .EDITOR , e .getMessage ());
150- return null ;
151- }
152- }
153-
154123 @ SuppressLint ("NewApi" )
155124 private void enableWebDebugging (boolean enable ) {
156125 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT ) {
@@ -200,7 +169,7 @@ public void onDomLoaded() {
200169 mWebView .post (new Runnable () {
201170 public void run () {
202171 String title = "I'm editing a post!" ;
203- String contentHtml = getHtmlFromFile ("example-content.html" );
172+ String contentHtml = Utils . getHtmlFromFile (getActivity (), "example-content.html" );
204173
205174 mWebView .execJavaScriptFromString ("ZSSEditor.getField('zss_field_content').setMultiline('true');" );
206175
0 commit comments