X

CHEEZY CODE


Interested In More?


We have various articles on different topics.
Choose your technology stack from links below.


Video Tutorials C# Android JavaScript


Get Latest Updates


5 Popular Open Source Android Libraries


Android Development has become easy these days. With so many open source libraries available, you can implement anything required for your app easily. Smart developers never re-invent the wheel, they build on top of available code base and focus on the app logic.


cheezycode-android-libraries



You might be wondering that it will require a huge effort to integrate those libraries in your app but with Android Studio it has become easier. You just need to add the Gradle dependency in your build.gradle file and you are done. But make sure you do not overuse the libraries because they certainly increase your app size. There is always a trade-off attached, so be decisive. Below are the libraries we find very useful in our app development process -

1. Retrofit


Retorfit is one of the most popular and powerful Android library for Networking developed by Square. Type-safe REST client that converts your REST API into Java interface. Easy to use, lightweight and fully customizable library . Annotation based HTTP request and response handling with custom parsing available. You can use any parser of your choice - GSON, Jackson etc.

public interface IProduct {  
 @GET("/product?q=Knife")  
 void getProductInfo(Callback<Product> response);  
}  

To call the API -
String url = "<!--SERVICE URL-->"; 
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(url).build();  

//Service Creation 
IProduct product= adapter.create(IProduct.class);  

//Method Call
product.getProductInfo(new Callback<Product>() {  
 
 @Override  
 public void success(Product data, Response response) {  
 }  

 @Override  
 public void failure(RetrofitError error) {  
 }  
});  

Code is cleaner and much simpler using Retrofit. Simple mechanism for synchronous and asynchronous request. If you add a callback, then it will be asynchronous otherwise it will be a synchronous call. You must try if you really want maintainable code base for your app. Get more information here.


2. ButterKnife


Another best library by Jake Wharton (Guy behind some of the best Android Libraries including Retrofit) to reduce your development time. You do not need to call findViewById for every view in your layout. Just use ButterKnife, it will inject views for you. It becomes repetitive to call findViewById for views in layout if you want to manipulate them with application code. Butterknife uses annotation to inject views. Even you can use annotation to handle events such as click. Visit official site for more info - Library

class MainActivity extends AppCompatActivity {
  @BindView(R.id.txtHeader) TextView txtHeader;
  @BindView(R.id.txtMessage) TextView txtMessage;
  @BindView(R.id.btnGenerate) Button btnGenerate;
  
  @Override 
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    ...
    txtHeader.setText("#cheezycode"); // NO NEED TO FIND VIEW BY ID
  }
  
  @OnClick(R.id.btnGenerate) //HANDLES CLICK AS WELL
  public void generate(View v) {
 
  }
}

3. Picasso


If you have written the code to download the images from web and have them displayed onto ImageView in Android , you must be aware of the complexity involved. This is a huge boilerplate code that can be avoided using this library. It abstracts out the whole process with a single line of code. It asynchronously download the images and cached them to avoid download in future. Again from Square - Refer official site here.

Picasso.with(context).load(url).into(view);

4. PugNotification


This library helps generate the notifications with a single line of code. It abstracts all the notification construction process. Lightweight and easy to use library covering many aspects of Notification in Android. Refer official docs here.

  PugNotification.with(this)
                .load()
                .title("What are you waiting for?")
                .message(R.string.app_name)
                .bigTextStyle("Welcome To CheezyCode !")
                .smallIcon(R.drawable.logo)
                .largeIcon(R.drawable.logo)
                .flags(Notification.DEFAULT_ALL)
                .autoCancel(true)
                .simple()
                .build();


5. SQLiteAssetHelper


This is one of the best set of classes if you want to manage your SQLite database creation and versioning in Android. If you want to pre-ship database with your app then you should definitely use this library as it manages the initial creation of the database from a file in assets/databases folder and even it will handle the upgrades of the SQLite file and its subsequent version.

Just put your pre-populated SQLite file in assets/databases folder and inherit SQLiteAssetHelper in your app and that's it. Now, when you access the DB for first time, this class will copy that DB for you with pre-populated data. Refer here for more info.

public class MyCheezyDB extends SQLiteAssetHelper {

    private static final String DATABASE_NAME = "myCheezyDB.db";
    private static final int DATABASE_VERSION = 1;

    public MyCheezyDB(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
}

In above code, file will be stored as assets/databases/myCheezyDB.db. You must try this if your app requires pre-populated DB.

These are some of the libraries we have been using in our Android app projects. Let us know about your tool-set and libraries that you find very useful in your development endeavor. Comment or reply for any concerns. Happy Reading.



Interested in learning android? Try our step by step android tutorial with the help of an app




No comments:

Post a Comment