Convenience extension methods for android's auto-generated /res folder R. class.

Overview

Donation About Jan Rabe Android Arsenal

Android Resource Extensions

Build Status Hits-of-Code Javadoc API Gradle Version Kotlin GitHub license androidx

Convenience extension methods for android's auto-generated /res folder R. class.

Basically everything in your res/ and /assets folder can be accessed via an extension function. Note: everything gets loaded with current activity context, if that is not available it uses application context.

Features:

Values
  • resBoolean
  • resInt
  • resLong
  • resString
  • resString(args)
  • localizedString(locale)
  • localizedResources(locale)
  • quantityString
  • quantityString(args)
  • resColorLong
  • resColor
  • resDimension
  • html
  • html
  • csv
  • resXml
  • resFraction
Arrays
  • resIntArray
  • resStringArray
  • resTextArray
  • resColorArray
  • resColorIntArray
  • resDrawableArray
  • resDrawableIdArray
Ids
  • resId
  • resName
  • resTypeName
  • resPackageName
  • resStringId
  • resDrawableId
  • resDrawableId((Exception)->Unit)
  • resColorDrawable
  • resGradientDrawable
Objects
  • resDrawable
  • colorDrawable
  • resAnim
  • resAnimator
  • resFont
  • resRaw
  • resInterpolator
  • resLayoutAnimation
  • resTransition
Layout
  • resLayout
  • inflate
Screen
  • dp
  • px
  • sp
  • pt
  • inches
  • mm
  • screenWidthDp
  • screenHeightDp
  • screenWidthPixels
  • screenHeightPixels
Assets
  • bytesFromAssets // thread-safe
  • stringFromAssets
Misc
  • isRightToLeft
  • isTelephoneLink
  • isMailToLink

ManifestPermissions

  • isGranted // checks if granted, doesn't trigger request

How to use

val my_integer: Int = R.integer.my_integer.resInt
val my_long: Long = R.integer.my_long.resLong
val my_string: String = R.string.my_string.resString
val my_string_args: String = R.string.my_string_args.resString("ipsum")
val my_string_args_float: String = R.string.my_string_args_float.resString(2f)
val my_localized_string: String = R.string.my_localized_string.localizedString(Locale.GERMAN)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    val my_localized_resources: Resources = localizedResources(this, Locale.GERMAN)
}
val my_quantityString: String = R.plurals.my_quantityString.quantityString(2)
val my_quantityString_args: String = R.plurals.my_quantityString_args.quantityString(2, "total")

val my_boolean: Boolean = R.bool.my_boolean.resBoolean
val my_color_long: Long = R.color.my_color_long.resColorLong
val my_color: Int = R.color.my_color.resColor
val my_dimension: Float = R.dimen.my_dimension.resDimension
val my_string_html: Spanned = """<a href="https://www.google.com/">Google</a>""".html
val my_html: Spanned = R.string.my_html.html
val my_csv: List<String> = R.string.my_csv.csv
val my_xml: XmlResourceParser = R.xml.lorem_ipsum.resXml
// 0.10f
val my_fraction: Float = R.fraction.my_fraction.resFraction(2, 2)
val my_int_array: IntArray = R.array.my_int_array.resIntArray
val my_string_array: Array<String> = R.array.my_string_array.resStringArray
val my_character_array: Array<CharSequence> = R.array.my_string_array.resTextArray
/*ColorRes*/
val my_icons_array: List<Int> = R.array.my_colors.resColorArray
/*ColorInt*/
val my_icons_array_color_int: List<Int> = R.array.my_colors.resColorIntArray
/*@DrawableRes*/
val my_colors_array: List<Int> = R.array.my_icons.resDrawableIdArray
/*@Drawable*/
val my_colors_array_drawable: List<Drawable> = R.array.my_icons.resDrawableArray
@IdRes val my_id: Int = "my_id".resId
val my_res_name: String = R.integer.my_res_name.resName
val my_res_type_name: String = R.integer.my_res_type_name.resTypeName
val my_res_package_name: String = R.integer.my_res_package_name.resPackageName
@StringRes val my_res_string_id: Int = "my_res_string_id".resStringId { it.printStackTrace() }
@DrawableRes val my_res_drawable_id: Int = "ic_share".resDrawableId
@DrawableRes val my_res_drawable_id_with_error_handling: Int = "ic_share".resDrawableId { it.printStackTrace() }
val my_drawable: Drawable = R.drawable.ic_share.resDrawable
val my_anim: Animation = R.anim.grow.resAnim
val my_animator: Animator = R.animator.flip_animation.resAnimator
val my_font: Typeface = R.font.lato.resFont
val my_raw: InputStream = R.raw.my_raw.resRaw
val my_interpolator: Interpolator = android.R.interpolator.anticipate_overshoot.resInterpolator
val my_res_layout_animation_controller: LayoutAnimationController = R.anim.layout_animation.resLayoutAnimation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    val my_transition: Transition = android.R.transition.explode.resTransition
}
val my_layout: XmlResourceParser = R.layout.activity_main.resLayout
val my_inflated_layout: View = R.layout.activity_main.inflate(root)
val my_dp: Float = 16f.dp
val my_dp_int: Int = 16.dp
val my_px: Float = 200f.px
val my_px_int: Int = 200.px
val my_sp: Float = 14f.sp
val my_pt: Float = 14f.pt
val my_inches: Float = 14f.inches
val my_mm: Float = 14f.mm
val my_screen_width_dp: Int = screenWidthDp
val my_screen_height_dp: Int = screenHeightDp
val my_screen_width_pixels: Int = screenWidthPixels
val my_screen_height_pixels: Int = screenHeightPixels
val my_bytes_from_assets: ByteArray? = "my_text.json".bytesFromAssets()
val my_string_from_assets: String? = "my_text.json".stringFromAssets()
val my_device_is_rtl: Boolean = isRightToLeft
val my_string_is_a_telephone_link: Boolean = Uri.parse("""<a href="tel:491771789232">Google</a>""").isTelephoneLink
val my_string_is_a_mailto_link: Boolean = Uri.parse("""<a href="mailto:[email protected]">Google</a>""").isMailToLink

val locationPermission : Boolean = Manifest.permission.ACCESS_FINE_LOCATION.isGranted

How to install

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.florent37:applicationprovider:1.0.0"
    implementation 'com.github.kibotu:AndroidResourceExtensions:{latest}'
}

Notes

Follow me on Twitter: @wolkenschauer

Let me know what you think: [email protected]

Contributions welcome!

License

Copyright 2019 Jan Rabe

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.
You might also like...
Simple extension for account suggestion and auto completion.

AccountAutoCompleteEditText Just a simple implementation for use of auto complete text view with device account suggestion Usage Just simply put an cu

Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor.
Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor.

1. AutoProxy Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a

Camera Folder:
Camera Folder: "Take a Photo from Camera" everywhere where you can open a photo file

When "Camera Folder" is installed many Android-Apps that can open jpg files can also take a photo from camera.

Kotlin backend based on the Clean Architecture principles. Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints, Gradle.
Kotlin backend based on the Clean Architecture principles. Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints, Gradle.

Kotlin Clean Architecture Backend Kotlin backend based on the Clean Architecture principles. The application is separated into three modules: Domain,

Fixtures for Kotlin providing generated values for unit testing

A tool to generate well-defined, but essentially random, input following the idea of constrained non-determinism.

Generated with spring boot kotlin starter kit

Kotlin backend Generated with spring boot kotlin starter kit The idea is to: Get a microservice written in kotlin for managing users and roles. To be

This folder contains the source code for the Words app codelab.

Words App This folder contains the source code for the Words app codelab. Introduction Words app allows you to select a letter and use Intents to navi

This folder contains the source code for the Words app codelab.

