Skip to content

Commit

Permalink
Merge pull request mozilla#774 from keverets/keep-screen-on
Browse files Browse the repository at this point in the history
Keep the screen on when in the Map Activity using setting (@keverets)
  • Loading branch information
garvankeeley committed Sep 13, 2014
2 parents d596c5f + 1962ffc commit 3bb127c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@
<string name="scroll_to_end">Scroll to End</string>
<string name="upload_observations_data_size">Size (KB):</string>
<string name="hardware_acceleration_title">Enable hardware acceleration</string>
<string name="keep_screen_on_title">Keep screen on while in map</string>
</resources>
4 changes: 4 additions & 0 deletions res/xml/stumbler_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
android:key="hardware_acceleration"
android:title="@string/hardware_acceleration_title"
android:defaultValue="true" />
<CheckBoxPreference
android:key="keep_screen_on"
android:title="@string/keep_screen_on_title"
android:defaultValue="true" />
</PreferenceScreen>
9 changes: 9 additions & 0 deletions src/org/mozilla/mozstumbler/client/ClientPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ClientPrefs extends Prefs {
private static final String LAT_PREF = "lat";
private static final String LON_PREF = "lon";
private static final String HARDWARE_ACCEL_PREF = "hardware_acceleration";
static final String KEEP_SCREEN_ON_PREF = "keep_screen_on";

protected ClientPrefs(Context context) {
super(context);
Expand Down Expand Up @@ -54,4 +55,12 @@ public boolean getIsHardwareAccelerated() {
public void setIsHardwareAccelerated(boolean on) {
setBoolPref(HARDWARE_ACCEL_PREF, on);
}

public boolean getKeepScreenOn() {
return getBoolPrefWithDefault(KEEP_SCREEN_ON_PREF, true);
}

public void setKeepScreenOn(boolean on) {
setBoolPref(KEEP_SCREEN_ON_PREF, on);
}
}
10 changes: 10 additions & 0 deletions src/org/mozilla/mozstumbler/client/PreferencesScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PreferencesScreen extends PreferenceActivity {
private CheckBoxPreference mWifiScanAlwaysSwitch;
private CheckBoxPreference mWifiPreference;
private CheckBoxPreference mIsHardwareAccelerated;
private CheckBoxPreference mKeepScreenOn;

private static ClientPrefs sPrefs;

Expand All @@ -48,6 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
mWifiPreference = (CheckBoxPreference) getPreferenceManager().findPreference("wifi_only");
mWifiScanAlwaysSwitch = (CheckBoxPreference) getPreferenceManager().findPreference("wifi_scan_always");
mIsHardwareAccelerated = (CheckBoxPreference) getPreferenceManager().findPreference("hardware_acceleration");
mKeepScreenOn = (CheckBoxPreference) getPreferenceManager().findPreference(ClientPrefs.KEEP_SCREEN_ON_PREF);

setNicknamePreferenceTitle(sPrefs.getNickname());
mWifiPreference.setChecked(sPrefs.getUseWifiOnly());
Expand Down Expand Up @@ -90,6 +92,14 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
});

mKeepScreenOn.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
sPrefs.setKeepScreenOn(newValue.equals(true));
return true;
}
});
}

private void setNicknamePreferenceTitle(String nickname) {
Expand Down
4 changes: 4 additions & 0 deletions src/org/mozilla/mozstumbler/client/mapview/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}

if (ClientPrefs.getInstance().getKeepScreenOn()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_map);

Expand Down

0 comments on commit 3bb127c

Please sign in to comment.