-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathMainActivity.java
99 lines (86 loc) · 4.02 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.mahc.custombottomsheet;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.mahc.custombottomsheetbehavior.BottomSheetBehaviorGoogleMapsLike;
import com.mahc.custombottomsheetbehavior.MergedAppBarLayout;
import com.mahc.custombottomsheetbehavior.MergedAppBarLayoutBehavior;
public class MainActivity extends AppCompatActivity {
int[] mDrawables = {
R.drawable.cheese_3,
R.drawable.cheese_3,
R.drawable.cheese_3,
R.drawable.cheese_3,
R.drawable.cheese_3,
R.drawable.cheese_3
};
TextView bottomSheetTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(" ");
}
/**
* If we want to listen for states callback
*/
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorlayout);
View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
final BottomSheetBehaviorGoogleMapsLike behavior = BottomSheetBehaviorGoogleMapsLike.from(bottomSheet);
behavior.addBottomSheetCallback(new BottomSheetBehaviorGoogleMapsLike.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehaviorGoogleMapsLike.STATE_COLLAPSED:
Log.d("bottomsheet-", "STATE_COLLAPSED");
break;
case BottomSheetBehaviorGoogleMapsLike.STATE_DRAGGING:
Log.d("bottomsheet-", "STATE_DRAGGING");
break;
case BottomSheetBehaviorGoogleMapsLike.STATE_EXPANDED:
Log.d("bottomsheet-", "STATE_EXPANDED");
break;
case BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT:
Log.d("bottomsheet-", "STATE_ANCHOR_POINT");
break;
case BottomSheetBehaviorGoogleMapsLike.STATE_HIDDEN:
Log.d("bottomsheet-", "STATE_HIDDEN");
break;
default:
Log.d("bottomsheet-", "STATE_SETTLING");
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
MergedAppBarLayout mergedAppBarLayout = findViewById(R.id.mergedappbarlayout);
MergedAppBarLayoutBehavior mergedAppBarLayoutBehavior = MergedAppBarLayoutBehavior.from(mergedAppBarLayout);
mergedAppBarLayoutBehavior.setToolbarTitle("Title Dummy");
mergedAppBarLayoutBehavior.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT);
}
});
bottomSheetTextView = (TextView) bottomSheet.findViewById(R.id.bottom_sheet_title);
ItemPagerAdapter adapter = new ItemPagerAdapter(this,mDrawables);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(adapter);
behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT);
//behavior.setCollapsible(false);
}
}