forked from organicmaps/organicmaps
[android][power manager] preferences ui
This commit is contained in:
parent
ebbe96400b
commit
2b35f8e3fc
8 changed files with 90 additions and 0 deletions
|
@ -1974,6 +1974,12 @@ Java_com_mapswithme_maps_Framework_nativeSetPowerManagerFacility(JNIEnv *, jclas
|
|||
static_cast<bool>(state));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeGetPowerManagerScheme(JNIEnv *, jclass)
|
||||
{
|
||||
return static_cast<jint>(frm()->GetPowerManager().GetScheme());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeSetPowerManagerScheme(JNIEnv *, jclass, jint schemeType)
|
||||
{
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
<string name="pref_navigation" translatable="false">Navigation</string>
|
||||
<string name="pref_information" translatable="false">Information</string>
|
||||
<string name="pref_transliteration" translatable="false">Transliteration</string>
|
||||
<string name="pref_power_management" translatable="false">PowerManagment</string>
|
||||
|
||||
<string name="notification_ticker_ltr" translatable="false">%1$s: %2$s</string>
|
||||
<string name="notification_ticker_rtl" translatable="false">%2$s :%1$s</string>
|
||||
|
|
|
@ -65,4 +65,16 @@
|
|||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="power_management_scheme">
|
||||
<item>@string/power_management_setting_never</item>
|
||||
<item>@string/power_management_setting_auto</item>
|
||||
<item>@string/power_managment_setting_manual_max</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="power_management_scheme_values">
|
||||
<item>1</item>
|
||||
<item>4</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -104,6 +104,13 @@
|
|||
android:entries="@array/mobile_data_options"
|
||||
android:entryValues="@array/mobile_data_options_values"
|
||||
android:order="14"/>
|
||||
<ListPreference
|
||||
android:key="@string/pref_power_management"
|
||||
android:title="@string/power_management_title"
|
||||
android:summary="@string/power_management_description"
|
||||
android:entries="@array/power_management_scheme"
|
||||
android:entryValues="@array/power_management_scheme_values"
|
||||
android:order="15"/>
|
||||
</android.support.v7.preference.PreferenceCategory>
|
||||
|
||||
<android.support.v7.preference.PreferenceCategory
|
||||
|
|
|
@ -515,6 +515,7 @@ public class Framework
|
|||
|
||||
public static native void nativeOnBatteryLevelChanged(int level);
|
||||
public static native void nativeSetPowerManagerFacility(int facilityType, boolean state);
|
||||
public static native int nativeGetPowerManagerScheme();
|
||||
public static native void nativeSetPowerManagerScheme(int schemeType);
|
||||
public static native void nativeSetViewportCenter(double lat, double lon, int zoom);
|
||||
public static native void nativeStopLocationFollow();
|
||||
|
|
|
@ -45,6 +45,7 @@ import com.mapswithme.maps.sound.LanguageData;
|
|||
import com.mapswithme.maps.sound.TtsPlayer;
|
||||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.NetworkPolicy;
|
||||
import com.mapswithme.util.PowerManagment;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.ThemeSwitcher;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -338,6 +339,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
initLoggingEnabledPrefsCallbacks();
|
||||
initEmulationBadStorage();
|
||||
initUseMobileDataPrefsCallbacks();
|
||||
initPowerManagementPrefsCallbacks();
|
||||
initOptOut();
|
||||
updateTts();
|
||||
}
|
||||
|
@ -564,6 +566,25 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
});
|
||||
}
|
||||
|
||||
private void initPowerManagementPrefsCallbacks()
|
||||
{
|
||||
final ListPreference powerManagementPref = (ListPreference)findPreference(
|
||||
getString(R.string.pref_power_management));
|
||||
if (powerManagementPref == null)
|
||||
return;
|
||||
|
||||
int curValue = PowerManagment.getScheme();
|
||||
powerManagementPref.setValue(String.valueOf(curValue));
|
||||
|
||||
powerManagementPref.setOnPreferenceChangeListener((preference, newValue) ->
|
||||
{
|
||||
String valueStr = (String)newValue;
|
||||
PowerManagment.setScheme(Integer.parseInt(valueStr));
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void initLoggingEnabledPrefsCallbacks()
|
||||
{
|
||||
Preference pref = findPreference(getString(R.string.pref_enable_logging));
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
36
android/src/com/mapswithme/util/PowerManagment.java
Normal file
36
android/src/com/mapswithme/util/PowerManagment.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue