Skip to content

Instantly share code, notes, and snippets.

@hilfritz
hilfritz / gist:db7b343f74eec965c343059fbb559705
Created August 3, 2017 06:29 — forked from orhanobut/gist:8665372
Up down animation for dialog fragment
// Slide up animation
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toXDelta="0" />
@hilfritz
hilfritz / README.md
Created August 3, 2017 06:30 — forked from polbins/README.md
Android Response Caching using Retrofit 1.9 + OkHttp 2.2

Android REST Controller with Cache-Control

Android REST Controller with Simple Cache Control Headers using Retrofit 1.9.0 + OkHttp 2.2.0

@hilfritz
hilfritz / gist:80449f31db05c3e393e4da84076feb24
Created November 16, 2017 03:01
Java: convert Map to Bundle
public Bundle convertMapToBundle(Map<String, String> data){
Bundle bundle = new Bundle();
for (Map.Entry<String, String> entry : data.entrySet()) {
bundle.putString(entry.getKey(), entry.getValue());
}
return bundle;
}
@hilfritz
hilfritz / ViewUtil.kt
Created November 17, 2017 08:24
Android Kotlin ViewUtil class
class ViewUtil {
fun disableButtonsTemporarily(viewList:ArrayList<View>){
try{
//DISABLE THE VIEW
updateViewsClickableAttribute(viewList, false)
//ENABLE THE VIEWS
val handler = Handler()
handler.postDelayed( {
// Do something after 5s = 5000ms
@hilfritz
hilfritz / LoginContracts.kt
Last active November 17, 2017 09:02
Viper explanations
//https://cheesecakelabs.com/blog/using-viper-architecture-android/
class LoginContracts {
interface View {
//1. this are the methods the presenter the contract can call (for displaying data)
// - implemented by fragment/activity/view
fun goToHomeScreen(user: User)
fun showError(message: String)
}
interface Presenter {
@hilfritz
hilfritz / gist:c34aaaacef191830ff80cd9b72cc8e6f
Last active November 23, 2017 06:37
Android Kotlin Clean Arch Boilerplates
-------------------------------------------------------------------
------------------------build.gradle-------------------------------
-------------------------------------------------------------------
/**
* RxJava2 and RxAndroid2 gradle setup
implementation 'com.android.support:design:26.1.0'
compile group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.5'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
*/
@hilfritz
hilfritz / Add filter to edittext
Last active November 28, 2017 06:52
Limit the inputs the edittext will receive
/**
* Usage:
* val limit0to24 = EditTextInputFilter(0, 23)
* val limitChars = EditTextInputFilter(arrayListOf("a","b","c","d","e","f","g","h", "ab", "cd"))
* input1.setFilters(arrayOf(limit0to24))
* input2.setFilters(arrayOf(limitChars))
*
*/
class EditTextInputFilter : InputFilter {
@hilfritz
hilfritz / gist:bc97f6844343b3a36d17637a08ab8881
Created January 15, 2018 06:31
Android show/hide view with fade
private void animateCountdown(final View textView){
ValueAnimator valueAnimator = ValueAnimator.ofFloat(1f, 0f);
valueAnimator.setDuration(800);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float alpha = Float.parseFloat(animation.getAnimatedValue().toString());
textView.setAlpha(alpha);
}
});
@hilfritz
hilfritz / gist:23ae7e8072de6f9ff1577a439828e016
Created June 5, 2018 06:42
Scrollable TextView inside Recyclerview
//recyclerview list item layout xml with scrollable textview
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
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"
android:orientation="vertical"
> <TextView
//kotlin code
editText.
filters = arrayOf<InputFilter>(object : InputFilter.AllCaps() {
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence {
return source.toString().toLowerCase()
}
})
//xml layout
<?xml version="1.0" encoding="utf-8"?>