Android

Top 10 free Android libraries for app development in android studio

Top 10 free Android libraries for app development in android studio

Whether you are new to Android or an experienced developer, everyone needs advice on resources or new libraries to improve and simplify development life.So here we will list the

Contents

Top 10 free Android libraries for App development in Android studio.

To summarize in short we all agree with my observation that why we need libraries for developing our Android applications.

Here are my observations:

Organizing Code

 

Don’t Repeat Yourself

 

Design Better Apps

 

Staying Up To Date 

BUTTER KNIFE

 

Butterknife is a view binding library that uses annotation to generate boilerplate code for us.It has been developed by Jake Wharton. It makes your code less and more clear. It is time saving to write repetitive lines of code.

To avoid writing repetitive code just like `findViewById(R.id.yourview)`, butterknife helps you to binds fields, method and views for you.


compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

You can use it in Activity,Fragment and view holders and also include the annotation to bind methods,event clicks and much more.

GSON

Gson is a Java library used for serializing and deserializing Java objects from and into JSON. A task you will frequently need to do if you communicate with APIs. We mostly use JSON because it’s lightweight and much simpler than XML.

// Serialize
String userJSON = new Gson().toJson(user);

// Deserialize
User user = new Gson().fromJson(userJSON, User.class);

We regularly using this library with Volley or Retrofit which we are seeing next.

RETROFIT

From their site: “Retrofit turns your REST API into a Java interface.” It’s an elegant solution for organizing API calls in a project. The request method and relative URL are added with an annotation, which makes code clean and simple.

dependencies {
    
   com.squareup.retrofit2:retrofit:2.4.0
}

 

With annotations, you can easily add a request body, manipulate the URL or headers and add query parameters.

Adding a return type to a method will make it synchronous, while adding a Callback will allow it to finish asynchronously with success or failure.

public interface RetrofitInterface {

    // asynchronously with a callback
    @GET("/api/user")
    User getUser(@Query("user_id") int userId, Callback<User> callback);

    // synchronously
    @POST("/api/user/register")
    User registerUser(@Body User user);
}


// example
RetrofitInterface retrofitInterface = new RestAdapter.Builder()
            .setEndpoint(API.API_URL).build().create(RetrofitInterface.class);

// fetch user with id 2048
retrofitInterface.getUser(2048, new Callback<User>() {
    @Override
    public void success(User user, Response response) {

    }

    @Override
    public void failure(RetrofitError retrofitError) {

    }
});

Retrofit uses Gson by default, so there is no need for custom parsing. Other converters are supported as well like jackson ,Moshi and others .Read more about converters .

VOLLEY

Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Every time you search on Google to call api from Android you will meet Volley before anyone.

dependencies {
    
    compile 'com.android.volley:volley:1.1.0'
}

Volley offers the following benefits:

  • Automatic scheduling of network requests.
  • Multiple concurrent network connections.
  • Transparent disk and memory response caching with standard HTTP cache coherence.
  • Support for request prioritization.
  • Cancellation request API. You can cancel a single request, or you can set blocks or scopes of requests to cancel.
  • Ease of customization, for example, for retry and backoff.
  • Strong ordering that makes it easy to correctly populate your UI with data fetched asynchronously from the network.
  • Debugging and tracing tools.

How to call Api using Volley

EVENTBUS

EventBus is a library that simplifies communication between different parts of your application. For example, sending something from an Activity to a running Service, or easy interaction between fragments. Here is an example we use if the Internet connection is lost, showing how to notify an activity:

public class NetworkStateReceiver extends BroadcastReceiver {

    // post event if there is no Internet connection
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        if(intent.getExtras()!=null) {
            NetworkInfo ni=(NetworkInfo) intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
            if(ni!=null && ni.getState()==NetworkInfo.State.CONNECTED) {
                // there is Internet connection
            } else if(intent
                .getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,Boolean.FALSE)) {
                // no Internet connection, send network state changed
                EventBus.getDefault().post(new NetworkStateChanged(false));
            }
}


// event

public class NetworkStateChanged {

    private mIsInternetConnected;

    public NetworkStateChanged(boolean isInternetConnected) {
        this.mIsInternetConnected = isInternetConnected;
    }

    public boolean isInternetConnected() {
        return this.mIsInternetConnected;
    }
}



public class HomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        EventBus.getDefault().register(this); // register EventBus
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this); // unregister EventBus
    }

    // method that will be called when someone posts an event NetworkStateChanged
    public void onEventMainThread(NetworkStateChanged event) {
        if (!event.isInternetConnected()) {
            Toast.makeText(this, "No Internet connection!", Toast.LENGTH_SHORT).show();
        }
    }

}

GLIDE

In any Android app we need to display images from the url or from local bitmap well thats what Glide made for.An image loading and caching library for Android focused on smooth scrolling.

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.6.1'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}

Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug in to Google’s Volley project or Square’s OkHttp library instead.

Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

PICASSO

Picasso allows for hassle-free image loading in your application—often in one line of code!

GRADLE

implementation 'com.squareup.picasso:picasso:2.71828'

Many common pitfalls of image loading on Android are handled automatically by Picasso:

  • Handling ImageView recycling and download cancelation in an adapter.
  • Complex image transformations with minimal memory use.
  • Automatic memory and disk caching.

ADAPTER DOWNLOADS

Adapter re-use is automatically detected and the previous download cancelled.

@Override public void getView(int position, View convertView, ViewGroup parent) {
  SquaredImageView view = (SquaredImageView) convertView;
  if (view == null) {
    view = new SquaredImageView(context);
  }
  String url = getItem(position);

  Picasso.get().load(url).into(view);
}

 

Also Picasso comes with great features like custom Image Transformation

Transform images to better fit into layouts and to reduce memory size.

Picasso.get()
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

 

TOASTY

Like writing “Hello World ” as our first program when we started learning programming we all love to use one control very frequently like Android Toast.

So why not making it appear stylish using the below dependency.

dependencies {
    ...
    implementation 'com.github.GrenderG:Toasty:1.2.8'
}

Android Asset Studio

We al know when developing apps we need icons and drawables but yuuck..we need to wait for designers to get free and give icons to us..And yeah Project manager is still on our head to deliver the build quickly..so here we can use the asset studio to generate the generic and custom icons for our apps.

Top 10 free Android libraries for app development in android studio
Android Asset Studio

 

Explore Android Asset Studio and decide how useful it is.

Recycler view

Recycler view : One of the most common library introduced by Google to replace the old Listview. However I have seen many programmers hesitate to use them just because of onItemCLicklistener is not present to handle item clicks. But still there are number of benefits like multiple view types, efficient scrolling , view recycling using viewholder and more.

We can use interface to handle the item clicks which is more efficient to handle the clicks in fragment or any activity.

At the end we can say that for every single task we don’t require to add library but we have to take care also we should not go on to reinvent the wheel again.

 

So guys I hope that we have covered most of the basic things which we need to develop an Android app in Android Studio. Please comment if we miss something in comment section.

Feeling glad to receive your comment