From 68c6f4cd95baefe3198dca9e8bd7d1ee3732f576 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Tue, 16 Feb 2016 14:37:53 +0100 Subject: [PATCH] Squashed 'libs/editor/' changes from 69aaa8a..4832795 4832795 Merge pull request #280 from wordpress-mobile/issue/remove-analytics-dependency dd68ccd Merge pull request #283 from wordpress-mobile/issue/282-localize-js-strings bec42a8 moved the brackets back into the JS code 2cd15b7 fix #282: localize JS strings by using js-java interface nativeState a64d3a7 Merge pull request #270 from wordpress-mobile/issue/242-image-container-lower-api 5339a22 Fixed some EditorFragment lint issues ab084be Used a String constant for naming the native state JS interface 0789069 Merge branch 'develop' into issue/242-image-container-lower-api 430d3a4 Merge pull request #278 from wordpress-mobile/issue/183-accessibility e4b9e76 s/Strike/Strikethrough/ ec9c6e9 Image thumbnail content description cda2f22 Make editor title i18nizable 9d92717 Merge branch 'develop' into issue/242-image-container-lower-api 67dec0b Change page title for accessibility 3167e9a add contentDescription to format bar buttons in the visual and legacy editors 29cea46 Fixed issue where compatibility upload overlays would sometimes consume a tap without triggering a tap callback for the associated image 7b26aa7 Fixed a display issue on API<19 where a dark blank space would appear below an uploading or failed image b95d94a Added a dark semi-transparent overlay for API<19 for uploading and failed images 9e1863f Revert to non-compatibility image container styling once image has begun uploading 34523c0 Hide the compatibility image upload overlay if an image upload fails and re-display it on resume abf7260 Use block instead of inline-block for the image container on pre=KitKat Android 86a985c On pre-KitKat Android, show an 'Uploading...' overlay instead of a progress bar for uploading images 047082a Updated ZSSEditor to get the current Android API level on init git-subtree-dir: libs/editor git-subtree-split: 48327953c76c593daefe93a16e41323631de5b73 --- .../android/editor/EditorFragment.java | 48 +++++++++++++++-- .../android/editor/RippleToggleButton.java | 7 ++- .../src/main/res/layout-w360dp/format_bar.xml | 10 +++- .../src/main/res/layout-w380dp/format_bar.xml | 10 +++- .../src/main/res/layout-w600dp/format_bar.xml | 8 +++ .../main/res/layout/dialog_image_options.xml | 3 +- .../src/main/res/layout/format_bar.xml | 10 +++- .../res/layout/fragment_edit_post_content.xml | 8 +++ .../src/main/res/values/strings.xml | 20 +++++++ .../editor-common/assets/ZSSRichTextEditor.js | 53 ++++++++++++++++--- libs/editor-common/assets/android-editor.html | 2 +- libs/editor-common/assets/editor-android.css | 52 ++++++++++++++++++ 12 files changed, 211 insertions(+), 20 deletions(-) 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" />