Skip to content

Commit a0427b3

Browse files
authored
Merge pull request #648 from wordpress-mobile/feature/awesome-accessibility-toggle-button-v2
Feature/awesome accessibility toggle button
2 parents f3b7a2d + 7ca51e7 commit a0427b3

File tree

5 files changed

+103
-77
lines changed

5 files changed

+103
-77
lines changed

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import android.view.MenuItem
3131
import android.view.MotionEvent
3232
import android.view.View
3333
import android.widget.PopupMenu
34+
import android.widget.ToggleButton
3435
import org.wordpress.android.util.AppLog
3536
import org.wordpress.android.util.ImageUtils
3637
import org.wordpress.android.util.PermissionUtils
@@ -138,32 +139,32 @@ open class MainActivity : AppCompatActivity(),
138139

139140
private val EXAMPLE =
140141
IMG +
141-
HEADING +
142-
BOLD +
143-
ITALIC +
144-
UNDERLINE +
145-
STRIKETHROUGH +
146-
ORDERED +
147-
LINE +
148-
UNORDERED +
149-
QUOTE +
150-
PREFORMAT +
151-
LINK +
152-
HIDDEN +
153-
COMMENT +
154-
COMMENT_MORE +
155-
COMMENT_PAGE +
156-
CODE +
157-
UNKNOWN +
158-
EMOJI +
159-
NON_LATIN_TEXT +
160-
LONG_TEXT +
161-
VIDEO +
162-
VIDEOPRESS +
163-
VIDEOPRESS_2 +
164-
AUDIO +
165-
GUTENBERG_CODE_BLOCK +
166-
QUOTE_RTL
142+
HEADING +
143+
BOLD +
144+
ITALIC +
145+
UNDERLINE +
146+
STRIKETHROUGH +
147+
ORDERED +
148+
LINE +
149+
UNORDERED +
150+
QUOTE +
151+
PREFORMAT +
152+
LINK +
153+
HIDDEN +
154+
COMMENT +
155+
COMMENT_MORE +
156+
COMMENT_PAGE +
157+
CODE +
158+
UNKNOWN +
159+
EMOJI +
160+
NON_LATIN_TEXT +
161+
LONG_TEXT +
162+
VIDEO +
163+
VIDEOPRESS +
164+
VIDEOPRESS_2 +
165+
AUDIO +
166+
GUTENBERG_CODE_BLOCK +
167+
QUOTE_RTL
167168

168169
private val isRunningTest: Boolean by lazy {
169170
try {
@@ -346,8 +347,10 @@ open class MainActivity : AppCompatActivity(),
346347
visualEditor.externalLogger = object : AztecLog.ExternalLogger {
347348
override fun log(message: String) {
348349
}
350+
349351
override fun logException(tr: Throwable) {
350352
}
353+
351354
override fun logException(tr: Throwable, message: String) {
352355
}
353356
}
@@ -359,6 +362,9 @@ open class MainActivity : AppCompatActivity(),
359362
mediaMenu?.setOnMenuItemClickListener(this@MainActivity)
360363
mediaMenu?.inflate(R.menu.menu_gallery)
361364
mediaMenu?.show()
365+
if (view is ToggleButton) {
366+
view.isChecked = false
367+
}
362368
}
363369
})
364370

@@ -369,29 +375,32 @@ open class MainActivity : AppCompatActivity(),
369375
mediaMenu?.setOnMenuItemClickListener(this@MainActivity)
370376
mediaMenu?.inflate(R.menu.menu_camera)
371377
mediaMenu?.show()
378+
if (view is ToggleButton) {
379+
view.isChecked = false
380+
}
372381
}
373382
})
374383

