Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Improved Resources Handling #167

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions core/foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,44 @@ public final class dev/teogor/ceres/core/foundation/ConnectivityManagerNetworkMo
public static fun newInstance (Landroid/content/Context;)Ldev/teogor/ceres/core/foundation/ConnectivityManagerNetworkMonitor;
}

public final class dev/teogor/ceres/core/foundation/DefaultResources : dev/teogor/ceres/core/foundation/Resources {
public static final field $stable I
public fun <init> (Landroid/content/res/Resources;)V
public fun getAnimation (I)Landroid/content/res/XmlResourceParser;
public fun getBoolean (I)Z
public fun getColor (I)I
public fun getDimension (I)F
public fun getDimensionPixelOffset (I)I
public fun getDimensionPixelSize (I)I
public fun getFloat (I)F
public fun getFraction (III)F
public fun getIdentifier (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
public fun getIntArray (I)[I
public fun getInteger (I)I
public fun getLayout (I)Landroid/content/res/XmlResourceParser;
public fun getQuantityString (II)Ljava/lang/String;
public fun getQuantityString (II[Ljava/lang/Object;)Ljava/lang/String;
public fun getQuantityText (II)Ljava/lang/CharSequence;
public fun getResourceEntryName (I)Ljava/lang/String;
public fun getResourceName (I)Ljava/lang/String;
public fun getResourcePackageName (I)Ljava/lang/String;
public fun getResourceTypeName (I)Ljava/lang/String;
public fun getString (I)Ljava/lang/String;
public fun getString (I[Ljava/lang/Object;)Ljava/lang/String;
public fun getStringArray (I)[Ljava/lang/String;
public fun getText (I)Ljava/lang/CharSequence;
public fun getText (ILjava/lang/CharSequence;)Ljava/lang/CharSequence;
public fun getTextArray (I)[Ljava/lang/CharSequence;
public fun getValue (ILandroid/util/TypedValue;Z)V
public fun getValue (Ljava/lang/String;Landroid/util/TypedValue;Z)V
public fun getValueForDensity (IILandroid/util/TypedValue;Z)V
public fun getXml (I)Landroid/content/res/XmlResourceParser;
public fun obtainTypedArray (I)Landroid/content/res/TypedArray;
public fun openRawResource (I)Ljava/io/InputStream;
public fun openRawResource (ILandroid/util/TypedValue;)Ljava/io/InputStream;
public fun openRawResourceFd (I)Landroid/content/res/AssetFileDescriptor;
}

public final class dev/teogor/ceres/core/foundation/FoundationGlobal {
public static final field $stable I
public static final field INSTANCE Ldev/teogor/ceres/core/foundation/FoundationGlobal;
Expand Down Expand Up @@ -228,6 +266,42 @@ public final class dev/teogor/ceres/core/foundation/PackageManagerUtils {
public final fun getVersionName ()Ljava/lang/String;
}

public abstract interface class dev/teogor/ceres/core/foundation/Resources {
public abstract fun getAnimation (I)Landroid/content/res/XmlResourceParser;
public abstract fun getBoolean (I)Z
public abstract fun getColor (I)I
public abstract fun getDimension (I)F
public abstract fun getDimensionPixelOffset (I)I
public abstract fun getDimensionPixelSize (I)I
public abstract fun getFloat (I)F
public abstract fun getFraction (III)F
public abstract fun getIdentifier (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
public abstract fun getIntArray (I)[I
public abstract fun getInteger (I)I
public abstract fun getLayout (I)Landroid/content/res/XmlResourceParser;
public abstract fun getQuantityString (II)Ljava/lang/String;
public abstract fun getQuantityString (II[Ljava/lang/Object;)Ljava/lang/String;
public abstract fun getQuantityText (II)Ljava/lang/CharSequence;
public abstract fun getResourceEntryName (I)Ljava/lang/String;
public abstract fun getResourceName (I)Ljava/lang/String;
public abstract fun getResourcePackageName (I)Ljava/lang/String;
public abstract fun getResourceTypeName (I)Ljava/lang/String;
public abstract fun getString (I)Ljava/lang/String;
public abstract fun getString (I[Ljava/lang/Object;)Ljava/lang/String;
public abstract fun getStringArray (I)[Ljava/lang/String;
public abstract fun getText (I)Ljava/lang/CharSequence;
public abstract fun getText (ILjava/lang/CharSequence;)Ljava/lang/CharSequence;
public abstract fun getTextArray (I)[Ljava/lang/CharSequence;
public abstract fun getValue (ILandroid/util/TypedValue;Z)V
public abstract fun getValue (Ljava/lang/String;Landroid/util/TypedValue;Z)V
public abstract fun getValueForDensity (IILandroid/util/TypedValue;Z)V
public abstract fun getXml (I)Landroid/content/res/XmlResourceParser;
public abstract fun obtainTypedArray (I)Landroid/content/res/TypedArray;
public abstract fun openRawResource (I)Ljava/io/InputStream;
public abstract fun openRawResource (ILandroid/util/TypedValue;)Ljava/io/InputStream;
public abstract fun openRawResourceFd (I)Landroid/content/res/AssetFileDescriptor;
}

public final class dev/teogor/ceres/core/foundation/SigningInfo {
public static final field $stable I
public fun <init> (ZZLjava/util/List;Ljava/util/List;)V
Expand Down Expand Up @@ -283,6 +357,43 @@ public final class dev/teogor/ceres/core/foundation/compositions/LocalPackageMan
public static final fun getLocalPackageManager ()Landroidx/compose/runtime/ProvidableCompositionLocal;
}

public final class dev/teogor/ceres/core/foundation/compositions/LocalResouresKt {
public static final fun ValueForDensityResource (IILandroid/util/TypedValue;ZLandroidx/compose/runtime/Composer;I)V
public static final fun ValueResource (ILandroid/util/TypedValue;ZLandroidx/compose/runtime/Composer;I)V
public static final fun ValueResource (Ljava/lang/String;Landroid/util/TypedValue;ZLandroidx/compose/runtime/Composer;I)V
public static final fun animationResource (ILandroidx/compose/runtime/Composer;I)Landroid/content/res/XmlResourceParser;
public static final fun booleanResource (ILandroidx/compose/runtime/Composer;I)Z
public static final fun colorResource (ILandroidx/compose/runtime/Composer;I)I
public static final fun dimensionPixelOffsetResource (ILandroidx/compose/runtime/Composer;I)I
public static final fun dimensionPixelSizeResource (ILandroidx/compose/runtime/Composer;I)I
public static final fun dimensionResource (ILandroidx/compose/runtime/Composer;I)F
public static final fun floatResource (ILandroidx/compose/runtime/Composer;I)F
public static final fun fractionResource (IIILandroidx/compose/runtime/Composer;I)F
public static final fun getLocalResources ()Landroidx/compose/runtime/ProvidableCompositionLocal;
public static final fun identifierResource (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroidx/compose/runtime/Composer;I)I
public static final fun intArrayResource (ILandroidx/compose/runtime/Composer;I)[I
public static final fun integerResource (ILandroidx/compose/runtime/Composer;I)I
public static final fun layoutResource (ILandroidx/compose/runtime/Composer;I)Landroid/content/res/XmlResourceParser;
public static final fun quantityStringResource (IILandroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun quantityStringResource (II[Ljava/lang/Object;Landroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun quantityTextResource (IILandroidx/compose/runtime/Composer;I)Ljava/lang/CharSequence;
public static final fun rawResource (ILandroid/util/TypedValue;Landroidx/compose/runtime/Composer;I)Ljava/io/InputStream;
public static final fun rawResource (ILandroidx/compose/runtime/Composer;I)Ljava/io/InputStream;
public static final fun rawResourceFd (ILandroidx/compose/runtime/Composer;I)Landroid/content/res/AssetFileDescriptor;
public static final fun resourceEntryNameResource (ILandroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun resourceNameResource (ILandroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun resourcePackageNameResource (ILandroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun resourceTypeNameResource (ILandroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun stringArrayResource (ILandroidx/compose/runtime/Composer;I)[Ljava/lang/String;
public static final fun stringResource (ILandroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun stringResource (I[Ljava/lang/Object;Landroidx/compose/runtime/Composer;I)Ljava/lang/String;
public static final fun textArrayResource (ILandroidx/compose/runtime/Composer;I)[Ljava/lang/CharSequence;
public static final fun textResource (ILandroidx/compose/runtime/Composer;I)Ljava/lang/CharSequence;
public static final fun textResource (ILjava/lang/CharSequence;Landroidx/compose/runtime/Composer;I)Ljava/lang/CharSequence;
public static final fun typedArrayResource (ILandroidx/compose/runtime/Composer;I)Landroid/content/res/TypedArray;
public static final fun xmlResource (ILandroidx/compose/runtime/Composer;I)Landroid/content/res/XmlResourceParser;
}

public final class dev/teogor/ceres/core/foundation/compositions/LocalVibratorKt {
public static final fun getLocalVibrator ()Landroidx/compose/runtime/ProvidableCompositionLocal;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/*
* Copyright 2023 teogor (Teodor Grigor)
*
* 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
*
* https://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.
*/

package dev.teogor.ceres.core.foundation

import android.annotation.SuppressLint
import android.content.res.AssetFileDescriptor
import android.content.res.TypedArray
import android.content.res.XmlResourceParser
import android.os.Build
import android.util.TypedValue
import androidx.annotation.AnimRes
import androidx.annotation.AnimatorRes
import androidx.annotation.AnyRes
import androidx.annotation.ArrayRes
import androidx.annotation.BoolRes
import androidx.annotation.ColorRes
import androidx.annotation.DimenRes
import androidx.annotation.FractionRes
import androidx.annotation.IntegerRes
import androidx.annotation.LayoutRes
import androidx.annotation.PluralsRes
import androidx.annotation.RawRes
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
import androidx.annotation.XmlRes
import java.io.InputStream

class DefaultResources(
private val resources: android.content.res.Resources,
) : Resources {
override fun getString(@StringRes id: Int): String {
return resources.getString(id)
}

override fun getString(@StringRes id: Int, vararg formatArgs: Any): String {
return resources.getString(id, *formatArgs)
}

override fun getStringArray(@ArrayRes id: Int): Array<String> {
return resources.getStringArray(id)
}

override fun getText(@StringRes id: Int): CharSequence {
return resources.getText(id)
}

override fun getText(@StringRes id: Int, def: CharSequence): CharSequence {
return resources.getText(id, def)
}

override fun getQuantityText(@PluralsRes id: Int, quantity: Int): CharSequence {
return resources.getQuantityText(id, quantity)
}

override fun getQuantityString(
@PluralsRes id: Int,
quantity: Int,
vararg formatArgs: Any,
): String {
return resources.getQuantityString(id, quantity, *formatArgs)
}

override fun getQuantityString(@PluralsRes id: Int, quantity: Int): String {
return resources.getQuantityString(id, quantity)
}

override fun getTextArray(@ArrayRes id: Int): Array<CharSequence> {
return resources.getTextArray(id)
}

override fun getIntArray(@ArrayRes id: Int): IntArray {
return resources.getIntArray(id)
}

override fun obtainTypedArray(@ArrayRes id: Int): TypedArray {
return resources.obtainTypedArray(id)
}

override fun getDimension(@DimenRes id: Int): Float {
return resources.getDimension(id)
}

override fun getDimensionPixelOffset(@DimenRes id: Int): Int {
return resources.getDimensionPixelOffset(id)
}

override fun getDimensionPixelSize(@DimenRes id: Int): Int {
return resources.getDimensionPixelSize(id)
}

override fun getFraction(@FractionRes id: Int, base: Int, pbase: Int): Float {
return resources.getFraction(id, base, pbase)
}

override fun getColor(@ColorRes id: Int): Int {
return resources.getColor(id)
}

override fun getBoolean(@BoolRes id: Int): Boolean {
return resources.getBoolean(id)
}

override fun getInteger(@IntegerRes id: Int): Int {
return resources.getInteger(id)
}

@RequiresApi(Build.VERSION_CODES.Q)
override fun getFloat(@DimenRes id: Int): Float {
return resources.getFloat(id)
}

override fun getLayout(@LayoutRes id: Int): XmlResourceParser {
return resources.getLayout(id)
}

override fun getAnimation(@AnimatorRes @AnimRes id: Int): XmlResourceParser {
return resources.getAnimation(id)
}

override fun getXml(@XmlRes id: Int): XmlResourceParser {
return resources.getXml(id)
}

override fun openRawResource(@RawRes id: Int): InputStream {
return resources.openRawResource(id)
}

override fun openRawResource(@RawRes id: Int, value: TypedValue?): InputStream {
return resources.openRawResource(id, value)
}

override fun openRawResourceFd(@RawRes id: Int): AssetFileDescriptor {
return resources.openRawResourceFd(id)
}

override fun getValue(@AnyRes id: Int, outValue: TypedValue?, resolveRefs: Boolean) {
resources.getValue(id, outValue, resolveRefs)
}

override fun getValueForDensity(
@AnyRes id: Int,
density: Int,
outValue: TypedValue?,
resolveRefs: Boolean,
) {
resources.getValueForDensity(id, density, outValue, resolveRefs)
}

override fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean) {
resources.getValue(name, outValue, resolveRefs)
}

@SuppressLint("DiscouragedApi")
override fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int {
return resources.getIdentifier(name, defType, defPackage)
}

override fun getResourceName(@AnyRes resid: Int): String {
return resources.getResourceName(resid)
}

override fun getResourcePackageName(@AnyRes resid: Int): String {
return resources.getResourcePackageName(resid)
}

override fun getResourceTypeName(@AnyRes resid: Int): String {
return resources.getResourceTypeName(resid)
}

override fun getResourceEntryName(@AnyRes resid: Int): String {
return resources.getResourceEntryName(resid)
}
}

interface Resources {
fun getString(@StringRes id: Int): String
fun getString(@StringRes id: Int, vararg formatArgs: Any): String
fun getStringArray(@ArrayRes id: Int): Array<String>
fun getText(@StringRes id: Int): CharSequence
fun getText(@StringRes id: Int, def: CharSequence): CharSequence
fun getQuantityText(@PluralsRes id: Int, quantity: Int): CharSequence
fun getQuantityString(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any): String
fun getQuantityString(@PluralsRes id: Int, quantity: Int): String
fun getTextArray(@ArrayRes id: Int): Array<CharSequence>
fun getIntArray(@ArrayRes id: Int): IntArray
fun obtainTypedArray(@ArrayRes id: Int): TypedArray
fun getDimension(@DimenRes id: Int): Float
fun getDimensionPixelOffset(@DimenRes id: Int): Int
fun getDimensionPixelSize(@DimenRes id: Int): Int
fun getFraction(@FractionRes id: Int, base: Int, pbase: Int): Float
fun getColor(@ColorRes id: Int): Int
fun getBoolean(@BoolRes id: Int): Boolean
fun getInteger(@IntegerRes id: Int): Int

@RequiresApi(Build.VERSION_CODES.Q)
fun getFloat(@DimenRes id: Int): Float
fun getLayout(@LayoutRes id: Int): XmlResourceParser
fun getAnimation(@AnimatorRes @AnimRes id: Int): XmlResourceParser
fun getXml(@XmlRes id: Int): XmlResourceParser
fun openRawResource(@RawRes id: Int): InputStream
fun openRawResource(@RawRes id: Int, value: TypedValue?): InputStream
fun openRawResourceFd(@RawRes id: Int): AssetFileDescriptor
fun getValue(@AnyRes id: Int, outValue: TypedValue?, resolveRefs: Boolean)
fun getValueForDensity(@AnyRes id: Int, density: Int, outValue: TypedValue?, resolveRefs: Boolean)
fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean)
fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int
fun getResourceName(@AnyRes resid: Int): String
fun getResourcePackageName(@AnyRes resid: Int): String
fun getResourceTypeName(@AnyRes resid: Int): String
fun getResourceEntryName(@AnyRes resid: Int): String
}
Loading