Jamun Standalone

Volley

A set of Custom Classes with UI components for network programming, integration and transaction handling in a better and standard way. This will help developers for making quality use of volley library.

Introduction

  • In this Library Jamun-Volley, we provide you a package of custom Volley Classes which ease your work while working with API calls.
  • You just need to setup all the configuration stuff (Like Header Meta-Data, Singleton Declarations this will be shown with example later in the documnet) at one place so that you don’t have to write same piece of code again and again. For example, MyApplication Class.
  • Jamun-Volley library has been developed keeping many parameters in mind by default the library support many auto-configuration like LUR-Cache, Request and ImageLoader Objects. But in case if you need To Edit Something We have also provided you to edit Definations and setting up new configuration parameters.
  • One of the main benifit of using Jamun-Volley LIbrary is that you can Post Any type of data and Retrive response in another format which wasn’t possible in traditional Volley Library.
  • THis Library also provide you File Downloading and Uploading classes which were upsent in Traditional Volley. With the help of this Library you can also manage of your file Downloading/Uploading progress easliy with Data Statistics.
  • Library’s most attractives UI Feature is that you are provided with CircularNetworkImageView with the help of which you can display your image in Attractive Circullar View. By Just using CircularNetworkImageView.
  • Library also provide you a UI Component to Show progress Data Statistics in Notification. But this also provide you a set of Function which help in Customization.
What’s New? (0.0.1)
  • Stable Official Version for Developers and Live Apps.
  • Custom UI components for Progress Notifications with Infinite and Counted progress bar. Also have data analytics.
  • Easy Calling Mechanism with Instant reply via Listeners and Return Functions
  • Lite version for minimal code calls with maximum Auto APIs Calling features
  • Need less calls with many customs methods to reach maximum developer satisfaction.
Quality Measures? for (0.0.2)

The following apps are using this library without facing any kind of Bugs.


Gradle Configuration

Add the dependency

dependencies {
        compile 'tk.jamun:volley:0.0.1'
}
Maven Config
<dependency>
  <groupId>tk.jamun</groupId>
  <artifactId>volley</artifactId>
  <version>0.0.1</version>
  <type>aar</type>
</dependency>

Features and Functionalities

As you all familiar with Basic calls Required in Accessing JSON Data of Type,

  • JSONObject Request
  • JSONArray Request
  • String Request

But this Library Provide you :

  • Network Response Request
  • Response Request with Response in String and Network

Uploading

  • Multipart Request for Payload
  • HTTPConnection Request for Payload with Notifcaion

Downloading

  • File Download Request for Payload
  • Image Download Request for Image
  • HTTPConnection Request for Payload with Notifcaion

Also for used in Background Services like Services, IntentServices, AsynTasks

Background Service Tasks

  • For Payload with Notifcaion
  • For JSONObject
  • For JSONArray
  • For String

Last but not Lease :

Error Response

  • With Status Code
  • With Predefined Status Replies

How to Implement

Once the project has been added to gradle, You can use these lines of code to configure pickers…

Step 1. Volley Setup

Library provide you a Better Approach and Efficent way to setup Google Volley Library, now you don’t need to create Volely singleton or create a Setup of LRU Cache for File buffering or caching or many more things developer need to set first to start volley.
And last but not least, no need of creating header again and again for each APIs calls, this will done automatically with one function call define in Application class for Global Access.

But here, these things are automate by calling some methods in Application class

 @Override
 public void onCreate() {
        super.onCreate();
        VolleySingleton.setInstance(mInstance);
        setAndRefreshVolleyHeaderCredentials();
 }
 // this function call required to setup or refresh your Header AuTH details
// from one place for whole further api calls.
 public void setAndRefreshVolleyHeaderCredentials() {
        VolleyNeeds.getInstance().setUpHeaders(ClassSharedPreference.getInstance()
        .getHeaderCredentials());
 }
 
 //If you want to setup LRU cache Size
 VolleySingleton.setLruCacheSize(int lruCacher);
 

