package cc.cubone.turbo.ui.widget.design;

import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.widget.Toolbar;
import android.view.View;

import butterknife.Bind;
import butterknife.ButterKnife;
import cc.cubone.turbo.R;
import cc.cubone.turbo.ui.base.BaseActivity;

/**
 * <ul>See also:
 * <li><a href="https://github.com/rubensousa/BottomSheetExample">BottomSheetExample</a>
 * <li><a href="https://github.com/miguelhincapie/CustomBottomSheetBehavior">CustomBottomSheetBehavior</a>
 * </ul>
 */
public class BottomSheetActivity extends BaseActivity {

    @Bind(R.id.bottom_sheet) View mBottomSheet;
    AppBarLayout mBottomSheetBarLayout;
    Toolbar mBottomSheetToolbar;

    private BottomSheetBehavior mBehavior;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_sheet);
        ButterKnife.bind(this);
        initViews();
    }

    private void initViews() {
        initToolbar();
        mBehavior = BottomSheetBehavior.from(mBottomSheet);
        mBottomSheetBarLayout = ButterKnife.findById(mBottomSheet, R.id.layout_bar);
        mBottomSheetToolbar = ButterKnife.findById(mBottomSheetBarLayout, R.id.tool_bar);
        holdStatusBar(mBottomSheetBarLayout);
    }

}

@@ -62,16 +62,59 @@
 Bundle;%0A
+import android.support.annotation.NonNull;%0A
 import a
@@ -281,16 +281,47 @@
 ew.View;
+%0Aimport android.view.ViewGroup;
 %0A%0Aimport
@@ -894,16 +894,61 @@
 ehavior;
+%0A    private int mBottomSheetBarLayoutHeight;
 %0A%0A    @O
@@ -1300,224 +1300,1492 @@
   mB
-ottomSheetBarLayout = ButterKnife.findById(mBottomSheet, R.id.layout_bar);%0A        mBottomSheetToolbar = ButterKnife.findById(mBottomSheetBarLayout, R.id.tool_bar);%0A        holdStatusBar(mBottomSheetBarLayout);%0A    %7D%0A
+ehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() %7B%0A            @Override%0A            public void onStateChanged(@NonNull View bottomSheet, int newState) %7B%0A            %7D%0A            @Override%0A            public void onSlide(@NonNull View bottomSheet, float slideOffset) %7B%0A                setViewHeight(mBottomSheetBarLayout,%0A                        (int) (mBottomSheetBarLayoutHeight * slideOffset));%0A            %7D%0A        %7D);%0A        mBottomSheetBarLayout = ButterKnife.findById(mBottomSheet, R.id.layout_bar);%0A        mBottomSheetToolbar = ButterKnife.findById(mBottomSheetBarLayout, R.id.tool_bar);%0A        mBottomSheetToolbar.setTitle(R.string.bottom_sheet);%0A        mBottomSheetToolbar.setNavigationIcon(android.support.v7.appcompat.R.drawable.abc_ic_clear_material);%0A        mBottomSheetToolbar.setNavigationOnClickListener(v -%3E mBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED));%0A        holdStatusBar(mBottomSheetBarLayout);%0A        mBottomSheetBarLayout.measure(%0A                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),%0A                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));%0A        mBottomSheetBarLayoutHeight = mBottomSheetBarLayout.getMeasuredHeight();%0A        setViewHeight(mBottomSheetBarLayout, 0);%0A    %7D%0A%0A    private void setViewHeight(View v, int h) %7B%0A        ViewGroup.LayoutParams params = v.getLayoutParams();%0A        params.height = h;%0A        v.setLayoutParams(params);%0A    %7D
 %0A%7D%0A

use bottom sheet callback