diff --git a/app/build.gradle b/app/build.gradle index b4ceb49..76cf03e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,6 +58,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release zipAlignEnabled true + shrinkResources true } } } diff --git a/app/src/main/java/com/hmatalonga/greenhub/fragments/HomeFragment.java b/app/src/main/java/com/hmatalonga/greenhub/fragments/HomeFragment.java index c8c221c..d0bd4e9 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/fragments/HomeFragment.java +++ b/app/src/main/java/com/hmatalonga/greenhub/fragments/HomeFragment.java @@ -50,6 +50,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; +import java.util.Locale; import static com.hmatalonga.greenhub.util.LogUtils.makeLogTag; @@ -368,7 +369,7 @@ private void resetBatteryCurrent() { private Runnable mRunnable = new Runnable() { @Override public void run() { - double now = Battery.getBatteryCurrentNow(mContext); + double now = Battery.getBatteryCurrentNowInAmperes(mContext); double level = Inspector.getCurrentBatteryLevel(); String value; @@ -378,7 +379,8 @@ public void run() { mBatteryCurrentMin.setText(value); value = "max: --"; mBatteryCurrentMax.setText(value); - value = mContext.getString(R.string.battery_full); + // value = mContext.getString(R.string.battery_full); + value = String.format(Locale.getDefault(), "%.3f", now) + " A"; mBatteryCurrentNow.setText(value); mHandler.postDelayed(this, Config.REFRESH_CURRENT_INTERVAL); return; @@ -386,17 +388,17 @@ public void run() { if (Math.abs(now) < Math.abs(mMin)) { mMin = now; - value = "min: " + mMin + " mA"; + value = "min: " + String.format(Locale.getDefault(), "%.3f", mMin) + " A"; mBatteryCurrentMin.setText(value); } if (Math.abs(now) > Math.abs(mMax)) { mMax = now; - value = "max: " + mMax + " mA"; + value = "max: " + String.format(Locale.getDefault(), "%.3f", mMax) + " A"; mBatteryCurrentMax.setText(value); } - value = now + " mA"; + value = String.format(Locale.getDefault(), "%.3f", now) + " A"; mBatteryCurrentNow.setText(value); mHandler.postDelayed(this, Config.REFRESH_CURRENT_INTERVAL); } diff --git a/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/DataEstimator.java b/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/DataEstimator.java index 7d26a63..8c15794 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/DataEstimator.java +++ b/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/DataEstimator.java @@ -83,8 +83,6 @@ public void onReceive(Context context, Intent intent) { return; } - LogUtils.logI(TAG, "Now: " + Battery.getBatteryCurrentNow(context)); - mIntent = intent; mAction = intent.getAction(); diff --git a/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/Inspector.java b/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/Inspector.java index 2876021..7de8402 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/Inspector.java +++ b/app/src/main/java/com/hmatalonga/greenhub/managers/sampling/Inspector.java @@ -405,7 +405,7 @@ static Sample getSample(final Context context, Intent intent) { batteryDetails.capacity = Battery.getBatteryDesignCapacity(context); batteryDetails.chargeCounter = Battery.getBatteryChargeCounter(context); batteryDetails.currentAverage = Battery.getBatteryCurrentAverage(context); - batteryDetails.currentNow = (int) Battery.getBatteryCurrentNow(context); + batteryDetails.currentNow = Battery.getBatteryCurrentNow(context); batteryDetails.energyCounter = Battery.getBatteryEnergyCounter(context); boolean isCharging = "Charging".equals(batteryStatus); @@ -417,11 +417,11 @@ static Sample getSample(final Context context, Intent intent) { EventBus.getDefault().post( new BatteryTimeEvent(batteryRemainingHours, batteryRemainingMinutes, isCharging) ); - Notifier.remainingBatteryTimeAlert( - context, - batteryRemainingHours + "h " + batteryRemainingMinutes + "m", - isCharging - ); +// Notifier.remainingBatteryTimeAlert( +// context, +// batteryRemainingHours + "h " + batteryRemainingMinutes + "m", +// isCharging +// ); newSample.batteryDetails = batteryDetails; newSample.batteryLevel = sCurrentBatteryLevel; diff --git a/app/src/main/java/com/hmatalonga/greenhub/models/Battery.java b/app/src/main/java/com/hmatalonga/greenhub/models/Battery.java index 4e921de..7c96380 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/models/Battery.java +++ b/app/src/main/java/com/hmatalonga/greenhub/models/Battery.java @@ -167,7 +167,7 @@ public static int getBatteryCurrentAverage(final Context context) { * @param context Application context * @return battery current now (in mA) */ - public static double getBatteryCurrentNow(final Context context) { + public static int getBatteryCurrentNow(final Context context) { int value = 0; BatteryManager manager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE); @@ -178,6 +178,25 @@ public static double getBatteryCurrentNow(final Context context) { return (value != 0 && value != Integer.MIN_VALUE) ? value : 0; } + /** + * Get the Battery current at the moment (in mA) + * + * @param context Application context + * @return battery current now (in mA) + */ + public static double getBatteryCurrentNowInAmperes(final Context context) { + int value = 0; + + BatteryManager manager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE); + if (manager != null) { + value = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW); + } + + value = (value != 0 && value != Integer.MIN_VALUE) ? value : 0; + + return (double) value / 1000000; + } + /** * Get the battery energy counter capacity (in mWh) * diff --git a/app/src/main/java/com/hmatalonga/greenhub/network/CommunicationManager.java b/app/src/main/java/com/hmatalonga/greenhub/network/CommunicationManager.java index 8aedebb..f9b82b7 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/network/CommunicationManager.java +++ b/app/src/main/java/com/hmatalonga/greenhub/network/CommunicationManager.java @@ -148,7 +148,7 @@ private void uploadSample(final int id) { final Upload upload = sample == null ? null : new Upload(bundleSample(sample)); realm.close(); - LogUtils.logI(TAG, "Sample found => " + String.valueOf(sample != null)); + LogUtils.logI(TAG, "Sample found => " + (sample != null)); if (sample == null && mCollection.hasNext()) { uploadSample(mCollection.next()); @@ -251,7 +251,7 @@ private JsonObject bundleSample(final Sample sample) { root.addProperty("uuId", sample.uuId); root.addProperty("timestamp", sample.timestamp); root.addProperty("version", sample.version); - root.addProperty("mDatabase", sample.database); + root.addProperty("database", sample.database); root.addProperty("batteryState", sample.batteryState); root.addProperty("batteryLevel", sample.batteryLevel); root.addProperty("memoryWired", sample.memoryWired); diff --git a/app/src/main/java/com/hmatalonga/greenhub/network/handlers/RegisterDeviceHandler.java b/app/src/main/java/com/hmatalonga/greenhub/network/handlers/RegisterDeviceHandler.java index cfd1cc1..3114152 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/network/handlers/RegisterDeviceHandler.java +++ b/app/src/main/java/com/hmatalonga/greenhub/network/handlers/RegisterDeviceHandler.java @@ -59,7 +59,7 @@ public RegisterDeviceHandler(final Context context) { String url = SettingsUtils.fetchServerUrl(context); if (BuildConfig.DEBUG) { - //url = Config.SERVER_URL_DEVELOPMENT; + url = Config.SERVER_URL_DEVELOPMENT; } Retrofit retrofit = new Retrofit.Builder() diff --git a/app/src/main/java/com/hmatalonga/greenhub/ui/adapters/ChartRVAdapter.java b/app/src/main/java/com/hmatalonga/greenhub/ui/adapters/ChartRVAdapter.java index 6d709b8..01d4126 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/ui/adapters/ChartRVAdapter.java +++ b/app/src/main/java/com/hmatalonga/greenhub/ui/adapters/ChartRVAdapter.java @@ -177,16 +177,23 @@ private LineData loadData(ChartCard card) { } private void setup(DashboardViewHolder holder, final ChartCard card) { - ValueFormatter formatterX = new ValueFormatter() { + + holder.chart.getXAxis().setValueFormatter(new ValueFormatter() { @Override - public String getFormattedValue(float value, AxisBase axis) { + public String getFormattedValue(float value) { return DateUtils.convertMilliSecondsToFormattedDate((long) value); } - }; + }); + + if (card.type == BATTERY_LEVEL) { + holder.chart.getAxisLeft().setAxisMaximum(1f); + } - ValueFormatter formatterY = new ValueFormatter() { + holder.chart.setExtraBottomOffset(5f); + holder.chart.getAxisLeft().setDrawGridLines(false); + holder.chart.getAxisLeft().setValueFormatter(new ValueFormatter() { @Override - public String getFormattedValue(float value, AxisBase axis) { + public String getFormattedValue(float value) { switch (card.type) { case BATTERY_LEVEL: return StringHelper.formatPercentageNumber(value); @@ -198,17 +205,7 @@ public String getFormattedValue(float value, AxisBase axis) { return String.valueOf(value); } } - }; - - holder.chart.getXAxis().setValueFormatter(formatterX); - - if (card.type == BATTERY_LEVEL) { - holder.chart.getAxisLeft().setAxisMaximum(1f); - } - - holder.chart.setExtraBottomOffset(5f); - holder.chart.getAxisLeft().setDrawGridLines(false); - holder.chart.getAxisLeft().setValueFormatter(formatterY); + }); holder.chart.getAxisRight().setDrawGridLines(false); holder.chart.getAxisRight().setDrawLabels(false); holder.chart.getXAxis().setDrawGridLines(false); diff --git a/app/src/main/java/com/hmatalonga/greenhub/ui/views/ChartMarkerView.java b/app/src/main/java/com/hmatalonga/greenhub/ui/views/ChartMarkerView.java index 9065086..eadb472 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/ui/views/ChartMarkerView.java +++ b/app/src/main/java/com/hmatalonga/greenhub/ui/views/ChartMarkerView.java @@ -90,7 +90,7 @@ public void refreshContent(Entry e, Highlight highlight) { public MPPointF getOffset() { if (mOffset == null) { // center the marker horizontally and vertically - mOffset = new MPPointF(-(getWidth() / 2), -getHeight()); + mOffset = new MPPointF(-(getWidth() >> 1), -getHeight()); } return mOffset; diff --git a/app/src/main/java/com/hmatalonga/greenhub/util/DateUtils.java b/app/src/main/java/com/hmatalonga/greenhub/util/DateUtils.java index 5a4d427..642f7e2 100644 --- a/app/src/main/java/com/hmatalonga/greenhub/util/DateUtils.java +++ b/app/src/main/java/com/hmatalonga/greenhub/util/DateUtils.java @@ -38,9 +38,9 @@ public class DateUtils { private static final String DATE_FORMAT = "dd-MM HH:mm"; private static SimpleDateFormat sSimpleDateFormat = - new SimpleDateFormat(DATE_FORMAT, Locale.UK); + new SimpleDateFormat(DATE_FORMAT, Locale.getDefault()); - public static String convertMilliSecondsToFormattedDate(Long milliSeconds) { + public static String convertMilliSecondsToFormattedDate(long milliSeconds) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); diff --git a/build.gradle b/build.gradle index 50ca05f..e5586cd 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { maven { url 'https://maven.fabric.io/public' } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.1' classpath 'io.realm:realm-gradle-plugin:5.1.0' // NOTE: Do not place your application dependencies here; they belong