项目作者: applibgroup

项目描述 :
Customizable bounce animation for any view.
高级语言: Java
项目地址: git://github.com/applibgroup/Bounceview-Ohos.git
创建时间: 2021-07-27T08:22:51Z
项目社区:https://github.com/applibgroup/Bounceview-Ohos

开源协议:Apache License 2.0

下载


Build
Quality Gate Status

Bounceview-Ohos

Its an HarmonyOS library that provides customizable bounce animation for any component update

Source

Inspired by https://github.com/hariprasanths/Bounceview-Android Version v0.2.0

Screenshot

Bounceview attached to TabList and List items

Bounceview attached to CustomDialogs and some cool animations

Getting Started

Installation Instructions

1.For using Bounceview-Ohos module in sample app, include the source code and add the below dependencies in entry/build.gradle to generate hap/support.har.

  1. dependencies {
  2. implementation project(path: ':bounceview-ohos')
  3. implementation fileTree(dir: 'libs', include: ['*.har'])
  4. testImplementation 'junit:junit:4.13'
  5. }

2.For using Bounceview-Ohos in separate application using har file, add the har file in the entry/libs folder and add the dependencies in entry/build.gradle file.

  1. dependencies {
  2. implementation fileTree(dir: 'libs', include: ['*.har'])
  3. testImplementation 'junit:junit:4.13'
  4. }
  1. For using Bounceview-Ohos from a remote repository in separate application, add the below dependencies in entry/build.gradle file.
    1. dependencies {
    2. implementation 'dev.applibgroup:bounceview-ohos:1.0.0'
    3. testCompile 'junit:junit:4.13'
    4. }

    Usage

Add animations to any components as below:

  1. Button button = (Button) findComponentById(ResourceTable.Id_button);
  2. BounceView.addAnimTo(button);

Use BounceView with dialogs:

CustomDialog is our custom class extending CommonDialog created for Bounce View animnation. Most of the functionalities will be similar to CommonDialog provided by HMOS platform.


Custom dialog is divided into three parts :

  1. title component
  2. content component
  3. button component


    User can set the custom layout for 1 & 2. If not set, baselayout will be set. But for button component similar to CommonDialog behaviour, user will not be able to customize the Button layout .


    In case user wants to customize the button layout, it is still possible by adding the customized buttons within the layout created for content component
  1. customDialog.setContentCustomComponent(customComponent);

a) Create Alert Dialog using CustomDialog

  1. // CustomDialog (Alert Dialog creation) when you directly set text, contents or button
  2. CustomDialog alertDialog = new CustomDialog(getContext());
  3. alertDialog.setTitleText("Alert Dialog");
  4. alertDialog.setContentText("Do you want to exit?");
  5. alertDialog.setCommonButton(0, "No", 100, 0, component12 -> alertDialog.destroy());
  6. alertDialog.setCommonButton(1, "Yes", 100, 0, component1 -> terminateAbility());
  7. alertDialog.setSize(400, 300);
  8. alertDialog.setAutoClosable(true);
  9. alertDialog.show();
  10. BounceView.addAnimTo(alertDialog); // always add BounceView after .show() is called

b) CustomDialog with customized layout by user

  1. // CustomDialog when you set customComponent
  2. CustomDialog commonDialog = new CustomDialog(getContext());
  3. DirectionalLayout customDialog = (DirectionalLayout) LayoutScatter.getInstance(getContext())
  4. .parse(ResourceTable.Layout_custom_dialog, null, false);
  5. // this Layout_custom_dialog may contain buttons(or any other components) and you can also add bounceview to it as shown above for components.
  6. commonDialog.setContentCustomComponent(customDialog);
  7. commonDialog.setAutoClosable(true);
  8. commonDialog.show();
  9. BounceView.addAnimTo(commonDialog); // always add BounceView after .show() is called

c) Adding the customized layout to Custom popup Dialog

  1. CustomPopupDialog
  2. DirectionalLayout customDialogLayout = (DirectionalLayout) LayoutScatter.getInstance(getContext())
  3. .parse(ResourceTable.Layout_custom_popup, null, false);
  4. CustomPopupDialog popupDialog = new CustomPopupDialog(getContext(), null); // can pass custom component and Dialog box width and height will be set to that of custom component
  5. popupDialog.setCustomComponent(customDialogLayout);
  6. popupDialog.setAutoClosable(true);
  7. popupDialog.show();
  8. BounceView.addAnimTo(popupDialog); // always add BounceView after .show() is called

CustomPopupDialog is our custom class extending PopupDialog created for Bounce View animnation. Most of the functionalities will be similar to PopupDialog provided by HMOS platform.
When you try to create default popup dialog by using setText("Hello World") or setBackColor(color) directly, these will be set to our defined base Layout in the library.

Some cool animations:

  1. //Bounce animation
  2. BounceView.addAnimTo(button1)
  3. .setScaleForPopOutAnim(1.1f, 1.1f);
  4. //Horizontal flip animation
  5. BounceView.addAnimTo(button2)
  6. .setScaleForPopOutAnim(1f, 0f);
  7. //Vertical flip animation
  8. BounceView.addAnimTo(button3)
  9. .setScaleForPopOutAnim(0f, 1f);
  10. //Flicker animation
  11. BounceView.addAnimTo(button4)
  12. .setScaleForPopOutAnim(0f, 0f);

Customize BounceView properties:

  1. Button button = (Button) findComponentById(ResourceTable.Id_button);
  2. BounceView.addAnimTo(button)
  3. //Default push in scalex: 0.9f , scaley: 0.9f
  4. .setScaleForPushInAnim(BounceView.PUSH_IN_SCALE_X, BounceView.PUSH_IN_SCALE_Y)
  5. //Default pop out scalex: 1.1f, scaley: 1.1f
  6. .setScaleForPopOutAnim(BounceView.POP_OUT_SCALE_X, BounceView.POP_OUT_SCALE_Y)
  7. //Default push in anim duration: 100 (in milliseconds)
  8. .setPushInAnimDuration(BounceView.PUSH_IN_ANIM_DURATION)
  9. //Default pop out anim duration: 100 (in milliseconds)
  10. .setPopOutAnimDuration(BounceView.POP_OUT_ANIM_DURATION)
  11. //Default interpolator: Animator.CurveType.ACCELERATE_DECELERATE
  12. .setInterpolatorPushIn(BounceView.DEFAULT_INTERPOLATOR)
  13. .setInterpolatorPopOut(BounceView.DEFAULT_INTERPOLATOR);

Show your support

Give a :star: if this project helped you!

License

Copyright :copyright: 2018 Hariprasanth S

This project is licensed under the Apache License, Version 2.0

You may also obtain a copy of the License at

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