5,600,725 Members 38,948 Now Online
XDA Developers Android and Mobile Development Forum

[Xposed][D800]Fix for theming the battery on AT&T devices

Tip us?
 
garyd9
Old
(Last edited by garyd9; 24th December 2013 at 12:53 AM.)
#1  
garyd9's Avatar
Recognized Developer - OP
Thanks Meter 1873
Posts: 1,836
Join Date: Sep 2006
Location: Pittsburgh, PA
Default [Xposed][D800]Fix for theming the battery on AT&T devices

Many people, myself included, have found that most "xposed" modules for theming the battery don't work properly on the D800 model of the LG G2. The typical result of these mods is that the battery theme will work when charging, but will revert to stock when not charging.

The reason is simple: The stock firmware will use a non-standard battery resource if the device is set up for AT&T. (The standard battery resource is named "stat_sys_battery", but LG uses "stat_sys_battery_atnt" for AT&T builds.) Most of those fancy battery theming xposed modules work by just replacing "stat_sys_battery."

So, I whipped together a quick xposed module to redirect stat_sys_battery_atnt to stat_sys_battery.... which "fixes" the battery theming modules.

(In case anyone is wondering, the stock stat_sys_battery differs only but slightly from the stat_sys_battery_atnt. The difference is that the red color of a nearly drained battery is a bit redder on the AT&T firmware. That's it.)

If you install this module (and activate it) without a seperate battery module, this will have no noticeable impact. (You might notice that your battery is a bit more orange when it's nearly empty. Then again, I doubt anyone could tell the difference unless you saw the two colors side by side.)

THIS MODULE IS COMPLETELY UNSUPPORTED. USE THIS AT YOUR OWN RISK. IF YOU DON'T KNOW HOW TO INSTALL AN XPOSED MODULE, YOU PROBABLY SHOULD NOT USE THIS. IF YOU AREN'T USING A NEARLY STOCK D800, THIS MODULE IS USELESS.
Attached Files
File Type: apk LGD800StdBattery.apk - [Click for QR Code] (263.9 KB, 57 views)

Donations: I don't accept donations, but if you are feeling charitable, help a child by going to http://www.shrinershospitalsforchildren.org/
and click the "Donate Now" link at the top.
The Following User Says Thank You to garyd9 For This Useful Post: [ Click to Expand ]
 
garyd9
Old
(Last edited by garyd9; 24th December 2013 at 12:53 AM.)
#2  
garyd9's Avatar
Recognized Developer - OP
Thanks Meter 1873
Posts: 1,836
Join Date: Sep 2006
Location: Pittsburgh, PA
SOURCE and USE:

As this is a completely unsupported module, I'm going to post the source. Anyone may re-use this in their own projects with a single request (not demand) by me: If you use this code in a project that allows partially free use, please keep this "feature" free to unpaid users.

This is the entire package:

Code:
package org.garyndenise.xposed.lgd800stdbattery;

import android.content.res.XResources;
import android.graphics.drawable.Drawable;
import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
import de.robv.android.xposed.XposedBridge;

public class Lgd800stdbattery implements IXposedHookZygoteInit, IXposedHookInitPackageResources {
	
	
	@Override
	public void initZygote(StartupParam startupParam) throws Throwable {
	}
	
	@Override
	public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable {
		if (!resparam.packageName.equals("com.android.systemui"))
			return;
		
		// find the id of the stat_sys_battery
		
		final int stat_sys_battery_id = resparam.res.getIdentifier("stat_sys_battery", "drawable", "com.android.systemui");
		
		if (stat_sys_battery_id == 0) {	
			XposedBridge.log("ERROR:  unable to find resource for stat_sys_battery!!");
		} else {
			
			// log the the replacement is taking place. (happens once per boot of systemui)
			XposedBridge.log("Replacing stat_sys_battery_atnt with stat_sys_battery");

			
			// perform the actual replacement.  Can't directly replace with a Drawable, so instead
			// replace with a DrawableLoader that just returns the stat_sys_battery
			resparam.res.setReplacement("com.android.systemui", "drawable", "stat_sys_battery_atnt", 
					new XResources.DrawableLoader() {
						
						@Override
						public Drawable newDrawable(XResources res, int id) throws Throwable {
							//return stat_sys_battery_drawable;
							return res.getDrawable(stat_sys_battery_id);
						}
					});
					
		}
	}
}

Donations: I don't accept donations, but if you are feeling charitable, help a child by going to http://www.shrinershospitalsforchildren.org/
and click the "Donate Now" link at the top.
The Following User Says Thank You to garyd9 For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes