* show in settings * drop support lib * drop unnecessary viewpager/tab bar * drop unused strings/resources Change-Id: I90c62d7b106ad744ae698044f6f17a759fcbf8a3tirimbino
parent
90ced08026
commit
9b5063f0ed
@ -0,0 +1,13 @@ |
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := AdvancedDisplay
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
include $(BUILD_PACKAGE) |
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH)) |
@ -0,0 +1,39 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||
package="com.cyanogenmod.settings.device" |
||||
android:sharedUserId="android.uid.system" > |
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> |
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> |
||||
|
||||
<application android:label="@string/app_name"> |
||||
<activity |
||||
android:name="com.cyanogenmod.settings.device.DisplaySettings" |
||||
android:launchMode="singleTop" |
||||
android:icon="@drawable/ic_settings_advanced_display" |
||||
android:hardwareAccelerated="true" |
||||
android:configChanges="orientation|keyboardHidden|screenSize" |
||||
android:label="@string/app_name" |
||||
android:theme="@style/Theme.Main" |
||||
android:excludeFromRecents="true" > |
||||
<intent-filter> |
||||
<action android:name="com.android.settings.action.EXTRA_SETTINGS" /> |
||||
</intent-filter> |
||||
<meta-data |
||||
android:name="com.android.settings.icon" |
||||
android:resource="@drawable/ic_settings_advanced_display" /> |
||||
<meta-data |
||||
android:name="com.android.settings.category" |
||||
android:value="com.android.settings.category.device" /> |
||||
</activity> |
||||
|
||||
<receiver android:name=".Startup"> |
||||
<intent-filter android:priority="100"> |
||||
<action android:name="android.intent.action.BOOT_COMPLETED" /> |
||||
</intent-filter> |
||||
</receiver> |
||||
|
||||
<activity android:name=".ScreenFragmentActivity" /> |
||||
|
||||
</application> |
||||
</manifest> |
@ -0,0 +1,30 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
Copyright (C) 2016 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License" |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24" |
||||
android:viewportHeight="24"> |
||||
|
||||
<path |
||||
android:pathData="M0 0h24v24H0z" /> |
||||
<path |
||||
android:fillColor="#000000" |
||||
android:pathData="M12.01 5.5L10 8h4l-1.99-2.5zM18 10v4l2.5-1.99L18 10zM6 10l-2.5 2.01L6 14v-4zm8 |
||||
6h-4l2.01 2.5L14 16zm7-13H3c-1.1 0-2 .9-2 2v14c0 1.1 .9 2 2 2h18c1.1 0 2-.9 |
||||
2-2V5c0-1.1-.9-2-2-2zm0 16.01H3V4.99h18v14.02z" /> |
||||
</vector> |
@ -0,0 +1,5 @@ |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:id="@+id/frameLayout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" /> |
||||
|
@ -0,0 +1,65 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
Copyright (C) 2012-2014 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
||||
<string-array name="mdnie_scenario_entries"> |
||||
<item>CyanogenMod (default)</item> |
||||
<item>UI</item> |
||||
<item>Video</item> |
||||
<item>Video warm</item> |
||||
<item>Video cold</item> |
||||
<item>Camera</item> |
||||
<item>Navigation</item> |
||||
<item>Gallery</item> |
||||
<item>VT</item> |
||||
</string-array> |
||||
|
||||
<string-array name="mdnie_scenario_entries_values" translatable="false"> |
||||
<item>0</item> |
||||
<item>1</item> |
||||
<item>2</item> |
||||
<item>3</item> |
||||
<item>4</item> |
||||
<item>5</item> |
||||
<item>6</item> |
||||
<item>7</item> |
||||
<item>8</item> |
||||
</string-array> |
||||
|
||||
<string-array name="mdnie_mode_entries"> |
||||
<item>Dynamic (default)</item> |
||||
<item>Standard</item> |
||||
<item>Natural</item> |
||||
<item>Movie</item> |
||||
</string-array> |
||||
|
||||
<string-array name="mdnie_mode_entries_values" translatable="false"> |
||||
<item>0</item> |
||||
<item>1</item> |
||||
<item>2</item> |
||||
<item>3</item> |
||||
</string-array> |
||||
|
||||
<string-array name="mdnie_negative_entries"> |
||||
<item>Normal</item> |
||||
<item>Inverted</item> |
||||
</string-array> |
||||
|
||||
<string-array name="mdnie_negative_entries_values" translatable="false"> |
||||
<item>0</item> |
||||
<item>1</item> |
||||
</string-array> |
||||
</resources> |
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
Copyright (C) 2016 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
<resources> |
||||
<!-- Palette colors referenced by top-level themes. --> |
||||
<color name="theme_primary">#ff263238</color> |
||||
<color name="theme_primary_dark">#ff21272b</color> |
||||
<color name="theme_accent">#ff009688</color> |
||||
</resources> |
@ -0,0 +1,26 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- Copyright (C) 2013 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
|
||||
<!-- These resources are around just to allow their values to be customized |
||||
for different hardware and product builds. --> |
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
||||
|
||||
<!-- MDNIE --> |
||||
<string name="mdnie_scenario_sysfs_file" translatable="false">"/sys/class/mdnie/mdnie/scenario"</string> |
||||
<string name="mdnie_mode_sysfs_file" translatable="false">"/sys/class/mdnie/mdnie/mode"</string> |
||||
<string name="mdnie_negative_sysfs_file" translatable="false">"/sys/class/mdnie/mdnie/negative"</string> |
||||
|
||||
</resources> |
@ -0,0 +1,20 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
Copyright (C) 2016 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
<resources> |
||||
<!-- ActionBar contentInsetStart --> |
||||
<dimen name="actionbar_subsettings_contentInsetStart">72dp</dimen> |
||||
</resources> |
@ -0,0 +1,31 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
Copyright (C) 2012-2014 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
||||
<string name="app_name">Advanced display</string> |
||||
|
||||
<!-- Screen Preference --> |
||||
<string name="category_screen_title">Screen</string> |
||||
<string name="screen_colors_title">Colors</string> |
||||
|
||||
<!-- mDNIe --> |
||||
<string name="mdnie_scenario_title_head">Scenario</string> |
||||
<string name="mdnie_scenario_summary_head">Set the mDNIe scenario</string> |
||||
<string name="mdnie_mode_title_head">Mode</string> |
||||
<string name="mdnie_mode_summary_head">Set the mDNIe mode</string> |
||||
<string name="mdnie_negative_title_head">Negative mode</string> |
||||
<string name="mdnie_negative_summary_head">Enable/disable inverted colors</string> |
||||
</resources> |
@ -0,0 +1,29 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
Copyright (C) 2016 The CyanogenMod Project |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License" |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
<resources> |
||||
<style name="Theme.Main" parent="@android:style/Theme.Material.Light.DarkActionBar"> |
||||
<item name="android:colorPrimary">@color/theme_primary</item> |
||||
<item name="android:colorPrimaryDark">@color/theme_primary_dark</item> |
||||
<item name="android:colorAccent">@color/theme_accent</item> |
||||
<!-- Redefine the ActionBar style for contentInsetStart --> |
||||
<item name="android:actionBarStyle">@style/Theme.ActionBar.SubSettings</item> |
||||
</style> |
||||
|
||||
<style name="Theme.ActionBar.SubSettings" parent="@android:style/Widget.Material.Light.ActionBar.Solid"> |
||||
<item name="android:contentInsetStart">@dimen/actionbar_subsettings_contentInsetStart</item> |
||||
</style> |
||||
</resources> |
@ -0,0 +1,36 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
<!-- Screen --> |
||||
<PreferenceCategory |
||||
android:title="@string/screen_colors_title"> |
||||
|
||||
<!-- mDNIe Scenario modes --> |
||||
<com.cyanogenmod.settings.device.mDNIeScenario |
||||
android:key="mdnie_scenario" |
||||
android:title="@string/mdnie_scenario_title_head" |
||||
android:summary="@string/mdnie_scenario_summary_head" |
||||
android:entries="@array/mdnie_scenario_entries" |
||||
android:entryValues="@array/mdnie_scenario_entries_values" |
||||
android:defaultValue="0" /> |
||||
|
||||
<!-- mDNIe Mode --> |
||||
<com.cyanogenmod.settings.device.mDNIeMode |
||||
android:key="mdnie_mode" |
||||
android:title="@string/mdnie_mode_title_head" |
||||
android:summary="@string/mdnie_mode_summary_head" |
||||
android:entries="@array/mdnie_mode_entries" |
||||
android:entryValues="@array/mdnie_mode_entries_values" |
||||
android:defaultValue="0" /> |
||||
|
||||
<!-- mDNIe Negative mode --> |
||||
<com.cyanogenmod.settings.device.mDNIeNegative |
||||
android:key="mdnie_negative" |
||||
android:title="@string/mdnie_negative_title_head" |
||||
android:summary="@string/mdnie_negative_summary_head" |
||||
android:entries="@array/mdnie_negative_entries" |
||||
android:entryValues="@array/mdnie_negative_entries_values" |
||||
android:defaultValue="0" /> |
||||
</PreferenceCategory> |
||||
|
||||
</PreferenceScreen> |
@ -0,0 +1,70 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import android.app.Activity; |
||||
import android.app.ActionBar; |
||||
import android.app.Activity; |
||||
import android.app.Fragment; |
||||
import android.app.FragmentTransaction; |
||||
import android.content.Context; |
||||
import android.os.Bundle; |
||||
import android.view.MenuItem; |
||||
import android.widget.FrameLayout; |
||||
|
||||
import com.cyanogenmod.settings.device.R; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
public class DisplaySettings extends Activity { |
||||
|
||||
public static final String SHARED_PREFERENCES_BASENAME = "com.cyanogenmod.settings.device"; |
||||
public static final String ACTION_UPDATE_PREFERENCES = "com.cyanogenmod.settings.device.UPDATE"; |
||||
public static final String KEY_MDNIE_SCENARIO = "mdnie_scenario"; |
||||
public static final String KEY_MDNIE_MODE = "mdnie_mode"; |
||||
public static final String KEY_MDNIE_NEGATIVE = "mdnie_negative"; |
||||
|
||||
ScreenFragmentActivity mFragment; |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
mFragment = new ScreenFragmentActivity(); |
||||
setContentView(R.layout.framelayout); |
||||
getFragmentManager().beginTransaction().add(R.id.frameLayout, mFragment).commit(); |
||||
|
||||
final ActionBar bar = getActionBar(); |
||||
bar.setTitle(R.string.app_name); |
||||
bar.setDisplayHomeAsUpEnabled(true); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
protected void onSaveInstanceState(Bundle outState) { |
||||
super.onSaveInstanceState(outState); |
||||
} |
||||
|
||||
@Override |
||||
public boolean onOptionsItemSelected(MenuItem item) { |
||||
switch (item.getItemId()) { |
||||
case android.R.id.home: |
||||
DisplaySettings.this.onBackPressed(); |
||||
default: |
||||
return super.onOptionsItemSelected(item); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import android.content.Context; |
||||
import android.content.res.Resources; |
||||
import android.content.SharedPreferences; |
||||
import android.os.Bundle; |
||||
import android.preference.CheckBoxPreference; |
||||
import android.preference.ListPreference; |
||||
import android.preference.Preference; |
||||
import android.preference.PreferenceActivity; |
||||
import android.preference.PreferenceCategory; |
||||
import android.preference.PreferenceFragment; |
||||
import android.preference.PreferenceManager; |
||||
import android.preference.PreferenceScreen; |
||||
import android.util.Log; |
||||
|
||||
import com.cyanogenmod.settings.device.R; |
||||
|
||||
public class ScreenFragmentActivity extends PreferenceFragment { |
||||
|
||||
private static final String PREF_ENABLED = "1"; |
||||
private static final String TAG = "DisplaySettings_Screen"; |
||||
private mDNIeScenario mmDNIeScenario; |
||||
private mDNIeMode mmDNIeMode; |
||||
private mDNIeNegative mmDNIeNegative; |
||||
|
||||
@Override |
||||
public void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
|
||||
addPreferencesFromResource(R.xml.screen_preferences); |
||||
PreferenceScreen preferenceScreen = getPreferenceScreen(); |
||||
Resources res = getResources(); |
||||
|
||||
/* mDNIe */ |
||||
mmDNIeScenario = (mDNIeScenario) findPreference(DisplaySettings.KEY_MDNIE_SCENARIO); |
||||
mmDNIeScenario.setEnabled(mDNIeScenario.isSupported(res.getString(R.string.mdnie_scenario_sysfs_file))); |
||||
|
||||
mmDNIeMode = (mDNIeMode) findPreference(DisplaySettings.KEY_MDNIE_MODE); |
||||
mmDNIeMode.setEnabled(mDNIeMode.isSupported(res.getString(R.string.mdnie_mode_sysfs_file))); |
||||
|
||||
mmDNIeNegative = (mDNIeNegative) findPreference(DisplaySettings.KEY_MDNIE_NEGATIVE); |
||||
mmDNIeNegative.setEnabled(mDNIeNegative.isSupported(res.getString(R.string.mdnie_negative_sysfs_file))); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
||||
|
||||
String key = preference.getKey(); |
||||
Log.w(TAG, "key: " + key); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public static boolean isSupported(String FILE) { |
||||
return Utils.fileExists(FILE); |
||||
} |
||||
|
||||
public static void restore(Context context) { |
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import android.content.BroadcastReceiver; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
|
||||
public class Startup extends BroadcastReceiver { |
||||
|
||||
@Override |
||||
public void onReceive(final Context context, final Intent bootintent) { |
||||
mDNIeScenario.restore(context); |
||||
mDNIeMode.restore(context); |
||||
mDNIeNegative.restore(context); |
||||
ScreenFragmentActivity.restore(context); |
||||
} |
||||
} |
@ -0,0 +1,83 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import android.util.Log; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.File; |
||||
import java.io.FileNotFoundException; |
||||
import java.io.FileOutputStream; |
||||
import java.io.FileReader; |
||||
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 = "DeviceSettings_Utils"; |
||||
private static final String TAG_READ = "DeviceSettings_Utils_Read"; |
||||
private static final String TAG_WRITE = "DeviceSettings_Utils_Write"; |
||||
|
||||
/** |
||||
* Write a string value to the specified file. |
||||
* |
||||
* @param filename The filename |
||||
* @param value The value |
||||
*/ |
||||
public static void writeValue(String filename, String value) { |
||||
FileOutputStream fos = null; |
||||
try { |
||||
fos = new FileOutputStream(new File(filename), false); |
||||
fos.write(value.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); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Check if the specified file exists. |
||||
* @param filename The filename |
||||
* @return Whether the file exists or not |
||||
*/ |
||||
public static boolean fileExists(String filename) { |
||||
return new File(filename).exists(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,61 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import android.content.SharedPreferences; |
||||
import android.util.AttributeSet; |
||||
import android.preference.Preference; |
||||
import android.preference.ListPreference; |
||||
import android.preference.Preference.OnPreferenceChangeListener; |
||||
import android.preference.PreferenceManager; |
||||
|
||||
public class mDNIeMode extends ListPreference implements OnPreferenceChangeListener { |
||||
|
||||
private static String FILE = null; |
||||
|
||||
public mDNIeMode(Context context, AttributeSet attrs) { |
||||
super(context, attrs); |
||||
this.setOnPreferenceChangeListener(this); |
||||
FILE = context.getResources().getString(R.string.mdnie_mode_sysfs_file); |
||||
} |
||||
|
||||
public static boolean isSupported(String filePath) { |
||||
return Utils.fileExists(filePath); |
||||
} |
||||
|
||||
/** |
||||
* Restore mdnie user mode setting from SharedPreferences. (Write to kernel.) |
||||
* @param context The context to read the SharedPreferences from |
||||
*/ |
||||
public static void restore(Context context) { |
||||
FILE = context.getResources().getString(R.string.mdnie_mode_sysfs_file); |
||||
if (!isSupported(FILE)) { |
||||
return; |
||||
} |
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); |
||||
Utils.writeValue(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_MODE, "0")); |
||||
} |
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) { |
||||
Utils.writeValue(FILE, (String) newValue); |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,61 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import java.io.IOException; |
||||
import android.content.Context; |
||||
import android.util.AttributeSet; |
||||
import android.content.SharedPreferences; |
||||
import android.preference.Preference; |
||||
import android.preference.ListPreference; |
||||
import android.preference.Preference.OnPreferenceChangeListener; |
||||
import android.preference.PreferenceManager; |
||||
|
||||
public class mDNIeNegative extends ListPreference implements OnPreferenceChangeListener { |
||||
|
||||
private static String FILE = null; |
||||
|
||||
public mDNIeNegative(Context context, AttributeSet attrs) { |
||||
super(context, attrs); |
||||
this.setOnPreferenceChangeListener(this); |
||||
FILE = context.getResources().getString(R.string.mdnie_negative_sysfs_file); |
||||
} |
||||
|
||||
public static boolean isSupported(String filePath) { |
||||
return Utils.fileExists(filePath); |
||||
} |
||||
|
||||
/** |
||||
* Restore mdnie user mode setting from SharedPreferences. (Write to kernel.) |
||||
* @param context The context to read the SharedPreferences from |
||||
*/ |
||||
public static void restore(Context context) { |
||||
FILE = context.getResources().getString(R.string.mdnie_negative_sysfs_file); |
||||
if (!isSupported(FILE)) { |
||||
return; |
||||
} |
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); |
||||
Utils.writeValue(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_NEGATIVE, "0")); |
||||
} |
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) { |
||||
Utils.writeValue(FILE, (String) newValue); |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,61 @@ |
||||
/* |
||||
* Copyright (C) 2012 The CyanogenMod Project |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package com.cyanogenmod.settings.device; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import android.content.SharedPreferences; |
||||
import android.util.AttributeSet; |
||||
import android.preference.Preference; |
||||
import android.preference.ListPreference; |
||||
import android.preference.Preference.OnPreferenceChangeListener; |
||||
import android.preference.PreferenceManager; |
||||
|
||||
public class mDNIeScenario extends ListPreference implements OnPreferenceChangeListener { |
||||
|
||||
private static String FILE = null; |
||||
|
||||
public mDNIeScenario(Context context, AttributeSet attrs) { |
||||
super(context,attrs); |
||||
this.setOnPreferenceChangeListener(this); |
||||
FILE = context.getResources().getString(R.string.mdnie_scenario_sysfs_file); |
||||
} |
||||
|
||||
public static boolean isSupported(String filePath) { |
||||
return Utils.fileExists(filePath); |
||||
} |
||||
|
||||
/** |
||||
* Restore mdnie "camera" setting from SharedPreferences. (Write to kernel.) |
||||
* @param context The context to read the SharedPreferences from |
||||
*/ |
||||
public static void restore(Context context) { |
||||
FILE = context.getResources().getString(R.string.mdnie_scenario_sysfs_file); |
||||
if (!isSupported(FILE)) { |
||||
return; |
||||
} |
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); |
||||
Utils.writeValue(FILE, sharedPrefs.getString(DisplaySettings.KEY_MDNIE_SCENARIO, "0")); |
||||
} |
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) { |
||||
Utils.writeValue(FILE, (String) newValue); |
||||
return true; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue