Creating and Publishing the ImageSliderView library to jCenter

Posted By : Daljeet Singh | 25-Jan-2018

The blog discusses the steps I undertook to create and publish the imagesliderview library to jCenter.This library lets you add an image slider to your android app and provides a few options for customization.

  • I started by creating a new android library module by going to the New->New Module option in the File menu of Android Studio and specified the name of the Library as imagesliderview.

  • I created a base SliderImage class to hold the images input and extended two new classes UrlImage and DrawableImage from it in order to display images from a url or drawable resource respectively.

  • I created an ImageFragment to display the images from the user.The ImageFragment uses the Glide library to place the image in an imageview by using its url/drawable id ,depending upon the type of input.

  • The next step was creating an ImageAdapter class that extended FragmentPagerAdapter to help display the input images in a ViewPager.

  • A SliderViewLayout class that extended FrameLayout was created next,to hold the view for the Image Slider.This SliderViewLayout also implemented ViewPager.OnChangeListener.The various attributes for the SliderViewLayout were defined in a attrs.xml file inside the res->values directory and the values for these were fetched in the getAttributes function of the SliderViewLayout.

  • A ViewPager was created inside the SliderViewLayout class and added to the view.Depending upon the input values for the attributes,the views for indicators and navigation arrows were added to the SliderViewLayout view.The views for the indicators and arrows were defined in separate classes.

  • The images arraylist is taken from the user in a setSliderImages function ,along with a value for a placeholder image(0, if default placeholder is to be used).The ImageAdapter is passed the arraylist of images to display in the ImageFragment along with a boolean that tells it whether to automatically loop the images in an infinite manner or not.The ImageAdapter is set as the adapter for the ViewPager.

  • Incase the images are to be looped,a timer runs every 'n' seconds to change the image,where n is defined by the user in the timeInterval attribute.

  • An ImageChangeListener interface is created ,whose function onImageChanged acts as a callback with the image position .This function helps in updating the position of the selected and unselected indicators every time the image changes in the sliderview.

After writing and testing the code for the library,the next major step was uploading the library to github and then publishing it to jCenter.

  • I created an account on bintray.com.I used my github account to signup on bintray.

  • Then I created a repository on bintray ,chose its name and type for the repo,these values were ImageSliderView and Maven in my case.

  • I added a new package named imagesliderview(same as my library's name) to the repo.I chose Apache 2.0 as the license,Development as the maturity,the git url for the website and the git url for the version control values while creating the package.

  • The next step was adding my bintray username and apikey(found by going to the edit profile section on bintray) to the local.properties file in my library project as this file is usually not committed to git ,hence the api key remains safe :

    bintray.user=daljeet33
    bintray.apikey=148xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    

     

  • Then I added the following classpaths under the dependencies for the bintray and maven plugins in the build.gradle of my project :

    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
    

     

  • The final part was adding the following info to the build.gradle of my library :

    ext {
        bintrayRepo = 'ImageSliderView' // repo name
        bintrayName = 'imagesliderview' //  same as library module name
    
        publishedGroupId = 'com.oodles' // module package name which will precede the library name on bintray
        libraryName = 'imagesliderview' //library name
        artifact = 'imagesliderview' // same as library module name
    
        siteUrl = 'https://github.com/daljeet33/imagesliderview-android'
        gitUrl = 'https://github.com/daljeet33/imagesliderview-android.git'
    
        libraryDescription = 'A library that lets you add a slider view with images in an android app'
        libraryVersion = '1.0'
    
        developerId ='daljeet33'
        developerName='Daljeet'
        developerEmail='daljeet@oodlestechnologies.com'
    
        licenseName = 'The Apache Software License, Version 2.0'
        licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
        allLicenses = ["Apache-2.0"]
    }
    
    and adding the following lines at the bottom of the build.gradle of the library module to help build the library files and upload them to my bintray package :
    apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
    apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
    

     

  • After this,I synced my project and switched to the root directory of my project in the terminal of Android Studio and ran the following command to upload the library to bintray:

    ./gradlew clean build install bintrayUpload
    

     

  • After everything went fine,I received a build successful message in the terminal and was able to see my library with its version 1.0 mentioned in my imagesliderview package on bintray.

  • I made a request to add the library to the jCenter repository by using the add to jCenter option visible inside the imagesliderview package.After a few hours,the request was approved and the library was added to jCenter.

Further instructions on using the library and its code can be found at this github link for the library.

About Author

Author Image
Daljeet Singh

Daljeet has experience developing android applications across a range of domains such as Cryptocurrency, Travel & Hotel Booking, Video Streaming and e-commerce. In his free time, he can be found playing/watching a game of football or reading up on either

Request for Proposal

Name is required

Comment is required

Sending message..