Giter Club home page Giter Club logo

android-lazy-library's Introduction

LouisLam's Lazy Library for Android

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.

Installation

implementation 'net.louislam.android:lazy:2.0.0'

Assumption

In all examples, this means Activity/Context object.

Lazy Alert Dialog

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 :( ");
});

Lazy Input Dialog

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

Lazy Confirmation Dialog

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?");
    }
    
}

Lazy Loading Dialog

Example Usage:

ProgressDialog loadingDialog = L.progressDialog(this, "Loading...");

Dismiss the dialog:

loadingDialog.dismiss();

Lazy Toast

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

Lazy Log

Log without a tag and support long string.

Example Usage:

L.log("[Debug] the activity is loaded.");

Disable/Enable Log globally

L.enableLog(false);

Lazy Storage

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

Lazy Start Activity

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

Others

Open URL in browser

L.openUrl(this, "http://google.com");

Get your app's version

L.getAppVersion(this);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.