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
//Double click detection | |
var timeSaver = 0L // Globaly | |
view.setOnTouchListener { _, event -> | |
when(event.action) { | |
MotionEvent.ACTION_DOWN -> { | |
if (System.currentTimeMillis() - timeSaver <= 500) { | |
// Do with double click | |
Toast.makeText(this, "DOUBLE_CLICK", Toast.LENGTH_SHORT).show() | |
} | |
timeSaver = System.currentTimeMillis() |
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
//Check network with RxJava2 | |
@SuppressLint("MissingPermission") // AccessNetworkState -> Add it yourself | |
fun isInternetOn(context: Context): Observable<Boolean> { | |
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val activeNetworkInfo: NetworkInfo? | |
activeNetworkInfo = connectivityManager.activeNetworkInfo | |
return Observable.just(activeNetworkInfo != null && activeNetworkInfo.isConnected) | |
.map { it } | |
.distinctUntilChanged() |
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
public void singleFadeInView(View v, long duration, final Consumer<Animation> onAnimEnd) { | |
AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f); | |
anim.setDuration(duration); | |
anim.setAnimationListener(new Animation.AnimationListener() { | |
@Override | |
public void onAnimationStart(Animation animation) {} | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
onAnimEnd.accept(animation); |
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
import android.content.Context; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.GestureDetector; | |
import android.view.MotionEvent; | |
import android.view.View; | |
public class ListClick implements RecyclerView.OnItemTouchListener { |
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
//Ted Permission is a great permission library to manage Runtime permission added since Android 6.0(Marshmallow) | |
//This example Uses RxJava 2 to get permission. | |
/** | |
* <b>Remember this need one dependency code</b> | |
* Code: implementation 'gun0912.ted:tedpermission-rx2:2.2.0' // Or later | |
* Might also need: implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' //Or later | |
* @param c is the Context | |
* @param deniedTitle is the Title when permission denied and you are showing a message that you need it | |
* @param deniedMessage is the Message | |
* @param doWithPermissionResult is a function that has a Boolean. If true the permission is granted |
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
/** | |
* Creates a 3D flip animation between two views. | |
* | |
* @param fromView First view in the transition. | |
* @param toView Second view in the transition. | |
*/ | |
class FlipAnimation(private var fromView: View?, private var toView: View?) : Animation() { | |
private var camera: Camera? = null | |
private var centerX: Float = 0.toFloat() |
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
import android.content.Context; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.GestureDetector; | |
import android.view.MotionEvent; | |
import android.view.View; | |
public class ListClick implements RecyclerView.OnItemTouchListener { | |
private GestureDetector gestureDetector; | |
private ClickListener clickListener; |
NewerOlder