@@ -13,6 +13,7 @@ import android.view.KeyEvent
1313import android.view.LayoutInflater
1414import android.view.MenuItem
1515import android.view.View
16+ import android.view.accessibility.AccessibilityEvent
1617import android.view.animation.Animation
1718import android.view.animation.AnimationUtils
1819import 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
0 commit comments