项目作者: Krupen

项目描述 :
Android library to animate Floating Action Button to Bottom Sheet Dialog and vice-versa
高级语言: Java
项目地址: git://github.com/Krupen/FabulousFilter.git
创建时间: 2017-06-26T11:36:38Z
项目社区:https://github.com/Krupen/FabulousFilter

开源协议:Apache License 2.0

下载


FabulousFilter

API Android Arsenal Material Up

Show some :heart: and star the repo to support the project

GitHub stars GitHub forks GitHub watchers GitHub followers
Twitter Follow

This library is the implementation of filter-concept posted on MaterialUp.com.

It makes animation of FloatingActionButton to BottomSheetDialog easy to implement.

Concept

fabulousfilter concept

Demo

fabulousfilter demo 1 fabulousfilter demo 1

Download

Gradle

Add the dependency to your app-level build.gradle file:

  1. dependencies {
  2. implementation 'io.github.krupen:fabulousfilter:0.0.6'
  3. }

Usage

Create a Fragment that extends AAH_FabulousFragment:

  1. public class MySampleFabFragment extends AAH_FabulousFragment {
  2. public static MySampleFabFragment newInstance() {
  3. MySampleFabFragment f = new MySampleFabFragment();
  4. return f;
  5. }
  6. @Override
  7. public void setupDialog(Dialog dialog, int style) {
  8. View contentView = View.inflate(getContext(), R.layout.filter_sample_view, null);
  9. RelativeLayout rl_content = (RelativeLayout) contentView.findViewById(R.id.rl_content);
  10. LinearLayout ll_buttons = (LinearLayout) contentView.findViewById(R.id.ll_buttons);
  11. contentView.findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
  12. @Override
  13. public void onClick(View v) {
  14. closeFilter("closed");
  15. }
  16. });
  17. //params to set
  18. setAnimationDuration(600); //optional; default 500ms
  19. setInterpolator(new AccelerateDecelerateInterpolator()); // optional
  20. setPeekHeight(300); // optional; default 400dp
  21. setCallbacks((Callbacks) getActivity()); //optional; to get back result
  22. setAnimationListener((AnimationListener) getActivity()); //optional; to get animation callbacks
  23. setViewgroupStatic(ll_buttons); // optional; layout to stick at bottom on slide
  24. setViewPager(vp_types); //optional; if you use viewpager that has scrollview
  25. setViewMain(rl_content); //necessary; main bottomsheet view
  26. setMainContentView(contentView); // necessary; call at end before super
  27. super.setupDialog(dialog, style); //call super at last
  28. }
  29. }

Create view for the fragment which has parent element AAH_FilterView:

  1. <com.allattentionhere.fabulousfilter.AAH_FilterView
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical">
  7. <RelativeLayout
  8. android:id="@+id/rl_content"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:layout_alignParentBottom="true"
  12. android:background="@color/orange"
  13. android:visibility="invisible"
  14. tools:ignore="MissingPrefix"
  15. tools:visibility="visible">
  16. <LinearLayout
  17. android:id="@+id/ll_buttons"
  18. android:layout_width="match_parent"
  19. android:layout_height="56dp"
  20. android:layout_alignParentBottom="true"
  21. android:background="@color/brown"
  22. android:orientation="horizontal"
  23. android:weightSum="2">
  24. </LinearLayout>
  25. </RelativeLayout>
  26. </com.allattentionhere.fabulousfilter.AAH_FilterView>

Start the fragment on click of FloatingActionButton as below:

  1. fab.setOnClickListener(new View.OnClickListener() {
  2. @Override
  3. public void onClick(View v) {
  4. MySampleFabFragment dialogFrag = MySampleFabFragment.newInstance();
  5. dialogFrag.setParentFab(fab);
  6. dialogFrag.show(getSupportFragmentManager(), dialogFrag.getTag());
  7. }
  8. });

Parameters

  • Main View (Required)

    This parameter specifies the ViewGroup of the bottom sheet to be shown after animation ends. It can be any ViewGroup(LinearLayout/FrameLayout etc):

    1. setViewMain(relativelayout_content);
  • Inflated Dialog View (Required)

    This parameter specifies the inflated view for the dialog:

    1. setMainContentView(contentDialogView);
  • Animation duration (Optional)

    This parameter sets animation duration of translate and scale animation in milliseconds:

    1. setAnimationDuration(600); // default 500ms
  • Interpolator (Optional)

    This parameter is used to set interpolator for fab animation:

    1. setInterpolator(new AccelerateDecelerateInterpolator());
  • Peek Height (Optional)

    This parameter sets the peek height of the bottom sheet in dp:

    1. setPeekHeight(300); // default 400dp
  • Callback (Optional)

    This parameter is used to get callback from AAH_FabulousFragment to the component that called it:

    1. setCallbacks((Callbacks) getActivity());

    To use it, implement the callback in the calling component(Activity/Fragment etc), example:
    ```
    public class MainSampleActivity extends AppCompatActivity implements AAH_FabulousFragment.Callbacks {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

    1. super.onCreate(savedInstanceState);
    2. setContentView(R.layout.activity_main_sample);

    }

    @Override
    public void onResult(Object result) {

    1. if (result.toString().equalsIgnoreCase("swiped_down")) {
    2. //do something or nothing
    3. } else {
    4. //handle result
    5. }

    }
    }

  1. * ### Animation Listener (Optional)
  2. This parameter is used to get animation callbacks.

setAnimationListener((AnimationListener) getActivity());

  1. To use it, implement the AnimationListener in the calling component(Activity/Fragment etc), example:

public class MainSampleActivity extends AppCompatActivity implements AAH_FabulousFragment.AnimationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_sample);
}

@Override
public void onOpenAnimationStart() {
//do something on open animation start
}

  1. @Override
  2. public void onOpenAnimationEnd() {
  3. //do something on open animation end
  4. }
  5. @Override
  6. public void onCloseAnimationStart() {
  7. //do something on close animation start
  8. }
  9. @Override
  10. public void onCloseAnimationEnd() {
  11. //do something on close animation start
  12. }

}

  1. * ### Static View (Optional)
  2. This parameter is used to make view in Bottom Sheet static when user slides it. It can be any ViewGroup(LinearLayout/FrameLayout etc):

setViewgroupStatic(linearlayout_buttons);

  1. * ### ViewPager (Optional)
  2. This parameter is used to support scrolling in ViewPager as BottomSheetDialog does not support multiple views with scroll:

setViewPager(viewPager);
```

Libraries by developer

Apps by developer

Price Stalker Show Card Game Safio chat Dota Picker Pro

License

Copyright 2017 Krupen Ghetiya

Licensed 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.