summaryrefslogtreecommitdiffstats
path: root/DeviceSettings/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'DeviceSettings/src/com')
-rw-r--r--DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java9
-rw-r--r--DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java1
-rw-r--r--DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java82
3 files changed, 79 insertions, 13 deletions
diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java
index 015dd7b..bc42a95 100644
--- a/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java
+++ b/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java
@@ -80,14 +80,15 @@ public class SensorsFragmentActivity extends PreferenceFragment {
public static void restore(Context context) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
- String gyroCalib = sharedPrefs.getString(DeviceSettings.KEY_USE_GYRO_CALIBRATION, "1");
+ boolean gyroCalib = sharedPrefs.getBoolean(DeviceSettings.KEY_USE_GYRO_CALIBRATION, true);
// When use gyro calibration value is set to 1, calibration is done at the same time, which
// means it is reset at each boot, providing wrong calibration most of the time at each reboot.
// So we only set it to "0" if user wants it, as it defaults to 1 at boot
- if (gyroCalib.compareTo("1") != 0)
- Utils.writeValue(FILE_USE_GYRO_CALIB, gyroCalib);
+ if (!gyroCalib)
+ Utils.writeValue(FILE_USE_GYRO_CALIB, "0");
- Utils.writeValue(FILE_TOUCHKEY_LIGHT, sharedPrefs.getString(DeviceSettings.KEY_TOUCHKEY_LIGHT, "1"));
+ boolean light = sharedPrefs.getBoolean(DeviceSettings.KEY_TOUCHKEY_LIGHT, true);
+ Utils.writeValue(FILE_TOUCHKEY_LIGHT, light);
}
}
diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java
index 7566273..a3b5135 100644
--- a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java
+++ b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java
@@ -31,6 +31,7 @@ public class Startup extends BroadcastReceiver {
RadioFragmentActivity.restore(context);
HapticFragmentActivity.restore(context);
VibratorIntensity.restore(context);
+ SensorsFragmentActivity.restore(context);
}
}
diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
index 9d4176c..237ea0f 100644
--- a/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
+++ b/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java
@@ -16,32 +16,96 @@
package com.cyanogenmod.settings.device;
+import android.util.Log;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.SyncFailedException;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Context;
public class Utils {
+ private static final String TAG = "GalaxyNoteSettings_Utils";
+ private static final String TAG_READ = "GalaxyNoteSettings_Utils_Read";
+ private static final String TAG_WRITE = "GalaxyNoteSettings_Utils_Write";
+
/**
* Write a string value to the specified file.
- * @param filename The filename
- * @param value The value
+ *
+ * @param filename The filename
+ * @param value The value
*/
public static void writeValue(String filename, String value) {
+ FileOutputStream fos = null;
try {
- FileOutputStream fos = new FileOutputStream(new File(filename));
+ fos = new FileOutputStream(new File(filename), false);
fos.write(value.getBytes());
fos.flush();
- fos.getFD().sync();
- fos.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ // fos.getFD().sync();
+ } catch (FileNotFoundException ex) {
+ Log.w(TAG, "file " + filename + " not found: " + ex);
+ } catch (SyncFailedException ex) {
+ Log.w(TAG, "file " + filename + " sync failed: " + ex);
+ } catch (IOException ex) {
+ Log.w(TAG, "IOException trying to sync " + filename + ": " + ex);
+ } catch (RuntimeException ex) {
+ Log.w(TAG, "exception while syncing file: ", ex);
+ } finally {
+ if (fos != null) {
+ try {
+ Log.w(TAG_WRITE, "file " + filename + ": " + value);
+ fos.close();
+ } catch (IOException ex) {
+ Log.w(TAG, "IOException while closing synced file: ", ex);
+ } catch (RuntimeException ex) {
+ Log.w(TAG, "exception while closing file: ", ex);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Write a string value to the specified file.
+ *
+ * @param filename The filename
+ * @param value The value
+ */
+ public static void writeValue(String filename, Boolean value) {
+ FileOutputStream fos = null;
+ String sEnvia;
+ try {
+ fos = new FileOutputStream(new File(filename), false);
+ if (value)
+ sEnvia = "1";
+ else
+ sEnvia = "0";
+ fos.write(sEnvia.getBytes());
+ fos.flush();
+ // fos.getFD().sync();
+ } catch (FileNotFoundException ex) {
+ Log.w(TAG, "file " + filename + " not found: " + ex);
+ } catch (SyncFailedException ex) {
+ Log.w(TAG, "file " + filename + " sync failed: " + ex);
+ } catch (IOException ex) {
+ Log.w(TAG, "IOException trying to sync " + filename + ": " + ex);
+ } catch (RuntimeException ex) {
+ Log.w(TAG, "exception while syncing file: ", ex);
+ } finally {
+ if (fos != null) {
+ try {
+ Log.w(TAG_WRITE, "file " + filename + ": " + value);
+ fos.close();
+ } catch (IOException ex) {
+ Log.w(TAG, "IOException while closing synced file: ", ex);
+ } catch (RuntimeException ex) {
+ Log.w(TAG, "exception while closing file: ", ex);
+ }
+ }
}
}