diff --git a/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java b/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java index a2f3fc54d363..ad019edb4e84 100755 --- a/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java +++ b/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java @@ -24,6 +24,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; +import android.webkit.JavascriptInterface; import android.webkit.URLUtil; import android.webkit.WebView; import android.widget.ToggleButton; @@ -59,6 +60,7 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli private static final String ARG_PARAM_CONTENT = "param_content"; private static final String JS_CALLBACK_HANDLER = "nativeCallbackHandler"; + private static final String JS_STATE_INTERFACE = "nativeState"; private static final String KEY_TITLE = "title"; private static final String KEY_CONTENT = "content"; @@ -366,13 +368,18 @@ private void setupFormatBarButtonMap(View view) { } protected void initJsEditor() { - if(!isAdded()) { + if (!isAdded()) { return; } String htmlEditor = Utils.getHtmlFromFile(getActivity(), "android-editor.html"); + if (htmlEditor != null) { + htmlEditor = htmlEditor.replace("%%TITLE%%", getString(R.string.visual_editor)); + } mWebView.addJavascriptInterface(new JsCallbackReceiver(this), JS_CALLBACK_HANDLER); + mWebView.addJavascriptInterface(new NativeStateJsInterface(getActivity().getApplicationContext()), + JS_STATE_INTERFACE); mWebView.loadDataWithBaseURL("file:///android_asset/", htmlEditor, "text/html", "utf-8", ""); @@ -1123,7 +1130,7 @@ private void updateVisualEditorFields() { private void hideActionBarIfNeeded() { ActionBar actionBar = getActionBar(); - if (getActionBar() != null + if (actionBar != null && !isHardwareKeyboardPresent() && mHideActionBarOnSoftKeyboardUp && mIsKeyboardOpen @@ -1138,8 +1145,8 @@ private void hideActionBarIfNeeded() { private void showActionBarIfNeeded() { ActionBar actionBar = getActionBar(); - if (getActionBar() != null && !actionBar.isShowing()) { - getActionBar().show(); + if (actionBar != null && !actionBar.isShowing()) { + actionBar.show(); } } @@ -1261,4 +1268,37 @@ private void applyFormattingHtmlMode(ToggleButton toggleButton, String tag) { mSourceViewContent.setSelection(selectionEnd + endTag.length()); } } + + private class NativeStateJsInterface { + Context mContext; + + NativeStateJsInterface(Context context) { + mContext = context; + } + + @JavascriptInterface + public String getStringEdit() { + return mContext.getString(R.string.edit); + } + + @JavascriptInterface + public String getStringTapToRetry() { + return mContext.getString(R.string.tap_to_try_again); + } + + @JavascriptInterface + public String getStringUploading() { + return mContext.getString(R.string.uploading); + } + + @JavascriptInterface + public String getStringUploadingGallery() { + return mContext.getString(R.string.uploading_gallery_placeholder); + } + + @JavascriptInterface + public int getAPILevel() { + return Build.VERSION.SDK_INT; + } + } } diff --git a/WordPressEditor/src/main/java/org/wordpress/android/editor/RippleToggleButton.java b/WordPressEditor/src/main/java/org/wordpress/android/editor/RippleToggleButton.java index 4d932b322e0b..fd2ac6110142 100644 --- a/WordPressEditor/src/main/java/org/wordpress/android/editor/RippleToggleButton.java +++ b/WordPressEditor/src/main/java/org/wordpress/android/editor/RippleToggleButton.java @@ -21,12 +21,11 @@ public class RippleToggleButton extends ToggleButton { private Paint mStrokePaint; public RippleToggleButton(Context context) { - super(context); - } + this(context, null); + } public RippleToggleButton(Context context, AttributeSet attrs) { - super(context, attrs); - init(); + this(context, attrs, 0); } public RippleToggleButton(Context context, AttributeSet attrs, int defStyle) { diff --git a/WordPressEditor/src/main/res/layout-w360dp/format_bar.xml b/WordPressEditor/src/main/res/layout-w360dp/format_bar.xml index 6b498fe0baee..fc2eb283e5f0 100644 --- a/WordPressEditor/src/main/res/layout-w360dp/format_bar.xml +++ b/WordPressEditor/src/main/res/layout-w360dp/format_bar.xml @@ -37,6 +37,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_media" android:background="@drawable/format_bar_button_media_selector"/> @@ -52,6 +54,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_italic" android:background="@drawable/format_bar_button_italic_selector" android:tag="@string/format_bar_tag_italic"/> @@ -60,6 +63,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_quote" android:background="@drawable/format_bar_button_quote_selector" android:tag="@string/format_bar_tag_blockquote"/> @@ -68,6 +72,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_ul" android:background="@drawable/format_bar_button_ul_selector" android:tag="@string/format_bar_tag_unorderedList"/> @@ -76,6 +81,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_ol" android:background="@drawable/format_bar_button_ol_selector" android:tag="@string/format_bar_tag_orderedList"/> @@ -84,6 +90,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_link" android:background="@drawable/format_bar_button_link_selector" android:tag="@string/format_bar_tag_link"/> @@ -100,6 +107,7 @@ style="@style/FormatBarHtmlButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_html" android:background="@drawable/format_bar_button_html_selector"/> - \ No newline at end of file + diff --git a/WordPressEditor/src/main/res/layout-w380dp/format_bar.xml b/WordPressEditor/src/main/res/layout-w380dp/format_bar.xml index bd8e1f900644..17d9f6d26358 100644 --- a/WordPressEditor/src/main/res/layout-w380dp/format_bar.xml +++ b/WordPressEditor/src/main/res/layout-w380dp/format_bar.xml @@ -31,6 +31,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:contentDescription="@string/format_bar_description_media" android:background="@drawable/format_bar_button_media_selector"/> @@ -48,6 +50,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:contentDescription="@string/format_bar_description_italic" android:background="@drawable/format_bar_button_italic_selector" android:tag="@string/format_bar_tag_italic"/> @@ -57,6 +60,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:contentDescription="@string/format_bar_description_quote" android:background="@drawable/format_bar_button_quote_selector" android:tag="@string/format_bar_tag_blockquote"/> @@ -66,6 +70,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:contentDescription="@string/format_bar_description_ul" android:background="@drawable/format_bar_button_ul_selector" android:tag="@string/format_bar_tag_unorderedList"/> @@ -75,6 +80,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:contentDescription="@string/format_bar_description_ol" android:background="@drawable/format_bar_button_ol_selector" android:tag="@string/format_bar_tag_orderedList"/> @@ -84,6 +90,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:contentDescription="@string/format_bar_description_link" android:background="@drawable/format_bar_button_link_selector" android:tag="@string/format_bar_tag_link"/> @@ -99,6 +106,7 @@ style="@style/FormatBarHtmlButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_html" android:background="@drawable/format_bar_button_html_selector"/> - \ No newline at end of file + diff --git a/WordPressEditor/src/main/res/layout-w600dp/format_bar.xml b/WordPressEditor/src/main/res/layout-w600dp/format_bar.xml index dcceb2ea9321..58f907084759 100644 --- a/WordPressEditor/src/main/res/layout-w600dp/format_bar.xml +++ b/WordPressEditor/src/main/res/layout-w600dp/format_bar.xml @@ -34,6 +34,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_media" android:background="@drawable/format_bar_button_media_selector"/> @@ -47,6 +48,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_bold" android:background="@drawable/format_bar_button_bold_selector" android:tag="@string/format_bar_tag_bold"/> @@ -55,6 +57,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_italic" android:background="@drawable/format_bar_button_italic_selector" android:tag="@string/format_bar_tag_italic"/> @@ -77,6 +80,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_link" android:background="@drawable/format_bar_button_link_selector" android:tag="@string/format_bar_tag_link"/> @@ -91,6 +95,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_ul" android:background="@drawable/format_bar_button_ul_selector" android:tag="@string/format_bar_tag_unorderedList"/> @@ -99,6 +104,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_ol" android:background="@drawable/format_bar_button_ol_selector" android:tag="@string/format_bar_tag_orderedList"/> @@ -107,6 +113,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_quote" android:background="@drawable/format_bar_button_quote_selector" android:tag="@string/format_bar_tag_blockquote"/> @@ -121,6 +128,7 @@ style="@style/FormatBarButtonTablet" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_html" android:background="@drawable/format_bar_button_html_selector"/> diff --git a/WordPressEditor/src/main/res/layout/dialog_image_options.xml b/WordPressEditor/src/main/res/layout/dialog_image_options.xml index 9b471f50832f..ead7e7653d37 100644 --- a/WordPressEditor/src/main/res/layout/dialog_image_options.xml +++ b/WordPressEditor/src/main/res/layout/dialog_image_options.xml @@ -21,6 +21,7 @@ - \ No newline at end of file + diff --git a/WordPressEditor/src/main/res/layout/format_bar.xml b/WordPressEditor/src/main/res/layout/format_bar.xml index a8e3e57a09af..5fb9c4fabe21 100644 --- a/WordPressEditor/src/main/res/layout/format_bar.xml +++ b/WordPressEditor/src/main/res/layout/format_bar.xml @@ -42,6 +42,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_media" android:background="@drawable/format_bar_button_media_selector"/> @@ -57,6 +59,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_italic" android:background="@drawable/format_bar_button_italic_selector" android:tag="@string/format_bar_tag_italic"/> @@ -65,6 +68,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_quote" android:background="@drawable/format_bar_button_quote_selector" android:tag="@string/format_bar_tag_blockquote"/> @@ -73,6 +77,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_ul" android:background="@drawable/format_bar_button_ul_selector" android:tag="@string/format_bar_tag_unorderedList"/> @@ -81,6 +86,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_ol" android:background="@drawable/format_bar_button_ol_selector" android:tag="@string/format_bar_tag_orderedList"/> @@ -89,6 +95,7 @@ style="@style/FormatBarButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_link" android:background="@drawable/format_bar_button_link_selector" android:tag="@string/format_bar_tag_link"/> @@ -106,6 +113,7 @@ style="@style/FormatBarHtmlButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_html" android:background="@drawable/format_bar_button_html_selector"/> - \ No newline at end of file + diff --git a/WordPressEditor/src/main/res/layout/fragment_edit_post_content.xml b/WordPressEditor/src/main/res/layout/fragment_edit_post_content.xml index 76fa09b2caa3..c94a08e5e27e 100644 --- a/WordPressEditor/src/main/res/layout/fragment_edit_post_content.xml +++ b/WordPressEditor/src/main/res/layout/fragment_edit_post_content.xml @@ -100,6 +100,7 @@ style="@style/LegacyToggleButton" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:contentDescription="@string/format_bar_description_bold" android:background="@drawable/legacy_format_bar_button_bold_selector" />