375384
aztec = Aztec.with(visualEditor, sourceEditor, toolbar, this)
376-
.setImageGetter(GlideImageLoader(this))
377-
.setVideoThumbnailGetter(GlideVideoThumbnailLoader(this))
378-
.setOnImeBackListener(this)
379-
.setOnTouchListener(this)
380-
.setHistoryListener(this)
381-
.setOnImageTappedListener(this)
382-
.setOnVideoTappedListener(this)
383-
.setOnAudioTappedListener(this)
384-
.setOnMediaDeletedListener(this)
385-
.setOnVideoInfoRequestedListener(this)
386-
.addPlugin(WordPressCommentsPlugin(visualEditor))
387-
.addPlugin(MoreToolbarButton(visualEditor))
388-
.addPlugin(PageToolbarButton(visualEditor))
389-
.addPlugin(CaptionShortcodePlugin(visualEditor))
390-
.addPlugin(VideoShortcodePlugin())
391-
.addPlugin(AudioShortcodePlugin())
392-
.addPlugin(HiddenGutenbergPlugin())
393-
.addPlugin(galleryButton)
394-
.addPlugin(cameraButton)
385+
.setImageGetter(GlideImageLoader(this))
386+
.setVideoThumbnailGetter(GlideVideoThumbnailLoader(this))
387+
.setOnImeBackListener(this)
388+
.setOnTouchListener(this)
389+
.setHistoryListener(this)
390+
.setOnImageTappedListener(this)
391+
.setOnVideoTappedListener(this)
392+
.setOnAudioTappedListener(this)
393+
.setOnMediaDeletedListener(this)
394+
.setOnVideoInfoRequestedListener(this)
395+
.addPlugin(WordPressCommentsPlugin(visualEditor))
396+
.addPlugin(MoreToolbarButton(visualEditor))
397+
.addPlugin(PageToolbarButton(visualEditor))
398+
.addPlugin(CaptionShortcodePlugin(visualEditor))
399+
.addPlugin(VideoShortcodePlugin())
400+
.addPlugin(AudioShortcodePlugin())
401+
.addPlugin(HiddenGutenbergPlugin())
402+
.addPlugin(galleryButton)
403+
.addPlugin(cameraButton)
395404

