下面列出了怎么用android.content.res.XResources的API类实例代码及写法,或者点击链接到github查看源代码。
public static void initResources(XSharedPreferences prefs, InitPackageResourcesParam resparam) {
XModuleResources modRes = XModuleResources.createInstance(GravityBox.MODULE_PATH, resparam.res);
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_SIGNAL_CLUSTER_HPLUS, false) &&
!Utils.isMtkDevice() && !Utils.isOxygenOs35Rom()) {
sQsHpResId = XResources.getFakeResId(modRes, R.drawable.ic_qs_signal_hp);
sSbHpResId = XResources.getFakeResId(modRes, R.drawable.stat_sys_data_fully_connected_hp);
resparam.res.setReplacement(sQsHpResId, modRes.fwd(R.drawable.ic_qs_signal_hp));
resparam.res.setReplacement(sSbHpResId, modRes.fwd(R.drawable.stat_sys_data_fully_connected_hp));
DATA_HP = new int[][]{
{sSbHpResId, sSbHpResId, sSbHpResId, sSbHpResId},
{sSbHpResId, sSbHpResId, sSbHpResId, sSbHpResId}
};
QS_DATA_HP = new int[]{sQsHpResId, sQsHpResId};
if (DEBUG) log("H+ icon resources initialized");
}
String lteStyle = prefs.getString(GravityBoxSettings.PREF_KEY_SIGNAL_CLUSTER_LTE_STYLE, "DEFAULT");
if (!lteStyle.equals("DEFAULT")) {
resparam.res.setReplacement(ModStatusBar.PACKAGE_NAME, "bool", "config_show4GForLTE",
lteStyle.equals("4G"));
}
}
public static void initResources(XSharedPreferences prefs, InitPackageResourcesParam resparam) {
XModuleResources modRes = XModuleResources.createInstance(GravityBox.MODULE_PATH, resparam.res);
mIconNotifResId = XResources.getFakeResId(modRes, R.drawable.ic_audio_notification);
resparam.res.setReplacement(mIconNotifResId, modRes.fwd(R.drawable.ic_audio_notification));
mIconNotifMuteResId = XResources.getFakeResId(modRes, R.drawable.ic_audio_notification_mute);
resparam.res.setReplacement(mIconNotifMuteResId, modRes.fwd(R.drawable.ic_audio_notification_mute));
}
private static void replaceRecoveryMessage() {
try {
Resources res = XResources.getSystem();
XResources.setSystemWideReplacement(
res.getIdentifier("reboot_to_reset_title", "string", "android"),
mRecoveryStr);
} catch (Throwable t) { /* ignore */ }
}
public static boolean hasTelephonySupport() {
try {
Resources res = XResources.getSystem();
return res.getBoolean(res.getIdentifier("config_voice_capable", "bool", "android"));
} catch (Throwable t) {
log("hasTelephonySupport(): " + t.getMessage());
return false;
}
}
public static void initResources(final XSharedPreferences prefs) {
try {
Resources systemRes = XResources.getSystem();
int translucentDecor = Integer.valueOf(prefs.getString(GravityBoxSettings.PREF_KEY_TRANSLUCENT_DECOR, "0"));
if (translucentDecor != 0) {
XResources.setSystemWideReplacement("android", "bool", "config_enableTranslucentDecor", translucentDecor == 1);
}
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_NAVBAR_OVERRIDE, false)) {
XResources.setSystemWideReplacement("android", "bool", "config_showNavigationBar",
prefs.getBoolean(GravityBoxSettings.PREF_KEY_NAVBAR_ENABLE,
SystemPropertyProvider.getSystemConfigBool(systemRes,
"config_showNavigationBar")));
}
XResources.setSystemWideReplacement("android", "bool", "config_unplugTurnsOnScreen",
prefs.getBoolean(GravityBoxSettings.PREF_KEY_UNPLUG_TURNS_ON_SCREEN,
SystemPropertyProvider.getSystemConfigBool(systemRes,
"config_unplugTurnsOnScreen")));
if (!Utils.isVerneeApolloDevice()) {
int pulseNotificationDelay = prefs.getInt(GravityBoxSettings.PREF_KEY_PULSE_NOTIFICATION_DELAY, -1);
if (pulseNotificationDelay != -1) {
XResources.setSystemWideReplacement("android", "integer", "config_defaultNotificationLedOff",
(pulseNotificationDelay));;
}
}
XResources.setSystemWideReplacement("android", "bool", "config_sip_wifi_only", false);
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_BRIGHTNESS_MASTER_SWITCH, false)) {
int brightnessMin = prefs.getInt(GravityBoxSettings.PREF_KEY_BRIGHTNESS_MIN, 20);
XResources.setSystemWideReplacement(
"android", "integer", "config_screenBrightnessSettingMinimum", brightnessMin);
if (DEBUG) log("Minimum brightness value set to: " + brightnessMin);
int screenDim = prefs.getInt(GravityBoxSettings.PREF_KEY_SCREEN_DIM_LEVEL, 10);
XResources.setSystemWideReplacement(
"android", "integer", "config_screenBrightnessDim", screenDim);
if (DEBUG) log("Screen dim level set to: " + screenDim);
}
// Safe media volume
Utils.TriState triState = Utils.TriState.valueOf(prefs.getString(
GravityBoxSettings.PREF_KEY_SAFE_MEDIA_VOLUME, "DEFAULT"));
if (DEBUG) log(GravityBoxSettings.PREF_KEY_SAFE_MEDIA_VOLUME + ": " + triState);
if (triState != Utils.TriState.DEFAULT) {
XResources.setSystemWideReplacement("android", "bool", "config_safe_media_volume_enabled",
triState == Utils.TriState.ENABLED);
if (DEBUG) log("config_safe_media_volume_enabled: " + (triState == Utils.TriState.ENABLED));
}
} catch (Throwable t) {
XposedBridge.log(t);
}
}
@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {
XResources.setSystemWideReplacement("android", "bool", "config_enableAutoPowerModes", true);
}
@Override
public void unhook() {
XResources.unhookLayout(resDir, id, XC_LayoutInflated.this);
}