Giter VIP home page Giter VIP logo

floatingmenu's Introduction

FloatingMenu

Android Arsenal Current Version Minimum SDK

Include in your project

In your root/build.gradle

allprojects {
  repositories {
  ...
  maven { url 'https://jitpack.io' }
  }
}  

In your app/build.gradle

dependencies {
  compile 'com.github.rjsvieira:floatingMenu:1.3.0'
}

Customization

The FloatingMenuButton central image allows the user to give it any appearance he desires.
The user can also specify a ClickListener and add it to it. Thanks to the FloatingMenuButton's composite clickListener, it will not override the animation toggling.

The FloatingMenuButton only accepts FloatingSubButton children.
Like the FloatingMenuButton, the FloatingSubButton can be configured to have a specific background and a ClickListener for interaction. The following XML file specifies the example on the radial gifs :

<rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton
  android:id="@+id/my_floating_button"
  android:layout_width="40dp"
  android:layout_height="40dp"
  android:scaleType="centerInside"
  app:layout_constraintBottom_toBottomOf="parent"
  app:layout_constraintLeft_toLeftOf="parent"
  app:layout_constraintRight_toRightOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  floatingMenuActionButton:animationType="radial"
  floatingMenuActionButton:dispositionEndAngle="360"
  floatingMenuActionButton:dispositionStartAngle="0"
  floatingMenuActionButton:subActionButtonRadius="100">

  <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
    android:id="@+id/sub_button_1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/one" />

  <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
    android:id="@+id/sub_button_2"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/two" />

  <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
    android:id="@+id/sub_button_3"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/three" />

  <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
    android:id="@+id/sub_button_4"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/four" />

  <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
    android:id="@+id/sub_button_5"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/five" />

</rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton>

Adding a FloatingSubButton programmatically

You can add a FloatingSubButton programmatically using the following lines of code.

FloatingSubButton floatingSubButton = new FloatingSubButton(this); // create the button
floatingSubButton.setBackground(getDrawable(R.drawable.four)); // specify a custom background

And add it to the parent FloatingButton by either specifying layout parameters or assuming default parameters (as default, the layoutParameters for the first button on the list will be considered)

floatingButton.addFloatingSubButton(floatingSubButton, customLayoutParameters); 

or

floatingButton.addFloatingSubButton(floatingSubButton); 

Attribute configuration list

Attribute Type Default Default
startAngle int The starting angle for button disposition 0
endAngle int The ending angle for button disposition 180
radius int The distance between the central button and its children 100(dp)
movementStyle MovementStyle (Enumerator) Configures whether the user can or not drag the FloatingMenu around MovementStyle.FREE
animationType AnimationType (Enumerator) The open/close animation for FloatingMenuButton AnimationType.EXPAND
openingDuration int The opening duration, in milliseconds, of the animation 500
closingDuration int The closing duration, in milliseconds, of the animation 500
lagBetweenItems int The lag duration between animating items. Affects only AnimationType.EXPAND 100
openingInterpolator Interpolator The opening interpolator. Allows different rythms on the animations OvershootInterpolator
closingInterpolator Interpolator The closing interpolator. Allows different rythms on the animations AccelerateDecelerateInterpolator
shouldRotate boolean Specify whether the items should rotate while animating. Available only in AnimationType.EXPAND true
shouldFade boolean Specify whether the items should fade while animating. Available only in AnimationType.EXPAND true
shouldScale boolean Specify whether the items should scale while animating. Available only in AnimationType.EXPAND true

FloatingMenuButton State Change Listener

You can track whether the FloatingMenuButton is in open or closed status

public interface FloatingMenuButtonStateChangeListener {

    void onMenuOpened(FloatingMenuButton menu);

    void onMenuClosed(FloatingMenuButton menu);

}

FloatingMenuButton Animation Handler (Wrapper)

You can configure the FloatingMenuButton programmatically rather than xml, specifying and settings its variables. Consider the following example :

floatingButton = (FloatingMenuButton) findViewById(R.id.my_floating_button);
floatingButton.setStartAngle(0)
        .setEndAngle(360)
        .setAnimationType(AnimationType.EXPAND)
        .setMovementStyle(MovementStyle.STICKED_TO_SIDES);
floatingButton.getAnimationHandler()
        .setOpeningAnimationDuration(500)
        .setClosingAnimationDuration(200)
        .setLagBetweenItems(0)
        .setOpeningInterpolator(new FastOutSlowInInterpolator())
        .setClosingInterpolator(new FastOutLinearInInterpolator())
        .shouldFade(true)
        .shouldScale(true)
        .shouldRotate(false);

