Merge pull request #2532 from HattinkT/battery_widget

Add battery status map widget
This commit is contained in:
Dmitriy Prodchenko 2016-05-12 10:30:12 +03:00
commit 1823545fc5
35 changed files with 47 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -10,6 +10,7 @@
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="map_widget_battery">Battery state</string>
<string name="move_marker_bottom_sheet_title">Move the map to change marker\'s position</string>
<string name="lat_lon_pattern">Lat: %1$.6f Lon: %2$.6f</string>
<string name="follow_us">Follow us</string>

View file

@ -152,6 +152,8 @@ public class MapInfoLayer extends OsmandMapLayer {
registerSideWidget(alt, R.drawable.ic_action_altitude, R.string.map_widget_altitude, "altitude", false, 20);
TextInfoWidget plainTime = ric.createPlainTimeControl(map);
registerSideWidget(plainTime, R.drawable.ic_action_time, R.string.map_widget_plain_time, "plain_time", false, 25);
TextInfoWidget battery = ric.createBatteryControl(map);
registerSideWidget(battery, R.drawable.ic_action_battery, R.string.map_widget_battery, "battery", false, 26);
}
public void recreateControls() {

View file

@ -3,6 +3,8 @@ package net.osmand.plus.views.mapwidgets;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
@ -17,6 +19,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.hardware.GeomagneticField;
import android.os.BatteryManager;
import android.text.format.DateFormat;
import android.view.View;
import android.view.ViewGroup;
@ -330,7 +333,7 @@ public class RouteInfoWidgetsFactory {
if (DateFormat.is24HourFormat(ctx)) {
setText(DateFormat.format("k:mm", time).toString(), null); //$NON-NLS-1$
} else {
setText(DateFormat.format("h:mm", time).toString(),
setText(DateFormat.format("h:mm", time).toString(),
DateFormat.format("aa", time).toString()); //$NON-NLS-1$
}
}
@ -341,8 +344,46 @@ public class RouteInfoWidgetsFactory {
plainTimeControl.setIcons(R.drawable.widget_time_day, R.drawable.widget_time_night);
return plainTimeControl;
}
public TextInfoWidget createBatteryControl(final MapActivity map){
final int battery = R.drawable.widget_battery_day;
final int batteryN = R.drawable.widget_battery_night;
final int batteryCharging = R.drawable.widget_battery_charging_day;
final int batteryChargingN = R.drawable.widget_battery_charging_night;
final OsmandApplication ctx = map.getMyApplication();
final TextInfoWidget batteryControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
long time = System.currentTimeMillis();
if (time - cachedLeftTime > 1000) {
cachedLeftTime = time;
Intent batteryIntent = ctx.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
if (level == -1 || scale == -1 || status == -1) {
setText("?", null);
setIcons(battery, batteryN);
} else {
boolean charging = ((status == BatteryManager.BATTERY_STATUS_CHARGING) ||
(status == BatteryManager.BATTERY_STATUS_FULL));
setText(String.format("%d%%", (level * 100) / scale), null );
setIcons(charging ? batteryCharging : battery, charging ? batteryChargingN : batteryN);
}
}
return false;
};
};
batteryControl.setText(null, null);
batteryControl.setIcons(battery, batteryN);
return batteryControl;
}
public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();