Skip to content

Instantly share code, notes, and snippets.

@jacobmoncur
Created January 15, 2016 04:57
Show Gist options
  • Save jacobmoncur/3cc4371c495cf75ca3c5 to your computer and use it in GitHub Desktop.
Save jacobmoncur/3cc4371c495cf75ca3c5 to your computer and use it in GitHub Desktop.

Extension Functions

Animator anim = ObjectAnimator.ofFloat(mainView, "translationY", 500.f);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(300);
anim.setStartDelay(100);

Animator anim1 = ObjectAnimator.ofFloat(otherView, "translationY", 200.f);
anim1.setInterpolator(new AccelerateDecelerateInterpolator());
anim1.setDuration(300);
anim1.setStartDelay(100);

...

Animator anim8 = ObjectAnimator.ofFloat(topView, "translationY", 100.f);
anim8.setInterpolator(new AccelerateDecelerateInterpolator());
anim8.setDuration(300);
anim8.setStartDelay(100);

AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(anim, anim1, ..., anim8);
animatorSet.start();
var animatorSet = AnimatorSet()
animatorSet.playTogether(
  mainView.translateY(300),
  otherView.translateY(200, delay = 60),
  ...
  topView.translateY(dip(500), delay = 120)
)
animatorSet.start()
fun SharedPreferences.edit(func: SharedPreferences.Editor.() -> Unit){
    val editor = edit()
    editor.func()
    editor.apply()
}

fun SharedPreferences.Editor.set(pair: Pair<String, String>) = putString(pair.first, pair.second)

val preferences = PreferenceManager.getDefaultSharedPreferences(context)

preferences.edit {
    set("test" to "other")
    set("this" to "that")
    remove("nothing")
}
fun View.showKeyboard() {
    var inputManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
}

editText.showKeyboard()
inline fun notification(context: Context, func: Notification.Builder.() -> Unit): Notification {
    val builder = Notification.Builder(context)
    builder.func()
    return builder.build()
}

val notification = notification(context) {
    setSmallIcon(R.drawable.small_icon)
    setContentTitle("")
    setContentText(message)
    setAutoCancel(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment