diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4058c4530f6..c54354aa364 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1685,6 +1685,11 @@ + + + + + + @@ -1826,6 +1843,21 @@ + + + + + + + + + + + + + + @@ -1889,5 +1921,13 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + diff --git a/README.md b/README.md new file mode 100644 index 00000000000..b013be09baa --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +android_packages_apps_Settings +============================== + +AnimeROM Settings + +Setting Based in OmniROM version with changes + +Beta + +Need more changes diff --git a/res/drawable-hdpi/ic_settings_performance2.png b/res/drawable-hdpi/ic_settings_performance2.png new file mode 100644 index 00000000000..d5694199a22 Binary files /dev/null and b/res/drawable-hdpi/ic_settings_performance2.png differ diff --git a/res/drawable-hdpi/ic_settings_system.png b/res/drawable-hdpi/ic_settings_system.png new file mode 100644 index 00000000000..920b65ec56c Binary files /dev/null and b/res/drawable-hdpi/ic_settings_system.png differ diff --git a/res/drawable-hdpi/ic_settings_themes.png b/res/drawable-hdpi/ic_settings_themes.png new file mode 100644 index 00000000000..3e0d2cabfca Binary files /dev/null and b/res/drawable-hdpi/ic_settings_themes.png differ diff --git a/res/drawable-mdpi/ic_settings_performance2.png b/res/drawable-mdpi/ic_settings_performance2.png new file mode 100644 index 00000000000..a97d54e982a Binary files /dev/null and b/res/drawable-mdpi/ic_settings_performance2.png differ diff --git a/res/drawable-mdpi/ic_settings_system.png b/res/drawable-mdpi/ic_settings_system.png new file mode 100644 index 00000000000..f738fd9f177 Binary files /dev/null and b/res/drawable-mdpi/ic_settings_system.png differ diff --git a/res/drawable-mdpi/ic_settings_themes.png b/res/drawable-mdpi/ic_settings_themes.png new file mode 100644 index 00000000000..7dd65fcc5d5 Binary files /dev/null and b/res/drawable-mdpi/ic_settings_themes.png differ diff --git a/res/drawable-xhdpi/ic_settings_performance2.png b/res/drawable-xhdpi/ic_settings_performance2.png new file mode 100644 index 00000000000..aa61cf57fae Binary files /dev/null and b/res/drawable-xhdpi/ic_settings_performance2.png differ diff --git a/res/drawable-xhdpi/ic_settings_system.png b/res/drawable-xhdpi/ic_settings_system.png new file mode 100644 index 00000000000..aa3b1fb2804 Binary files /dev/null and b/res/drawable-xhdpi/ic_settings_system.png differ diff --git a/res/drawable-xhdpi/ic_settings_themes.png b/res/drawable-xhdpi/ic_settings_themes.png new file mode 100644 index 00000000000..3c6b596f1b9 Binary files /dev/null and b/res/drawable-xhdpi/ic_settings_themes.png differ diff --git a/res/drawable/anime_header.png b/res/drawable/anime_header.png new file mode 100644 index 00000000000..1a5aa3e9612 Binary files /dev/null and b/res/drawable/anime_header.png differ diff --git a/res/drawable/github.png b/res/drawable/github.png new file mode 100644 index 00000000000..a3e3993bfdc Binary files /dev/null and b/res/drawable/github.png differ diff --git a/res/drawable/twitter_bird.png b/res/drawable/twitter_bird.png new file mode 100644 index 00000000000..78cf7205569 Binary files /dev/null and b/res/drawable/twitter_bird.png differ diff --git a/res/layout/dev_pref.xml b/res/layout/dev_pref.xml new file mode 100644 index 00000000000..fa96ebea391 --- /dev/null +++ b/res/layout/dev_pref.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/layout/installed_app_details.xml b/res/layout/installed_app_details.xml index 347c12b838f..efc8e91010c 100644 --- a/res/layout/installed_app_details.xml +++ b/res/layout/installed_app_details.xml @@ -62,6 +62,13 @@ android:layout_marginTop="4dip" android:text="@string/app_notifications_switch_label" /> + + + + + + + diff --git a/res/values-es/anime_strings.xml b/res/values-es/anime_strings.xml new file mode 100644 index 00000000000..33103e6aa77 --- /dev/null +++ b/res/values-es/anime_strings.xml @@ -0,0 +1,60 @@ + + + + + + HALO + Comportamiento de HALO + Lista negra de HALO + Lista blanca de HALO + Habilitar HALO + Si se marca activar la función de HALO (La ventana flotante en aplicaciones recientes no se vería afectada) + Ocultar HALO después de la actividad + HALO aparecerá para las tareas de entrada y desplazarse fuera de la vista después de un tiempo + HALO inverso + Aplica para cambiar de tareas y mover gestos + Política HALO + Habilita las notificaciones de listas negras/blancas + Lista negra + Lista blanca + Pausar aplicación activa + Al abrir una aplicación con HALO la aplicación de base se pondrá en pausa + Modo ninja + HALO desaparecerá por completo cuando están vacíos + Habilitar mensaje emergente + Mostrar cuadro de mensaje para las notificaciones entrantes + Ping on unlock + HALO hará ping cuando el dispositivo está desbloqueado si se han recibido nuevas notificaciones + Tamaño de HALO + Define lo grande que va a ser HALO + Minúsculo + Pequeño + Normal (predeterminado) + Grande + Gigantesco + Monstruoso + Conteo notificación + Mostrar conteo de notificación en HALO + No mostrar nada + Total + Por applicación + Ambos + Animación de cuadro Mensaje + Animación de cuadro de mensaje de Halo para las notificaciones entrantes + Ninguna + Flip + + diff --git a/res/values-es/custom_strings.xml b/res/values-es/custom_strings.xml index 2ed1c622373..0b1a28ede0e 100644 --- a/res/values-es/custom_strings.xml +++ b/res/values-es/custom_strings.xml @@ -16,7 +16,7 @@ - Versión de Omni + Versión de AnimeROM Desconocida diff --git a/res/values-zh-rCN/anime_strings.xml b/res/values-zh-rCN/anime_strings.xml new file mode 100644 index 00000000000..c05ef339609 --- /dev/null +++ b/res/values-zh-rCN/anime_strings.xml @@ -0,0 +1,63 @@ + + + + + + + + HALO + HALO行为 + HALO黑名单 + HALO白名单 + 启用HALO + 启用HALO悬浮窗口(最近的应用程序将不会受到影响) + 活动后隐藏HALO + HALO将出现传入的任务和滚动出视线一段时间后 + 交换HALO + 交换任务切换和移动的触发手势 + HALO策略 + 启用黑/白名单列表通知 + 黑名单 + 白名单 + 暂停活动应用 + 当通过HALO打开一个应用时,相关应用将处于暂停状态。 + 隐身模式 + 当没有任务时HALO将完全消失 + 启用消息弹出窗口 + 有新通知时显示消息弹出窗口 + ping解锁 + 如果收到新的通知,设备将解锁HALO + HALO大小 + 设置HALO的显示大小 + 迷你 + + 正常 (默认) + + 巨大 + 庞大 + 消息数量 + 在HALO上显示消息数量 + + 总数 + 每个应用程序 + 两者都显示 + 消息框动画 + 新通知HALO消息框动画 + + 翻转 + + + diff --git a/res/values/custom_arrays.xml b/res/values/anime_arrays.xml similarity index 65% rename from res/values/custom_arrays.xml rename to res/values/anime_arrays.xml index 5b1e24e96ff..9a3563be6da 100644 --- a/res/values/custom_arrays.xml +++ b/res/values/anime_arrays.xml @@ -2,7 +2,7 @@ + + @string/halo_size_miniscule + @string/halo_size_small + @string/halo_size_default + @string/halo_size_large + @string/halo_size_gigantic + @string/halo_size_monster + + + + 0.6 + 0.8 + 1.0 + 1.2 + 1.4 + 1.6 + + + + @string/halo_state_black + @string/halo_state_white + + + + 1 + 0 + + + + @string/halo_notification_count_none + @string/halo_notification_count_total + @string/halo_notification_count_individual + @string/halo_notification_count_both + + + + 1 + 2 + 3 + 4 + + + + @string/halo_msgbox_animation_none + @string/halo_msgbox_animation_flip + + + + 1 + 2 + + + + 12m + 16m + 24m + 32m + 48m + + + + 12m + 16m + 24m + 32m + 36m + 40m + 44m + 48m + + + + 128KB + 1024KB + 2048KB + 3072KB + 4096KB + + + + + + @string/theme_auto_mode_off + @string/theme_auto_mode_lightsensor + @string/theme_auto_mode_twilight + + + + 0 + 1 + 2 + + + diff --git a/res/values/anime_attrs.xml b/res/values/anime_attrs.xml new file mode 100644 index 00000000000..e550b0a7460 --- /dev/null +++ b/res/values/anime_attrs.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/res/values/custom_strings.xml b/res/values/anime_strings.xml similarity index 70% rename from res/values/custom_strings.xml rename to res/values/anime_strings.xml index 4d7a1240e91..06c96cbfae4 100644 --- a/res/values/custom_strings.xml +++ b/res/values/anime_strings.xml @@ -1,5 +1,5 @@ - - Omni version + AnimeROM version Unknown @@ -156,7 +156,7 @@ Warning - ART is not supported by OmniROM. This setting is included for experimentation only and has the potential to cause instability, crashes, data loss or prevent the proper boot of your device. Visit <a href=\"http://source.android.com/devices/tech/dalvik/art.html\">Introducing ART</a> for more information.<br/><br/>We request you do not file bug reports if you have enabled ART as your runtime.<br/><br/>Are you sure you want to reboot to change runtime from %1$s to %2$s? + ART is not supported by AnimeROM. This setting is included for experimentation only and has the potential to cause instability, crashes, data loss or prevent the proper boot of your device. Visit <a href=\"http://source.android.com/devices/tech/dalvik/art.html\">Introducing ART</a> for more information.<br/><br/>We request you do not file bug reports if you have enabled ART as your runtime.<br/><br/>Are you sure you want to reboot to change runtime from %1$s to %2$s? Two @@ -253,5 +253,101 @@ Single Expandable Expanded + About misc settings + + + HALO + HALO Behavior + Blacklist from HALO + Whitelist from HALO + Enable HALO + If checked enable HALO feature (floating window on recent apps would not be affected) + Hide HALO after activity + HALO will appear for incoming tasks and scroll out of sight after a while + Reverse HALO + Applies for task switching and moving gestures + HALO policy + Enables black/white listing notifications + Black list + White list + Pause active app + When opening an app with HALO the underlying app will get paused + Ninja mode + HALO will disappear completely when empty + Enable message pop-up + Show message box for incoming notifications + Ping on unlock + HALO will ping when device is unlocked if new notifications were received + HALO size + Defines how big HALO is going to be + Miniscule + Small + Normal (default) + Large + Gigantic + Monster + Notification count + Display notification counts on HALO + None + Total + Per app + Both + Message box animation + Halo message box animation for incoming notifications + None + Flip + + + + About AnimeROM + Mexican Developers + Developers + Graphic Designer + Gerrit Code Review + Help us make Anime a better ROM + AnimeROM Source + https://github.com/AnimeROM + The Secret Sauce + https://github.com/AnimeROM + xperiafan13 + (C) 2014 The AnimeROM Project. + Powered by: + \nXPerience and GingerXperia. + Klozz Jesus TeamMEX in XDA-Developers + Mack Ankh + + VM Settings + AnimeROM + Other Settings + + GMaps Hack + Performance Hack + + + Use JIT + Use the Dalvik just-in-time compiler (requires reboot) + + + VM heap size + Maximum amount of memory per VM heap (requires reboot) + + + SD Card Cache size + Amount of Cache memory for SD Card reads (requires reboot) + + + Disable boot animation + Don\'t show the boot animation for faster boot + + + Special features category + + + The Real Darkness AnimeROM + Switch theme + Manual + On light condition change + On daytime + Automatic light condition change mode is enabled. Manual switching is not possible. diff --git a/res/values/strings.xml b/res/values/strings.xml index 37a5955abb3..b83f9cb2c9e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4910,4 +4910,15 @@ + + + Status bar + AnimeROM™ interface + XPerience™ Settings Ops + Center clock + On the status bar aligns the clock to center (Wait for restarting SystemUI) +App Ops + Fine-grained permission controls + Developer XPerience™ + XPerience™ Themes diff --git a/res/xml/device_info_settings.xml b/res/xml/device_info_settings.xml index c44be006b2d..c52194ad6d7 100644 --- a/res/xml/device_info_settings.xml +++ b/res/xml/device_info_settings.xml @@ -17,7 +17,7 @@ - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/performance_hack.xml b/res/xml/performance_hack.xml new file mode 100644 index 00000000000..fd8c814479d --- /dev/null +++ b/res/xml/performance_hack.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + diff --git a/res/xml/prefs_about.xml b/res/xml/prefs_about.xml new file mode 100644 index 00000000000..fdbc9619959 --- /dev/null +++ b/res/xml/prefs_about.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/settings_headers.xml b/res/xml/settings_headers.xml index 1b28616a2e9..149c7335fd2 100644 --- a/res/xml/settings_headers.xml +++ b/res/xml/settings_headers.xml @@ -58,23 +58,33 @@ android:fragment="com.android.settings.WirelessSettings" android:icon="@drawable/empty_icon" /> + + -
+ +
+ +
+ android:icon="@drawable/ic_settings_system" />
+ android:icon="@drawable/ic_settings_performance2" />
+ +
+ + +
diff --git a/res/xml/theme_settings.xml b/res/xml/theme_settings.xml new file mode 100644 index 00000000000..79b3165717b --- /dev/null +++ b/res/xml/theme_settings.xml @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/src/com/android/settings/About.java b/src/com/android/settings/About.java new file mode 100644 index 00000000000..ad19f0c8fff --- /dev/null +++ b/src/com/android/settings/About.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 AnimeROM + * + * 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.android.settings; + +import android.content.ActivityNotFoundException; +import android.content.ComponentName; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceGroup; +import android.preference.PreferenceScreen; + +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +import java.util.ArrayList; +import java.util.Collections; + +public class About extends SettingsPreferenceFragment { + + public static final String TAG = "About"; + + private static final String ANIME_REVIEW = "https://github.com/AnimeROM"; //Github of AnimeROM PUT HERE + private static final String ANIME_TWITTER = "https://github.com/AnimeROM"; // twiter or any ?? + private static final String XPERIAFAN13 = "https://www.facebook.com/miguelangel.sanchezbravo"; + private static final String KLOZZ = "https://twitter.com/klozz_"; + private static final String MACK = ""; // Any??? + + Preference mReviewUrl; + Preference mxperiafan13; + Preference mklozz; + Preference mtdm; + Preference mMack; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setTitle(R.string.about_anime); + addPreferencesFromResource(R.xml.prefs_about); + + mReviewUrl = findPreference("anime_gerrit"); + mxperiafan13 = findPreference("xperiafan13"); + mklozz = findPreference("klozz"); + mMack = findPreference("Mack"); + + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + if (preference == mReviewUrl) { + launchUrl(ANIME_REVIEW); + return true; + } else if (preference == mxperiafan13) { + launchUrl(XPERIAFAN13); + return true; + } else if (preference == mklozz) { + launchUrl(KLOZZ); + return true; + } else if (preference == mtdm) { + launchUrl(ANIME_TWITTER); + return true; + } else if (preference == mMack) { + launchUrl(ANIME_TWITTER); + return true; + } + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + + private void launchUrl(String url) { + Uri uriUrl = Uri.parse(url); + Intent whatever = new Intent(Intent.ACTION_VIEW, uriUrl); + getActivity().startActivity(whatever); + } +} diff --git a/src/com/android/settings/DeveloperPreference.java b/src/com/android/settings/DeveloperPreference.java new file mode 100644 index 00000000000..50ee8084c36 --- /dev/null +++ b/src/com/android/settings/DeveloperPreference.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2014 AnimeROM + * + * 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.android.settings; + +import android.content.Context; +import android.content.Intent; +import android.content.res.TypedArray; +import android.graphics.Point; +import android.net.Uri; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.Display; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import com.android.settings.R; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class DeveloperPreference extends Preference { + private static final String TAG = "DeveloperPreference"; + private ImageView twitterButton; + private ImageView githubButton; + + private TextView devName; + + private String nameDev; + private String twitterName; + private String githubLink; + private final Display mDisplay; + private TypedArray typedArray; + private TextView twitter; + + public DeveloperPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + typedArray = context.obtainStyledAttributes(attrs, R.styleable.DeveloperPreference); + nameDev = typedArray.getString(R.styleable.DeveloperPreference_nameDev); + twitterName = typedArray.getString(R.styleable.DeveloperPreference_twitterHandle); + githubLink = typedArray.getString(R.styleable.DeveloperPreference_githubLink); + + WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); + mDisplay = wm.getDefaultDisplay(); + } + + @Override + protected View onCreateView(ViewGroup parent) { + super.onCreateView(parent); + View layout = View.inflate(getContext(), R.layout.dev_pref, null); + twitterButton = (ImageView) layout.findViewById(R.id.twitter_button); + githubButton = (ImageView) layout.findViewById(R.id.github_button); + devName = (TextView) layout.findViewById(R.id.name); + return layout; + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + try { + if (githubLink != null) { + final OnClickListener openGithub = new OnClickListener() { + @Override + public void onClick(View v) { + Uri githubURL = Uri.parse(githubLink); + final Intent intent = new Intent(Intent.ACTION_VIEW, githubURL); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + getContext().startActivity(intent); + } + }; + githubButton.setOnClickListener(openGithub); + } else { + githubButton.setVisibility(View.GONE); + } + } catch (Exception e) { + // Do nothing + } + + try { + if (twitterName != null) { + final OnPreferenceClickListener openTwitter = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Uri twitterURL = Uri.parse("http://twitter.com/#!/" + twitterName); + final Intent intent = new Intent(Intent.ACTION_VIEW, twitterURL); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + getContext().startActivity(intent); + return true; + } + }; + + // changed to clicking the preference to open twitter + // it was a hit or miss to click the twitter bird + this.setOnPreferenceClickListener(openTwitter); + } else { + twitterButton.setVisibility(View.INVISIBLE); + } + } catch (Exception e) { + // Do nothing + } + if (devName != null) { + devName.setText(nameDev); + } + } +} diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java index 486afab9d91..96170352092 100644 --- a/src/com/android/settings/DeviceInfoSettings.java +++ b/src/com/android/settings/DeviceInfoSettings.java @@ -95,7 +95,7 @@ public void onCreate(Bundle icicle) { setStringSummary(KEY_BUILD_NUMBER, Build.DISPLAY); findPreference(KEY_BUILD_NUMBER).setEnabled(true); findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion()); - setValueSummary(KEY_MOD_VERSION, "ro.omni.version"); + setValueSummary(KEY_MOD_VERSION, "ro.anime.version"); if (!SELinux.isSELinuxEnabled()) { String status = getResources().getString(R.string.selinux_status_disabled); diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 2e49fc201e6..0294d6f4e7c 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -34,6 +34,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; +import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.nfc.NfcAdapter; import android.os.Bundle; @@ -84,6 +85,7 @@ import com.android.settings.print.PrintJobSettingsFragment; import com.android.settings.print.PrintServiceSettingsFragment; import com.android.settings.print.PrintSettingsFragment; +import com.android.settings.slim.themes.ThemeEnabler; import com.android.settings.tts.TextToSpeechSettings; import com.android.settings.users.UserSettings; import com.android.settings.vpn2.VpnSettings; @@ -133,6 +135,8 @@ public class Settings extends PreferenceActivity private Header mParentHeader; private boolean mInLocalHeaderSwitch; + private int mCurrentState = 0; + // Show only these settings for restricted users private int[] SETTINGS_FOR_RESTRICTED = { R.id.wireless_section, @@ -794,6 +798,7 @@ private static class HeaderAdapter extends ArrayAdapter
{ private final WifiEnabler mWifiEnabler; private final BluetoothEnabler mBluetoothEnabler; + public static ThemeEnabler mThemeEnabler; private AuthenticatorHelper mAuthHelper; private DevicePolicyManager mDevicePolicyManager; @@ -809,9 +814,12 @@ private static class HeaderViewHolder { private LayoutInflater mInflater; static int getHeaderType(Header header) { - if (header.fragment == null && header.intent == null) { + if (header.fragment == null && header.intent == null + && header.id != R.id.theme_settings) { return HEADER_TYPE_CATEGORY; - } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) { + } else if (header.id == R.id.wifi_settings + || header.id == R.id.bluetooth_settings + || header.id == R.id.theme_settings) { return HEADER_TYPE_SWITCH; } else if (header.id == R.id.security_settings) { return HEADER_TYPE_BUTTON; @@ -857,6 +865,7 @@ public HeaderAdapter(Context context, List
objects, // Switches inflated from their layouts. Must be done before adapter is set in super mWifiEnabler = new WifiEnabler(context, new Switch(context)); mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context)); + mThemeEnabler = new ThemeEnabler(context, new Switch(context)); mDevicePolicyManager = dpm; } @@ -926,8 +935,10 @@ public View getView(int position, View convertView, ViewGroup parent) { // Would need a different treatment if the main menu had more switches if (header.id == R.id.wifi_settings) { mWifiEnabler.setSwitch(holder.switch_); - } else { + } else if (header.id == R.id.bluetooth_settings) { mBluetoothEnabler.setSwitch(holder.switch_); + } else if (header.id == R.id.theme_settings) { + mThemeEnabler.setSwitch(holder.switch_); } updateCommonHeaderView(header, holder); break; @@ -1001,11 +1012,13 @@ private void setHeaderIcon(HeaderViewHolder holder, Drawable icon) { public void resume() { mWifiEnabler.resume(); mBluetoothEnabler.resume(); + mThemeEnabler.resume(); } public void pause() { mWifiEnabler.pause(); mBluetoothEnabler.pause(); + mThemeEnabler.resume(); } } @@ -1068,6 +1081,16 @@ public void onAccountsUpdated(Account[] accounts) { invalidateHeaders(); } + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + if (newConfig.uiThemeMode != mCurrentState && HeaderAdapter.mThemeEnabler != null) { + mCurrentState = newConfig.uiThemeMode; + HeaderAdapter.mThemeEnabler.setSwitchState(); + } + } + public static void requestHomeNotice() { sShowNoHomeNotice = true; } diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index 0a382b57892..ac199de8efd 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -290,6 +290,10 @@ public void onDetach() { } } } + + public void setTitle(int resId) { + getActivity().setTitle(resId); + } protected boolean hasNextButton() { return ((ButtonBarHandler)getActivity()).hasNextButton(); diff --git a/src/com/android/settings/animerom/PerformanceHack.java b/src/com/android/settings/animerom/PerformanceHack.java new file mode 100644 index 00000000000..8edcd3020e2 --- /dev/null +++ b/src/com/android/settings/animerom/PerformanceHack.java @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2014 ShockGensMOD initial MOD + * AnimeROM 2014 + * Miguel Angel Sánchez Bravo xperiafan13@xda + * + * 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.android.settings.animerom; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.io.IOException; +import java.io.DataOutputStream; +import java.io.DataInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import android.os.Bundle; +import android.os.SystemProperties; +import android.preference.CheckBoxPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceScreen; + +import android.content.Context; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.Utils; + +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.provider.Settings; + +public class PerformanceHack extends SettingsPreferenceFragment implements + Preference.OnPreferenceChangeListener { + + private static final String GMAPS_HACK_PREF = "pref_gmaps_hack"; + + private static final String GMAPS_HACK_PERSIST_PROP = "persist.sys.gmaps_hack"; + + private static final String GMAPS_HACK_DEFAULT = "0"; + + public static final String KSM_RUN_FILE = "/sys/kernel/mm/ksm/run"; + + public static final String KSM_PREF = "pref_ksm"; + + public static final String KSM_PREF_DISABLED = "0"; + + public static final String KSM_PREF_ENABLED = "1"; + + public static final String KSM_SLEEP_RUN_FILE = "/sys/kernel/mm/ksm/sleep_millisecs"; + + public static final String KSM_SLEEP_PREF = "pref_ksm_sleep"; + + private static final String KSM_SLEEP_PROP = "ksm_sleep_time"; + + public static final String KSM_SLEEP_PREF_DEFAULT = "2000"; + + public static final String KSM_SCAN_RUN_FILE = "/sys/kernel/mm/ksm/pages_to_scan"; + + public static final String KSM_SCAN_PREF = "pref_ksm_scan"; + + private static final String KSM_SCAN_PROP = "ksm_scan_time"; + + public static final String KSM_SCAN_PREF_DEFAULT = "128"; + + public static final String LOWMEMKILL_RUN_FILE = "/sys/module/lowmemorykiller/parameters/minfree"; + + public static final String LOWMEMKILL_PREF = "pref_lowmemkill"; + + private static final String LOWMEMKILL_PROP = "lowmemkill"; + + public static final String LOWMEMKILL_PREF_DEFAULT = "6400,8960,19200,23040,38400,64000"; + + public static final String ADJ_RUN_FILE = "/sys/module/lowmemorykiller/parameters/adj"; + + public static final String ADJ_PREF = "pref_adj"; + + private static final String ADJ_PROP = "adj"; + + public static final String ADJ_PREF_DEFAULT = "0,1,2,3,4,10"; + + public static final String VSYNC_RUN_FILE = "/d/clk/mdp_vsync_clk/enable"; + + public static final String VSYNC_PREF = "pref_vsync"; + + private static final String VSYNC_PROP = "vsync"; + + public static final String VSYNC_PREF_DEFAULT = "1"; + + private static final String GENERAL_CATEGORY = "general_category"; + + private static final String JIT_PREF = "pref_jit_mode"; + + private static final String JIT_ENABLED = "int:jit"; + + private static final String JIT_DISABLED = "int:fast"; + + private static final String JIT_PERSIST_PROP = "persist.sys.jit-mode"; + + private static final String JIT_PROP = "dalvik.vm.execution-mode"; + + private static final String HEAPSIZE_PREF = "pref_heapsize"; + + private static final String HEAPSIZE_PROP = "dalvik.vm.heapsize"; + + private static final String HEAPSIZE_PERSIST_PROP = "persist.sys.vm.heapsize"; + + private static final String HEAPSIZE_DEFAULT = "48m"; // Experimental values (Check ypur device config) + + private static final String SDCARDCACHESIZE_PREF = "pref_sdcardcachesize"; + + private static final String SDCARDCACHESIZE_PROP = "sys.sdcardcache.readsize"; + + private static final String SDCARDCACHESIZE_PERSIST_PROP = "persist.sys.sdcardcachereadsize"; + + private static final String SDCARDCACHESIZE_DEFAULT = "2048KB"; // Experimental value + + private static final String DISABLE_BOOTANIMATION_PREF = "pref_disable_bootanimation"; + + private static final String DISABLE_BOOTANIMATION_PERSIST_PROP = "persist.sys.nobootanimation"; + + private static final String DISABLE_BOOTANIMATION_DEFAULT = "0"; + + private CheckBoxPreference mGmapsHackPref; + + private CheckBoxPreference mKSMPref; + + private ListPreference mKSMSleepPref; + + private ListPreference mKSMScanPref; + + private ListPreference mLowMemKillPref; + + private ListPreference mADJKillPref; + + private ListPreference mVSYNCPref; + + private CheckBoxPreference mJitPref; + + private CheckBoxPreference mDisableBootanimPref; + + private ListPreference mHeapsizePref; + + private ListPreference mSdcardcachesizePref; + + private int swapAvailable = 1; + + private int ksmAvailable = -1; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getPreferenceManager() != null) { + + addPreferencesFromResource(R.xml.performance_hack); + + PreferenceScreen prefSet = getPreferenceScreen(); + + String temp; + + mGmapsHackPref = (CheckBoxPreference) prefSet.findPreference(GMAPS_HACK_PREF); + mKSMPref = (CheckBoxPreference) prefSet.findPreference(KSM_PREF); + mKSMSleepPref = (ListPreference) prefSet.findPreference(KSM_SLEEP_PREF); + mKSMScanPref = (ListPreference) prefSet.findPreference(KSM_SCAN_PREF); + mLowMemKillPref = (ListPreference) prefSet.findPreference(LOWMEMKILL_PREF); + mADJKillPref = (ListPreference) prefSet.findPreference(ADJ_PREF); + mVSYNCPref = (ListPreference) prefSet.findPreference(VSYNC_PREF); + + mJitPref = (CheckBoxPreference) prefSet.findPreference(JIT_PREF); + String jitMode = SystemProperties.get(JIT_PERSIST_PROP, + SystemProperties.get(JIT_PROP, JIT_ENABLED)); + mJitPref.setChecked(JIT_ENABLED.equals(jitMode)); + + mHeapsizePref = (ListPreference) prefSet.findPreference(HEAPSIZE_PREF); + mHeapsizePref.setValue(SystemProperties.get(HEAPSIZE_PERSIST_PROP, + SystemProperties.get(HEAPSIZE_PROP, HEAPSIZE_DEFAULT))); + mHeapsizePref.setOnPreferenceChangeListener(this); + + mSdcardcachesizePref = (ListPreference) prefSet.findPreference(SDCARDCACHESIZE_PREF); + mSdcardcachesizePref.setValue(SystemProperties.get(SDCARDCACHESIZE_PERSIST_PROP, + SystemProperties.get(SDCARDCACHESIZE_PROP, SDCARDCACHESIZE_DEFAULT))); + mSdcardcachesizePref.setOnPreferenceChangeListener(this); + + mDisableBootanimPref = (CheckBoxPreference) prefSet.findPreference(DISABLE_BOOTANIMATION_PREF); + String disableBootanimation = SystemProperties.get(DISABLE_BOOTANIMATION_PERSIST_PROP, DISABLE_BOOTANIMATION_DEFAULT); + mDisableBootanimPref.setChecked("1".equals(disableBootanimation)); + + String gmapshack = SystemProperties.get(GMAPS_HACK_PERSIST_PROP, GMAPS_HACK_DEFAULT); + mGmapsHackPref.setChecked("1".equals(gmapshack)); + + if (isKsmAvailable()) { + temp = null; + mKSMSleepPref.setValue(temp); + mKSMSleepPref.setOnPreferenceChangeListener(this); + } else { + prefSet.removePreference(mKSMSleepPref); + } + + if (isKsmAvailable()) { + temp = null; + mKSMScanPref.setValue(temp); + mKSMScanPref.setOnPreferenceChangeListener(this); + } else { + prefSet.removePreference(mKSMScanPref); + } + + temp = null; + + mLowMemKillPref.setValue(temp); + mLowMemKillPref.setOnPreferenceChangeListener(this); + + if (temp == null) { + prefSet.removePreference(mLowMemKillPref); + } + + temp = null; + + mADJKillPref.setValue(temp); + mADJKillPref.setOnPreferenceChangeListener(this); + + if (temp == null) { + prefSet.removePreference(mADJKillPref); + } + + mVSYNCPref = (ListPreference) prefSet.findPreference(VSYNC_PREF); + + mVSYNCPref.setValue(temp); + mVSYNCPref.setOnPreferenceChangeListener(this); + + if (temp == null) { + prefSet.removePreference(mVSYNCPref); + } + } + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + + if (preference == mGmapsHackPref) { + SystemProperties.set(GMAPS_HACK_PERSIST_PROP, + mGmapsHackPref.isChecked() ? "1" : "0"); + return true; + } + + if (preference == mKSMPref) { + return true; + } + + if (preference == mJitPref) { + SystemProperties.set(JIT_PERSIST_PROP, + mJitPref.isChecked() ? JIT_ENABLED : JIT_DISABLED); + return true; + } + + if (preference == mDisableBootanimPref) { + SystemProperties.set(DISABLE_BOOTANIMATION_PERSIST_PROP, + mDisableBootanimPref.isChecked() ? "1" : "0"); + return true; + } + + return false; + } + + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference == mKSMSleepPref) { + if (newValue != null) { + SystemProperties.set(KSM_SLEEP_PROP, (String)newValue); + return true; + } + } + + if (preference == mKSMScanPref) { + if (newValue != null) { + SystemProperties.set(KSM_SCAN_PROP, (String)newValue); + return true; + } + } + + if (preference == mLowMemKillPref) { + if (newValue != null) { + SystemProperties.set(LOWMEMKILL_PROP, (String)newValue); + return true; + } + } + + if (preference == mADJKillPref) { + if (newValue != null) { + SystemProperties.set(ADJ_PROP, (String)newValue); + return true; + } + } + + if (preference == mVSYNCPref) { + if (newValue != null) { + SystemProperties.set(VSYNC_PROP, (String)newValue); + return true; + } + } + + if (preference == mHeapsizePref) { + if (newValue != null) { + SystemProperties.set(HEAPSIZE_PERSIST_PROP, (String)newValue); + return true; + } + } + + if (preference == mSdcardcachesizePref) { + if (newValue != null) { + SystemProperties.set(SDCARDCACHESIZE_PERSIST_PROP, (String)newValue); + return true; + } + } + + return false; + } + + private boolean isKsmAvailable() { + if (ksmAvailable < 0) { + ksmAvailable = new File(KSM_RUN_FILE).exists() ? 1 : 0; + } + return ksmAvailable > 0; + } +} diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java index 1127c792795..7165ca082b3 100644 --- a/src/com/android/settings/applications/InstalledAppDetails.java +++ b/src/com/android/settings/applications/InstalledAppDetails.java @@ -1,18 +1,18 @@ /** - * Copyright (C) 2007 The Android Open Source 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. - */ +* Copyright (C) 2007 The Android Open Source 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.android.settings.applications; @@ -86,14 +86,14 @@ import android.widget.TextView; /** - * Activity to display application information from Settings. This activity presents - * extended information associated with a package like code, data, total size, permissions - * used by the application and also the set of default launchable activities. - * For system applications, an option to clear user data is displayed only if data size is > 0. - * System applications that do not want clear user data do not have this option. - * For non-system applications, there is no option to clear data. Instead there is an option to - * uninstall the application. - */ +* Activity to display application information from Settings. This activity presents +* extended information associated with a package like code, data, total size, permissions +* used by the application and also the set of default launchable activities. +* For system applications, an option to clear user data is displayed only if data size is > 0. +* System applications that do not want clear user data do not have this option. +* For non-system applications, there is no option to clear data. Instead there is an option to +* uninstall the application. +*/ public class InstalledAppDetails extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, ApplicationsState.Callbacks { @@ -947,14 +947,14 @@ private void refreshSizeInfo() { long dataSize = mAppEntry.dataSize; if (Environment.isExternalStorageEmulated()) { codeSize += mAppEntry.externalCodeSize; - dataSize += mAppEntry.externalDataSize; + dataSize += mAppEntry.externalDataSize; } else { if (mLastExternalCodeSize != mAppEntry.externalCodeSize) { mLastExternalCodeSize = mAppEntry.externalCodeSize; mExternalCodeSize.setText(getSizeStr(mAppEntry.externalCodeSize)); } - if (mLastExternalDataSize != mAppEntry.externalDataSize) { - mLastExternalDataSize = mAppEntry.externalDataSize; + if (mLastExternalDataSize != mAppEntry.externalDataSize) { + mLastExternalDataSize = mAppEntry.externalDataSize; mExternalDataSize.setText(getSizeStr( mAppEntry.externalDataSize)); } } @@ -992,9 +992,9 @@ private void refreshSizeInfo() { } /* - * Private method to handle clear message notification from observer when - * the async operation from PackageManager is complete - */ +* Private method to handle clear message notification from observer when +* the async operation from PackageManager is complete +*/ private void processClearMsg(Message msg) { int result = msg.arg1; String packageName = mAppEntry.info.packageName; @@ -1038,10 +1038,10 @@ private void processMoveMsg(Message msg) { } /* - * Private method to initiate clearing user data when the user clicks the clear data - * button for a system package - */ - private void initiateClearUserData() { +* Private method to initiate clearing user data when the user clicks the clear data +* button for a system package +*/ + private void initiateClearUserData() { mClearDataButton.setEnabled(false); // Invoke uninstall or clear user data based on sysPackage String packageName = mAppEntry.info.packageName; @@ -1318,9 +1318,9 @@ private int getPremiumSmsPermission(String packageName) { } /* - * Method implementing functionality of buttons clicked - * @see android.view.View.OnClickListener#onClick(android.view.View) - */ +* Method implementing functionality of buttons clicked +* @see android.view.View.OnClickListener#onClick(android.view.View) +*/ public void onClick(View v) { String packageName = mAppEntry.info.packageName; if(v == mUninstallButton) { diff --git a/src/com/android/settings/applications/LinearColorBar.java b/src/com/android/settings/applications/LinearColorBar.java index f374c293b32..b0921fefb10 100644 --- a/src/com/android/settings/applications/LinearColorBar.java +++ b/src/com/android/settings/applications/LinearColorBar.java @@ -16,8 +16,8 @@ import android.widget.LinearLayout; public class LinearColorBar extends LinearLayout { - static final int LEFT_COLOR = 0xff0099cc; - static final int MIDDLE_COLOR = 0xff0099cc; + static final int LEFT_COLOR = 0xffcccccc; + static final int MIDDLE_COLOR = 0xffcccccc; static final int RIGHT_COLOR = 0xff888888; static final int GRAY_COLOR = 0xff555555; static final int WHITE_COLOR = 0xffffffff; @@ -271,4 +271,4 @@ protected void onDraw(Canvas canvas) { canvas.drawRect(mRect, mPaint); } } -} \ No newline at end of file +} diff --git a/src/com/android/settings/slim/ThemeEnabler.java b/src/com/android/settings/slim/ThemeEnabler.java new file mode 100644 index 00000000000..ad4f9c6b40e --- /dev/null +++ b/src/com/android/settings/slim/ThemeEnabler.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2013 SlimRoms + * + * 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.android.settings.slim.themes; + +import android.content.Context; +import android.content.res.Configuration; +import android.database.ContentObserver; +import android.os.Handler; +import android.os.UserHandle; +import android.provider.Settings; +import android.widget.CompoundButton; +import android.widget.Switch; +import android.widget.Toast; + +import com.android.settings.R; + +public class ThemeEnabler implements CompoundButton.OnCheckedChangeListener { + private final Context mContext; + private Switch mSwitch; + private boolean mStateMachineEvent; + private boolean mEnabled; + + private boolean mAttached; + private SettingsObserver mSettingsObserver; + + private final class SettingsObserver extends ContentObserver { + SettingsObserver(Handler handler) { + super(handler); + } + + void observe() { + mContext.getContentResolver().registerContentObserver( + Settings.Secure.getUriFor( + Settings.Secure.UI_THEME_AUTO_MODE), + false, this); + } + + @Override + public void onChange(boolean selfChange) { + setSwitchState(); + } + } + + public ThemeEnabler(Context context, Switch switch_) { + mContext = context; + mSwitch = switch_; + mSettingsObserver = new SettingsObserver(new Handler()); + } + + public void resume() { + mSwitch.setOnCheckedChangeListener(this); + if (!mAttached) { + mAttached = true; + mSettingsObserver.observe(); + } + setSwitchState(); + } + + public void pause() { + mSwitch.setOnCheckedChangeListener(null); + if (mAttached) { + mAttached = false; + mContext.getContentResolver().unregisterContentObserver(mSettingsObserver); + } + } + + public void setSwitch(Switch switch_) { + if (mSwitch == switch_) return; + mSwitch.setOnCheckedChangeListener(null); + mSwitch = switch_; + mSwitch.setOnCheckedChangeListener(this); + setSwitchState(); + } + + public void setSwitchState() { + mEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), + Settings.Secure.UI_THEME_AUTO_MODE, 0, + UserHandle.USER_CURRENT) != 1; + + boolean state = mContext.getResources().getConfiguration().uiThemeMode + == Configuration.UI_THEME_MODE_HOLO_DARK; + mStateMachineEvent = true; + mSwitch.setChecked(state); + mStateMachineEvent = false; + } + + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (mStateMachineEvent) { + return; + } + if (!mEnabled) { + Toast.makeText(mContext, R.string.theme_auto_switch_mode_error, + Toast.LENGTH_SHORT).show(); + setSwitchState(); + return; + } + // Handle a switch change + // we currently switch between holodark and hololight till either + // theme engine is ready or lightheme is ready. Currently due of + // missing light themeing hololight = system base theme + Settings.Secure.putIntForUser(mContext.getContentResolver(), + Settings.Secure.UI_THEME_MODE, isChecked + ? Configuration.UI_THEME_MODE_HOLO_DARK + : Configuration.UI_THEME_MODE_HOLO_LIGHT, + UserHandle.USER_CURRENT); + } + +} diff --git a/src/com/android/settings/slim/ThemeSettings.java b/src/com/android/settings/slim/ThemeSettings.java new file mode 100644 index 00000000000..b30788114d4 --- /dev/null +++ b/src/com/android/settings/slim/ThemeSettings.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2013 Slimroms + * + * 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.android.settings.slim.themes; + +import android.app.ActionBar; +import android.app.Activity; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.UserHandle; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceScreen; +import android.preference.ListPreference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.provider.Settings; +import android.util.Log; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; +import android.widget.Switch; + +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +public class ThemeSettings extends SettingsPreferenceFragment { + + private static final String THEME_AUTO_MODE = + "pref_theme_auto_mode"; + + private ListPreference mThemeAutoMode; + private ThemeEnabler mThemeEnabler; + + private int mCurrentState = 0; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.theme_settings); + + PreferenceScreen prefSet = getPreferenceScreen(); + + mThemeAutoMode = (ListPreference) prefSet.findPreference(THEME_AUTO_MODE); + mThemeAutoMode.setValue(String.valueOf( + Settings.Secure.getIntForUser(getContentResolver(), + Settings.Secure.UI_THEME_AUTO_MODE, 0, + UserHandle.USER_CURRENT))); + mThemeAutoMode.setSummary(mThemeAutoMode.getEntry()); + + mThemeAutoMode.setOnPreferenceChangeListener( + new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, + Object newValue) { + String val = (String) newValue; + Settings.Secure.putInt(getContentResolver(), + Settings.Secure.UI_THEME_AUTO_MODE, + Integer.valueOf(val)); + int index = mThemeAutoMode.findIndexOfValue(val); + mThemeAutoMode.setSummary( + mThemeAutoMode.getEntries()[index]); + return true; + } + }); + + final Activity activity = getActivity(); + final Switch actionBarSwitch = new Switch(activity); + + if (activity instanceof PreferenceActivity) { + PreferenceActivity preferenceActivity = (PreferenceActivity) activity; + if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) { + final int padding = activity.getResources().getDimensionPixelSize( + R.dimen.action_bar_switch_padding); + actionBarSwitch.setPaddingRelative(0, 0, padding, 0); + activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, + ActionBar.DISPLAY_SHOW_CUSTOM); + activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams( + ActionBar.LayoutParams.WRAP_CONTENT, + ActionBar.LayoutParams.WRAP_CONTENT, + Gravity.CENTER_VERTICAL | Gravity.END)); + } + } + mThemeEnabler = new ThemeEnabler(activity, actionBarSwitch); + + } + + @Override + public void onResume() { + super.onResume(); + if (mThemeEnabler != null) { + mThemeEnabler.resume(); + } + } + + @Override + public void onPause() { + super.onPause(); + if (mThemeEnabler != null) { + mThemeEnabler.pause(); + } + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + if (newConfig.uiThemeMode != mCurrentState && mThemeEnabler != null) { + mCurrentState = newConfig.uiThemeMode; + mThemeEnabler.setSwitchState(); + } + } + +}