Set a default temperature unit

Bump the DB version and set a default temperature unit in
global settings

Change-Id: I14f80e1b3fa3ae4a47769c02b5ebd6a905a53e46
TICKET: CYNGNOS-2751
This commit is contained in:
Luis Vidal 2016-05-06 16:34:50 -07:00
parent e4886a668f
commit 186ae8353d
3 changed files with 26 additions and 1 deletions

View File

@ -107,4 +107,7 @@
<!-- Default values for protected component managers -->
<string name="def_protected_component_managers" translatable="false">com.android.settings|com.android.launcher3|com.cyanogenmod.trebuchet</string>
<!-- Default temperature unit (CELSIUS) -->
<integer name="def_temperature_unit">2</integer>
</resources>

View File

@ -46,7 +46,7 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{
private static final boolean LOCAL_LOGV = false;
private static final String DATABASE_NAME = "cmsettings.db";
private static final int DATABASE_VERSION = 4;
private static final int DATABASE_VERSION = 5;
public static class CMTableNames {
public static final String TABLE_SYSTEM = "system";
@ -201,6 +201,22 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{
upgradeVersion = 4;
}
if (upgradeVersion < 5) {
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT INTO global(name,value)"
+ " VALUES(?,?);");
loadIntegerSetting(stmt, CMSettings.Global.WEATHER_TEMPERATURE_UNIT,
R.integer.def_temperature_unit);
db.setTransactionSuccessful();
} finally {
if (stmt != null) stmt.close();
db.endTransaction();
}
upgradeVersion = 5;
}
// *** Remember to update DATABASE_VERSION above!
if (upgradeVersion < newVersion) {
@ -342,6 +358,9 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{
loadStringSetting(stmt,
CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE,
R.string.def_power_notifications_ringtone);
loadIntegerSetting(stmt, CMSettings.Global.WEATHER_TEMPERATURE_UNIT,
R.integer.def_temperature_unit);
} finally {
if (stmt != null) stmt.close();
}

View File

@ -117,6 +117,9 @@ public class CMSettingsProviderDefaultsTest extends AndroidTestCase {
GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE,
"R.string.def_power_notifications_ringtone"));
GLOBAL_SETTINGS_DEFAULTS.add(new Setting(
CMSettings.Global.WEATHER_TEMPERATURE_UNIT,
"R.integer.def_temperature_unit"));
}
@Override