From a24f04fafd95854c75097bff12c2030e973662c9 Mon Sep 17 00:00:00 2001 From: Daniel Hillenbrand Date: Sun, 17 Jun 2012 12:24:13 +0200 Subject: settings: some fixes on touchkey restore, cosmetic changes --- DeviceSettings/AndroidManifest.xml | 5 +- .../settings/device/HapticFragmentActivity.java | 2 +- .../settings/device/ScreenFragmentActivity.java | 19 ++++- .../src/com/cyanogenmod/settings/device/Utils.java | 82 +++++++++++++++++++--- 4 files changed, 93 insertions(+), 15 deletions(-) diff --git a/DeviceSettings/AndroidManifest.xml b/DeviceSettings/AndroidManifest.xml index d658983..d373ded 100644 --- a/DeviceSettings/AndroidManifest.xml +++ b/DeviceSettings/AndroidManifest.xml @@ -22,9 +22,10 @@ - - + + + diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java index 527e931..59047fa 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java @@ -33,7 +33,7 @@ import com.cyanogenmod.settings.device.R; public class HapticFragmentActivity extends PreferenceFragment { private static final String PREF_ENABLED = "1"; - private static final String TAG = "GalaxyS3Parts_General"; + private static final String TAG = "GalaxyS3Settings_General"; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java index e0d225f..37f25b8 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java @@ -33,7 +33,7 @@ import com.cyanogenmod.settings.device.R; public class ScreenFragmentActivity extends PreferenceFragment { private static final String PREF_ENABLED = "1"; - private static final String TAG = "GalaxyS3Parts_General"; + private static final String TAG = "GalaxyS3Settings_General"; private mDNIeScenario mmDNIeScenario; private mDNIeMode mmDNIeMode; private mDNIeNegative mmDNIeNegative; @@ -82,7 +82,20 @@ public class ScreenFragmentActivity extends PreferenceFragment { public static void restore(Context context) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - Utils.writeValue(FILE_TOUCHKEY_DISABLE, sharedPrefs.getString(DeviceSettings.KEY_TOUCHKEY_LIGHT, "0")); - Utils.writeValue(FILE_TOUCHKEY_BRIGHTNESS, sharedPrefs.getString(DeviceSettings.KEY_TOUCHKEY_LIGHT, "1")); + + Boolean light = sharedPrefs.getBoolean(DeviceSettings.KEY_TOUCHKEY_LIGHT, true); + String disabled; + String brightness; + + if (light == true) { + disabled = "0"; + brightness = "1"; + } else { + disabled = "1"; + brightness = "2"; + } + + Utils.writeValue(FILE_TOUCHKEY_DISABLE, disabled); + Utils.writeValue(FILE_TOUCHKEY_BRIGHTNESS, brightness); } } diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Utils.java index 9d4176c..d4df92f 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 = "GalaxyS3Settings_Utils"; + private static final String TAG_READ = "GalaxyS3Settings_Utils_Read"; + private static final String TAG_WRITE = "GalaxyS3Settings_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); + } + } } } -- cgit v1.1