@@ -59,79 +59,70 @@ Add the `SpeedDialView` to your layout:
5959
6060#### Action items
6161Add the items to the ` SpeedDialView ` :
62- ``` java
63- SpeedDialView speedDialView = findViewById(R . id. speedDial);
62+ ``` kotlin
63+ val speedDialView = findViewById< SpeedDialView > (R .id.speedDial)
6464speedDialView.addActionItem(
65- new SpeedDialActionItem .Builder (R . id. fab_link, R . drawable. ic_link_white_24dp)
66- .create()
67- );
68-
65+ SpeedDialActionItem .Builder (R .id.fab_no_label, R .drawable.ic_link_white_24dp)
66+ .create())
6967```
7068
7169If the color customization is not requested, it is also possible to inflate the Action items
7270form a Menu Resource:
73- ``` java
74- speedDialView. inflate(R . menu. menu_speed_dial);
71+ ``` kotlin
72+ speedDialView.inflate(R .menu.menu_speed_dial)
7573```
7674Only the attributes ` android:id ` , ` android:icon ` and ` android:title ` are supported.
7775
7876#### Click listeners
7977Add the click listeners:
80- ``` java
81- speedDialView. setOnActionSelectedListener(new SpeedDialView .OnActionSelectedListener () {
82- @Override
83- public boolean onActionSelected (SpeedDialActionItem speedDialActionItem ) {
84- switch (speedDialActionItem. getId()) {
85- case R . id. fab_link:
86- showToast(" Link action clicked!" );
87- return false ; // true to keep the Speed Dial open
88- default :
89- return false ;
78+ ``` kotlin
79+ speedDialView.setOnActionSelectedListener(SpeedDialView .OnActionSelectedListener { actionItem ->
80+ when (actionItem.id) {
81+ R .id.fab_no_label -> {
82+ showToast(" No label action clicked!\n Closing with animation" )
83+ speedDialView.close() // To close the Speed Dial with animation
84+ return @OnActionSelectedListener true // false will close it without animation
9085 }
9186 }
92- });
87+ false
88+ })
9389```
9490
9591### Optional steps
9692#### Add the main action click listener
97- ``` java
98- speedDialView. setOnChangeListener(new SpeedDialView .OnChangeListener () {
99- @Override
100- public void onMainActionSelected () {
101- // Call your main action here
102- return false ; // true to keep the Speed Dial open
93+ ``` kotlin
94+ speedDialView.setOnChangeListener(object : SpeedDialView .OnChangeListener {
95+ override fun onMainActionSelected (): Boolean {
96+ showToast(" Main action clicked!" )
97+ return false // True to keep the Speed Dial open
10398 }
10499
105- @Override
106- public void onToggleChanged (boolean isOpen ) {
107- Log . d(TAG , " Speed dial toggle state changed. Open = " + isOpen);
100+ override fun onToggleChanged (isOpen : Boolean ) {
101+ Log .d(TAG , " Speed dial toggle state changed. Open = $isOpen " )
108102 }
109- });
103+ })
110104```
111105
112106#### Customizing the items
113107The ` SpeedDialActionItem.Builder ` provides several setters to customize the aspect of one item:
114108
115- ``` java
116- mSpeedDialView. addActionItem(
117- new SpeedDialActionItem .Builder (R . id. fab_custom_color, R . drawable. ic_custom_color)
118- .setFabBackgroundColor(ResourcesCompat . getColor(getResources(), R . color. material_white_1000, getTheme()))
119- .setFabImageTintColor(ResourcesCompat . getColor(getResources(), R . color. inbox_primary, getTheme()))
120- .setLabel(getString(R . string. label_custom_color))
121- .setLabelColor(Color . WHITE )
122- .setLabelBackgroundColor(ResourcesCompat . getColor(getResources(), R . color. inbox_primary, getTheme()))
123- .setLabelClickable(false )
124- .create()
125- );
109+ ``` kotlin
110+ speedDialView.addActionItem(SpeedDialActionItem .Builder (R .id.fab_custom_color, drawable)
111+ .setFabBackgroundColor(ResourcesCompat .getColor(getResources(), R .color.material_white_1000, getTheme()))
112+ .setFabImageTintColor(ResourcesCompat .getColor(getResources(), R .color.inbox_primary, getTheme()))
113+ .setLabel(getString(R .string.label_custom_color))
114+ .setLabelColor(Color .WHITE )
115+ .setLabelBackgroundColor(ResourcesCompat .getColor(getResources(), R .color.inbox_primary, getTheme()))
116+ .setLabelClickable(false )
117+ .create())
126118```
127119Is is also possible to specify a theme to easily change the FAB background and ripple effect color:
128120
129- ``` java
130- mSpeedDialView. addActionItem(
131- new SpeedDialActionItem .Builder (R . id. fab_custom_theme, R . drawable. ic_theme_white_24dp)
132- .setLabel(getString(R . string. label_custom_theme))
133- .setTheme(R . style. AppTheme_Purple )
134- .create());
121+ ``` kotlin
122+ speedDialView.addActionItem(SpeedDialActionItem .Builder (R .id.fab_custom_theme, R .drawable.ic_theme_white_24dp)
123+ .setLabel(getString(R .string.label_custom_theme))
124+ .setTheme(R .style.AppTheme_Purple )
125+ .create())
135126```
136127``` xml
137128<style name =" AppTheme.Purple" parent =" AppTheme" >
@@ -162,9 +153,9 @@ and then provide the instance of that layout to the `SpeedDialView`:
162153 app : sdOverlayLayout =" @id/overlay" />
163154```
164155or
165- ``` java
166- SpeedDialOverlayLayout overlayLayout = findViewById(R . id. overlay);
167- mSpeedDialView . setSpeedDialOverlayLayout(overlayLayout);
156+ ``` kotlin
157+ val overlayLayout = findViewById< SpeedDialOverlayLayout > (R .id.overlay)
158+ speedDialView .setSpeedDialOverlayLayout(overlayLayout)
168159```
169160
170161#### Hiding the FAB when scrolling a ` RecyclerView ` or a ` NestedScrollView `
@@ -180,20 +171,20 @@ the convenience string resource `@string/speeddial_scrolling_view_snackbar_behav
180171```
181172
182173Or programmatically:
183- ``` java
184- CoordinatorLayout . LayoutParams params = ( CoordinatorLayout . LayoutParams ) speedDialView . getLayoutParams();
185- params. setBehavior( new SpeedDialView .ScrollingViewSnackbarBehavior ());
186- speedDialView. requestLayout();
174+ ``` kotlin
175+ val params = speedDialView.layoutParams as CoordinatorLayout . LayoutParams
176+ params.behavior = SpeedDialView .ScrollingViewSnackbarBehavior ()
177+ speedDialView.requestLayout()
187178```
188179
189180NB: for the behaviors to work, ` SpeedDialView ` needs to be a direct child of ` CoordinatorLayout `
190181
191182#### Disabling ` SnackbarBehavior `
192183Since the ` SnackbarBehavior ` is enabled by default and, afaik, it is not possible to remove a Behavior, simply use apply the ` SpeedDialView.NoBehavior ` instead:
193- ``` java
194- CoordinatorLayout . LayoutParams params = ( CoordinatorLayout . LayoutParams ) speedDialView . getLayoutParams();
195- params. setBehavior( new SpeedDialView .NoBehavior ());
196- speedDialView. requestLayout();
184+ ``` kotlin
185+ val params = speedDialView.layoutParams as CoordinatorLayout . LayoutParams
186+ params.behavior = SpeedDialView .NoBehavior ()
187+ speedDialView.requestLayout()
197188```
198189
199190### Sample project
@@ -250,7 +241,7 @@ This project is based on [floating-action-menu by ArthurGhazaryan](https://githu
250241
251242## Licenses
252243```
253- Copyright 2018 Roberto Leinardi.
244+ Copyright 2019 Roberto Leinardi.
254245
255246Licensed to the Apache Software Foundation (ASF) under one or more contributor
256247license agreements. See the NOTICE file distributed with this work for
0 commit comments