-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98bcfb2
commit a8cfdfa
Showing
10 changed files
with
248 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/kienht/bubble_picker/AsyncActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.kienht.bubble_picker | ||
|
||
import android.content.res.TypedArray | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.Toast | ||
import com.kienht.bubblepicker.BubblePickerListener | ||
import com.kienht.bubblepicker.adapter.BubblePickerAdapter | ||
import com.kienht.bubblepicker.model.BubbleGradient | ||
import com.kienht.bubblepicker.model.PickerItem | ||
import com.kienht.bubblepicker.rendering.BubblePicker | ||
|
||
/** | ||
* @author kienht | ||
* @since 20/07/2018 | ||
*/ | ||
class AsyncActivity : AppCompatActivity(), BubblePickerListener { | ||
|
||
lateinit var images: TypedArray | ||
lateinit var colors: TypedArray | ||
|
||
private var picker: BubblePicker? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.async_activity) | ||
|
||
val titles = resources.getStringArray(R.array.countries) | ||
colors = resources.obtainTypedArray(R.array.colors) | ||
images = resources.obtainTypedArray(R.array.images) | ||
|
||
Handler().postDelayed({ | ||
picker = BubblePicker(this, null) | ||
picker!!.adapter = object : BubblePickerAdapter { | ||
override val totalCount = titles.size | ||
|
||
override fun getItem(position: Int): PickerItem { | ||
return PickerItem().apply { | ||
title = titles[position] | ||
gradient = BubbleGradient(colors.getColor((position * 2) % 8, 0), | ||
colors.getColor((position * 2) % 8 + 1, 0), BubbleGradient.VERTICAL) | ||
} | ||
} | ||
} | ||
|
||
picker!!.bubbleSize = 10 | ||
picker!!.listener = this@AsyncActivity | ||
|
||
setContentView(picker) | ||
|
||
}, 3000) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
if (picker != null) { | ||
picker!!.onResume() | ||
} | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
if (picker != null) { | ||
picker!!.onPause() | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
colors.resources | ||
images.resources | ||
} | ||
|
||
override fun onBubbleSelected(item: PickerItem) { | ||
toast("Selected: " + item.title!!) | ||
} | ||
|
||
override fun onBubbleDeselected(item: PickerItem) { | ||
toast("Unselected: " + item.title!!) | ||
} | ||
|
||
private fun toast(text: String) = Toast.makeText(this, text, Toast.LENGTH_SHORT).show() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/kienht/bubble_picker/SyncActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.kienht.bubble_picker | ||
|
||
import android.content.res.TypedArray | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.Toast | ||
import com.kienht.bubblepicker.BubblePickerListener | ||
import com.kienht.bubblepicker.adapter.BubblePickerAdapter | ||
import com.kienht.bubblepicker.model.BubbleGradient | ||
import com.kienht.bubblepicker.model.PickerItem | ||
import kotlinx.android.synthetic.main.sync_activity.* | ||
|
||
/** | ||
* @author kienht | ||
* @since 20/07/2018 | ||
*/ | ||
class SyncActivity : AppCompatActivity() { | ||
|
||
lateinit var images: TypedArray | ||
lateinit var colors: TypedArray | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.sync_activity) | ||
|
||
val titles = resources.getStringArray(R.array.countries) | ||
colors = resources.obtainTypedArray(R.array.colors) | ||
images = resources.obtainTypedArray(R.array.images) | ||
|
||
picker.adapter = object : BubblePickerAdapter { | ||
override val totalCount = titles.size | ||
|
||
override fun getItem(position: Int): PickerItem { | ||
return PickerItem().apply { | ||
title = titles[position] | ||
gradient = BubbleGradient(colors.getColor((position * 2) % 8, 0), | ||
colors.getColor((position * 2) % 8 + 1, 0), BubbleGradient.VERTICAL) | ||
imgUrl = "http://sohanews.sohacdn.com/2018/4/11/hat9-1523392964439195574255.jpg" | ||
} | ||
} | ||
} | ||
|
||
picker.bubbleSize = 10 | ||
picker.listener = object : BubblePickerListener { | ||
override fun onBubbleDeselected(item: PickerItem) { | ||
toast("Unselected: " + item.title!!) | ||
} | ||
|
||
override fun onBubbleSelected(item: PickerItem) { | ||
toast("Selected: " + item.title!!) | ||
} | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
picker.onResume() | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
picker.onPause() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
colors.resources | ||
images.resources | ||
} | ||
|
||
private fun toast(text: String) = Toast.makeText(this, text, Toast.LENGTH_SHORT).show() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/white" | ||
android:orientation="vertical"> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:background="@android:color/white" | ||
android:orientation="vertical"> | ||
|
||
<com.kienht.bubblepicker.rendering.BubblePicker | ||
android:id="@+id/picker" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:backgroundColor="@android:color/white" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.