This library contains essential Android extensions which we use in daily projects
Gradle:
Add it in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependency to your module build.gradle
file
dependencies {
implementation 'com.github.Eldhopj:android-extensions:1.1'
}
For info on using in the maven and others, see the jitpack docs page.
- .blockInput -> Blocks the user touch inputs. Usually useful when we doing some loading and we have to prevent user inputs on that moment
- .unblockInput -> Unblocks the user touch inputs
Please go thorough the Activity Extensions code documentation for more information
- .toStringMap -> Convert the key & string values in the bundle to Map entries
- .toMap -> Convert the key & values in the bundle to Map entries
Please go thorough the Bundle Extension code documentation for more information
-
.getColorCompat -> Get Color from res
Parameters 1.colorId -> color resource id
-
.getDrawableCompat -> Get drawable from res
Parameters 1.colorId -> drawable resource id
-
.toast -> Shows Toast message
Parameters 1.message -> toast message, either in string or string res 2.duration -> toast duration (not mandatory). Default value is short
-
.browse -> Open an url in browser
Parameters 1.url -> web url 2.newTask -> enable FLAG_ACTIVITY_NEW_TASK (not mandatory). Default value is false
-
.hideKeyboard -> Hides the keyboard from the user
Parameters 1.view -> view id
-
.showKeyboard -> Displays the keyboard to the user
Parameters 1.view -> view id
-
.isOnline -> Checks whether device is connected to network or not.
-
.isConnectedToWifiNetwork -> Checks whether the device is connected to Wi-Fi or not.
-
.isConnectedToCellularNetwork -> Checks whether the device is connected to Mobile-data or not.
-
.openAppInPlayStore -> Opens the App in play store. Usually useful for doing review and ratings.
-
.getAppVersionCode -> Get app version code
-
.getAppVersionName -> Get app version name
-
.resourceToUri -> Returns the resource in Uri format
Parameters 1.resId -> Resource id.
-
.getAppUserAgent -> Returns the App user-agent which can be used to pass in the API headers or params.
-
.getAppName -> Get app name
-
.weakReference -> Returns the weak reference of the context.
Please go thorough the Context Extension code documentation
- .value -> Get EditText value
Please go thorough the EditText Extension code documentation for more information
-
.toast -> Shows Toast message
Parameters 1.message -> toast message, either in string or string res 2.duration -> toast duration (not mandatory). Default value is short
Please go thorough the Fragment Extensions code documentation for more information
-
.isEllipsized -> Returns true if the text is ellipsized
-
.setFontFamily -> Overrides the default typeface with the font resource Provided.
Parameters 1.fontRes -> Font Resource id
-
.textAppearance -> Set Text appearance
Parameters 1.context -> context 2.resId -> Style res id
-
.underLine -> Extension method underLine for TextView.
-
.bold -> Extension method bold for TextView.
Please go thorough the TextView Extensions code documentation for more information
-
.setOnSafeClickListener -> Restrict multiple consecutive click events for the view.
Parameters 1.defaultInterval -> defaultInterval Interval to wait until click is enabled (not mandatory). Default interval is 800ms
-
.enable -> Make View Enable
-
.disable -> Make view Disable, goes in a disabled color and clicks wont accept
-
.gone -> Make the view Gone
-
.visible -> Make the view Visible
-
.snackbar -> Shows Snackbar
Parameters 1.messageRes -> snackbar message 2.length -> duration 3.actionRes -> action button text (optinal). Needed only if there is any action for snackbar 4.actionColor -> Color of action button (optinal)
Sample Code:
button.setOnSafeClickListener { view ->
view?.snackbar(
R.string.app_name,
Snackbar.LENGTH_INDEFINITE,
R.string.retry,
R.color.black
){
toast("action clicked")
}
}
Please go thorough the View Extensions code documentation for more information