Skip to content

Commit

Permalink
Merge branch 'release-2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
markormesher committed Feb 9, 2018
2 parents dcb3d68 + 50a0f49 commit 4237dd8
Show file tree
Hide file tree
Showing 5 changed files with 11,049 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package uk.co.markormesher.android_fab.app

import android.content.Context
import android.graphics.Typeface
import android.os.*
import android.support.annotation.StringRes
import android.support.v7.app.AppCompatActivity
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
import android.widget.TextView
import android.widget.Toast
import kotlinx.android.synthetic.main.demo_activity.*
import uk.co.markormesher.android_fab.FloatingActionButton
Expand Down Expand Up @@ -99,6 +101,14 @@ class DemoActivity: AppCompatActivity() {
return true
}

override fun onPrepareItemLabel(context: Context, position: Int, label: TextView) {
// make the first item bold if there are multiple items
// (this isn't a design pattern, it's just to demo the functionality)
if (position == 0 && speedDialSize > 1) {
label.setTypeface(label.typeface, Typeface.BOLD)
}
}

// rotate the "+" icon only
override fun fabRotationDegrees(): Float = if (buttonIcon == 0) 135F else 0F
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static def getSecrets() {
@SuppressWarnings("GroovyUnusedDeclaration")
static def getProps() {
Properties properties = new Properties()
properties['version_code'] = 15
properties['version_name'] = '2.1.0'
properties['version_code'] = 16
properties['version_name'] = '2.2.0'
return properties
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,22 @@ class FloatingActionButton: RelativeLayout {
setSpeedDialMenuItemViewOrder(view)

view.menu_item_label.text = menuItem.getLabel()
speedDialMenuAdapter?.onPrepareItemLabel(context, i, view.menu_item_label)

if (Build.VERSION.SDK_INT >= 21) {
(view.menu_item_card as CardView).setCardBackgroundColor(adapter.getBackgroundColour(i))
} else {
((view.menu_item_card as ViewGroup).background as GradientDrawable).setColor(adapter.getBackgroundColour(i))
}
speedDialMenuAdapter?.onPrepareItemCard(context, i, view.menu_item_card)

if (Build.VERSION.SDK_INT >= 16) {
view.menu_item_icon_wrapper.background = menuItem.getIcon()
} else {
@Suppress("DEPRECATION")
view.menu_item_icon_wrapper.setBackgroundDrawable(menuItem.getIcon())
}
speedDialMenuAdapter?.onPrepareItemIconWrapper(context, i, view.menu_item_icon_wrapper)

view.alpha = 0F
view.visibility = GONE
Expand All @@ -365,6 +368,10 @@ class FloatingActionButton: RelativeLayout {
}
}
}

if (speedDialMenuOpen) {
animateSpeedDialMenuItems(true)
}
}

private fun toggleSpeedDialMenu() {
Expand Down Expand Up @@ -436,12 +443,18 @@ class FloatingActionButton: RelativeLayout {
})
}

private fun animateSpeedDialMenuItems() {
private fun animateSpeedDialMenuItems(immediate: Boolean = false) {
if (busyAnimatingSpeedDialMenuItems) {
return
}
busyAnimatingSpeedDialMenuItems = true

val duration = if (immediate) {
0L
} else {
SPEED_DIAL_ANIMATION_DURATION
}

val distance = fab_card.height.toFloat()
speedDialMenuViews.forEachIndexed { i, v ->
if (speedDialMenuOpen) {
Expand All @@ -456,7 +469,7 @@ class FloatingActionButton: RelativeLayout {
v.animate()
.translationY(translation)
.alpha(if (speedDialMenuOpen) 1f else 0f)
.setDuration(SPEED_DIAL_ANIMATION_DURATION)
.setDuration(duration)
.setListener(object: AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
busyAnimatingSpeedDialMenuItems = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package uk.co.markormesher.android_fab
import android.content.Context
import android.graphics.Color
import android.support.annotation.ColorInt
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView

abstract class SpeedDialMenuAdapter {

Expand Down Expand Up @@ -36,6 +39,26 @@ abstract class SpeedDialMenuAdapter {
*/
@ColorInt open fun getBackgroundColour(position: Int): Int = Color.argb(255, 192, 192, 192)

/**
* Apply formatting to the `TextView` used for the label of the menu item at the given position.
* Note: positions start at zero closest to the FAB and increase for items further away.
*/
open fun onPrepareItemLabel(context: Context, position: Int, label: TextView) {}

/**
* Apply formatting to the view used for the card behind the icon at the given position.
* Note: the view will be a `CardView` on SDK 21+ and a `LinearLayout` on SDK 20 and below.
* Note: positions start at zero closest to the FAB and increase for items further away.
*/
open fun onPrepareItemCard(context: Context, position: Int, card: View) {}

/**
* Apply formatting to the `LinearLayout` that wraps the icon of the menu item at the given position.
* This is called after the icon is set as the background of the given wrapper.
* Note: positions start at zero closest to the FAB and increase for items further away.
*/
open fun onPrepareItemIconWrapper(context: Context, position: Int, label: LinearLayout) {}

/**
* Gets the number of degrees to rotate the FAB's icon when the speed-dial menu opens.
* This is useful for the popular "plus icon"/"close icon" transition.
Expand Down
Loading

0 comments on commit 4237dd8

Please sign in to comment.