Method define in Sharepreference class for accessing AUth header Details.Example after login or registeration, setup your auth Fundamental in SharedPrefrence and push refresh to set for Global Use

public ArrayList<ModelHeader> getHeaderCredentials() {
    ArrayList<ModelHeader> headerArrayList = new ArrayList<>();
    headerArrayList.add(new ModelHeader(KEY_USER_ID, ""));
    headerArrayList.add(new ModelHeader(KEY_TOKEN, ""));
    headerArrayList.add(new ModelHeader(TAG,DATA));
    headerArrayList.add(new ModelHeader(TAG,DATA));
    headerArrayList.add(new ModelHeader(TAG,DATA));
    return headerArrayList;
}

Thats it. Your all setup is now Done in Two lines.

Step 1. APIs integration with Jamun-Volley

As you all familiar with Basic calls Required in Accessing JSON Data, as you seen it have similar calling structure for Developer to feel familiar but with full advance automation,

  • No need of Extra header calls
  • No Need of Priority setup
  • No Need of Retry Policy Calls

Code Now,

  • JSONObject Request
VolleyJsonObjectRequest jsonObjectRequest =
        new VolleyJsonObjectRequest(Request.Method.POST, url,@Nullable body,
            new VolleyResponse.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
            }
        }, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                MySnackBar.showSnackBarForMessage(activity, statusCode, errorMessage);
            }
        });
        VolleyNeeds.getInstance().setVolleyExtraCalls(jsonObjectRequest);  
        
// for Get Request
VolleyJsonObjectRequest jsonObjectRequest = new VolleyJsonObjectRequest(url,
             new VolleyResponse.Listener<JSONObject>() {....

  • JSONArray Request
VolleyJsonArrayRequest jsonArrayRequest =
        new VolleyJsonArrayRequest(Request.Method.POST, url,@Nullable body,
            new VolleyResponse.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
            }
        }, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                MySnackBar.showSnackBarForMessage(activity, statusCode, errorMessage);
            }
        });
        VolleyNeeds.getInstance().setVolleyExtraCalls(jsonArrayRequest);    

// for Get Request
VolleyJsonArrayRequest jsonArrayRequest = new VolleyJsonArrayRequest(url,
             new VolleyResponse.Listener<JSONArray>() {....

  • String Request
VolleyStringRequest volleyStringRequest = 
        new VolleyStringRequest(Request.Method.POST, url,@Nullable body,
            new VolleyResponse.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
            }
        }, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                MySnackBar.showSnackBarForMessage(activity, statusCode, errorMessage);
            }
        });
        VolleyNeeds.getInstance().setVolleyExtraCalls(volleyStringRequest);    
  • Network Response Request
 VolleyNetworkRequest volleyNetworkRequest = 
         new VolleyNetworkRequest(Request.Method.POST, URL, @Nullable body,
            new VolleyResponse.Listener<Integer>() {
            @Override
            public void onResponse(Integer response) {
                if (VolleyNeeds.getInstance().checkResponseCode(response)) {
                    // for response between 200 to 300
                } else {
                    MySnackBar.showSnackBarForMessage(ActivityProfileChange.this,
                      R.string.connection_something_went_wrong);
                }
            }
        }, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
            }
        });
        VolleyNeeds.getInstance().setVolleyExtraCalls(volleyNetworkRequest);
  • Response Request
VolleyResponseRequests volleyStringRequest = 
            new VolleyResponseRequests(Request.Method.POST, url,
               @Nullable body, new VolleyResponse.Listener<String>() {
            @Override
            public void onResponse(String response) {
            }
        },new VolleyResponse.Listener<Integer>() {
            @Override
            public void onResponse(Integer response) {
                if (VolleyNeeds.getInstance().checkResponseCode(response)) {
                    // for response between 200 to 300
                } else {
                    MySnackBar.showSnackBarForMessage(ActivityProfileChange.this,
                    R.string.connection_something_went_wrong);
                }
            }
        }, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                MySnackBar.showSnackBarForMessage(activity, statusCode, errorMessage);
            }
        });
        VolleyNeeds.getInstance().setVolleyExtraCalls(volleyStringRequest);    
  • Multipart File Uploading Request
