ResOf is an android resource wrapper library.

Related tags

Resources ResOf
Overview

ResOf

License Android Arsenal

ResOf is an android resource wrapper library.

Install

project/build.gradle

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

app/build.gradle

dependencies {
    implementation 'com.github.dev-weiqi:ResOf:$latestVersion'
}

Usage

Just use it! You don't need to do any initialization!

xml

ResOf ">
<resources>
    <string name="app_name">ResOfstring>
resources>
  1. Function
val appName = stringOf(R.string.app_name)
Log.v(TAG,"AppName: $appName !")
--------------------
V/TAG: AppName: ResOf !
  1. Extension
val appName = R.string.app_name.resOf.string()
Log.v(TAG,"AppName: $appName !")
--------------------
V/TAG: AppName: ResOf !

Supported Resources

Resource Type AAPT class Function Kotlin Extension Return Type
Animation R.anim animOf resOf.anim Animation
Boolean R.bool boolOf resOf.bool Boolean
Color R.color colorIntOf resOf.colorInt Int
ColorStateList R.color colorStateListOf resOf.colorStateList ColorStateList
Dimension R.dimen dimenOf resOf.dimen Float
Dimen R.dimen dimenOffsetOf resOf.dimenOffset Int
Dimen R.dimen dimenSizeOf resOf.dimenSize Int
Drawable R.drawable drawableOf resOf.drawable Drawable
Font R.font fontOf resOf.font Typeface
Fraction R.fraction fractionOf resOf.fraction Float
IntArray R.array intArrayOf resOf.intArray IntArray
Integer R.integer integerOf resOf.integer Int
Interpolator R.interpolator interpolatorOf resOf.interpolator Interpolator
Layout R.layout layoutOf resOf.layout XmlResourceParser
Plurals R.plurals pluralsOf resOf.plurals String
Raw R.raw rawOf resOf.raw InputStream
String R.string stringOf resOf.string String
StringArray R.array stringArrayOf resOf.stringArray Array
TypedArray R.array typedArrayOf resOf.typedArray TypedArray
Xml R.xml xmlOf resOf.xml XmlResourceParser

Contribution

Contributions are always welcome. If you have any ideas or suggestions, you can create a Github issue. I will get to you as soon as possible.

License

Copyright 2021 Wei-Qi Wang

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...
TaggerString is very light library which allows to build dynamic string resource in much more readable way.

TaggerString TaggerString is very light library which allows to build dynamic string resource in much more readable way. I guess that every Android de

SVG to Android VectorDrawable XML resource file
SVG to Android VectorDrawable XML resource file

svg2android [Deprecated - use official Vector Asset Studio directly from Android Studio] Convert SVG to Android VectorDrawable XML resource file. Extr

proguard resource for Android by wechat team

AndResGuard Read this in other languages: English, 简体中文. AndResGuard is a tooling for reducing your apk size, it works like the ProGuard for Java sour

Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis
Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis

Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis

SVG to Android VectorDrawable XML resource file
SVG to Android VectorDrawable XML resource file

svg2android [Deprecated - use official Vector Asset Studio directly from Android Studio] Convert SVG to Android VectorDrawable XML resource file. Extr

Taskify - An app to manage your daily tasks and boost your productivity. Taskify is built using kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Taskify - An app to manage your daily tasks and boost your productivity. Taskify is built using kotlin and follows all modern android Development practices and hence is a good learning resource for beginners

Taskify Taskify is an app to manage your daily tasks and boost your productivity Video Introduction 📹 This is a small introduction video about Taskif

Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners

Healthify Healthify is an app to track your daily water intake and sleep and boost your work efficiency. Video Introduction 📹 This is a small introdu

HostelMate - A Need For Hosteler (An Android App that helps students to find the best resource like hostels and tiffin centers etc.)
HostelMate - A Need For Hosteler (An Android App that helps students to find the best resource like hostels and tiffin centers etc.)

