-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathKotlinSampleActivity.kt
388 lines (348 loc) · 14.7 KB
/
KotlinSampleActivity.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
package com.andrognito.flashbardemo
import android.graphics.Typeface
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.andrognito.flashbar.Flashbar
import com.andrognito.flashbar.anim.FlashAnim
import kotlinx.android.synthetic.main.activity_main.*
class KotlinSampleActivity : AppCompatActivity() {
private val TAG = "Flashbar"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var flashbar: Flashbar? = null
show.setOnClickListener {
if (flashbar == null) {
flashbar = basic()
}
flashbar?.show()
}
dismiss.setOnClickListener {
flashbar?.dismiss()
}
}
private fun basic(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.message("This is a basic flashbar")
.build()
}
private fun basicDuration(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.duration(500)
.message("This is a flashbar with duration")
.build()
}
private fun gravityTop(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.message("Flashbar is shown at the top")
.build()
}
private fun gravityBottom(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.message("Flashbar is shown at the bottom")
.build()
}
private fun titleBasic(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.title("Hello Flashbar")
.message("You can put any message of any length here.")
.build()
}
private fun titleAdvanced(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.title("Hello World")
.titleColorRes(R.color.white)
.titleSizeInSp(28f)
.message("The font and size of the text is changed here.")
.titleTypeface(Typeface.createFromAsset(assets, "BeautifulAndOpenHearted.ttf"))
.build()
}
private fun messageBasic(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World")
.message(
"This is a short message. But your message can be of any length and the "
+ "with view will dynamically adjust itself. You can try to put "
+ "very long messages as well. This can be really useful for "
+ "putting up a lot of information to the user like feature "
+ "explanation, tutorials, etc.")
.build()
}
private fun messageAdvanced(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World")
.message("This is a short message")
.messageColor(ContextCompat.getColor(this, R.color.white))
.messageSizeInSp(16f)
.messageTypeface(Typeface.createFromAsset(assets, "BeautifulAndOpenHearted.ttf"))
.build()
}
private fun background(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("The background color can be changed to any color of your choice.")
.backgroundColorRes(R.color.colorPrimaryDark)
.build()
}
private fun backgroundDrawable(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can have gradients by setting background drawable.")
.backgroundDrawable(R.drawable.bg_gradient)
.build()
}
private fun overlay(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show a modal overlay to give a dim effect in the entire screen.")
.backgroundColorRes(R.color.colorPrimaryDark)
.showOverlay()
.build()
}
private fun overlayAdvanced(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show a modal overlay to give a dim effect in the entire screen.")
.backgroundColorRes(R.color.colorPrimaryDark)
.showOverlay()
.overlayColorRes(R.color.modal)
.overlayBlockable()
.build()
}
private fun primaryActionBasic(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can click on the primary action button.")
.primaryActionText("TRY")
.build()
}
private fun primaryActionAdvanced(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.backgroundColorRes(R.color.colorPrimaryDark)
.message("You can click on the primary action button.")
.primaryActionText("TRY")
.primaryActionTextColorRes(R.color.colorAccent)
.primaryActionTextSizeInSp(20f)
.build()
}
private fun primaryActionListener(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can click on the primary action button.")
.primaryActionText("TRY")
.primaryActionTapListener(object : Flashbar.OnActionTapListener {
override fun onActionTapped(bar: Flashbar) {
bar.dismiss()
}
})
.build()
}
private fun positiveNegativeAction(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show either or both of the positive/negative buttons and customize them similar to the primary button.")
.backgroundColorRes(R.color.colorPrimaryDark)
.positiveActionText("YES")
.negativeActionText("NO")
.positiveActionTapListener(object : Flashbar.OnActionTapListener {
override fun onActionTapped(bar: Flashbar) {
bar.dismiss()
}
})
.negativeActionTapListener(object : Flashbar.OnActionTapListener {
override fun onActionTapped(bar: Flashbar) {
bar.dismiss()
}
})
.positiveActionTextColorRes(R.color.colorAccent)
.negativeActionTextColorRes(R.color.colorAccent)
.build()
}
private fun iconBasic(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show a default icon on the left side of the with view.")
.showIcon()
.build()
}
private fun iconAdvanced(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show a default icon on the left side of the with view.")
.backgroundColorRes(R.color.colorPrimaryDark)
.showIcon()
.icon(R.drawable.ic_drop)
.iconColorFilterRes(R.color.colorAccent)
.build()
}
private fun progressBasic(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show the progress bar on either the left or right side of the view")
.showProgress(Flashbar.ProgressPosition.LEFT)
.build()
}
private fun progressAdvanced(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show the progress bar on either the left or right side of the view")
.backgroundColorRes(R.color.colorPrimaryDark)
.showProgress(Flashbar.ProgressPosition.RIGHT)
.progressTintRes(R.color.colorAccent)
.build()
}
private fun enterExitAnimation(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can change the enter/exit animation of the flashbar")
.backgroundColorRes(R.color.colorPrimaryDark)
.enterAnimation(FlashAnim.with(this)
.animateBar()
.duration(750)
.alpha()
.overshoot())
.exitAnimation(FlashAnim.with(this)
.animateBar()
.duration(400)
.accelerateDecelerate())
.build()
}
private fun enterExitAnimationSlide(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can change the enter/exit animation of the flashbar")
.backgroundColorRes(R.color.colorPrimaryDark)
.enterAnimation(FlashAnim.with(this)
.animateBar()
.duration(400)
.slideFromLeft()
.overshoot())
.exitAnimation(FlashAnim.with(this)
.animateBar()
.duration(250)
.slideFromLeft()
.accelerate())
.build()
}
private fun iconAnimation(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can show a default icon on the left side of the with view.")
.backgroundColorRes(R.color.colorPrimaryDark)
.showIcon()
.icon(R.drawable.ic_drop)
.iconColorFilterRes(R.color.colorAccent)
.iconAnimation(FlashAnim.with(this)
.animateIcon()
.pulse()
.alpha()
.duration(750)
.accelerate())
.build()
}
private fun showListener(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.title("Hello World!")
.message("You can listen to events when the flashbar is shown.")
.barShowListener(object : Flashbar.OnBarShowListener {
override fun onShowing(bar: Flashbar) {
Log.d(TAG, "Flashbar is showing")
}
override fun onShowProgress(bar: Flashbar, progress: Float) {
Log.d(TAG, "Flashbar is showing with progress: $progress")
}
override fun onShown(bar: Flashbar) {
Log.d(TAG, "Flashbar is shown")
}
})
.build()
}
private fun dismissListener(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.title("Hello World!")
.duration(500)
.message("You can listen to events when the flashbar is dismissed.")
.barDismissListener(object : Flashbar.OnBarDismissListener {
override fun onDismissing(bar: Flashbar, isSwiped: Boolean) {
Log.d(TAG, "Flashbar is dismissing with $isSwiped")
}
override fun onDismissProgress(bar: Flashbar, progress: Float) {
Log.d(TAG, "Flashbar is dismissing with progress $progress")
}
override fun onDismissed(bar: Flashbar,
event: Flashbar.DismissEvent) {
Log.d(TAG, "Flashbar is dismissed with event $event")
}
})
.build()
}
private fun barTap(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can listen to tap events inside or outside te bar.")
.listenBarTaps(object : Flashbar.OnTapListener {
override fun onTap(flashbar: Flashbar) {
Log.d(TAG, "Bar tapped")
}
})
.listenOutsideTaps(object : Flashbar.OnTapListener {
override fun onTap(flashbar: Flashbar) {
Log.d(TAG, "Outside tapped")
}
})
.build()
}
private fun swipeToDismiss(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.TOP)
.title("Hello World!")
.message("You can swipe the flashbar to dismiss it.")
.enableSwipeToDismiss()
.build()
}
private fun barShadow(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.title("Hello World!")
.message("You can swipe the flashbar to dismiss it.")
.castShadow(true, 4)
.build()
}
private fun vibration(): Flashbar {
return Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.title("Hello World!")
.message("You can swipe the flashbar to dismiss it.")
.vibrateOn(Flashbar.Vibration.SHOW, Flashbar.Vibration.DISMISS)
.build()
}
}