// Setup calls for setting file for Uploadind
Map<String, ModelByPart> params = new HashMap<>();

// params.put(TAG,new ModelByPart(FileName,fileDataFromBitmap,"image/"+ext.));
params.put(API_TAG, new ModelByPart(file.getName(),VolleyHelper
      .getFileDataFromBitmap(BitmapFactory.decodeFile(mCurrentPhotoPath.getAbsolutePath())),
      "image/" + file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase()));
                        
VolleyMultipartRequest multipartRequest = new VolleyMultipartRequest(URL, params,
     new VolleyResponse.Listener<String>() {
         @Override
         public void onResponse(String response) {
                    
    }, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                MySnackBar.showSnackBarForMessage(ActivityProfileChange.this,
               statusCode, errorMessage);
            }
        });
VolleyNeeds.getInstance().setVolleyExtraCalls(multipartRequest);
   
  • Last Call to setup Request for Execution is By
VolleyNeeds.getInstance().setVolleyExtraCalls(jsonObjectRequestSetAvatar);    
  • Volley in Background Service

Jamun Volley Background Services provide you a better and efficent approach to Upload or Download data payloads in background tasks.
It will help developers to maintain session during payload uploading and downloading. This will return result after complete execution, so no need to maintain another threads for waiting response.

There are different types to use Jamun-Volley in Background Tasks :-

  1. Get Request
String response = VolleyBackgroundServices.getInstance()
           .volleyToGetData(URL, new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                //Error Response
            }
        });
  1. Post Request
String response = VolleyBackgroundServices.getInstance()
           .volleyToSendData(URL, payload,new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                //Error Response
            }
        });
  1. Get Post Request
//integer Methods are Request.Method.POST,Request.Method.GET,
// Request.Method.DELETE,Request.Method.UPDATE
String response = VolleyBackgroundServices.getInstance()
            .volleyToGetPostData(Method,URL, payload,new VolleyResponse.ErrorListener() {
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                //Error Response
            }
        });
  1. Upload File
//Methods are Request.Method.POST,Request.Method.GET,Request.Method.DELETE,
//Request.Method.UPDATE
// Tag name used for uploading file with API tag
String response = VolleyBackgroundServices.getInstance()
            .volleyToSendFile(File, Method, URL, tagName,new VolleyResponse.ErrorListener(){
            @Override
            public void onErrorResponse(int statusCode, String errorMessage) {
                //Error Response
            }
        });
  1. Close In-Between

Using this method, help you stoping APIs call in between;

VolleyBackgroundServices.getInstance().stopServices();
  • HTTPConnection Request for Payload with Notifcaion
  1. Uploading File
    /**
     * Method helps you uploading heavy files with HttpURLConnection request.
     * Method required AsyncTasks or Service to handle uploading;
     * Otherwise thrown NetworkOnMainThreadException
     * @param url Request URL for Upload payload
     * @param sourceFile Source file need to be Upload
     * @param helperNotification HelperNotification class for Notified
     * user by Progress Notification
     * @param notificationId Unique id for Progress Notification
     * @return APIs response
     */
String response = VolleyDownUpFiles.getInstance()
.uploadFile(URL, SourceFile, HelperNotification, notificationId);
  1. Downloading File
    /**
     * Method helps you downloading heavy files with HttpURLConnection request.
     * Method required AsyncTasks or Service to handle uploading;
     * Otherwise thrown NetworkOnMainThreadException
     * @param requestUrl Request URL for Upload payload
     * @param filePath Download file need to be Saved
     * @param helperNotification HelperNotification class for Notified 
     * user by Progress Notification
     * @param notificationId Unique id for Progress Notification
     * @return APIs response
     */
