forked from OfficeDev/ui-fabric-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BottomSheetActivity.kt
221 lines (204 loc) · 10.3 KB
/
BottomSheetActivity.kt
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
package com.microsoft.officeuifabricdemo.demos
import android.os.Bundle
import com.microsoft.officeuifabric.bottomsheet.BottomSheet
import com.microsoft.officeuifabric.bottomsheet.BottomSheetDialog
import com.microsoft.officeuifabric.bottomsheet.BottomSheetItem
import com.microsoft.officeuifabric.snackbar.Snackbar
import com.microsoft.officeuifabricdemo.DemoActivity
import com.microsoft.officeuifabricdemo.R
import kotlinx.android.synthetic.main.activity_bottom_sheet.*
import kotlinx.android.synthetic.main.activity_demo_detail.*
class BottomSheetActivity : DemoActivity(), BottomSheetItem.OnClickListener {
override val contentLayoutId: Int
get() = R.layout.activity_bottom_sheet
private var bottomSheetDialog: BottomSheetDialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Single line items
show_with_single_line_items_button.setOnClickListener {
val bottomSheet = BottomSheet.newInstance(
arrayListOf(
BottomSheetItem(
R.id.bottom_sheet_item_flag,
R.drawable.ic_fluent_flag_24_regular,
getString(R.string.bottom_sheet_item_flag_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_reply,
R.drawable.ic_fluent_reply_24_regular,
getString(R.string.bottom_sheet_item_reply_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_forward,
R.drawable.ic_fluent_forward_24_regular,
getString(R.string.bottom_sheet_item_forward_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_delete,
R.drawable.ic_delete_24_regular,
getString(R.string.bottom_sheet_item_delete_title)
)
)
)
bottomSheet.show(supportFragmentManager, null)
}
// Double line items
show_with_double_line_items_button.setOnClickListener {
val bottomSheet = BottomSheet.newInstance(
arrayListOf(
BottomSheetItem(
R.id.bottom_sheet_item_camera,
R.drawable.ic_camera_24_regular,
getString(R.string.bottom_sheet_item_camera_title),
getString(R.string.bottom_sheet_item_camera_subtitle)
),
BottomSheetItem(
R.id.bottom_sheet_item_gallery,
R.drawable.ic_image_library_24_regular,
getString(R.string.bottom_sheet_item_gallery_title),
getString(R.string.bottom_sheet_item_gallery_subtitle)
),
BottomSheetItem(
R.id.bottom_sheet_item_videos,
R.drawable.ic_video_24_regular,
getString(R.string.bottom_sheet_item_videos_title),
getString(R.string.bottom_sheet_item_videos_subtitle)
),
BottomSheetItem(
R.id.bottom_sheet_item_manage,
R.drawable.ic_settings_24_regular,
getString(R.string.bottom_sheet_item_manage_title),
getString(R.string.bottom_sheet_item_manage_subtitle)
)
)
)
bottomSheet.show(supportFragmentManager, null)
}
// Single line header
show_with_single_line_items_and_header_button.setOnClickListener {
val bottomSheet = BottomSheet.newInstance(
arrayListOf(
BottomSheetItem(
R.id.bottom_sheet_item_flag,
R.drawable.ic_fluent_flag_24_regular,
getString(R.string.bottom_sheet_item_flag_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_reply,
R.drawable.ic_fluent_reply_24_regular,
getString(R.string.bottom_sheet_item_reply_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_forward,
R.drawable.ic_fluent_forward_24_regular,
getString(R.string.bottom_sheet_item_forward_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_delete,
R.drawable.ic_delete_24_regular,
getString(R.string.bottom_sheet_item_delete_title)
)
),
BottomSheetItem(
title = getString(R.string.bottom_sheet_item_single_line_header)
)
)
bottomSheet.show(supportFragmentManager, null)
}
// Double line header
show_with_double_line_items_and_two_line_header_button.setOnClickListener {
val bottomSheet = BottomSheet.newInstance(
arrayListOf(
BottomSheetItem(
R.id.bottom_sheet_item_double_line_header_share,
R.drawable.ic_share_24_filled,
getString(R.string.bottom_sheet_item_double_line_header_share)
),
BottomSheetItem(
R.id.bottom_sheet_item_double_line_header_move,
R.drawable.ic_folder_move_24_regular,
getString(R.string.bottom_sheet_item_double_line_header_move)
),
BottomSheetItem(
R.id.bottom_sheet_item_double_line_header_delete,
R.drawable.ic_delete_24_regular,
getString(R.string.bottom_sheet_item_double_line_header_delete)
),
BottomSheetItem(
R.id.bottom_sheet_item_double_line_header_info,
R.drawable.ic_info_24_regular,
getString(R.string.bottom_sheet_item_double_line_header_info),
useDivider = true
)
),
BottomSheetItem(
imageId = R.drawable.ic_folder_24_regular,
title = getString(R.string.bottom_sheet_item_double_line_header),
subtitle = getString(R.string.bottom_sheet_item_double_line_header_subtitle)
)
)
bottomSheet.show(supportFragmentManager, null)
}
// Dialog
show_bottom_sheet_dialog_button.setOnClickListener {
if (bottomSheetDialog == null) {
bottomSheetDialog = BottomSheetDialog(
this,
arrayListOf(
BottomSheetItem(
R.id.bottom_sheet_item_clock,
R.drawable.ic_clock_24_regular,
getString(R.string.bottom_sheet_item_clock_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_alarm,
R.drawable.ic_alert_24_regular,
getString(R.string.bottom_sheet_item_alarm_title)
),
BottomSheetItem(
R.id.bottom_sheet_item_time_zone,
R.drawable.ic_globe_24_regular,
getString(R.string.bottom_sheet_item_time_zone_title)
)
)
)
bottomSheetDialog?.onItemClickListener = this
}
bottomSheetDialog?.show()
}
}
override fun onDestroy() {
super.onDestroy()
bottomSheetDialog?.dismiss()
}
override fun onBottomSheetItemClick(item: BottomSheetItem) {
when(item.id) {
// Single line items & single line header
R.id.bottom_sheet_item_flag -> showSnackbar(resources.getString(R.string.bottom_sheet_item_flag_toast))
R.id.bottom_sheet_item_reply -> showSnackbar(resources.getString(R.string.bottom_sheet_item_reply_toast))
R.id.bottom_sheet_item_forward -> showSnackbar(resources.getString(R.string.bottom_sheet_item_forward_toast))
R.id.bottom_sheet_item_delete -> showSnackbar(resources.getString(R.string.bottom_sheet_item_delete_toast))
// Double line items
R.id.bottom_sheet_item_camera -> showSnackbar(resources.getString(R.string.bottom_sheet_item_camera_toast))
R.id.bottom_sheet_item_gallery -> showSnackbar(resources.getString(R.string.bottom_sheet_item_gallery_toast))
R.id.bottom_sheet_item_videos -> showSnackbar(resources.getString(R.string.bottom_sheet_item_videos_toast))
R.id.bottom_sheet_item_manage -> showSnackbar(resources.getString(R.string.bottom_sheet_item_manage_toast))
// Double line header
R.id.bottom_sheet_item_double_line_header_move -> showSnackbar(getString(R.string.bottom_sheet_item_double_line_header_move_toast))
R.id.bottom_sheet_item_double_line_header_share -> showSnackbar(getString(R.string.bottom_sheet_item_double_line_header_share_toast))
R.id.bottom_sheet_item_double_line_header_delete -> showSnackbar(getString(R.string.bottom_sheet_item_double_line_header_delete_toast))
R.id.bottom_sheet_item_double_line_header_info -> showSnackbar(getString(R.string.bottom_sheet_item_double_line_header_info_toast))
// Dialog
R.id.bottom_sheet_item_clock -> showSnackbar(resources.getString(R.string.bottom_sheet_item_clock_toast))
R.id.bottom_sheet_item_alarm -> showSnackbar(resources.getString(R.string.bottom_sheet_item_alarm_toast))
R.id.bottom_sheet_item_time_zone -> showSnackbar(resources.getString(R.string.bottom_sheet_item_time_zone_toast))
}
}
private fun showSnackbar(message: String) {
Snackbar.make(root_view, message).show()
}
}