Choose the letter, choose the word from a list then press it to google search for it. Ps. Learnt from Android-Basics-Kotlin powered by Google.

This folder contains the source code for the Words app codelab.

Words App This folder contains the source code for the Words app codelab. Introduction Words app allows you to select a letter and use Intents to navi

This folder contains the source code for the Bus Scheduler app codelab

Bus Scheduler App This folder contains the source code for the Bus Scheduler app codelab. Introduction The Bus Scheduler app displays a list of bus st

This folder contains the source code for the Words app codelab

Words App This folder contains the source code for the Words app codelab. Introd

DSL for JPA Criteria API without generated metamodel and reflection.
DSL for JPA Criteria API without generated metamodel and reflection.

Kotlin JDSL Kotlin JDSL is DSL for JPA Criteria API without generated metamodel and reflection. It helps you write a JPA query like writing an SQL sta

An Android app that gives you a password generated by a given phrase with a custom algorithm, it also has password and biometric security.

An Android app that gives you a password generated by a given phrase with a custom algorithm, it also has password and biometric security.

Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension.

ViewBinding Delegate Extension Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension. Binding inst

Bind Android views and callbacks to fields and methods.
Bind Android views and callbacks to fields and methods.

Butter Knife Attention: This tool is now deprecated. Please switch to view binding. Existing versions will continue to work, obviously, but only criti

Navigation Drawer Activity with material design style and simplified methods

MaterialNavigationDrawer Navigation Drawer Activity with material design style and simplified methods       It requires 10+ API and android support v7

Android - Annotate methods to use as listeners for a sensor.
Android - Annotate methods to use as listeners for a sensor.

SensorAnnotations Annotate methods to use as listeners for sensor events. public class MyActivity extends Activity { /** * Perform actions as

Bind Android views and callbacks to fields and methods.
Bind Android views and callbacks to fields and methods.

Butter Knife Attention: This tool is now deprecated. Please switch to view binding. Existing versions will continue to work, obviously, but only criti

A framework for hook java methods.
A framework for hook java methods.

Legend Projects are out of date, plese move to: Whale Hook What is Legend? Legend is a Hook framework for Android Development, it allows you to Hook J

Owner
Jan Rabe
Native Android / Unity Developer & Technocrat #kotlin #csharp #unity #opensource
Jan Rabe
Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any type of design pattern

What is Kotlin Extension Function ? Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any ty

mohsen 21 Dec 3, 2022
A set of web-based tools for generating graphics and other assets that would eventually be in an Android application's res/ directory.

Android Asset Studio Open the Android Asset Studio See the older version if you're having trouble with the new version A web-based set of tools for ge

Roman Nurik 6.3k Dec 31, 2022
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

Mike Penz 1.8k Nov 10, 2022
Androids EditText that animates the typed text. EditText is extended to create AnimatedEditText and a PinEntryEditText.

AnimatedEditText for Android This repository contains AnimatedEditText and TextDrawable all of which extend the behaviour of EditText and implement fe

Ali Muzaffar 439 Nov 29, 2022
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

Mike Penz 1.8k Nov 10, 2022
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

Mike Penz 1.8k Nov 10, 2022
A collection of useful extension methods for Android

Kotlin Jetpack A collection of useful extension methods for Android Arguments Bindings Preferences Bindings Resources Bindings Arguments Bindings publ

Vladimir Mironov 187 Nov 10, 2022
Most used extension methods for Kotlin

Extensify Most used extension methods for Kotlin Download Step 1. Add the JitPack repository to your build file allprojects { repositories {

Mobven 36 Aug 25, 2022
A kotlin library of extension functions that add smalltalk style methods to objects.

KtTalk A kotlin library of extension functions that add smalltalk style methods to objects. Motivation Smalltalk is a pure OO language in which everyt

null 11 Oct 16, 2021
AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.

AutoscaleEditText AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size. Latest Version How to use

Txus Ballesteros 354 Nov 28, 2022