Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.
Adrián Rivero edited this page May 7, 2017 · 54 revisions

DecleX Introduction

DecleX is a framework that aims to get closer to the idea of a fully Declarative Language for Android Development. It is totally based on AndroidAnnotations; in a similar fashion, we want to facilitate the writing and the maintenance of Android applications to the highest level which has not been achieved up to now.

But that's not all! In the last years, we programmers have struggled with new APIs, and most of them become obsolete in a very short period of time so we have to keep learning those APIs again and again. Additionally, they are difficult to understand and frequently we make mistakes by copying from a previous implementation or spending hours in what should be something as easy as a declaration... and that's what DecleX helps to do... reducing lines of codes to just declaring what we want.

But instead of words, let's see this in an example... Most of us have implemented APIs like Facebook Login for Android, or Google+ Platform for Android... It depends on programmers, but how many lines do we have to write again and again just to implement those APIs in our applications? With Declex we do it in few lines of code... or better, declarations of what we want to do:

@UseFacebookSDK(modelClass=User.class)
@EActivity(R.layout.activity_login)
public class LoginActivity extends Activity {

    @Click
    void btnFacebookLogin() {
        $AlertDialog().message("You will be logged in with Facebook")
                      .positiveButton("Continue").negativeButton("Cancelled");

        if ($AlertDialog.NegativeButtonPressed) {
            $Toast("Cancelled!");
        }

        $FacebookLogin();
        $MainActivity();
        finish();
    }

}

But what does exactly this code do?... well, in an activity exists a Button with id "btnFacebookLogin", when we click on it, an Alert Dialog is displayed to the user to confirm or cancel. If the user cancels, a Toast is shown, if not then it is requested to Facebook SDK to Login the user, and after a successful login, we open a new Activity called MainActivity, and close the current activity.

And there's more, all the data of the logged user is stored in a model automatically (User.class), in order to be uploaded to a custom server, or stored locally in a SQLite DB to display the information quickly in the application (both actions can be handled automatically by DecleX simply providing the Model as in the example). Let's say the MainActivity shows all the information of the logged user, so it'll be as easy as declaring:

@EActivity(R.layout.activity_main)
public class MainActivity extends Activity {

    @Model
    @Populate
    User user;

}

This code is enough to display all the user information in the MainActivity (user Image, Name, Email, Age), this shows how easy and powerful is populating views with DecleX.


DecleX stands over 4 Pillars:

We’ve used many Open Source Libraries, first of all AndroidAnnotations, ActiveAndroid, EventBus, Picasso, OkHttp 3, GSon, Saripaar. For sure you have used some of those libraries before and definitely they helped us to save a lot of time, besides that they help us to make the code cleaner and easier to maintain. So proudly we have included them into our library, helping us to achieve our goals.

Important! This documentation should be read in conjuction to AndroidAnnotations documentation, because it is an important part of DecleX library as well.

Important! DecleX is fully compatible with AndroidAnnotations 4.3.0