From 2b35f8e3fc6cf3da196d1e97ac340a58cc0defb4 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Mon, 21 Jan 2019 13:07:29 +0300 Subject: [PATCH] [android][power manager] preferences ui --- android/jni/com/mapswithme/maps/Framework.cpp | 6 ++++ android/res/values/donottranslate.xml | 1 + android/res/values/string-arrays.xml | 12 +++++++ android/res/xml/prefs_main.xml | 7 ++++ .../src/com/mapswithme/maps/Framework.java | 1 + .../maps/settings/SettingsPrefsFragment.java | 21 +++++++++++ .../src/com/mapswithme/util/BatteryState.java | 6 ++++ .../com/mapswithme/util/PowerManagment.java | 36 +++++++++++++++++++ 8 files changed, 90 insertions(+) create mode 100644 android/src/com/mapswithme/util/PowerManagment.java diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 9d95eaee61..e6e74fc460 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1974,6 +1974,12 @@ Java_com_mapswithme_maps_Framework_nativeSetPowerManagerFacility(JNIEnv *, jclas static_cast(state)); } +JNIEXPORT jint JNICALL +Java_com_mapswithme_maps_Framework_nativeGetPowerManagerScheme(JNIEnv *, jclass) +{ + return static_cast(frm()->GetPowerManager().GetScheme()); +} + JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeSetPowerManagerScheme(JNIEnv *, jclass, jint schemeType) { diff --git a/android/res/values/donottranslate.xml b/android/res/values/donottranslate.xml index a0095f73f7..34b066c0a4 100644 --- a/android/res/values/donottranslate.xml +++ b/android/res/values/donottranslate.xml @@ -69,6 +69,7 @@ Navigation Information Transliteration + PowerManagment %1$s: %2$s %2$s :%1$s diff --git a/android/res/values/string-arrays.xml b/android/res/values/string-arrays.xml index 49aec4adbb..82d2f78643 100644 --- a/android/res/values/string-arrays.xml +++ b/android/res/values/string-arrays.xml @@ -65,4 +65,16 @@ 1 2 + + + @string/power_management_setting_never + @string/power_management_setting_auto + @string/power_managment_setting_manual_max + + + + 1 + 4 + 3 + diff --git a/android/res/xml/prefs_main.xml b/android/res/xml/prefs_main.xml index 445cc1ce50..cc4a23e746 100644 --- a/android/res/xml/prefs_main.xml +++ b/android/res/xml/prefs_main.xml @@ -104,6 +104,13 @@ android:entries="@array/mobile_data_options" android:entryValues="@array/mobile_data_options_values" android:order="14"/> + + { + String valueStr = (String)newValue; + PowerManagment.setScheme(Integer.parseInt(valueStr)); + + return true; + }); + } + private void initLoggingEnabledPrefsCallbacks() { Preference pref = findPreference(getString(R.string.pref_enable_logging)); diff --git a/android/src/com/mapswithme/util/BatteryState.java b/android/src/com/mapswithme/util/BatteryState.java index bf7b73e7cc..15c8f2ab6a 100644 --- a/android/src/com/mapswithme/util/BatteryState.java +++ b/android/src/com/mapswithme/util/BatteryState.java @@ -37,6 +37,12 @@ public final class BatteryState return new State(getLevel(batteryStatus), getChargingStatus(batteryStatus)); } + @IntRange(from=0, to=100) + public static int getLevel() + { + return getState().mLevel; + } + @ChargingStatus public static int getChargingStatus() { diff --git a/android/src/com/mapswithme/util/PowerManagment.java b/android/src/com/mapswithme/util/PowerManagment.java new file mode 100644 index 0000000000..8afd65451b --- /dev/null +++ b/android/src/com/mapswithme/util/PowerManagment.java @@ -0,0 +1,36 @@ +package com.mapswithme.util; + +import android.support.annotation.IntDef; + +import com.mapswithme.maps.Framework; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public final class PowerManagment +{ + // It should consider to power_managment::Scheme from + // map/power_management/power_management_schemas.hpp + public static final int NONE = 0; + public static final int NORMAL = 1; + public static final int MEDIUM = 2; + public static final int HIGH = 3; + public static final int AUTO = 4; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({ NONE, NORMAL, MEDIUM, HIGH, AUTO }) + @interface SchemeType + { + } + + @SchemeType + public static int getScheme() + { + return Framework.nativeGetPowerManagerScheme(); + } + + public static void setScheme(@SchemeType int value) + { + Framework.nativeSetPowerManagerScheme(value); + } +}