Code Monkey home page Code Monkey logo

floatingactionbuttonspeeddial's Introduction

Floating Action Button Speed Dial

Maven metadata URI GitHub release Travis GitHub license Stars

Android library providing an implementation of the Material Design Floating Action Button Speed Dial.

Demo

Features

  • MinSdk 15
  • Highly customizable (label, icon, ripple, fab and label background colors, themes support)
  • Same animations as in Inbox by Gmail
  • Option to have different icons for open/close state
  • Optional overlay/touch guard layout
  • Support for bottom, left and right menu expansion (left and right have no labels)
  • Out-of-the box support for Snackbar behavior
  • Optional support for RecyclerView and NestedScrollView behavior
  • Support for VectorDrawable
  • Easy to use

To Do

How to use

Gradle setup

The library is available on Jcenter so no additonal repository is required.

Dependencies entry (latest version: Maven metadata URI):

implementation "com.leinardi.android:speed-dial:<latest version>"

Basic use

Add the SpeedDialView to your layout:

<com.leinardi.android.speeddial.SpeedDialView
    android:id="@+id/speedDial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    app:srcCompat="@drawable/ic_add_white_24dp" />

Add the items to the SpeedDialView:

SpeedDialView speedDialView = findViewById(R.id.speedDial);
speedDialView.addFabOptionItem(
        new SpeedDialActionItem.Builder(R.id.fab_link, R.drawable.ic_link_white_24dp)
                .create()
);

Add the click listeners:

speedDialView.setMainFabOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (speedDialView.isFabMenuOpen()) {
            speedDialView.closeOptionsMenu();
        }
    }
});

speedDialView.setOptionFabSelectedListener(new SpeedDialView.OnOptionFabSelectedListener() {
    @Override
    public void onOptionFabSelected(SpeedDialActionItem speedDialActionItem) {
        switch (speedDialActionItem.getId()) {
            case R.id.fab_link:
                showToast("Link action clicked!");
                break;
            default:
                break;
        }
    }
});

Optional steps

Customizing the items

The SpeedDialActionItem.Builder provides several setters to customize the aspect of one item:

mSpeedDialView.addFabOptionItem(
        new SpeedDialActionItem.Builder(R.id.fab_custom_color, R.drawable.ic_custom_color)
                .setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.material_white_1000, getTheme()))
                .setFabImageTintColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme()))
                .setLabel(getString(R.string.label_custom_color))
                .setLabelColor(Color.WHITE)
                .setLabelBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme()))
                .setLabelClickable(false)
                .create()
);

Is is also possible to specify a theme to easily change the FAB background and ripple effect color:

mSpeedDialView.addFabOptionItem(
        new SpeedDialActionItem.Builder(R.id.fab_custom_theme, R.drawable.ic_theme_white_24dp)
                .setLabel(getString(R.string.label_custom_theme))
                .setTheme(R.style.AppTheme_Purple)
                .create());
<style name="AppTheme.Purple" parent="AppTheme">
    <item name="colorPrimary">@color/material_purple_500</item>
    <item name="colorPrimaryDark">@color/material_purple_700</item>
    <item name="colorAccent">@color/material_purple_a700</item>
    <item name="colorControlHighlight">@color/material_purple_200</item>
</style>

Adding an overlay/touch guard when the menu is open (like Inbox by Gmail)

You simply need to add the SpeedDialOverlayLayout to your layout:

<com.leinardi.android.speeddial.SpeedDialOverlayLayout
    android:id="@+id/overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

and then provide the instance of that layout to the SpeedDialView:

SpeedDialOverlayLayout speedDialOverlayLayout = findViewById(R.id.overlay);
mSpeedDialView.setSpeedDialOverlayLayout(speedDialOverlayLayout);

Hiding the FAB when scrolling a RecyclerView or a NestedScrollView

Just apply the ScrollingViewSnackbarBehavior to the SpeedDialView. This can be done via XML using the convenience string resource @string/speeddial_scrolling_view_snackbar_behavior:

<com.leinardi.android.speeddial.SpeedDialView
    android:id="@+id/speedDial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/speeddial_scrolling_view_snackbar_behavior" />

Or programmatically:

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) speedDialView.getLayoutParams();
params.setBehavior(new SpeedDialView.ScrollingViewSnackbarBehavior());
speedDialView.requestLayout();

NB: for the behaviors to work, SpeedDialView needs to be a direct child of CoordinatorLayout

Disabling SnackbarBehavior

Since the SnackbarBehavior is enabled by default and, afaik, it is not possible to remove a Behavior, simply use apply the SpeedDialView.NoBehavior instead:

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) speedDialView.getLayoutParams();
params.setBehavior(new SpeedDialView.NoBehavior());
speedDialView.requestLayout();

Sample project

A fully working example is available here.

Demo

Video

https://www.youtube.com/watch?v=tWowiF5ElAg

Sample app

Get it on the Play Store

Screenshots

API 27 and 16

Bottom and left expansion

Changelog

See the CHANGELOG.md

Credits

This project is based on floating-action-menu by ArthurGhazaryan.

Licenses

Copyright 2018 Roberto Leinardi.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements.  See the NOTICE file distributed with this work for
additional information regarding copyright ownership.  The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy of
the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
License for the specific language governing permissions and limitations under
the License.

floatingactionbuttonspeeddial's People

Contributors

arthur-ghazaryan avatar leinardi avatar wasylews avatar

Watchers

 avatar  avatar  avatar

Forkers

abufawwaz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.