String response = VolleyDownUpFiles.getInstance()
.downloadFile(URL, filePath, HelperNotification, notificationId);
  1. Stop Service
VolleyDownUpFiles.getInstance().stop();
  1. Customize Buffer Size

Different file have differnt size in Uploading, this required volley to create a buffer to maintain file in Uploading Tasks;
Need to be set according to mean of the Files Size to stop MemoryBufferSizeException;

VolleyDownUpFiles.getInstance().stop();
Dependency
  • Android Volley v1.1.0
  • Java jar org.apache.http.legacy.jar
Credits

Desgin & Developed by : Jatin Sahgal
(Linkedin & Website & Blog & GitHub)

More Library under Jamun
  • Pickers
    Pickers Library provide you a set of Pickers like Country, Language, Share and Intent Chooser.
  • Share
    provide you Intent Chooser with great UI/UX. It automatically retrieve the sort list of all the apps which can share the file. This functionality saves much of your task. You can also share dialog Picker for sending Large files. For this you just need to call a single function with file as Argument.
  • Country-Pickers
    allow you to access Country picking functionality with great UI/UX design, and there are numerous of function which help you to modify picker as per your requirements. Library has been provided with four custom UI initiate mode you can decide how the view of picker can be initiate. You can also decide weather picker inherit Single or Multi Selection property. Library consists of updated collection of country name, code and there flags. We are using APIs base structure to avoid increase in the size of apk due to flag Images. This module Maintain the database so that you don’t need to call APIs again and again rather than you can choose when to refresh the Database and fetch new real time data.
  • Language-Pickers
    provides you read-made Language picker which is easy to use and comes with great UI/UX, and there are numerous of function which help you to modify picker as per your requirements. Library has been provided with four custom UI initiate mode you can decide how the view of picker can be initiate. You can also decide weather picker inherit Single or Multi Selection property.
  • Scanner
    is a collection of Beautiful Activity which help others to make there own Custom QR/Barcode Scanner.
  • Calendar
    is a collection of Beautiful Activities which help others to make there Fully Custom Calendar View with Single and Multi Date Picker Functionality
  • UI
    library is a set of UI Views, Custom Component and Collection of Helper Classes which help Developer for making quality Product. Such as Camera, Gallery, Number of Pickers, Calendar, Date Pickers, Dialogs and many more Helper UI and Backend Component.
  • Camera
    library provide you Custom Complete Camera view with full features like Flash, Rotation, Gallery Picker, Focus, Tap to capture, Confirmation window and last but not least cropping feature. It also provide you file path in return so that developer can feel a friendly handy way to Deal After.
  • Gallery
    have some Beautiful UI Components and Multi files Mode for android Developers to give there app a A Rich look With single and Multi picker Functionality.
  • CircularImageView
    Library provide you a custom set of Android Elements that have custom views and properties like CircularImageView Element which provide you both XML and Java Code functions for Circular view with vector compatibility.
  • CircularNetworkImageView
    Library provide you a custom set of Android Elements that have custom views and properties like CircularNetworkImageView Element which provide you both XML and Java Code functions for Circular Volley Network view with vector compatibility.
  • SinglePageBrowser
    Library provide you two type Single PagerĀ  In-APP Browser Functionality with Event Handling and Functions to Customize Views. It also provide you Copy to clipboard, Open in Browser and share link feature in-Built.
  • MultiPageBrowser
    Library provide you two type Multi Pager In-APP Browser Functionality with Event Handling and Functions to Customize Views. It also provide you Copy to clipboard, Open in Browser and share link feature in-Built.
  • Volley
    A set of Custom Classes with UI components for network programming, integration and transaction handling in a better and standard way. This will help developers for making quality use of volley library..
License
Copyright (c) 2018 Jatin Sahgal

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About the author

Jatin Sahgal

Jamun is a collection of cool android Libraries, Elements classes and more over Utils who help other developer to build a different quality android product by putting material design themes in there mind.

1 Comment

Leave a Comment