Skip to content

Instantly share code, notes, and snippets.

View ubuntudroid's full-sized avatar

Sven Bendel ubuntudroid

View GitHub Profile
<string name="some_string">Hello %1$s</string>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap content"
android:text="Hello, gradient!"
app:background_gradient_colors="@{@intArray/some_colors}"/>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="some_colors">
<item>@color/color0</item>
<item>@color/color1</item>
<item>@color/color2</item>
<item>@color/color3</item>
<item>@color/color4</item>
</integer-array>
</resources>
object ViewBindingAdapters {
@JvmStatic
@BindingAdapter("background_gradient_colors")
fun setBackgroundColors(view: View, colors: IntArray) {
view.background = GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT,
colors
)
}
def localPropertyApiToken = … // read api token from local.properties
def systemEnvApiToken = … // read api token from system environment variable
ext.api_token = localPropertyApiToken != null ? localPropertyApiToken : systemEnvApiToken
Properties properties = new Properties()
def propertiesFile = project.rootProject.file('local.properties')
if (propertiesFile.exists()) {
 properties.load(propertiesFile.newDataInputStream())
}
ext.apiToken = properties.getProperty('api.token')
ext.apiToken = System.getenv('API_TOKEN') // replace the ext. prefix with def if you don’t want to provide the API token to the default properties which you can then access from all your build scripts
api.token=123456789abcdef
class SidebarPresenter(val userInfoRepository: UserInfoRepository) {
fun init() {
...
userInfoRepository
.getNameStateObservable()
.mergeWith(
Observable.from(arrayOf("Arthur Dent", "Genghis Temüjin Khan", "Know-Nothing Bozo the Non-Wonder Dog", ""))
.zipWith(
Observable.interval(5, TimeUnit.SECONDS),
class SidebarPresenter(val userInfoRepository: UserInfoRepository) {
fun init() {
...
userInfoRepository
.getNameStateObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe { userName -> userNameTextView.setText(userName) }
...
}