Ben Brown bio photo

Ben Brown

Electronics and Embedded Systems Engineering

Email Twitter Facebook Github

Contents

Getting the RFAB library to work in Android studio as of March 2016

Hi, this a quick update for any others like me who are trying to get this library up and running in Android Studio.

Step 1

Open your build.gradle for your app (Not the project!). At the bottom of the file there should be the dependencies section, in this section insert the following entries:

	compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.wangjiegulu:AndroidBucket:1.0.4'
    compile 'com.github.wangjiegulu:RapidFloatingActionButton:1.0.3'

After these are added gradle will inform you that its configuration is out of sync, choose the option to sync the configuration and gradle will automatically setup the required dependencies for you.

##Step 2

In your layour file for your view you will need to add the markup to show the FAB on your display. The following code is what i use for mine, tweak as needed.

<com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout
        xmlns:rfal="http://schemas.android.com/apk/res-auto"
        android:id="@+id/activity_main_rfal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        rfal:rfal_frame_color="#ffffff"
        rfal:rfal_frame_alpha="0.7" >
        <com.wangjie.rapidfloatingactionbutton.RapidFloatingActionButton
            xmlns:rfab="http://schemas.android.com/apk/res-auto"
            android:id="@+id/activity_main_rfab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:layout_marginRight="15dp"
            android:layout_marginEnd="15dp"
            android:layout_marginBottom="15dp"
            android:padding="8dp"
            rfab:rfab_size="normal"
            rfab:rfab_drawable="@drawable/rfab__drawable_rfab_default"
            rfab:rfab_color_normal="#ffdd00"
            rfab:rfab_color_pressed="#ffb022"
            rfab:rfab_shadow_radius="7dp"
            rfab:rfab_shadow_color="#999999"
            rfab:rfab_shadow_dx="5dp"
            rfab:rfab_shadow_dy="5dp"
            />
    </com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout>

##Step 3 Code integration. Shown here is the main activity code that is used to interact with the FAB:

package com.ralimtek.wheelofwellbeing;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.wangjie.androidbucket.utils.ABTextUtil;
import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionButton;
import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionHelper;
import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout;
import com.wangjie.rapidfloatingactionbutton.contentimpl.labellist.RFACLabelItem;
import com.wangjie.rapidfloatingactionbutton.contentimpl.labellist.RapidFloatingActionContentLabelList;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements RapidFloatingActionContentLabelList.OnRapidFloatingActionContentLabelListListener, NavigationView.OnNavigationItemSelectedListener {
    private RapidFloatingActionHelper rfabHelper;

    @Override
    public void onRFACItemLabelClick(int position, RFACLabelItem item) {
        rfabHelper.toggleContent();
        int positionIndex = 6 - position;
    }

    @Override
    public void onRFACItemIconClick(int position, RFACLabelItem item) {
        rfabHelper.toggleContent();
        int positionIndex = 6 - position;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        RapidFloatingActionContentLabelList rfaContent = new RapidFloatingActionContentLabelList(getApplicationContext());

        rfaContent.setOnRapidFloatingActionContentLabelListListener(this);
        List<RFACLabelItem> items = new ArrayList<>();
        items.add(new RFACLabelItem<Integer>()
                        .setLabel("Menu1")
                        .setResId(R.drawable.bulb)
                        .setIconNormalColor(0xFFffb022)
                        .setIconPressedColor(0xFFffb022)
                        .setWrapper(0)
        );
        items.add(new RFACLabelItem<Integer>()
                        .setLabel("Menu2")
                        .setResId(R.drawable.person)
                        .setIconNormalColor(0xFF0ee5ff)
                        .setIconPressedColor(0xFF0ee5ff)
                        .setWrapper(0)
        );
       
        rfaContent
                .setItems(items)
                .setIconShadowRadius(ABTextUtil.dip2px(getApplicationContext(), 5))
                .setIconShadowColor(0xff888888)
                .setIconShadowDy(ABTextUtil.dip2px(getApplicationContext(), 5))
        ;
        rfabHelper = new RapidFloatingActionHelper(
                getApplicationContext(),
                (RapidFloatingActionLayout) findViewById(R.id.activity_main_rfal),
                (RapidFloatingActionButton) findViewById(R.id.activity_main_rfab),
                rfaContent
        ).build();
    }

    
}

##Step 5 Debug and test :) This should be the minimum required to get up and running, there is plenty more out there :)