Usage (samples)
Add dependency:
dependencies {
implementation 'com.github.dyvoker:android-utils:0.1.0'
}
Some helpfull classes using application context. So I recommend to use App singleton:
public class App extends Application {
private static App instance;
@NonNull
public static Context context() {
return instance.getApplicationContext();
}
@NonNull
public static ResHelper resHelper() {
return instance.resHelper;
}
@NonNull
public static Toaster toaster() {
return instance.toaster;
}
private ResHelper resHelper;
private Toaster toaster;
@Override
public void onCreate() {
super.onCreate();
instance = this;
resHelper = new ResHelper(getApplicationContext());
toaster = new Toaster(getApplicationContext());
}
}
And add in AndroidManifest.xml of your project:
<manifest>
...
<application
...
android:name=".App"
>
...
</application>
...
</manifest>
Helping class to show Toasts. Simple:
App.toaster().showToast(App.resHelper().getString(R.string.toast_test_text), Toaster.LONG);
Max custom:
Drawable icon = App.resHelper().getDrawable(R.drawable.ic_report, null);
App.toaster().showToast(
App.resHelper().getString(R.string.toast_test_text),
Toaster.LONG,
Toaster.DARK_TOAST,
icon
);
Helping class to work with dp and px.
Helping class for working with colors.
Helping class for work with layouts.
Helping class to work with Resources.