Skip to content

xihadulislam/AndroidUtils

Repository files navigation

Android Utils

alt text

To get a Git project into your build

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	  }
   }
  

Step 2. Add the dependency

dependencies {
    implementation 'com.github.xihadulislam:AndroidUtils:2.0.5'
}
  

Usage

Access shared preference easily

      val sharePrefSettings = AndroidUtils.getSharePrefSetting(this);

        sharePrefSettings.setBoolValue("key", false)
        val kBoolean = sharePrefSettings.getBoolValue("key")
        
        Log.d(TAG, "onCreate: $kBoolean")

        sharePrefSettings.setStringValue("key2", "xihad islam")
        val xd = sharePrefSettings.getStringValue("key2")
        
        Log.d(TAG, "onCreate: $xd")

Make a click effect of all view

   AndroidUtils.applyClickEffect(view)
   view.setOnClickListener{}

Generate a random unique uuid in ine line

   val uId: String = AndroidUtils.uId() // example: 42N35260Y390345AM

Check your Internet connection is Available or not

        
   AndroidUtils.isInternetAvailable(context) // it will return true or false

Screenshot Utils

take Screenshot Of a View

        
  var image : Bitmap = AndroidUtils.takeScreenshotOfView(rootView,200,200) // height & width is optional 
         
  var image2 : Bitmap = AndroidUtils.takeScreenshotOfView(rootView) // height & width is optional 

protect To Take Screenshot of a Screen

   AndroidUtils.protectToScreenshot(this) // 

Number Utils

   val numberUtils: NumberUtils = AndroidUtils.getNumberUtils()
   numberUtils.numberToWords(100)
   numberUtils.numberInBangla("100")
        
   // or you can use it with Quick Access
        
   val word = AndroidUtils.numberToWords(100)
        
   val banglaNumber = AndroidUtils.numberInBangla("12-10-2022")
        
   val banNumber = AndroidUtils.getDigitBanglaFromEnglish("1234")
        
   val enNumber = AndroidUtils.getDigitEnglishFromBangla(banNumber)

Payment Utils

     
  val includingTax = AndroidUtils.getIncludingTax(100,20)
        
  val excludingTax = AndroidUtils.getExcludingTax(100,25)
        
  val num = AndroidUtils.twoDigitDouble(14.4444334343)
        
  val str:String = AndroidUtils.twoDigitString(14.364433)
        
  val num = AndroidUtils.stringToNumber("13")

Encryption Utils

     
  val encrypt = AndroidUtils.encrypt("hello from xihad")
        
  val decrypt = AndroidUtils.decrypt(encrypt) // hello from xihad
  

Application Utils

     
  AndroidUtils.setWebView(url, webView) // load webview
  
  val systemApplications : List<ApplicationInfo> = AndroidUtils.getSystemApplications(context)
  
  val installApplications : List<ApplicationInfo> = AndroidUtils.getInstallApplications(context)
  
  val allApplications : List<ApplicationInfo> = AndroidUtils.getAllApplications(context)
  
  val is = AndroidUtils.isAppOnForeground(context)
  
  val isPack= AndroidUtils.isSystemPackage(context)
  

Here a Sample code snippet for SnackBar

  toast.setOnClickListener {
            AndroidUtils.toast(this, "show something")
        }

        showSnack.setOnClickListener {
            AndroidUtils.getSnackBar(this).snackBar("show something")
        }

        showSnackSuccess.setOnClickListener {
            AndroidUtils.getSnackBar(this).successSnack(root, "show something")
        }

        showSnackInfo.setOnClickListener {
            AndroidUtils.getSnackBar(this).infoSnack(root, "show something", Gravity.BOTTOM, fun() {
                AndroidUtils.toast(this, "click")
            })
        }

        showSnackWarning.setOnClickListener {
            AndroidUtils.getSnackBar(this).warningSnack(root, "show something")
        }

        showSnackError.setOnClickListener {
            AndroidUtils.getSnackBar(this).errorSnack(root, "show something")
        }

Intent several activities just need one line code

           startNextActivity.setOnClickListener {
            AndroidUtils.getIntent().startNextActivity(this, SecondActivity::class.java)
        }

        afterNextActivity.setOnClickListener {
            AndroidUtils.getIntent().afterNextActivity(this, 2000, SecondActivity::class.java)
        }

        startFacebookIntent.setOnClickListener {
            AndroidUtils.getIntent().startFacebookIntent(this, "url")
        }

      

Sample project

Clone this repo and check out the app module.

Author

This is my First built library, so if you face any issues or errors feel free to tell me. I will update it continuously.

Share

Like this project? Why not share to your friend :)

            

Licence

Copyright 2021 @xihad islam.

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.