This file contains hidden or 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
#!/bin/bash | |
# | |
# Written by Chris Arceneaux | |
# GitHub: https://github.com/carceneaux | |
# Email: [email protected] | |
# Website: http://arsano.ninja | |
# | |
# Updated by Miloš Černilovský | |
# GitHub: https://github.com/milhauscz | |
# |
This file contains hidden or 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
<resources> | |
<declare-styleable name="MaterialSpinner"> | |
<attr name="emptyText" format="reference|string" /> | |
</declare-styleable> | |
</resources> |
This file contains hidden or 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
@BindingAdapter("selectedPosition") | |
fun setSelectedPosition(view: MaterialSpinner, position: Int) { | |
if (view.selectedPosition != position) { | |
view.selectedPosition = position | |
} | |
} | |
@InverseBindingAdapter(attribute = "selectedPosition") | |
fun getSelectedPosition(view: MaterialSpinner): Int { | |
return view.selectedPosition |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<data> | |
<import type="com.google.android.material.textfield.TextInputLayout" /> | |
<variable | |
name="viewModel" | |
type="com.example.SpinnerViewModel" /> |
This file contains hidden or 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
@BindingAdapter("items") | |
fun bindItems(view: MaterialSpinner, items: List<ExampleItem>?) { | |
if (items == null) return | |
view.setAdapter(ExampleSpinnerArrayAdapter(view.context, items)) | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<data> | |
<variable | |
name="item" | |
type="com.example.ExampleItem" /> |
This file contains hidden or 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
class ExampleSpinnerArrayAdapter(context: Context, objects: List<ExampleItem>) : MaterialSpinnerAdapter<ExampleItem>(context, objects) { | |
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | |
// implement viewholder pattern | |
val view: View | |
// automatically generated binding class | |
val binding: ExampleItemBinding | |
if (convertView == null) { | |
// view is new - we have to inflate the binding object and set it as a tag | |
binding = ExampleItemBinding.inflate(inflater, parent, false) | |
view = binding.root |
This file contains hidden or 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
/** | |
* Custom adapter for [MaterialSpinner]. Just implement [getView] to provide the given View, e. g. | |
* by using [inflater]. In case of data binding, the binding object can be set as the given View's | |
* tag to be able to retrieve it when reusing the given View and implement custom viewholder pattern. | |
* [selectedItemPosition] can be used for updating the selected View's UI. When used together with | |
* [MaterialSpinner], [selectedItemPosition] is updated automatically and [notifyDataSetChanged] is called. | |
* | |
* Created by Milos Cernilovsky on 4/21/21 | |
*/ | |
abstract class MaterialSpinnerAdapter<T>(context: Context, private val objects: List<T>) : BaseAdapter(), Filterable { |
This file contains hidden or 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
/** | |
* Custom implementation of an Android spinner (combo box) with material theme by using AutocompleteTextView. | |
* Recommended to use together with [MaterialSpinnerAdapter]. | |
* | |
* Supports listening to and updating the selected position e. g. from a LiveData object bound via | |
* the `selectedPosition` two-way binding adapter. The empty text value can be bound via 'emptyText' | |
* attr (custom styleable must be declared in attrs.xml). | |
* | |
* If [MaterialSpinnerAdapter] is used, its [MaterialSpinnerAdapter.selectedItemPosition] is | |
* automatically updated when selection changes. |
This file contains hidden or 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
/** | |
* Should be called from [Activity.onCreate]. | |
* @see hideSystemUI | |
* @see showSystemUI | |
*/ | |
fun Activity.showBelowCutout() { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | |
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER | |
} | |
} |
NewerOlder