Every single time, I always forgot how to create a simple alert dialog without googling. I was always wondering why we cannot have a simple way to show alert dialog in Android just like the JavaScript's alert().
So I decided to create this library to do that.
L.alert(this, "Hi.");
Without this, it would be like:
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setMessage("Hi.");
b.setCancelable(false);
b.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
b.show();
It is more simple, right?
Of course, android-lazy-library
contains other lazy functions. Please check examples below.
implementation 'net.louislam.android:lazy:2.0.0'
In all examples, this
means Activity/Context object.
I love this so much. <3
Usage:
L.alert(this, "I am Alert.");
Alert Dialog with callback:
L.alert(this, "Boss: Where is Louis!?", (dialog, which) -> {
L.alert(MainActivity.this, "Louis: here :( ");
});
Example Usage:
L.inputDialog(this, "What is your name?", value -> {
String name = value;
L.alert(MainActivity.this, "My name is: " + name);
});
With default value (add a parameter to the last)
L.inputDialog(this, "What is your name?", value -> {
String name = value;
L.alert(MainActivity.this, "My name is: " + name);
}, "Louis");
Example Usage:
L.confirmDialog(this, "Are you sure?", (dialog, which) -> {
// Do something here if clicked "Yes"
});
For those activity classes already implement OnClickListener
public class LoginActivity extends Activity implements OnClickListener {
public void quit() {
L.confirmDialog(this, "Are you sure?");
}
}
Example Usage:
ProgressDialog loadingDialog = L.progressDialog(this, "Loading...");
Dismiss the dialog:
loadingDialog.dismiss();
Toast is so simple, but I still want to make it lazy.
L.toast(this, "Hi, I am Toast.");
L.toast(this, "Hi, I am Toast with duration.", true);
Log without a tag and support long string.
Example Usage:
L.log("[Debug] the activity is loaded.");
Disable/Enable Log globally
L.enableLog(false);
Store
LStorage.store(this, "key", "valueString");
LStorage.store(this, "key", 123456);
LStorage.store(this, "key", 3.14f);
LStorage.store(this, "key", true);
Get
LStorage.getString(this, "key");
LStorage.getInt(this, "key");
LStorage.getFloat(this, "key");
LStorage.getBoolean(this, "key");
Example Usage:
L.startActivity(this, "LoginActivity");
or
L.startActivity(this, LoginActivity.class);
or (For result)
1314 = Request Code
L.startActivity(this, LoginActivity.class, 1314);
or (starting an activity for result with bundle)
Bundle bundle = new Bundle();
L.startActivity(this, LoginActivity.class, 1314, bundle);
Open URL in browser
L.openUrl(this, "http://google.com");
Get your app's version
L.getAppVersion(this);