forked from Aliucord/Aliucord
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed625d7
commit 00291d6
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.aliucord.api; | ||
|
||
import android.content.Context; | ||
import android.content.res.*; | ||
import android.graphics.drawable.Drawable; | ||
import android.util.DisplayMetrics; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.core.content.res.ResourcesCompat; | ||
|
||
import com.aliucord.Utils; | ||
|
||
public class ResourcesExt extends Resources { | ||
|
||
String packageName; | ||
|
||
/** | ||
* Create a new Resources object on top of an existing set of assets in an | ||
* AssetManager. | ||
* | ||
* @param assets Previously created AssetManager. | ||
* @param metrics Current display metrics to consider when | ||
* selecting/computing resource values. | ||
* @param config Desired device configuration to consider when | ||
* selecting/computing resource values (optional). | ||
* @deprecated Resources should not be constructed by apps. | ||
* @param packageName The name of the package this Resources object should be associated with. | ||
* See {@link Context#createConfigurationContext(Configuration)}. | ||
*/ | ||
public ResourcesExt(AssetManager assets, DisplayMetrics metrics, Configuration config, String packageName) { | ||
super(assets, metrics, config); | ||
this.packageName = packageName; | ||
} | ||
|
||
public View inflate(String defType, String name, ViewGroup root, boolean attachToRoot) { | ||
var xml = getLayout(getIdentifier(name, defType, packageName)); | ||
|
||
return Utils.appActivity.getLayoutInflater().inflate(xml, root, attachToRoot); | ||
}; | ||
|
||
public int getIdentifier(String name, String defType) { | ||
return getIdentifier(name, defType, packageName); | ||
}; | ||
|
||
public Drawable getDrawable(String name) { | ||
return ResourcesCompat.getDrawable(this, getIdentifier(name, "drawable"), null ); | ||
}; | ||
} |