Tuesday, October 27, 2015

How To Add Floating Action Button Library (futuresimple)



This tutorial is based on the Floating Action Button Library available at https://github.com/futuresimple/android-floating-action-button.

.
How To Add Floating Action Button Library (futuresimple)
2) Unzip the package and find the folder "library".
3) Run Android Studio and create a new project.
4) Edit the file gradle.properties by referring to the codes in the downloaded package.
VERSION_NAME=1.10.1
VERSION_CODE=15
GROUP=com.getbase
POM_DESCRIPTION=Floating Action Button for Android based on Material Design specification
POM_URL=https://github.com/futuresimple/android-floating-action-button
POM_SCM_URL=https://github.com/futuresimple/android-floating-action-button
POM_SCM_CONNECTION=scm:git:git://github.com/futuresimple/android-floating-action-button.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/futuresimple/android-floating-action-button.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=https://github.com/futuresimple/android-floating-action-button/blob/master/LICENSE.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=chalup
POM_DEVELOPER_NAME=Jerzy Chalupski
5) In Android Studio, go to menu File/New/Import Module...
6) Select the "library" folder in the downloaded package.
7) Add an item to your dependencies section, e.g in build.gradle (module:app)
dependencies {
  compile project(':library')
}
Dependencies section example .
8) Start working on your project.
9) If you are not sure on where to start, copy the sample folder to your project.
9a) Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.getbase.floatingactionbutton.sample">
    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/Theme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
9b) Res files
9c) MainActivity.java
package com.getbase.floatingactionbutton.sample;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import android.app.Activity;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class MainActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.pink_icon).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Toast.makeText(MainActivity.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT).show();
      }
    });
    FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
    button.setSize(FloatingActionButton.SIZE_MINI);
    button.setColorNormalResId(R.color.pink);
    button.setColorPressedResId(R.color.pink_pressed);
    button.setIcon(R.drawable.ic_fab_star);
    button.setStrokeVisible(false);
    final View actionB = findViewById(R.id.action_b);
    FloatingActionButton actionC = new FloatingActionButton(getBaseContext());
    actionC.setTitle("Hide/Show Action above");
    actionC.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        actionB.setVisibility(actionB.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
      }
    });
    final FloatingActionsMenu menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
    menuMultipleActions.addButton(actionC);
    final FloatingActionButton removeAction = (FloatingActionButton) findViewById(R.id.button_remove);
    removeAction.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        ((FloatingActionsMenu) findViewById(R.id.multiple_actions_down)).removeButton(removeAction);
      }
    });
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.getPaint().setColor(getResources().getColor(R.color.white));
    ((FloatingActionButton) findViewById(R.id.setter_drawable)).setIconDrawable(drawable);
    final FloatingActionButton actionA = (FloatingActionButton) findViewById(R.id.action_a);
    actionA.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        actionA.setTitle("Action A clicked");
      }
    });
    // Test that FAMs containing FABs with visibility GONE do not cause crashes
    findViewById(R.id.button_gone).setVisibility(View.GONE);
    final FloatingActionButton actionEnable = (FloatingActionButton) findViewById(R.id.action_enable);
    actionEnable.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        menuMultipleActions.setEnabled(!menuMultipleActions.isEnabled());
      }
    });
    FloatingActionsMenu rightLabels = (FloatingActionsMenu) findViewById(R.id.right_labels);
    FloatingActionButton addedOnce = new FloatingActionButton(this);
    addedOnce.setTitle("Added once");
    rightLabels.addButton(addedOnce);
    FloatingActionButton addedTwice = new FloatingActionButton(this);
    addedTwice.setTitle("Added twice");
    rightLabels.addButton(addedTwice);
    rightLabels.removeButton(addedTwice);
    rightLabels.addButton(addedTwice);
  }
}
.

No comments:

Post a Comment