Skip to content

Latest commit

 

History

History
93 lines (76 loc) · 1.78 KB

README.md

File metadata and controls

93 lines (76 loc) · 1.78 KB

Android Utils

API

Usage (samples)

Add dependency:

dependencies {
    implementation 'com.github.dyvoker:android-utils:0.1.0'
}

App singleton

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>

Utils classes

Toaster

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
);

DpUtils

Helping class to work with dp and px.

ColorUtils

Helping class for working with colors.

LayoutUtils

Helping class for work with layouts.

ResHelper

Helping class to work with Resources.