Skip to content

Instantly share code, notes, and snippets.

View vudunguit's full-sized avatar

Vu Dung vudunguit

  • Project Kanzen
  • Ho Chi Minh city, Viet Nam
View GitHub Profile
@vudunguit
vudunguit / BadgedFourThreeImageView
Last active August 18, 2016 10:26
ImageView support set badge drawable(gift...). I just extracted the widgets from Plaid app developed by Nick Butcher(https://github.com/nickbutcher).
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
@vudunguit
vudunguit / ViewPagerFragmentAdapter
Created September 7, 2016 02:48
Utils class for viewpager adapter with fragment content
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.text.TextUtils;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@vudunguit
vudunguit / RxEventBus.java
Created September 9, 2016 07:29 — forked from nicolasjafelle/RxEventBus.java
Event Bus implementation with RxJava. It also post all event in the UI Thread.
import android.os.Handler;
import android.os.Looper;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import rx.Subscription;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.internal.util.SubscriptionList;
@vudunguit
vudunguit / AddCookiesInterceptor.java
Created September 13, 2016 02:11 — forked from tsuharesu/AddCookiesInterceptor.java
Handle Cookies easily with Retrofit/OkHttp
/**
* This interceptor put all the Cookies in Preferences in the Request.
* Your implementation on how to get the Preferences MAY VARY.
* <p>
* Created by tsuharesu on 4/1/15.
*/
public class AddCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
@vudunguit
vudunguit / LocationHelper
Created September 26, 2016 08:35
LocationHelper is a class help deal with location service
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@vudunguit
vudunguit / color hex percentage
Created February 24, 2017 04:07
Android Material Design Colours
100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
93% — ED
92% — EB
91% — E8
@vudunguit
vudunguit / RxJava.md
Created May 3, 2017 04:18 — forked from cesarferreira/RxJava.md
Party tricks with RxJava, RxAndroid & Retrolambda

View Click

Instead of the verbose setOnClickListener:

RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));

Filter even numbers

Observable
    .just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
@vudunguit
vudunguit / TabControler.kt
Last active April 18, 2018 08:04
Class help views check change controller, same RadioGroup but more flexible
import android.view.View
class TabControler : View.OnClickListener {
private var listener: OnCheckedChangeListener? = null
private val tabs = mutableListOf<View>()
private var lastSelected: Int = 0
fun setTabs(firstSelected: Int, vararg views: View) {
tabs.clear()
for (i in views.indices) {
@vudunguit
vudunguit / InstaModel
Created August 9, 2017 02:53
Instagram accesstoken (sample)
public class InstaModel {
public static final String CLIENT_ID = "31f1cc932c264e5da2711ad437753c78";
public static final String CLIENT_SECRET = "3db8f5ff74474cadba35a6a2bf518b5d";
public static final String CALLBACK_URL = "https://medium.com/@vutiendunguit";
public static final String GRANT_TYPE = "authorization_code";
public static final String AUTH_URL = "https://api.instagram.com/oauth/authorize/";
public static final String TOKEN_URL = "https://api.instagram.com/oauth/access_token";
public static final String API_URL = "https://api.instagram.com/v1";
@vudunguit
vudunguit / BuildOkHttpClient
Created May 10, 2018 11:08
Cache OkHttpClient
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(new RewriteRequestInterceptor())
.addNetworkInterceptor(new RewriteResponseCacheControlInterceptor())