Sunday, March 4, 2018

Android - Style drawer toggle


values/style.xml

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <!-- The drawing color for the bars -->
    <item name="color">@android:color/white</item>
    <!-- Whether bars should rotate or not during transition -->
    <item name="spinBars">true</item>
    <!-- The total size of the drawable -->
    <item name="drawableSize">12sp</item>
    <!-- The max gap between the bars when they are parallel to each other -->
    <item name="gapBetweenBars">4sp</item>
    <!-- The thickness (stroke size) for the bar paint -->
    <item name="thickness">2sp</item>
</style>

<style name="CustomTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Add following -->
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

AndroidManifest.xml

<application
    android:theme="@style/CustomTheme">
</application>

Android - Get battery capacity via reflection



double batteryCapacity = 0.f;

final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";

try {
    mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS)
            .getConstructor(Context.class).newInstance(this);
} catch (Exception e) {
    e.printStackTrace();
}

try {
    batteryCapacity = (Double) Class
            .forName(POWER_PROFILE_CLASS)
            .getMethod("getAveragePower", java.lang.String.class)
            .invoke(mPowerProfile_, "battery.capacity");
} catch (Exception e) {
    e.printStackTrace();
}