Skip to content

Commit

Permalink
Moved setting strings to string.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpMaster committed Sep 19, 2016
1 parent 16d8dba commit b30b8db
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 64 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.cooper.wheellog"
minSdkVersion 18
targetSdkVersion 24
versionCode 31
versionName "1.6.0"
versionCode 32
versionName "1.7.0"
}
buildTypes {
release {
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/cooper/wheellog/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -725,25 +725,25 @@ public void onPageSelected(int position) {

private void loadPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
use_mph = sharedPreferences.getBoolean("use_mph", false);
int max_speed = sharedPreferences.getInt("max_speed", 30) * 10;
use_mph = sharedPreferences.getBoolean(getString(R.string.use_mph), false);
int max_speed = sharedPreferences.getInt(getString(R.string.max_speed), 30) * 10;
wheelView.setMaxSpeed(max_speed);
wheelView.setUseMPH(use_mph);
wheelView.invalidate();

boolean alarms_enabled = sharedPreferences.getBoolean("alarms_enabled", false);
boolean alarms_enabled = sharedPreferences.getBoolean(getString(R.string.alarms_enabled), false);

WheelData.getInstance().setAlarmsEnabled(alarms_enabled);

if (alarms_enabled) {
int alarm1Speed = sharedPreferences.getInt("alarm_1_speed", 0);
int alarm2Speed = sharedPreferences.getInt("alarm_2_speed", 0);
int alarm3Speed = sharedPreferences.getInt("alarm_3_speed", 0);
int alarm1Battery = sharedPreferences.getInt("alarm_1_battery", 0);
int alarm2Battery = sharedPreferences.getInt("alarm_2_battery", 0);
int alarm3Battery = sharedPreferences.getInt("alarm_3_battery", 0);
int current_alarm = sharedPreferences.getInt("alarm_current", 0);
boolean disablePhoneVibrate = sharedPreferences.getBoolean("disable_phone_vibrate", false);
int alarm1Speed = sharedPreferences.getInt(getString(R.string.alarm_1_speed), 0);
int alarm2Speed = sharedPreferences.getInt(getString(R.string.alarm_2_speed), 0);
int alarm3Speed = sharedPreferences.getInt(getString(R.string.alarm_3_speed), 0);
int alarm1Battery = sharedPreferences.getInt(getString(R.string.alarm_1_battery), 0);
int alarm2Battery = sharedPreferences.getInt(getString(R.string.alarm_2_battery), 0);
int alarm3Battery = sharedPreferences.getInt(getString(R.string.alarm_3_battery), 0);
int current_alarm = sharedPreferences.getInt(getString(R.string.alarm_current), 0);
boolean disablePhoneVibrate = sharedPreferences.getBoolean(getString(R.string.disable_phone_vibrate), false);

WheelData.getInstance().setPreferences(
alarm1Speed, alarm1Battery,
Expand All @@ -754,9 +754,9 @@ private void loadPreferences() {
} else
wheelView.setWarningSpeed(0);

boolean auto_log = sharedPreferences.getBoolean("auto_log", false);
boolean log_location = sharedPreferences.getBoolean("log_location_data", false);
boolean auto_upload = sharedPreferences.getBoolean("auto_upload", false);
boolean auto_log = sharedPreferences.getBoolean(getString(R.string.auto_log), false);
boolean log_location = sharedPreferences.getBoolean(getString(R.string.log_location_data), false);
boolean auto_upload = sharedPreferences.getBoolean(getString(R.string.auto_upload), false);

if (auto_log)
MainActivityPermissionsDispatcher.acquireStoragePermissionWithCheck(this);
Expand Down
33 changes: 17 additions & 16 deletions app/src/main/java/com/cooper/wheellog/PreferencesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onClick(DialogInterface dialog, int which) {
case "use_mph":
getActivity().sendBroadcast(new Intent(Constants.ACTION_PEBBLE_AFFECTING_PREFERENCE_CHANGED));
break;
case "max_mph":
case "max_speed":
getActivity().sendBroadcast(new Intent(Constants.ACTION_PEBBLE_AFFECTING_PREFERENCE_CHANGED));
break;
}
Expand All @@ -108,10 +108,10 @@ public void onClick(View view) {
switch (currentScreen) {
case Main:
tb.setTitle("Settings");
Preference speed_button = findPreference("speed_preferences");
Preference logs_button = findPreference("log_preferences");
Preference alarm_button = findPreference("alarm_preferences");
Preference watch_button = findPreference("watch_preferences");
Preference speed_button = findPreference(getString(R.string.speed_preferences));
Preference logs_button = findPreference(getString(R.string.log_preferences));
Preference alarm_button = findPreference(getString(R.string.alarm_preferences));
Preference watch_button = findPreference(getString(R.string.watch_preferences));

if (speed_button != null) {
speed_button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand Down Expand Up @@ -180,9 +180,9 @@ public boolean onPreferenceClick(Preference preference) {

public void refreshVolatileSettings() {
if (currentScreen == SettingsScreen.Logs) {
correctCheckState("auto_log");
correctCheckState("log_location_data");
correctCheckState("auto_upload");
correctCheckState(getString(R.string.auto_log));
correctCheckState(getString(R.string.log_location_data));
correctCheckState(getString(R.string.auto_upload));
}
}

Expand All @@ -199,15 +199,16 @@ private void correctCheckState(String preference) {
}

private void hideShowSeekBars() {
boolean alarms_enabled = getPreferenceManager().getSharedPreferences().getBoolean("alarms_enabled", false);
boolean alarms_enabled = getPreferenceManager().getSharedPreferences()
.getBoolean(getString(R.string.alarms_enabled), false);
String[] seekbar_preferences = {
"alarm_1_speed",
"alarm_2_speed",
"alarm_3_speed",
"alarm_1_battery",
"alarm_2_battery",
"alarm_3_battery",
"alarm_current"};
getString(R.string.alarm_1_speed),
getString(R.string.alarm_2_speed),
getString(R.string.alarm_3_speed),
getString(R.string.alarm_1_battery),
getString(R.string.alarm_2_battery),
getString(R.string.alarm_3_battery),
getString(R.string.alarm_current)};

for (String preference : seekbar_preferences) {
SeekBarPreference seekbar = (SeekBarPreference) findPreference(preference);
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/com/cooper/wheellog/utils/SettingsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;

import timber.log.Timber;
import com.cooper.wheellog.R;


public class SettingsUtil {
Expand Down Expand Up @@ -41,46 +41,46 @@ public static boolean getBoolean(Context context, String preference) {
}

public static boolean isAutoLogEnabled(Context context) {
return getSharedPreferences(context).getBoolean("auto_log", false);
return getSharedPreferences(context).getBoolean(context.getString(R.string.auto_log), false);
}

public static void setAutoLog(Context context, boolean enabled) {
getSharedPreferences(context).edit().putBoolean("auto_log", enabled).apply();
getSharedPreferences(context).edit().putBoolean(context.getString(R.string.auto_log), enabled).apply();
}

public static boolean isLogLocationEnabled(Context context) {
return getSharedPreferences(context).getBoolean("log_location_data", false);
return getSharedPreferences(context).getBoolean(context.getString(R.string.log_location_data), false);
}

public static void setLogLocationEnabled(Context context, boolean enabled) {
getSharedPreferences(context).edit().putBoolean("log_location_data", enabled).apply();
getSharedPreferences(context).edit().putBoolean(context.getString(R.string.log_location_data), enabled).apply();
}

public static boolean isUseGPSEnabled(Context context) {
return getSharedPreferences(context).getBoolean("use_gps", false);
return getSharedPreferences(context).getBoolean(context.getString(R.string.use_gps), false);
}

public static boolean isAutoUploadEnabled(Context context) {
return getSharedPreferences(context).getBoolean("auto_upload", false);
return getSharedPreferences(context).getBoolean(context.getString(R.string.auto_upload), false);
}

public static void setAutoUploadEnabled(Context context, boolean enabled) {
getSharedPreferences(context).edit().putBoolean("auto_upload", enabled).apply();
getSharedPreferences(context).edit().putBoolean(context.getString(R.string.auto_upload), enabled).apply();
}

private static SharedPreferences getSharedPreferences(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
}

public static boolean isUseMPH(Context context) {
return getSharedPreferences(context).getBoolean("use_mph", false);
return getSharedPreferences(context).getBoolean(context.getString(R.string.use_mph), false);
}

public static int getMaxSpeed(Context context) {
return getSharedPreferences(context).getInt("max_speed", 30);
return getSharedPreferences(context).getInt(context.getString(R.string.max_speed), 30);
}

public static int getHornMode(Context context) {
return Integer.parseInt(getSharedPreferences(context).getString("horn_mode", "0"));
return Integer.parseInt(getSharedPreferences(context).getString(context.getString(R.string.horn_mode), "0"));
}
}
31 changes: 31 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,35 @@
<string name="logging_error_network_disabled">Location logging using GSM Network was requested but this location provider is disabled. No location data will be logged.</string>
<string name="logging_error_all_location_providers_disabled">Location has been disabled within Android. No location data will be logged.</string>
<string name="raw_distance">Raw Distance</string>

// PREFERENCES
<string name="speed_preferences" translatable="false">speed_preferences</string>
<string name="log_preferences" translatable="false">log_preferences</string>
<string name="alarm_preferences" translatable="false">alarm_preferences</string>
<string name="watch_preferences" translatable="false">watch_preferences</string>

// ALARM PREFERENCES
<string name="alarms_enabled" translatable="false">alarms_enabled</string>
<string name="disable_phone_vibrate" translatable="false">disable_phone_vibrate</string>
<string name="alarm_1_speed" translatable="false">alarm_1_speed</string>
<string name="alarm_1_battery" translatable="false">alarm_1_battery</string>
<string name="alarm_2_speed" translatable="false">alarm_2_speed</string>
<string name="alarm_2_battery" translatable="false">alarm_2_battery</string>
<string name="alarm_3_speed" translatable="false">alarm_3_speed</string>
<string name="alarm_3_battery" translatable="false">alarm_3_battery</string>
<string name="alarm_current" translatable="false">alarm_current</string>

// LOG PREFERENCES
<string name="auto_log" translatable="false">auto_log</string>
<string name="auto_upload" translatable="false">auto_upload</string>
<string name="log_location_data" translatable="false">log_location_data</string>
<string name="use_gps" translatable="false">use_gps</string>

// SPEED PREFERENCES
<string name="use_mph" translatable="false">use_mph</string>
<string name="max_speed" translatable="false">max_speed</string>

// WATCH PREFERENCES
<string name="horn_mode" translatable="false">horn_mode</string>

</resources>
8 changes: 4 additions & 4 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<Preference
android:key="speed_preferences"
android:key="@string/speed_preferences"
android:title="Speed Settings"
android:icon="@drawable/ic_speedometer_white_24dp"/>

<Preference
android:key="log_preferences"
android:key="@string/log_preferences"
android:title="Log Settings"
android:icon="@drawable/ic_show_chart_white_24dp"/>

<Preference
android:key="alarm_preferences"
android:key="@string/alarm_preferences"
android:title="Alarm Settings"
android:icon="@drawable/ic_vibration_white_24dp"/>

<Preference
android:key="watch_preferences"
android:key="@string/watch_preferences"
android:title="Watch Preferences"
android:icon="@drawable/ic_watch_white_24dp" />

Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/xml/preferences_alarms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
xmlns:sample="http://schemas.android.com/apk/res-auto">

<CheckBoxPreference
android:key="alarms_enabled"
android:key="@string/alarms_enabled"
android:title="Enable Alarms"
android:summary="Allow the phone to vibrate as a warning" />

<CheckBoxPreference
android:key="disable_phone_vibrate"
android:key="@string/disable_phone_vibrate"
android:dependency="alarms_enabled"
android:title="Disable Phone Vibration"
android:summary="Phone will not vibrate but the alarm will be passed to a connected Pebble Watch" />
Expand All @@ -18,7 +18,7 @@
android:title="Speed Alarm 1">

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_1_speed"
android:key="@string/alarm_1_speed"
android:title="Speed"
android:summary="Speed that triggers the alarm"
android:defaultValue="29"
Expand All @@ -30,7 +30,7 @@
sample:msbp_dialogEnabled="true"/>

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_1_battery"
android:key="@string/alarm_1_battery"
android:title="Battery Percent"
android:summary="Battery percent that activates the alarm"
android:defaultValue="100"
Expand All @@ -47,7 +47,7 @@
android:title="Speed Alarm 2">

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_2_speed"
android:key="@string/alarm_2_speed"
android:title="Speed"
android:summary="Speed that triggers the alarm"
android:defaultValue="0"
Expand All @@ -59,7 +59,7 @@
sample:msbp_dialogEnabled="true"/>

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_2_battery"
android:key="@string/alarm_2_battery"
android:title="Battery Percent"
android:summary="Battery percent that activates the alarm"
android:defaultValue="0"
Expand All @@ -76,7 +76,7 @@
android:title="Speed Alarm 3">

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_3_speed"
android:key="@string/alarm_3_speed"
android:title="Speed"
android:summary="Speed that triggers the alarm"
android:defaultValue="0"
Expand All @@ -88,7 +88,7 @@
sample:msbp_dialogEnabled="true"/>

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_3_battery"
android:key="@string/alarm_3_battery"
android:title="Battery Percent"
android:summary="Battery percent that activates the alarm"
android:defaultValue="0"
Expand All @@ -105,7 +105,7 @@
android:title="Current Alarm">

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="alarm_current"
android:key="@string/alarm_current"
android:title="Current"
android:summary="Current that triggers the alarm"
android:defaultValue="35"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/xml/preferences_logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="auto_log"
android:key="@string/auto_log"
android:title="Auto Log"
android:summary="Start logging automatically when a wheel is connected" />

<CheckBoxPreference
android:key="auto_upload"
android:key="@string/auto_upload"
android:title="Auto Upload Logs"
android:summary="Automatically upload log files to Google Drive" />

<CheckBoxPreference
android:key="log_location_data"
android:key="@string/log_location_data"
android:title="Log location"
android:summary="Include location data within the logs" />

<CheckBoxPreference
android:key="use_gps"
android:key="@string/use_gps"
android:dependency="log_location_data"
android:title="Use GPS for location"
android:summary="Use GPS for location rather than network provider. GPS is more accurate but may consume more battery power" />
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/xml/preferences_speed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
xmlns:sample="http://schemas.android.com/apk/res-auto">

<CheckBoxPreference
android:key="use_mph"
android:key="@string/use_mph"
android:title="Use MPH"
android:summary="Show speed in miles rather than kilometers" />

<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="max_speed"
android:key="@string/max_speed"
android:title="Max Speed"
android:summary="The maximum speed shown on the outer dial"
android:enabled="true"
android:defaultValue="30"

sample:msbp_minValue="10"
sample:msbp_maxValue="50"
sample:msbp_interval="1"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences_watch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<ListPreference
android:key="horn_mode"
android:key="@string/horn_mode"
android:title="Horn Mode"
android:defaultValue="0"
android:entries="@array/horn_modes"
Expand Down

0 comments on commit b30b8db

Please sign in to comment.