396405
// initialize the plugins, text & HTML
397406
if (!isRunningTest) {

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import android.view.KeyEvent
1313
import android.view.LayoutInflater
1414
import android.view.MenuItem
1515
import android.view.View
16+
import android.view.accessibility.AccessibilityEvent
1617
import android.view.animation.Animation
1718
import android.view.animation.AnimationUtils
1819
import android.widget.FrameLayout
@@ -256,7 +257,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
256257
override fun onMenuItemClick(item: MenuItem?): Boolean {
257258
val checked = (item?.isChecked == false)
258259
item?.isChecked = checked
259-
val headingButton = findViewById<ToggleButton>(R.id.format_bar_button_heading)
260+
val headingButton = findViewById<ToggleButton>(ToolbarAction.HEADING.buttonId)
260261

261262
when (item?.itemId) {
262263
// Heading Menu
@@ -626,42 +627,39 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
626627
}
627628

628629
private fun selectHeadingMenuItem(textFormats: ArrayList<ITextFormat>) {
629-
val headingButton = findViewById<ToggleButton>(R.id.format_bar_button_heading)
630+
val headingButton = findViewById<ToggleButton>(ToolbarAction.HEADING.buttonId)
630631
// Use unnumbered heading selector by default.
631632
updateHeadingMenuItem(AztecTextFormat.FORMAT_PARAGRAPH, headingButton)
632633
headingMenu?.menu?.findItem(R.id.paragraph)?.isChecked = true
633-
if (textFormats.size != 0) {
634-
foreach@ for (it in textFormats) {
635-
when (it) {
636-
AztecTextFormat.FORMAT_HEADING_1 -> headingMenu?.menu?.findItem(R.id.heading_1)?.isChecked = true
637-
AztecTextFormat.FORMAT_HEADING_2 -> headingMenu?.menu?.findItem(R.id.heading_2)?.isChecked = true
638-
AztecTextFormat.FORMAT_HEADING_3 -> headingMenu?.menu?.findItem(R.id.heading_3)?.isChecked = true
639-
AztecTextFormat.FORMAT_HEADING_4 -> headingMenu?.menu?.findItem(R.id.heading_4)?.isChecked = true
640-
AztecTextFormat.FORMAT_HEADING_5 -> headingMenu?.menu?.findItem(R.id.heading_5)?.isChecked = true
641-
AztecTextFormat.FORMAT_HEADING_6 -> headingMenu?.menu?.findItem(R.id.heading_6)?.isChecked = true
642-
// TODO: Uncomment when Preformat is to be added back as a feature
643-
// AztecTextFormat.FORMAT_PREFORMAT -> headingMenu?.menu?.findItem(R.id.preformat)?.isChecked = true
644-
else -> continue@foreach
645-
}
646-
647-
updateHeadingMenuItem(it, headingButton)
634+
foreach@ for (it in textFormats) {
635+
when (it) {
636+
AztecTextFormat.FORMAT_HEADING_1 -> headingMenu?.menu?.findItem(R.id.heading_1)?.isChecked = true
637+
AztecTextFormat.FORMAT_HEADING_2 -> headingMenu?.menu?.findItem(R.id.heading_2)?.isChecked = true
638+
AztecTextFormat.FORMAT_HEADING_3 -> headingMenu?.menu?.findItem(R.id.heading_3)?.isChecked = true
639+
AztecTextFormat.FORMAT_HEADING_4 -> headingMenu?.menu?.findItem(R.id.heading_4)?.isChecked = true
640+
AztecTextFormat.FORMAT_HEADING_5 -> headingMenu?.menu?.findItem(R.id.heading_5)?.isChecked = true
641+
AztecTextFormat.FORMAT_HEADING_6 -> headingMenu?.menu?.findItem(R.id.heading_6)?.isChecked = true
642+
// TODO: Uncomment when Preformat is to be added back as a feature
643+
// AztecTextFormat.FORMAT_PREFORMAT -> headingMenu?.menu?.findItem(R.id.preformat)?.isChecked = true
644+
else -> continue@foreach
648645
}
646+
647+
updateHeadingMenuItem(it, headingButton)
649648
}
650649
}
651650

652651
private fun selectListMenuItem(textFormats: ArrayList<ITextFormat>) {
653-
val listButton = findViewById<ToggleButton>(R.id.format_bar_button_list)
652+
val listButton = findViewById<ToggleButton>(ToolbarAction.LIST.buttonId)
654653
updateListMenuItem(AztecTextFormat.FORMAT_NONE, listButton)
655654
listMenu?.menu?.findItem(R.id.list_none)?.isChecked = true
656-
if (textFormats.size != 0) {
657-
foreach@ for (it in textFormats) {
658-
when (it) {
659-
AztecTextFormat.FORMAT_UNORDERED_LIST -> listMenu?.menu?.findItem(R.id.list_unordered)?.isChecked = true
660-
AztecTextFormat.FORMAT_ORDERED_LIST -> listMenu?.menu?.findItem(R.id.list_ordered)?.isChecked = true
661-
else -> continue@foreach
662-
}
663-
updateListMenuItem(it, listButton)
655+
foreach@ for (it in textFormats) {
656+
when (it) {
657+
AztecTextFormat.FORMAT_UNORDERED_LIST -> listMenu?.menu?.findItem(R.id.list_unordered)?.isChecked = true
658+
AztecTextFormat.FORMAT_ORDERED_LIST -> listMenu?.menu?.findItem(R.id.list_ordered)?.isChecked = true
659+
else -> continue@foreach
664660
}
661+
updateListMenuItem(it, listButton)
662+
665663
}
666664
}
667665

@@ -824,6 +822,8 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
824822
override fun onAnimationEnd(animation: Animation) {
825823
buttonMediaCollapsed.visibility = View.GONE
826824
buttonMediaExpanded.visibility = View.VISIBLE
825+
buttonMediaExpanded.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
826+
buttonMediaExpanded.isChecked = true
827827
}
828828

829829
override fun onAnimationRepeat(animation: Animation) {
@@ -841,6 +841,8 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
841841
override fun onAnimationEnd(animation: Animation) {
842842
buttonMediaCollapsed.visibility = View.VISIBLE
843843
buttonMediaExpanded.visibility = View.GONE
844+
buttonMediaCollapsed.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
845+
buttonMediaCollapsed.isChecked = false
844846
}
845847

846848
override fun onAnimationRepeat(animation: Animation) {
@@ -856,12 +858,26 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
856858
headingMenu = PopupMenu(context, view)
857859
headingMenu?.setOnMenuItemClickListener(this)
858860
headingMenu?.inflate(R.menu.heading)
861+
headingMenu?.setOnDismissListener({
862+
if (getSelectedHeadingMenuItem() == null || getSelectedHeadingMenuItem() == AztecTextFormat.FORMAT_PARAGRAPH) {
863+
findViewById<ToggleButton>(ToolbarAction.HEADING.buttonId).isChecked = false
864+
} else {
865+
findViewById<ToggleButton>(ToolbarAction.HEADING.buttonId).isChecked = true
866+
}
867+
})
859868
}
860869

861870
private fun setListMenu(view: View) {
862871
listMenu = PopupMenu(context, view)
863872
listMenu?.setOnMenuItemClickListener(this)
864873
listMenu?.inflate(R.menu.list)
874+
listMenu?.setOnDismissListener({
875+
if (getSelectedListMenuItem() == null) {
876+
findViewById<ToggleButton>(ToolbarAction.LIST.buttonId).isChecked = false
877+
} else {
878+
findViewById<ToggleButton>(ToolbarAction.LIST.buttonId).isChecked = true
879+
}
880+
})
865881
}
866882

867883
private fun updateListMenuItem(textFormat: ITextFormat, listButton: ToggleButton) {
@@ -961,7 +977,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
961977
}
962978

963979
private fun toggleListMenuSelection(listMenuItemId: Int, isChecked: Boolean) {
964-
val listButton = findViewById<ToggleButton>(R.id.format_bar_button_list)
980+
val listButton = findViewById<ToggleButton>(ToolbarAction.LIST.buttonId)
965981
if (isChecked) {
966982
listMenu?.menu?.findItem(listMenuItemId)?.isChecked = true
967983

aztec/src/main/res/layout/aztec_format_bar_advanced.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
android:layout_width="wrap_content"
4949
android:layout_height="match_parent"
5050
android:background="@drawable/format_bar_button_media_collapsed_selector"
51-
android:contentDescription="@string/format_bar_description_media">
51+
android:contentDescription="@string/format_bar_description_media_normal">
5252
</org.wordpress.aztec.toolbar.RippleToggleButton>
5353

5454
<org.wordpress.aztec.toolbar.RippleToggleButton
@@ -57,7 +57,7 @@
5757
android:layout_width="wrap_content"
5858
android:layout_height="match_parent"
5959
android:background="@drawable/format_bar_button_media_expanded_selector"
60-
android:contentDescription="@string/format_bar_description_media"
60+
android:contentDescription="@string/format_bar_description_media_expanded"
6161
android:visibility="gone">
6262
</org.wordpress.aztec.toolbar.RippleToggleButton>
6363

aztec/src/main/res/layout/aztec_format_bar_basic.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
android:layout_width="wrap_content"
4747
android:layout_height="match_parent"
4848
android:background="@drawable/format_bar_button_media_collapsed_selector"
49-
android:contentDescription="@string/format_bar_description_media">
49+
android:contentDescription="@string/format_bar_description_media_normal">
5050
</org.wordpress.aztec.toolbar.RippleToggleButton>
5151

5252
<org.wordpress.aztec.toolbar.RippleToggleButton
@@ -55,7 +55,7 @@
5555
android:layout_width="wrap_content"
5656
android:layout_height="match_parent"
5757
android:background="@drawable/format_bar_button_media_expanded_selector"
58-
android:contentDescription="@string/format_bar_description_media"
58+
android:contentDescription="@string/format_bar_description_media_expanded"
5959
android:visibility="gone">
6060
</org.wordpress.aztec.toolbar.RippleToggleButton>
6161

aztec/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<string name="format_bar_description_quote">Block quote</string>
2727
<string name="format_bar_description_link">Link</string>
2828
<string name="format_bar_description_horizontal_rule">Horizontal Rule</string>
29-
<string name="format_bar_description_media">Media</string>
29+
<string name="format_bar_description_media_normal">Show Media Options</string>
30+
<string name="format_bar_description_media_expanded">Hide Media Options</string>
3031
<string name="format_bar_description_list">List</string>
3132
<string name="format_bar_description_html">HTML</string>
3233
<string name="format_bar_description_ellipsis_collapse">Collapse Toolbar</string>

0 commit comments

Comments
 (0)