Android-Study-Jams-Hostel-Mate HostelMate - A Need For Hosteler (An Android App that helps students to find the best resource like hostels and tiffin

An open resource for Douban API with NETEASY Music's  UI.
An open resource for Douban API with NETEASY Music's UI.

扫码关注公众号有惊喜 (转载本站文章请注明作者和出处 方志朋的博客) 瓣呀,一个非官方的豆瓣app 首页分为三大模块,包括:电影、看书、音乐。而电影模块又包括最近热门电影、TOP250;看书模块包括综合、文学、流行、文化、生活五个部分;音乐模块包括流行、经典、韩系、欧美四个模块。 首页界面风格采用M

Secure your REST APIs with Spring Security, Resource and Authorization Server from zero to JWT

Secure REST APIs with Spring ./mvnw RTFM YouTube: Spring Security Patterns YouTube: Spring Security 5.5 From Taxi to Takeoff Official Apache Maven doc

Go-inspired defer-based resource management

defer-kt Golang-inspired resource management library. Add to your project Gradle implementation "me.jason5lee:defer:1.0.1" Gradle Kotlin DSL implement

Reason about resource-safety in the same way you reason about Structured Concurrency with SuspendApp!

Reason about resource-safety in the same way you reason about Structured Concurrency with SuspendApp!

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

EasyPermissions-ktx Kotlin version of the popular googlesample/easypermissions wrapper library to simplify basic system permissions logic on Android M

Very easy to use wrapper library for Android SharePreferences

Treasure English document Treasure是一个Android平台上基于SharePreferences的偏好存储库,只需要定义接口,无需编写实现,默认支持Serializable和Parcelable。运行时0反射,不仅使用方便而且性能和原生写法几乎无差别。 使用方法 1

Android AsyncTask wrapper library, written in Kotlin

KillerTask This is a Kotlin Android library to create async background tasks. Inspired by TinyTask, but more beautiful and easy to use for Kotlin Andr

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

This library is a set of simple wrapper classes that are aimed to help you easily access android device information.
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

🪁 Android Resources Wrapper Library
🪁 Android Resources Wrapper Library

Kite Android Resource Wrapper Library. TLDR Fed up with typing ContextCompat, resources and context all over your apps to access your resources? Say n

A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Comments
  • ResOfExtension improvements

    ResOfExtension improvements

    Hey! Nice work so far.

    My only recommendation is that you might wanna think of improving ResOfExtension. Since you aren't controlling if the Int instance is actually a resource or just some random number (1, 2, 3, ...), you're basically polluting every Int declaration across an app with plenty of methods which 99% of the time aren't useful and just plain confusing for someone who's not aware of what ResOf does.

    For example:

    • 1.asString() should return "1", not throw some exception.
    • 1.asBool() should return true, not throw some exception.
    • 1.asInteger() should return 1, not throw some exception.

    You might wanna have something like Int.resOf.string() for example. This way you nest every extension under resOf, indicating the actual use of it, and cleaning up Int instances from methods that can be interpreted as a simple toSomeObject() method (specially when as is a casting keyword).

    Cheers

    enhancement important 
    opened by mradzinski 4
  • activity theming not respected

    activity theming not respected

    I'm with you on passing context everywhere is one of the most annoying things in android and we need to come up with better solutions and also I like your idea using the androidx startup-runtime!

    however you might want to hook up on the ActivityLifecycleCallbacks to also use the current activity to for retrieving correct activity themed values if available. another drawback is that it doesn't work with services, e.g. workmanager, push notifications, since application context is not the correct context to retrieve the values.

    here is my solution to the same problem https://github.com/kibotu/AndroidResourceExtensions

    it also fails on layout themed attributes though.

    another thing is that creating wrapper classes ResOfWrapper for every single resource retrieval seems a bit wasteful, have you thought of using inline classes instead?

    opened by kibotu 1
Releases(1.1.2)
Owner
Joseph Wang
Android Developer
Joseph Wang
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
:ballot_box_with_check: [Cheatsheet] Tips and tricks for Android Development

Cheatsheet about tips and tricks for Android Development. This is a simple set of tips and tricks regarding Android Development which I have gathered

Nishant Srivastava 4.6k Dec 24, 2022
[] Easily create a simple, attractive and seamless custom action bar style for your Android application

Android Action Bar Style Generator ####DEPRECATED: Consider using Toolbar or its support library equivalent.#### The Android Action Bar Style Generato

Jeff Gilfelt 1k Nov 10, 2022
Blogs about Android

Android Blogs See also: https://github.com/vbauer/java-blogs Groups & Companies Androcid http://www.androcid.com Androidized http://www.androidized.co

Vladislav Bauer 499 Nov 13, 2022
Gradle plugin that creates FindBugs reports for android projects

findbugs-android A Gradle plugin that creates FindBugs tasks for each variant of android application or library project Project site: https://findbugs

Chaitanya Pramod 131 Dec 29, 2022
Learn How to use Google Map API for Android from Basic to Advance with complete examples.

Complete-Google-Map-API-Tutorial Learn How to use Google Map API for Android from Basic to Advance. Satellite View 3D Building Map and StreetView Lear

Next 117 Dec 8, 2022
Convenience extension methods for android's auto-generated /res folder R. class.

Android Resource Extensions Convenience extension methods for android's auto-generated /res folder R. class. Basically everything in your res/ and /as

Jan Rabe 41 Jul 21, 2022
Wynncraft API Wrapper - Simple wrapper to get Wynncraft Stats of a player or a guild and more in Java

WynncraftAPIWrapper Simple wrapper to get Wynncraft Stats of a player or a guild

byBackfish 3 Sep 27, 2022
Phrase is an Android string resource templating library

Phrase - Android string formatting CharSequence formatted = Phrase.from("Hi {first_name}, you are {age} years old.") .put("first_name", firstName)

Square 1.4k Dec 9, 2022
🚀 A very customizable library that allows you to present menu items (from menu resource and/or other sources) to users as a bottom sheet.

SlidingUpMenu A library that allows you to present menu items (from menu resource and/or other sources) to users as a bottom sheet. Gradle Dependency

Rasheed Sulayman 26 Jul 17, 2022