|
| 1 | +package com.yuvraj.livesmashbardemo |
| 2 | + |
| 3 | +import android.arch.lifecycle.LifecycleOwner |
| 4 | +import android.arch.lifecycle.MutableLiveData |
| 5 | +import android.os.Bundle |
| 6 | +import android.os.Handler |
| 7 | +import android.support.v4.content.ContextCompat |
| 8 | +import android.support.v7.app.AppCompatActivity |
| 9 | +import android.support.v7.widget.LinearLayoutManager |
| 10 | +import com.yuvraj.livesmashbar.anim.AnimIconBuilder |
| 11 | +import com.yuvraj.livesmashbar.enums.BarStyle |
| 12 | +import com.yuvraj.livesmashbar.enums.DismissEvent |
| 13 | +import com.yuvraj.livesmashbar.enums.GravityView |
| 14 | +import com.yuvraj.livesmashbar.lintener.OnEventDismissListener |
| 15 | +import com.yuvraj.livesmashbar.lintener.OnEventListener |
| 16 | +import com.yuvraj.livesmashbar.lintener.OnEventShowListener |
| 17 | +import com.yuvraj.livesmashbar.lintener.OnEventTapListener |
| 18 | +import com.yuvraj.livesmashbar.view.LiveSmashBar |
| 19 | +import kotlinx.android.synthetic.main.activity_sample.* |
| 20 | + |
| 21 | +class SampleActivity : AppCompatActivity(), OnEventTapListener, |
| 22 | + OnEventListener, OnEventDismissListener, OnEventShowListener, |
| 23 | + SampleRecyclerAdapter.OnItemClickListener, LifecycleOwner { |
| 24 | + |
| 25 | + var listSamples = arrayListOf<String>(); |
| 26 | + |
| 27 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 28 | + super.onCreate(savedInstanceState) |
| 29 | + setContentView(R.layout.activity_sample) |
| 30 | + |
| 31 | + createSamplesList(); |
| 32 | + |
| 33 | + recycler_samples.layoutManager = LinearLayoutManager(this); |
| 34 | + recycler_samples.adapter = SampleRecyclerAdapter(this, listSamples, this); |
| 35 | + } |
| 36 | + |
| 37 | + private fun createSamplesList() { |
| 38 | + listSamples.add("Simple LiveSmashBar") |
| 39 | + listSamples.add("Simple LiveSmashBar with Icon & Action button") |
| 40 | + listSamples.add("Simple Dialog LiveSmashBar with Icon & Action button") |
| 41 | + listSamples.add("Simple Overlay LiveSmashBar") |
| 42 | + listSamples.add("Simple LiveSmashBar using LiveData & LifecycleOwner") |
| 43 | + listSamples.add("Simple LiveSmashBar with Gravity Top") |
| 44 | + listSamples.add("Simple LiveSmashBar with Gravity Top , Icon & Action button") |
| 45 | + listSamples.add("Simple Dialog LiveSmashBar with Gravity Top , Icon & Action button") |
| 46 | + listSamples.add("Simple Dialog LiveSmashBar with Gravity Top") |
| 47 | + listSamples.add("Simple LiveSmashBar Pulse Animation effect") |
| 48 | + } |
| 49 | + |
| 50 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 51 | + |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | + override fun onTap(liveSmashBar: LiveSmashBar) { |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | + override fun onDismissing(bar: LiveSmashBar, isSwiped: Boolean) { |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + override fun onDismissProgress(bar: LiveSmashBar, progress: Float) { |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + override fun onDismissed(bar: LiveSmashBar, event: DismissEvent) { |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + override fun onShowing(bar: LiveSmashBar) { |
| 72 | + |
| 73 | + } |
| 74 | + |
| 75 | + override fun onShowProgress(bar: LiveSmashBar, progress: Float) { |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + override fun onShown(bar: LiveSmashBar) { |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + override fun onItemClick(position: Int) { |
| 84 | + when (position) { |
| 85 | + 0 -> |
| 86 | + LiveSmashBar.Builder(this) |
| 87 | + .title(getString(R.string.title)) |
| 88 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 89 | + .description(getString(R.string.description)) |
| 90 | + .descriptionColor(ContextCompat.getColor(this, R.color.white)) |
| 91 | + .gravity(GravityView.BOTTOM) |
| 92 | + .duration(3000) |
| 93 | + .show(); |
| 94 | + |
| 95 | + 1 -> |
| 96 | + LiveSmashBar.Builder(this) |
| 97 | + .icon(R.mipmap.ic_launcher) |
| 98 | + .title(getString(R.string.title)) |
| 99 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 100 | + .description(getString(R.string.description)) |
| 101 | + .descriptionColor(ContextCompat.getColor(this, R.color.white)) |
| 102 | + .gravity(GravityView.BOTTOM) |
| 103 | + .duration(3000) |
| 104 | + .primaryActionText("DONE") |
| 105 | + .primaryActionTextColor(ContextCompat.getColor(this, R.color.white)) |
| 106 | + .primaryActionEventListener(object : OnEventTapListener { |
| 107 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 108 | + bar.dismiss() |
| 109 | + } |
| 110 | + }) |
| 111 | + .show(); |
| 112 | + |
| 113 | + 2 -> |
| 114 | + LiveSmashBar.Builder(this) |
| 115 | + .icon(R.mipmap.ic_launcher) |
| 116 | + .title(getString(R.string.title)) |
| 117 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 118 | + .description(getString(R.string.description)) |
| 119 | + .descriptionColor(ContextCompat.getColor(this, R.color.white)) |
| 120 | + .gravity(GravityView.BOTTOM) |
| 121 | + .backgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)) |
| 122 | + .setBarStyle(BarStyle.DIALOG) |
| 123 | + .positiveActionText("DONE") |
| 124 | + .positiveActionTextColor(ContextCompat.getColor(this, R.color.white)) |
| 125 | + .positiveActionEventListener(object : OnEventTapListener { |
| 126 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 127 | + bar.dismiss() |
| 128 | + } |
| 129 | + }) |
| 130 | + .negativeActionText("CLOSE") |
| 131 | + .negativeActionTextColor(ContextCompat.getColor(this, R.color.white)) |
| 132 | + .negativeActionEventListener(object : OnEventTapListener { |
| 133 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 134 | + bar.dismiss() |
| 135 | + } |
| 136 | + }) |
| 137 | + .show(); |
| 138 | + 3 -> |
| 139 | + LiveSmashBar.Builder(this) |
| 140 | + .showIcon() |
| 141 | + .icon(R.mipmap.ic_launcher) |
| 142 | + .title(getString(R.string.flutter_title)) |
| 143 | + .titleColor(ContextCompat.getColor(this, R.color.slate_black)) |
| 144 | + .description(getString(R.string.flutter_info)) |
| 145 | + .descriptionColor(ContextCompat.getColor(this, R.color.slate_black)) |
| 146 | + .gravity(GravityView.BOTTOM) |
| 147 | + .dismissOnTapOutside() |
| 148 | + .showOverlay() |
| 149 | + .overlayBlockable() |
| 150 | + .backgroundColor(ContextCompat.getColor(this, R.color.white)) |
| 151 | + .show(); |
| 152 | + |
| 153 | + 4 -> { |
| 154 | + |
| 155 | + val liveData: MutableLiveData<Unit> = MutableLiveData() |
| 156 | + |
| 157 | + LiveSmashBar.Builder(this) |
| 158 | + .showIcon() |
| 159 | + .icon(R.mipmap.ic_launcher) |
| 160 | + .title(getString(R.string.flutter_title)) |
| 161 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 162 | + .description(getString(R.string.flutter_info)) |
| 163 | + .descriptionColor(ContextCompat.getColor(this, R.color.white)) |
| 164 | + .gravity(GravityView.BOTTOM) |
| 165 | + .duration(3000) |
| 166 | + .liveDataCallback(this, liveData) |
| 167 | + |
| 168 | + Handler().postDelayed({ |
| 169 | + liveData.postValue(Unit) |
| 170 | + }, 2000) |
| 171 | + } |
| 172 | + |
| 173 | + 5 -> |
| 174 | + LiveSmashBar.Builder(this) |
| 175 | + .icon(R.mipmap.ic_launcher) |
| 176 | + .title(getString(R.string.description)) |
| 177 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 178 | + .gravity(GravityView.TOP) |
| 179 | + .duration(3000) |
| 180 | + .show() |
| 181 | + |
| 182 | + 6 -> |
| 183 | + LiveSmashBar.Builder(this) |
| 184 | + .showIcon() |
| 185 | + .icon(R.mipmap.ic_launcher) |
| 186 | + .title(getString(R.string.flutter_title)) |
| 187 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 188 | + .description(getString(R.string.flutter_info)) |
| 189 | + .descriptionColor(ContextCompat.getColor(this, R.color.white)) |
| 190 | + .gravity(GravityView.TOP) |
| 191 | + .duration(3000) |
| 192 | + .primaryActionText("DONE") |
| 193 | + .primaryActionTextColor(ContextCompat.getColor(this, R.color.white)) |
| 194 | + .primaryActionEventListener(object : OnEventTapListener { |
| 195 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 196 | + bar.dismiss() |
| 197 | + } |
| 198 | + }) |
| 199 | + .show() |
| 200 | + |
| 201 | + 7 -> |
| 202 | + LiveSmashBar.Builder(this) |
| 203 | + .icon(R.mipmap.ic_launcher) |
| 204 | + .title(getString(R.string.title)) |
| 205 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 206 | + .description(getString(R.string.description)) |
| 207 | + .descriptionColor(ContextCompat.getColor(this, R.color.white)) |
| 208 | + .gravity(GravityView.TOP) |
| 209 | + .setBarStyle(BarStyle.DIALOG) |
| 210 | + .positiveActionText("DONE") |
| 211 | + .positiveActionTextColor(ContextCompat.getColor(this, R.color.white)) |
| 212 | + .positiveActionEventListener(object : OnEventTapListener { |
| 213 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 214 | + bar.dismiss() |
| 215 | + } |
| 216 | + }) |
| 217 | + .negativeActionText("CLOSE") |
| 218 | + .negativeActionTextColor(ContextCompat.getColor(this, R.color.white)) |
| 219 | + .negativeActionEventListener(object : OnEventTapListener { |
| 220 | + override fun onActionTapped(bar: LiveSmashBar) { |
| 221 | + bar.dismiss() |
| 222 | + } |
| 223 | + }) |
| 224 | + .show(); |
| 225 | + |
| 226 | + 8 -> |
| 227 | + LiveSmashBar.Builder(this) |
| 228 | + .showIcon() |
| 229 | + .icon(R.mipmap.ic_launcher) |
| 230 | + .title(getString(R.string.flutter_title)) |
| 231 | + .titleColor(ContextCompat.getColor(this, R.color.slate_black)) |
| 232 | + .description(getString(R.string.flutter_info)) |
| 233 | + .descriptionColor(ContextCompat.getColor(this, R.color.slate_black)) |
| 234 | + .gravity(GravityView.TOP) |
| 235 | + .dismissOnTapOutside() |
| 236 | + .showOverlay() |
| 237 | + .overlayBlockable() |
| 238 | + .backgroundColor(ContextCompat.getColor(this, R.color.white)) |
| 239 | + .show(); |
| 240 | + |
| 241 | + 9 -> |
| 242 | + LiveSmashBar.Builder(this) |
| 243 | + .icon(R.mipmap.ic_launcher) |
| 244 | + .iconAnimation(AnimIconBuilder(this).pulse()) |
| 245 | + .title(getString(R.string.description)) |
| 246 | + .titleColor(ContextCompat.getColor(this, R.color.white)) |
| 247 | + .gravity(GravityView.TOP) |
| 248 | + .duration(3000) |
| 249 | + .show() |
| 250 | + } |
| 251 | + } |
| 252 | +} |
0 commit comments