Skip to content

Instantly share code, notes, and snippets.

View colinmadere's full-sized avatar
🛵
N/A

Colin Madere colinmadere

🛵
N/A
View GitHub Profile
@colinmadere
colinmadere / UnauthorizedInterceptor.kt
Created April 21, 2017 21:52
OkHttp (Retrofit) unauthorized redirect interceptor
class UnauthorizedRedirectInterceptor(val appContext: Context) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(chain.request())
if (response.code() == 401) {
val intent = Intent(appContext, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
appContext.startActivity(intent)
}
return response
@colinmadere
colinmadere / CooperativeScrollGestureListener.java
Last active August 29, 2015 14:13
CooperativeScrollGestureListener
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ViewGroup;
/**
* Detects if scroll gesture happens, and if the secondary (often, the "inner" scrollable is at the
* edge in the direction the gesture is in, have the primary scrollable process the gesture
*/
public class CooperativeScrollGestureListener implements GestureDetector.OnGestureListener {
@colinmadere
colinmadere / progress_bar_circular_green.xml
Created October 28, 2014 18:28
Counter-clockwise circle progress bar that starts at the top
meter.setProgressDrawable(getResources().getDrawable(R.drawable.progress_bar_circular_green));
// rotate circle progress bar to make it look like it's counter-clockwise and starting at the top
meter.setRotation((-progress / 100f * 360f) - 90f);
meter.setVisibility(View.VISIBLE);
meter.setProgress(progress);