@@ -9,11 +9,10 @@ import android.view.KeyEvent
99import android.view.LayoutInflater
1010import android.view.MenuItem
1111import android.view.View
12- import android.widget.FrameLayout
13- import android.widget.PopupMenu
12+ import android.view.animation.Animation
13+ import android.view.animation.AnimationUtils
14+ import android.widget.*
1415import android.widget.PopupMenu.OnMenuItemClickListener
15- import android.widget.Toast
16- import android.widget.ToggleButton
1716import org.wordpress.aztec.AztecText
1817import org.wordpress.aztec.R
1918import org.wordpress.aztec.TextFormat
@@ -27,18 +26,29 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
2726 private var listMenu: PopupMenu ? = null
2827 private var sourceEditor: SourceViewEditText ? = null
2928 private var dialogShortcuts: AlertDialog ? = null
29+ private var isAdvanced: Boolean = false
30+ private var isExpanded: Boolean = false
3031 private var isMediaModeEnabled: Boolean = false
3132
33+ private lateinit var buttonScroll: HorizontalScrollView
34+ private lateinit var buttonEllipsisCollapse: RippleToggleButton
35+ private lateinit var buttonEllipsisExpand: RippleToggleButton
36+ private lateinit var layoutExpandedTranslateInRight: Animation
37+ private lateinit var layoutExpandedTranslateOutLeft: Animation
38+ private lateinit var ellipsisSpinLeft: Animation
39+ private lateinit var ellipsisSpinRight: Animation
40+ private lateinit var layoutExpanded: LinearLayout
41+
3242 constructor (context: Context ) : super (context) {
33- initView()
43+ initView(null )
3444 }
3545
3646 constructor (context: Context , attrs: AttributeSet ) : super (context, attrs) {
37- initView()
47+ initView(attrs )
3848 }
3949
4050 constructor (context: Context , attrs: AttributeSet , defStyleAttr: Int ) : super (context, attrs, defStyleAttr) {
41- initView()
51+ initView(attrs )
4252 }
4353
4454 fun setToolbarListener (listener : AztecToolbarClickListener ) {
@@ -255,6 +265,8 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
255265 val restoredState = savedState.state
256266 toggleHtmlMode(restoredState.getBoolean(" isSourceVisible" ))
257267 enableMediaMode(restoredState.getBoolean(" isMediaMode" ))
268+ isExpanded = restoredState.getBoolean(" isExpanded" )
269+ setAdvancedState()
258270 }
259271
260272 override fun onSaveInstanceState (): Parcelable {
@@ -263,6 +275,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
263275 val bundle = Bundle ()
264276 bundle.putBoolean(" isSourceVisible" , sourceEditor?.visibility == View .VISIBLE )
265277 bundle.putBoolean(" isMediaMode" , isMediaModeEnabled)
278+ bundle.putBoolean(" isExpanded" , isExpanded)
266279 savedState.state = bundle
267280 return savedState
268281 }
@@ -283,8 +296,14 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
283296 })
284297 }
285298
286- private fun initView () {
287- View .inflate(context, R .layout.aztec_format_bar, this )
299+ private fun initView (attrs : AttributeSet ? ) {
300+ val styles = context.obtainStyledAttributes(attrs, R .styleable.AztecToolbar , 0 , R .style.AztecToolbarStyle )
301+ isAdvanced = styles.getBoolean(R .styleable.AztecToolbar_advanced , false )
302+ styles.recycle()
303+
304+ val layout = if (isAdvanced) R .layout.aztec_format_bar_advanced else R .layout.aztec_format_bar_basic
305+ View .inflate(context, layout, this )
306+ setAdvancedState()
288307
289308 for (toolbarAction in ToolbarAction .values()) {
290309 val button = findViewById(toolbarAction.buttonId)
@@ -314,8 +333,11 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
314333 val actions = ArrayList <ToolbarAction >()
315334
316335 for (action in ToolbarAction .values()) {
317- val view = findViewById(action.buttonId) as ToggleButton
318- if (view.isChecked) actions.add(action)
336+ if (action != ToolbarAction .ELLIPSIS_COLLAPSE &&
337+ action != ToolbarAction .ELLIPSIS_EXPAND ) {
338+ val view = findViewById(action.buttonId) as ToggleButton
339+ if (view.isChecked) actions.add(action)
340+ }
319341 }
320342
321343 return actions
@@ -375,6 +397,8 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
375397 ToolbarAction .LIST -> listMenu?.show()
376398 ToolbarAction .LINK -> editor!! .showLinkDialog()
377399 ToolbarAction .HTML -> aztecToolbarListener?.onToolbarHtmlModeClicked()
400+ ToolbarAction .ELLIPSIS_COLLAPSE -> animateToolbarCollapse()
401+ ToolbarAction .ELLIPSIS_EXPAND -> animateToolbarExpand()
378402 else -> {
379403 Toast .makeText(context, " Unsupported action" , Toast .LENGTH_SHORT ).show()
380404 }
@@ -424,6 +448,34 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
424448 return null
425449 }
426450
451+ fun setExpanded (expanded : Boolean ) {
452+ isExpanded = expanded
453+ setAdvancedState()
454+ }
455+
456+ private fun animateToolbarCollapse () {
457+ buttonEllipsisCollapse.startAnimation(ellipsisSpinLeft)
458+ isExpanded = false
459+ }
460+
461+ private fun animateToolbarExpand () {
462+ buttonEllipsisExpand.startAnimation(ellipsisSpinRight)
463+ isExpanded = true
464+ }
465+
466+ private fun setAdvancedState () {
467+ if (isAdvanced) {
468+ setButtonViews()
469+ setAnimations()
470+
471+ if (isExpanded) {
472+ showExpandedToolbar()
473+ } else {
474+ showCollapsedToolbar()
475+ }
476+ }
477+ }
478+
427479 private fun selectHeadingMenuItem (textFormats : ArrayList <TextFormat >) {
428480 if (textFormats.size == 0 ) {
429481 // Select paragraph by default.
@@ -478,6 +530,68 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
478530 }
479531 }
480532
533+ private fun setAnimations () {
534+ layoutExpandedTranslateInRight = AnimationUtils .loadAnimation(context, R .anim.translate_in_right)
535+
536+ layoutExpandedTranslateOutLeft = AnimationUtils .loadAnimation(context, R .anim.translate_out_left)
537+ layoutExpandedTranslateOutLeft.setAnimationListener(
538+ object : Animation .AnimationListener {
539+ override fun onAnimationEnd (animation : Animation ) {
540+ layoutExpanded.visibility = View .GONE
541+ }
542+
543+ override fun onAnimationRepeat (animation : Animation ) {
544+ }
545+
546+ override fun onAnimationStart (animation : Animation ) {
547+ }
548+ }
549+ )
550+
551+ ellipsisSpinLeft = AnimationUtils .loadAnimation(context, R .anim.spin_left_90)
552+ ellipsisSpinLeft.setAnimationListener(
553+ object : Animation .AnimationListener {
554+ override fun onAnimationEnd (animation : Animation ) {
555+ buttonEllipsisCollapse.visibility = View .GONE
556+ buttonEllipsisExpand.visibility = View .VISIBLE
557+ }
558+
559+ override fun onAnimationRepeat (animation : Animation ) {
560+ }
561+
562+ override fun onAnimationStart (animation : Animation ) {
563+ buttonScroll.smoothScrollTo(0 , 0 )
564+ layoutExpanded.startAnimation(layoutExpandedTranslateOutLeft)
565+ }
566+ }
567+ )
568+
569+ ellipsisSpinRight = AnimationUtils .loadAnimation(context, R .anim.spin_right_90)
570+ ellipsisSpinRight.setAnimationListener(
571+ object : Animation .AnimationListener {
572+ override fun onAnimationEnd (animation : Animation ) {
573+ buttonEllipsisCollapse.visibility = View .VISIBLE
574+ buttonEllipsisExpand.visibility = View .GONE
575+ }
576+
577+ override fun onAnimationRepeat (animation : Animation ) {
578+ }
579+
580+ override fun onAnimationStart (animation : Animation ) {
581+ layoutExpanded.visibility = View .VISIBLE
582+ layoutExpanded.startAnimation(layoutExpandedTranslateInRight)
583+ }
584+ }
585+ )
586+ }
587+
588+ private fun setButtonViews () {
589+ layoutExpanded = findViewById(R .id.format_bar_button_layout_expanded) as LinearLayout
590+ buttonScroll = findViewById(R .id.format_bar_button_scroll) as HorizontalScrollView
591+ buttonEllipsisCollapse = findViewById(R .id.format_bar_button_ellipsis_collapse) as RippleToggleButton
592+ buttonEllipsisExpand = findViewById(R .id.format_bar_button_ellipsis_expand) as RippleToggleButton
593+ }
594+
481595 private fun setHeadingMenu (view : View ) {
482596 headingMenu = PopupMenu (context, view)
483597 headingMenu?.setOnMenuItemClickListener(this )
@@ -517,6 +631,18 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
517631 }
518632 }
519633
634+ private fun showCollapsedToolbar () {
635+ layoutExpanded.visibility = View .GONE
636+ buttonEllipsisCollapse.visibility = View .GONE
637+ buttonEllipsisExpand.visibility = View .VISIBLE
638+ }
639+
640+ private fun showExpandedToolbar () {
641+ layoutExpanded.visibility = View .VISIBLE
642+ buttonEllipsisCollapse.visibility = View .VISIBLE
643+ buttonEllipsisExpand.visibility = View .GONE
644+ }
645+
520646 private fun toggleHtmlMode (isHtmlMode : Boolean ) {
521647 ToolbarAction .values().forEach { action ->
522648 if (action == ToolbarAction .HTML ) {
0 commit comments