floatingmenu's People

Contributors

rjsvieira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

floatingmenu's Issues

toggleMenu() or openMenu() are not working when called.

Hi, I have this code:

private fun updateButton(question: Question) { when (question.type) { SplashActivity.TYPE_SJL_ABCD -> setCorrectButtons(question) SplashActivity.TYPE_SJL_RESPONSE -> setResponseButton(question) SplashActivity.TYPE_MAT_ABCD -> setCorrectButtons(question) SplashActivity.TYPE_MAT_RESPONSE -> setResponseButton(question) } }

private fun setResponseButton(question: Question) { my_floating_button.setOnClickListener(null) my_floating_button.setOnClickListener { MaterialDialog.Builder(this) .title(R.string.app_name) .content(R.string.app_name) .inputType(InputType.TYPE_CLASS_TEXT) .input(R.string.app_name, R.string.app_name) { _, input -> question.correctResponse.let { it2 -> onResponseSelected(input.toString(), question.number, it2, question.question + ".jpg") } }.show() } }

`private fun setCorrectButtons(question: Question) {

    my_floating_button.setOnClickListener(null)

    my_floating_button.setOnClickListener {
        my_floating_button.toggleMenu()
    }

    val llp = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)
    llp.width = SingleChoiceQuestionFragment.convertDpToPixel(50f, this)
    llp.height = SingleChoiceQuestionFragment.convertDpToPixel(50f, this)

    my_floating_button.subMenuButtons.clear()

    val responses = question.responses
    for (i in responses.size - 1 downTo 0) {
        val floatingSubButton = FloatingSubButton(this)
        var d: TextDrawable
        if (responses[i] == resposesList[question.number]?.yourResponse) {
            d = TextDrawable.builder()
                    .beginConfig()
                    .withBorder(4) /* thickness in px */
                    .textColor(Color.parseColor("#26c6da"))
                    .bold()
                    .endConfig()
                    .buildRound(responses[i], Color.WHITE)
        } else {
            d = TextDrawable.builder().buildRound(responses[i], Color.parseColor("#26c6da"))
        }
        floatingSubButton.background = d
        my_floating_button.addFloatingSubButton(floatingSubButton, llp)
        floatingSubButton.setOnClickListener {
            my_floating_button.closeMenu()
            question.correctResponse.let { it1 -> onResponseSelected(responses[i], question.number, it1, question.question + ".jpg") }
            setCorrectButtons(question)
        }
    }
}`

The listener always gets called when I click the button. The method toggleMenu() does nothing when called. It does not open the menu even if it has 4 childs in it. I've done debugging

Sub buttons are visible in other tabs

I have several tabs in my activity. If I open the FloatingMenuButton and move to other tabs, the sub buttons are visible there. Is there any method like this : setClosedOnTouchOutside(true) ?

when use databinding, it goes wrong

I override setContent() method, to dynamic add FloatingMenuButton
such as:

    @Override
    public void setContentView(int layoutResID) {
            super.setContentView(layoutResID);
            FrameLayout fLayout = new FrameLayout(this);
            ViewGroup contentContainer = (ViewGroup) this.findViewById(android.R.id.content);
            ViewGroup parent = (ViewGroup) contentContainer.getParent();
            parent.removeView(contentContainer);
            fLayout.addView(contentContainer);
            parent.addView(fLayout);
            floatingMenu = (FloatingMenuButton) LayoutInflater.from(this).inflate(R.layout.menu, parent, false);
            fLayout.addView(floatingMenu);
    }

then DataBindingUtil.setContentView(this, R.layout.my_layout) return a null object

I found that you add FloatingSubButton inner android.R.id.content too, which cause following problem.

When DataBindingUtil invoke bindToAddedViews()

