create account

Material Design 2.0 Android Toolbar by bxute

View this thread on: hive.blogpeakd.comecency.com
· @bxute · (edited)
$0.29
Material Design 2.0 Android Toolbar
#### Repository
https://github.com/bxute/MaterialToobar

#### An android library for Material toolbar with animations and interaction.
Have a quick look at this:

![Toolbar ](https://user-images.githubusercontent.com/10809719/41024399-c042e618-698c-11e8-8a6a-0933158547dd.jpg)

You can make use of this library in your project and can customise the experience of your users.
It enables you to get rid of boring static toolbar which sticks to bottom.

1.Add Module dependency in `app/build.gradle` file
```
	dependencies {
	        implementation 'com.github.bxute:MaterialToobar:v1.0'
	}

```

2.Add this XML to your activity
```xml
 <xute.materialtoolbar.BottomToolbar
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
```

And you are good to go!

### How to receive callbacks from Buttons of Toolbar

`BottomToolbar` class is equipped with a callback support for this.
A sample usage of this is:
```java
 BottomToolbar bottomToolbar = findViewById(R.id.bottom_toolbar);
        bottomToolbar.setButtonClickListener(new BottomToolbar.ButtonClickListener() {
            @Override
            public void onPlusButtonClicked() {
                Toast.makeText(MainActivity.this,"Button clicked!",Toast.LENGTH_LONG).show();
            }
        });
```

A complete interaction of this toolbar can be 
![complete interactio.gif](https://cdn.steemitimages.com/DQmVdwiVgf5uRps8bsRMUpTuupsQEqYZRtYEooancwRMSed/complete%20interactio.gif)

### How is this interaction made ?

This whole interaction consists of 4 parts:
1. Growing Circle
2. Shrinking Rectangle
3. Drawing Toolbar with animation
4. Drawing Buttons

Each step consists of controlled animation with managed delays.

First we drawn a circle and them kept it increasing till It fills the entire screen.

**To get radius of Screen**
```
 maxScreenRadius = (float) Math.sqrt(Math.pow(mScreenHeight, 2) + Math.pow(mScreenWidth, 2));
```

Then the animation is run using:
```
ValueAnimator growingCircleRadiusAnimator = ValueAnimator.ofFloat(startGrowingCircleRadius, maxScreenRadius);
        growingCircleRadiusAnimator.setDuration(GROW_CIRCLE_DURATION);
        growingCircleRadiusAnimator.setInterpolator(new AccelerateInterpolator(2f));
        growingCircleRadiusAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                mCircleRadius = (float) valueAnimator.getAnimatedValue();
                invalidate();
            }
        });
```

At each update of animation, we are updating the radius and invalidating the view.

After Circle Growing animation ends, we start Rectangle shrinking process.
It looks like the same circle is shrink in the form of Rectangle.

We shrink rectangle till it reaches `Toolbar height`.

You can notice the curved cut part.
Its not a normal rectangle. This required us to take use of `Path` and define the path of whole rectangle dynamically.

Toolbar path is set by a helper method:
```
 private void setToolbarPath(int mCurveRadius) {
        mToobarPath.reset();
        mToobarPath.moveTo((-1) * toolbarOffsetInPx, toolbarStartY);
        mToobarPath.lineTo(screenHorizontalMidPoint - mCurveRadius, toolbarStartY);
        mToobarPath.lineTo(screenHorizontalMidPoint, toolbarDippedPointY);
        mToobarPath.lineTo(screenHorizontalMidPoint + mCurveRadius, toolbarStartY);
        mToobarPath.lineTo(mScreenWidth + toolbarOffsetInPx, toolbarStartY);
        mToobarPath.lineTo(mScreenWidth + toolbarOffsetInPx, mScreenHeight);
        mToobarPath.lineTo((-1) * toolbarOffsetInPx, mScreenHeight + toolbarOffsetInPx);
        mToobarPath.lineTo((-1) * toolbarOffsetInPx, toolbarStartY);
        mToobarPath.close();
        mButtonPaint.setPathEffect(new CornerPathEffect(mCurveRadius / 3));
        mCurvePaint.setPathEffect(new CornerPathEffect(mCurveRadius / 3));
    }
```

It takes 1 parameter of radius of the curve and generate the Path.

Shake effect if due to `BounceInterpolator` while completing the animation.

### How can you receive callback from button?

There is a callback method defined in the interface

```
 public interface ButtonClickListener {
        void onPlusButtonClicked();
    }
```

You can set listener on this view.

All Touch event on this view was getting interpreted as click. To constraint the area of click, we used a help method to check that touched coordinates belongs to button area.

```
private boolean cordinateInsideButton(float x, float y) {
        if (x > buttonLeftX && x < buttonRightX && y > buttonTopY && y < buttonBottomY) {
            return true;
        }
        return false;
    }
```

### Contributions

I will love to hear suggestions and PR are welcome on above given repository.

### Concluding statement
I love playing with android framework. Android interaction fascinates me a lot and it pushes me to try out new things.


### Github Commit:
https://github.com/bxute/MaterialToobar/commit/7083f5e1193f24a12c6d1fe205f1b28a042499e2
👍  , , , , , , , , , , ,
properties (23)
authorbxute
permlinkmaterial-design-2-0-android-toolbar
categoryutopian-io
json_metadata{"tags":["utopian-io","development","hapramp"],"image":["https://user-images.githubusercontent.com/10809719/41024399-c042e618-698c-11e8-8a6a-0933158547dd.jpg","https://cdn.steemitimages.com/DQmVdwiVgf5uRps8bsRMUpTuupsQEqYZRtYEooancwRMSed/complete%20interactio.gif"],"links":["https://github.com/bxute/MaterialToobar","https://github.com/bxute/MaterialToobar/commit/7083f5e1193f24a12c6d1fe205f1b28a042499e2"],"app":"steemit/0.1","format":"markdown"}
created2018-06-06 07:46:15
last_update2018-06-06 07:53:45
depth0
children3
last_payout2018-06-13 07:46:15
cashout_time1969-12-31 23:59:59
total_payout_value0.236 HBD
curator_payout_value0.051 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,059
author_reputation7,043,008,489,088
root_title"Material Design 2.0 Android Toolbar"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id59,492,231
net_rshares98,918,870,286
author_curate_reward""
vote details (12)
@a-0-0 ·
Check out https://steemit.com/@a-0-0
properties (22)
authora-0-0
permlinkre-bxute-material-design-2-0-android-toolbar-20180606t074643000z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://steemit.com/@a-0-0"],"app":"steemit/0.1"}
created2018-06-06 07:46:45
last_update2018-06-06 07:46:45
depth1
children0
last_payout2018-06-13 07:46:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length36
author_reputation-4,863,186,238,920
root_title"Material Design 2.0 Android Toolbar"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id59,492,285
net_rshares0
@codingdefined ·
Thank you for your contribution. Material Design in Android is too common and its not anything unique, it would be good if you can make it unique like anyone can change the design as per their needs without the need to understand coding, something of that sort.


Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
properties (22)
authorcodingdefined
permlinkre-bxute-material-design-2-0-android-toolbar-20180609t115119882z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-06-09 11:51:18
last_update2018-06-09 11:51:18
depth1
children0
last_payout2018-06-16 11:51:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length623
author_reputation529,290,120,145,947
root_title"Material Design 2.0 Android Toolbar"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id59,982,084
net_rshares0
@the-dragon ·
Good work!
I am sure this library will help someone looking to implement Material Design 2.0.
properties (22)
authorthe-dragon
permlinkre-bxute-material-design-2-0-android-toolbar-20180612t080159488z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-06-12 08:02:00
last_update2018-06-12 08:02:00
depth1
children0
last_payout2018-06-19 08:02:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length93
author_reputation1,461,184,535,530
root_title"Material Design 2.0 Android Toolbar"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id60,413,214
net_rshares0