Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Butcher nickbutcher

View GitHub Profile
View vector_gradient_inline_resource_syntax.xml
<!-- Copyright 2018 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<vector ...>
<path android:pathData="...">
<aapt:attr name="android:fillColor">
<gradient .../>
</aapt:attr>
</path>
</vector>
View vector_cheeky_animated_state_list.xml
<!-- Copyright 2018 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<animated-selector ...>
<item android:state_foo="true" android:drawable="@drawable/some_vector" />
<item android:drawable="@drawable/some_other_vector" />
<!-- no transitions specified -->
</animated-selector>
View vector_progressbar_binding_adapter_usage.xml
<!-- Copyright 2018 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<layout ...>
<data>
<import type="your.package.R" alias="R" />
...
</data>
<ProgressBar ...
app:indeterminateDrawableCompat="@{R.drawable.foo}" />
View vector_LoadCompatDrawable.kt
/* Copyright 2018 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
val progressBar = findViewById<ProgressBar>(R.id.loading)
val drawable = AppCompatResources.getDrawable(context, R.drawable.loading_indeterminate)
progressBar.indeterminateDrawable = drawable
View vector_ProgressBarBindingAdapter.kt
/* Copyright 2018 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@BindingAdapter("indeterminateDrawableCompat")
fun bindIndeterminateProgress(progressBar: ProgressBar, @DrawableRes id: Int) {
val drawable = AppCompatResources.getDrawable(progressBar.context, id)
progressBar.indeterminateDrawable = drawable
}
View vector_context_theme_wrapper.kt
/* Copyright 2018 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
val themedContext = ContextThemeWrapper(context, R.style.baz)
val drawable = AppCompatResources.getDrawable(themedContext, R.drawable.vector)
@nickbutcher
nickbutcher / timestamp.sh
Created Apr 3, 2017
A script for setting creation and modification dates on all files within a folder. Specify the first date in the script then all files are stamped in alphabetical order, increasing by 1s.
View timestamp.sh
USAGE="Set the desired date/time in the script and then call: timestamp /path/to/folder"
DATE="022109002017" # month day hour min year
if (( $# != 1 )); then
echo "Illegal parameters"
echo $USAGE
exit 2
fi
if [ ! -d $1 ]; then
View ShowbizView.kt
/*
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@nickbutcher
nickbutcher / avd_bundle.xml
Last active Jun 20, 2019
An example of the Android xml bundle format for creating an AnimatedVectorDrawable. See https://plus.google.com/+NickButcher/posts/A8KKxnJdg4r
View avd_bundle.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
View naive_animated_binding.kt
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
fun animateVisibility(view: View, visible: Boolean) {
view.visibility = View.VISIBLE
if (visible) {
ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f).start()
} else {
ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f).apply {
doOnEnd { view.visibility = View.GONE }
}.start()