Skip to content

Instantly share code, notes, and snippets.

@VivekNeel
Created May 15, 2017 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VivekNeel/639328e6e383a3b2cd04b096e239498f to your computer and use it in GitHub Desktop.
Save VivekNeel/639328e6e383a3b2cd04b096e239498f to your computer and use it in GitHub Desktop.
A resource util component to be used everywhere. Just inject and start using
package in.justickets.android.util;
import android.app.Application;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
/**
* Created by vivek on 15/05/17.
* This class must be used whenever any resource is required (String , Color , Drawable etc.)
*/
@Module
public class JTResourceUtil {
private Context mContext;
public JTResourceUtil(Context context) {
this.mContext = context;
}
@Provides
@Singleton
JTResourceUtil provideResourceUtil(Application application) {
return new JTResourceUtil(application.getApplicationContext());
}
public String getString(@StringRes int id) {
return mContext.getString(id);
}
@ColorInt
public int getColor(@ColorRes int id) {
return ContextCompat.getColor(mContext, id);
}
public Drawable getDrawable(@DrawableRes int id) {
return ContextCompat.getDrawable(mContext, id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment