Created
May 15, 2017 10:55
-
-
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
This file contains 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
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