private static <T extends ViewDataBinding> T bindToAddedViews(DataBindingComponent component, ViewGroup parent, int startChildren, int layoutId) {
    final int endChildren = parent.getChildCount(); // parent is R.id.content, count is subButton size + 1
    final int childrenAdded = endChildren - startChildren;
    if (childrenAdded == 1) {
        final View childView = parent.getChildAt(endChildren - 1);
        return bind(count, childView, layoutId);
    } else {
        final View[] children = new View[childrenAdded];
        for (int i = 0; i < childrenAdded; i++) {
           children[i] = parent.getChildAt(i + startChildren);
       }
       return bind(component, children, layoutId);
    }

The bind() method in else invoke return (T) sMapper.getDataBinder(bindingComponent, roots, layoutId); which return null, while the 'bind()' method in if can return correct binding object.

null pointer exception

Attempt to invoke virtual method 'rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton.setStartAngle(int)' on a null object reference

How to set a limit of where the button can be placed

Hello, I would like to know if there's a way for me to set a limit of where the button can be placed. Or at least, how I could implement a OnDragListener to know if my button is in the wrong place and then, limit it. I want this feature so that my subbuttons will always show with the right spacing.

I can't get the library

I followed the guide in README.
In root/build.gradle

allprojects {
  repositories {
  ...
  maven { url 'https://jitpack.io' }
  }
}

In app/build.gradle

dependencies {
  compile 'com.github.rjsvieira:FloatingMenuButton:1.1.0'
}

But I got this after sync: "Failed to resolve: com.github.rjsvieira:FloatingMenuButton:1.1.0".

bug

first my english is so bad;

  1. my scence is viewpager+ fragment ;
    2 use your floatingmenubutton +floatingsubbutton+mybutton if i toggle my viewpager your floatingsubbutton will not miss; i want mybutton was error ;so i canle mybutton ;result: your view still not miss

XML FloatingMenuButton is not working

Hi, here is my sample code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:floatingMenuActionButton="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton
        android:id="@+id/my_floating_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        floatingMenuActionButton:anchored="true"
        floatingMenuActionButton:animationType="radial"
        floatingMenuActionButton:dispositionEndAngle="0"
        floatingMenuActionButton:dispositionStartAngle="360"
        floatingMenuActionButton:subActionButtonRadius="300">

        <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/two" />

        <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_2"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/one" />

    </rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton>

</LinearLayout>

After starting an activity, It looks like the first button is hidden from the second one, which is the only one showing. Also the buttons are not displayed correctly but they overlap the floating menu button.

Am I doing something wrong?

SubButton onClickListener

Hi

I have a fragment and when I try to find subbutton for set onClickListener the findViewById return null.

    sub_button_1 = (FloatingSubButton) rootView.findViewById(R.id.sub_button_1);
    sub_button_1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        }
    });

Can you help me ?

Thanks in advance
Paolo

Demo app

Hello,
Can you please include a demo app for the library?

Unable to start activity ComponentInfo in MainActivity

Just imported the gradle and placed the xml in MainActivity. The project is being built properly but crashes right on start
Project build.gradle

buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.3'
        }
    }


allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.lamia.faq"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        incremental false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.github.rjsvieira:floatingMenu:1.0.0'
    testCompile 'junit:junit:4.12'

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.lamia.faq.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />


    <rjsv.FloatingMenuButton.FloatingMenuButton.FloatingMenuButton
        android:id="@+id/my_floating_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:scaleType="centerInside"
        >

        <rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />

        <rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_2"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />

        <rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_3"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />

        <rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_4"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />

        <rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
            android:id="@+id/sub_button_5"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />

    </rjsv.FloatingMenuButton.FloatingMenuButton.FloatingMenuButton>
</RelativeLayout>

android.view.InflateException: Binary XML file line #19: Error inflating class rjsv.FloatingMenuButton.FloatingMenuButton.FloatingMenuButton

Caused by: java.lang.ClassNotFoundException: Didn't find class "rjsv.FloatingMenuButton.FloatingMenuButton.FloatingMenuButton" on path: DexPathList[[zip file "/data/app/com.example.lamia.faq-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Set Radius does not work

I am trying to set different radiuses but the behavior is same for all values

Please find the code snippet below:

My XML - Its inside horizontal linear layout

<rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton
                android:id="@+id/my_floating_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="10dp"
                android:layout_marginRight="10dp"
                floatingMenuActionButton:animationType="radial"
                floatingMenuActionButton:dispositionEndAngle="90"
                floatingMenuActionButton:dispositionStartAngle="-90"
                floatingMenuActionButton:subActionButtonRadius="1000">

                <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
                    android:id="@+id/sub_button_1"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@android:drawable/btn_minus" />

                <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
                    android:id="@+id/sub_button_2"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@android:drawable/btn_minus" />

                <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
                    android:id="@+id/sub_button_3"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@android:drawable/btn_minus" />

                <rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
                    android:id="@+id/sub_button_4"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@android:drawable/btn_minus" />

            </rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton>

Please find below my java code:

FloatingMenuButton fab_1 = findViewById(R.id.my_floating_button);
        fab_1.setStartAngle(-90)
                .setEndAngle(90)
                .setRadius(500)
                .setAnimationType(AnimationType.RADIAL)
                .setMovementStyle(MovementStyle.STICKED_TO_SIDES);

Please let me know why the setRadius is not working and how can I fix that issue.

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.