galaxys2: pimp my vibrator
Change-Id: I71781be97d01598f83be3db828ebaf91c8211b78
This commit is contained in:
parent
954a88f71a
commit
036beb482d
@ -0,0 +1,59 @@
|
||||
<?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.
|
||||
-->
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingBottom="20dip">
|
||||
|
||||
<TextView android:id="@+id/vibrator_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/vibrator_tuning_title"
|
||||
android:paddingTop="10dip"
|
||||
android:paddingLeft="20dip"
|
||||
android:paddingRight="20dip" />
|
||||
<TextView android:id="@+id/vibrator_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingTop="10dip"
|
||||
android:paddingLeft="20dip"
|
||||
android:paddingRight="20dip" />
|
||||
<SeekBar android:id="@+id/vibrator_seekbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/vibrator_text"
|
||||
android:paddingTop="2dip"
|
||||
android:paddingLeft="20dip"
|
||||
android:paddingRight="20dip" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textWarn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/vibrator_seekbar"
|
||||
android:paddingTop="8dip"
|
||||
android:gravity="center"
|
||||
android:text="@string/vibrator_warning"
|
||||
android:textSize="15dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
@ -34,11 +34,6 @@
|
||||
<string name="accelerometer_dialog_head">Kalibrering fuldført</string>
|
||||
<string name="accelerometer_dialog_message">Accelerometeret er kalibreret.</string>
|
||||
|
||||
<string name="category_haptic_title">Haptik</string>
|
||||
<string name="vibrator_subcat_title">Vibrator</string>
|
||||
<string name="vibrator_intensity_title_head">Vibrator-styrke</string>
|
||||
<string name="vibrator_intensity_summary_head">Indstil vibratorens intensitet</string>
|
||||
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Slå HSDPA/HSUPA til/fra</string>
|
||||
|
@ -2,6 +2,8 @@
|
||||
<resources>
|
||||
<string name="app_name">Erweiterte Einstellungen</string>
|
||||
|
||||
<string name="defaults_button">Zurücksetzen</string>
|
||||
|
||||
<string name="category_screen_title">Bildschirm</string>
|
||||
<string name="screen_colors_title">Farben</string>
|
||||
<string name="mdnie_scenario_title_head">mDNIe-Szenario</string>
|
||||
@ -34,10 +36,14 @@
|
||||
<string name="accelerometer_dialog_head">Kalibrierung beendet</string>
|
||||
<string name="accelerometer_dialog_message">Der Beschleunigungssensor wurde kalibriert</string>
|
||||
|
||||
<!-- Haptic Preference -->
|
||||
<string name="category_haptic_title">Haptik</string>
|
||||
<string name="vibrator_subcat_title">Vibration</string>
|
||||
<string name="vibrator_intensity_title_head">Intensität</string>
|
||||
<string name="vibrator_intensity_summary_head">Vibrations-Intensität</string>
|
||||
|
||||
<!-- VibratorTuning -->
|
||||
<string name="vibrator_title">Vibrator</string>
|
||||
<string name="vibrator_tuning_title">Vibrationsstärke</string>
|
||||
<string name="vibrator_tuning_summary_head">Stärke des Vibrationseffektes einstellen</string>
|
||||
<string name="vibrator_warning">Vorsicht: Höhere Werte als %1$d werden nicht empfohlen</string>
|
||||
|
||||
<string name="category_radio_title">Mobilfunk</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
|
@ -30,9 +30,10 @@
|
||||
<string name="accelerometer_dialog_head">Calibración realizada</string>
|
||||
<string name="accelerometer_dialog_message">El sensor ha sido calibrado satisfactoriamente</string>
|
||||
<string name="category_haptic_title">Háptica</string>
|
||||
<string name="vibrator_subcat_title">Vibración</string>
|
||||
<string name="vibrator_intensity_title_head">Intensidad de vibración</string>
|
||||
<string name="vibrator_intensity_summary_head">Establecer la intensidad de vibración</string>
|
||||
<string name="vibrator_title">Vibración</string>
|
||||
<string name="vibrator_tuning_title">Intensidad de vibración</string>
|
||||
<string name="vibrator_tuning_summary_head">Establecer la intensidad de vibración</string>
|
||||
<string name="vibrator_warning">No son recomendables valores mayores de %1$d</string>
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Habilitar HSDPA/HSUPA</string>
|
||||
|
@ -34,11 +34,6 @@
|
||||
<string name="accelerometer_dialog_head">Kalibrointi valmis</string>
|
||||
<string name="accelerometer_dialog_message">Sensori kalibroitu onnistuneesti</string>
|
||||
|
||||
<string name="category_haptic_title">Haptinen</string>
|
||||
<string name="vibrator_subcat_title">Värinä</string>
|
||||
<string name="vibrator_intensity_title_head">Värinän voimakkuus</string>
|
||||
<string name="vibrator_intensity_summary_head">Säädä värinän voimakkuutta</string>
|
||||
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Ota HSDPA/HSUPA käyttöön</string>
|
||||
|
@ -44,9 +44,10 @@
|
||||
<string name="accelerometer_dialog_head">Calibrage terminé</string>
|
||||
<string name="accelerometer_dialog_message">Le capteur a été correctement calibré.</string>
|
||||
<string name="category_haptic_title">Haptique</string>
|
||||
<string name="vibrator_subcat_title">Vibreur</string>
|
||||
<string name="vibrator_intensity_title_head">Intensité du vibreur</string>
|
||||
<string name="vibrator_intensity_summary_head">Définir l\'intensité du vibreur</string>
|
||||
<string name="vibrator_title">Vibreur</string>
|
||||
<string name="vibrator_tuning_title">Intensité du vibreur</string>
|
||||
<string name="vibrator_tuning_summary_head">Définir l\'intensité du vibreur</string>
|
||||
<string name="vibrator_warning">Les valeurs supérieurs à %1$d ne sont pas recommandées</string>
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Activer HSDPA/HSUPA</string>
|
||||
|
@ -34,11 +34,6 @@
|
||||
<string name="accelerometer_dialog_head">Kalibrálás befejezve</string>
|
||||
<string name="accelerometer_dialog_message">Az érzékelő sikeresen bekalibrálva.</string>
|
||||
|
||||
<string name="category_haptic_title">Érintési visszajelzés</string>
|
||||
<string name="vibrator_subcat_title">Rezgés</string>
|
||||
<string name="vibrator_intensity_title_head">Rezgés erőssége</string>
|
||||
<string name="vibrator_intensity_summary_head">Rezgés erősségének beállítása</string>
|
||||
|
||||
<string name="category_radio_title">GSM Rádió</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">HSDPA/HSUPA engedélyezése</string>
|
||||
|
@ -29,10 +29,11 @@
|
||||
<string name="calibrate_accelerometer_summary_head">Posizionare il telefono su una superficie orizzontale piana e premere per effettuare la calibrazione</string>
|
||||
<string name="accelerometer_dialog_head">Calibrazione effettuata</string>
|
||||
<string name="accelerometer_dialog_message">Il sensore è stato correttamente calibrato.</string>
|
||||
<string name="category_haptic_title">Feedback tattile</string>
|
||||
<string name="vibrator_subcat_title">Vibratore</string>
|
||||
<string name="vibrator_intensity_title_head">Intensità vibrazione</string>
|
||||
<string name="vibrator_intensity_summary_head">Imposta l\'intensità della vibrazione</string>
|
||||
<string name="category_haptic_title">Aptico</string>
|
||||
<string name="vibrator_title">Vibrazione</string>
|
||||
<string name="vibrator_tuning_title">Intensità vibrazione</string>
|
||||
<string name="vibrator_tuning_summary_head">Modifica l\'intensità della vibrazione del feedback aptico</string>
|
||||
<string name="vibrator_warning">Valori superiori a %1$d non sono raccomandati</string>
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Abilita HSDPA/HSUPA</string>
|
||||
|
@ -49,9 +49,10 @@
|
||||
<string name="accelerometer_dialog_message">De sensor is succesvol gekalibreerd.</string>
|
||||
|
||||
<string name="category_haptic_title">Trillen</string>
|
||||
<string name="vibrator_subcat_title">Trillen</string>
|
||||
<string name="vibrator_intensity_title_head">Trilintensiteit</string>
|
||||
<string name="vibrator_intensity_summary_head">Trilintensiteit instellen</string>
|
||||
<string name="vibrator_title">Trilapparaat</string>
|
||||
<string name="vibrator_tuning_title">Trilintensiteit</string>
|
||||
<string name="vibrator_tuning_summary_head">Trilintensiteit instellen</string>
|
||||
<string name="vibrator_warning">Waarden hoger dan %1$d worden niet aangeraden</string>
|
||||
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
|
@ -34,11 +34,6 @@
|
||||
<string name="accelerometer_dialog_head">Skalibrowano</string>
|
||||
<string name="accelerometer_dialog_message">Akcelerometr został poprawnie skalibrowany.</string>
|
||||
|
||||
<string name="category_haptic_title">Dotyk</string>
|
||||
<string name="vibrator_subcat_title">Wibracje</string>
|
||||
<string name="vibrator_intensity_title_head">Intensywność wibracji</string>
|
||||
<string name="vibrator_intensity_summary_head">Ustaw intensywność wibracji</string>
|
||||
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Aktywuj HSDPA/HSUPA</string>
|
||||
|
@ -21,10 +21,11 @@
|
||||
<string name="touchkey_timeout_title_head">Tempo limite da luz de fundo</string>
|
||||
<string name="touchkey_timeout_summary_head">Quanto tempo a luz de fundo irá ficar acesa depois do botão ser pressionado</string>
|
||||
<string name="category_sensors_title">Sensores</string>
|
||||
<string name="category_haptic_title">Resposta Tátil</string>
|
||||
<string name="vibrator_subcat_title">Vibração</string>
|
||||
<string name="vibrator_intensity_title_head">Intensidade da Vibração</string>
|
||||
<string name="vibrator_intensity_summary_head">Define a intensidade da vibração</string>
|
||||
<string name="category_haptic_title">Resposta tátil</string>
|
||||
<string name="vibrator_title">Vibração</string>
|
||||
<string name="vibrator_tuning_title">Intensidade da vibração</string>
|
||||
<string name="vibrator_tuning_summary_head">Ajusar a intensidade da resposta por vibração</string>
|
||||
<string name="vibrator_warning">Valores maiores que %1$d não são recomendados</string>
|
||||
<string name="category_radio_title">Rádio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">Ativa HSDPA/HSUPA</string>
|
||||
@ -40,4 +41,4 @@
|
||||
<string name="dockaudio_subcat_title">Áudio</string>
|
||||
<string name="use_dock_audio_title_head">Usar áudio USB do dock</string>
|
||||
<string name="use_dock_audio_summary_head">Usar a saída de áudio passiva no dock</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -34,10 +34,14 @@
|
||||
<string name="accelerometer_dialog_head">Калибровка выполнена</string>
|
||||
<string name="accelerometer_dialog_message">Датчик успешно откалиброван</string>
|
||||
|
||||
<!-- Haptic Preference -->
|
||||
<string name="category_haptic_title">Отклик</string>
|
||||
<string name="vibrator_subcat_title">Вибрация</string>
|
||||
<string name="vibrator_intensity_title_head">Интенсивность вибрации</string>
|
||||
<string name="vibrator_intensity_summary_head">Установка интенсивности вибрации</string>
|
||||
|
||||
<!-- VibratorTuning -->
|
||||
<string name="vibrator_title">Вибрация</string>
|
||||
<string name="vibrator_tuning_title">Интенсивность вибрации</string>
|
||||
<string name="vibrator_tuning_summary_head">Установка интенсивности вибрации</string>
|
||||
<string name="vibrator_warning">Не рекомендуется установка значения выше %1$d</string>
|
||||
|
||||
<string name="category_radio_title">Модем</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
|
@ -49,11 +49,6 @@
|
||||
<string name="accelerometer_dialog_head">校准完成</string>
|
||||
<string name="accelerometer_dialog_message">感应器已被成功的校准。</string>
|
||||
|
||||
<string name="category_haptic_title">振动</string>
|
||||
<string name="vibrator_subcat_title">振动器</string>
|
||||
<string name="vibrator_intensity_title_head">振动器强度</string>
|
||||
<string name="vibrator_intensity_summary_head">设置振动器强度</string>
|
||||
|
||||
<string name="category_radio_title">无线电</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
<string name="hspa_summary_head">启用 HSDPA/HSUPA</string>
|
||||
|
@ -86,22 +86,6 @@
|
||||
<item>100</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="vibrator_intensity_entries">
|
||||
<item>0%</item>
|
||||
<item>25%</item>
|
||||
<item>50% (Default)</item>
|
||||
<item>75%</item>
|
||||
<item>100%</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="vibrator_intensity_entries_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>25</item>
|
||||
<item>50</item>
|
||||
<item>75</item>
|
||||
<item>100</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="hspa_entries">
|
||||
<item>UMTS Only</item>
|
||||
<item>HSDPA Only</item>
|
||||
@ -115,23 +99,23 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="touchkey_timeout_entries">
|
||||
<item>Never</item>
|
||||
<item>1 second</item>
|
||||
<item>2 seconds</item>
|
||||
<item>3 seconds (Default)</item>
|
||||
<item>4 seconds</item>
|
||||
<item>5 seconds</item>
|
||||
<item>6 seconds</item>
|
||||
<item>Never</item>
|
||||
<item>1 second</item>
|
||||
<item>2 seconds</item>
|
||||
<item>3 seconds (Default)</item>
|
||||
<item>4 seconds</item>
|
||||
<item>5 seconds</item>
|
||||
<item>6 seconds</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="touchkey_timeout_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>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
29
DeviceSettings/res/values/config.xml
Normal file
29
DeviceSettings/res/values/config.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?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">
|
||||
|
||||
<!-- Vibrator Tuning -->
|
||||
<bool name="has_vibrator_tuning">true</bool>
|
||||
<string name="vibrator_sysfs_file">"/sys/vibrator/pwm_val"</string>
|
||||
<string name="intensity_max_value">100</string>
|
||||
<string name="intensity_warning_threshold">75</string>
|
||||
<string name="intensity_default_value">50</string>
|
||||
<string name="intensity_min_value">0</string>
|
||||
|
||||
</resources>
|
@ -2,6 +2,8 @@
|
||||
<resources>
|
||||
<string name="app_name">Advanced settings</string>
|
||||
|
||||
<string name="defaults_button">Reset to default</string>
|
||||
|
||||
<string name="category_screen_title">Screen</string>
|
||||
<string name="screen_colors_title">Colors</string>
|
||||
<string name="mdnie_scenario_title_head">Scenario</string>
|
||||
@ -34,10 +36,14 @@
|
||||
<string name="accelerometer_dialog_head">Calibration done</string>
|
||||
<string name="accelerometer_dialog_message">The sensor has been successfully calibrated.</string>
|
||||
|
||||
<!-- Haptic Preference -->
|
||||
<string name="category_haptic_title">Haptic</string>
|
||||
<string name="vibrator_subcat_title">Vibrator</string>
|
||||
<string name="vibrator_intensity_title_head">Vibrator Intensity</string>
|
||||
<string name="vibrator_intensity_summary_head">Set vibrator intensity</string>
|
||||
|
||||
<!-- VibratorTuning -->
|
||||
<string name="vibrator_title">Vibrator</string>
|
||||
<string name="vibrator_tuning_title">Vibration strength</string>
|
||||
<string name="vibrator_tuning_summary_head">Adjust the strength of the vibration feedback</string>
|
||||
<string name="vibrator_warning">Values higher than %1$d are not recommended</string>
|
||||
|
||||
<string name="category_radio_title">Radio</string>
|
||||
<string name="hspa_title_head">HSPA</string>
|
||||
|
@ -1,13 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory
|
||||
android:title="@string/vibrator_subcat_title">
|
||||
<com.cyanogenmod.settings.device.VibratorIntensity
|
||||
android:key="vibrator_intensity"
|
||||
android:title="@string/vibrator_intensity_title_head"
|
||||
android:summary="@string/vibrator_intensity_summary_head"
|
||||
android:entries="@array/vibrator_intensity_entries"
|
||||
android:entryValues="@array/vibrator_intensity_entries_values"
|
||||
android:defaultValue="50" />
|
||||
android:title="@string/vibrator_title">
|
||||
<com.cyanogenmod.settings.device.VibratorTuningPreference
|
||||
android:key="vibrator_tuning"
|
||||
android:title="@string/vibrator_tuning_title"
|
||||
android:dialogTitle="@string/vibrator_tuning_title" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@ -46,7 +46,6 @@ public class DeviceSettings extends FragmentActivity {
|
||||
public static final String KEY_TOUCHSCREEN_SENSITIVITY = "touchscreen_sensitivity";
|
||||
public static final String KEY_TOUCHKEY_LIGHT = "touchkey_light";
|
||||
public static final String KEY_TOUCHKEY_TIMEOUT = "touchkey_timeout";
|
||||
public static final String KEY_VIBRATOR_INTENSITY = "vibrator_intensity";
|
||||
public static final String KEY_USE_DOCK_AUDIO = "dock_audio";
|
||||
|
||||
ViewPager mViewPager;
|
||||
|
@ -17,9 +17,9 @@
|
||||
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;
|
||||
@ -32,27 +32,33 @@ import com.cyanogenmod.settings.device.R;
|
||||
|
||||
public class HapticFragmentActivity extends PreferenceFragment {
|
||||
|
||||
private static final String PREF_ENABLED = "1";
|
||||
private static final String TAG = "DeviceSettings_Haptic";
|
||||
public static final String KEY_VIBRATOR_TUNING = "vibrator_tuning";
|
||||
|
||||
private static boolean sVibratorTuning;
|
||||
private VibratorTuningPreference mVibratorTuning;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Resources res = getResources();
|
||||
sVibratorTuning = res.getBoolean(R.bool.has_vibrator_tuning);
|
||||
|
||||
addPreferencesFromResource(R.xml.haptic_preferences);
|
||||
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
|
||||
if (sVibratorTuning) {
|
||||
String vibratorFilePath = res.getString(R.string.vibrator_sysfs_file);
|
||||
mVibratorTuning = (VibratorTuningPreference) findPreference(KEY_VIBRATOR_TUNING);
|
||||
mVibratorTuning.setEnabled(VibratorTuningPreference.isSupported(vibratorFilePath));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
|
||||
String boxValue;
|
||||
String key = preference.getKey();
|
||||
|
||||
Log.w(TAG, "key: " + key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,6 @@ public class Startup extends BroadcastReceiver {
|
||||
ScreenFragmentActivity.restore(context);
|
||||
SensorsFragmentActivity.restore(context);
|
||||
TouchkeyTimeout.restore(context);
|
||||
VibratorIntensity.restore(context);
|
||||
VibratorTuningPreference.restore(context);
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,11 @@ 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;
|
||||
@ -33,6 +35,25 @@ public class Utils {
|
||||
private static final String TAG_READ = "DeviceSettings_Utils_Read";
|
||||
private static final String TAG_WRITE = "DeviceSettings_Utils_Write";
|
||||
|
||||
// Read value from sysfs interface
|
||||
public static String readOneLine(String sFile) {
|
||||
BufferedReader brBuffer;
|
||||
String sLine = null;
|
||||
|
||||
try {
|
||||
brBuffer = new BufferedReader(new FileReader(sFile), 512);
|
||||
try {
|
||||
sLine = brBuffer.readLine();
|
||||
} finally {
|
||||
Log.w(TAG_READ, "file " + sFile + ": " + sLine);
|
||||
brBuffer.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG_READ, "IO Exception when reading /sys/ file", e);
|
||||
}
|
||||
return sLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string value to the specified file.
|
||||
*
|
||||
@ -128,7 +149,6 @@ public class Utils {
|
||||
return new File(filename).exists();
|
||||
}
|
||||
|
||||
|
||||
public static void showDialog(Context ctx, String title, String message) {
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
|
||||
alertDialog.setTitle(title);
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 VibratorIntensity extends ListPreference implements OnPreferenceChangeListener {
|
||||
|
||||
public VibratorIntensity(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
private static final String FILE = "/sys/vibrator/pwm_val";
|
||||
|
||||
public static boolean isSupported() {
|
||||
return Utils.fileExists(FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore vibrator intensity setting from SharedPreferences. (Write to kernel.)
|
||||
* @param context The context to read the SharedPreferences from
|
||||
*/
|
||||
public static void restore(Context context) {
|
||||
if (!isSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Utils.writeValue(FILE, sharedPrefs.getString(DeviceSettings.KEY_VIBRATOR_INTENSITY, "50"));
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Utils.writeValue(FILE, (String) newValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.cyanogenmod.settings.device;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LightingColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.DialogPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Button;
|
||||
|
||||
import java.lang.Math;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* Special preference type that allows configuration of vibrator intensity settings on Sony
|
||||
* Devices
|
||||
*/
|
||||
public class VibratorTuningPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
|
||||
private static final String TAG = "DeviceSettings_Vibrator";
|
||||
|
||||
private static String FILE_PATH = null;
|
||||
private static int MAX_VALUE;
|
||||
private static int WARNING_THRESHOLD;
|
||||
private static int DEFAULT_VALUE;
|
||||
private static int MIN_VALUE;
|
||||
|
||||
private SeekBar mSeekBar;
|
||||
private TextView mValue;
|
||||
private TextView mWarning;
|
||||
|
||||
private String mOriginalValue;
|
||||
private int mOriginalPercent;
|
||||
|
||||
private Drawable mProgressDrawable;
|
||||
private Drawable mProgressThumb;
|
||||
private LightingColorFilter mRedFilter;
|
||||
|
||||
public VibratorTuningPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
FILE_PATH = context.getResources().getString(R.string.vibrator_sysfs_file);
|
||||
MAX_VALUE = Integer.valueOf(context.getResources().getString(R.string.intensity_max_value));
|
||||
WARNING_THRESHOLD = Integer.valueOf(context.getResources().getString(R.string.intensity_warning_threshold));
|
||||
DEFAULT_VALUE = Integer.valueOf(context.getResources().getString(R.string.intensity_default_value));
|
||||
MIN_VALUE = Integer.valueOf(context.getResources().getString(R.string.intensity_min_value));
|
||||
|
||||
setDialogLayoutResource(R.layout.preference_dialog_vibrator_tuning);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
builder.setNeutralButton(R.string.defaults_button, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
|
||||
mSeekBar = (SeekBar) view.findViewById(R.id.vibrator_seekbar);
|
||||
mValue = (TextView) view.findViewById(R.id.vibrator_value);
|
||||
mWarning = (TextView) view.findViewById(R.id.textWarn);
|
||||
|
||||
String strWarnMsg = getContext().getResources().getString(R.string.vibrator_warning, strengthToPercent(WARNING_THRESHOLD));
|
||||
mWarning.setText(strWarnMsg);
|
||||
|
||||
Drawable progressDrawable = mSeekBar.getProgressDrawable();
|
||||
if (progressDrawable instanceof LayerDrawable) {
|
||||
LayerDrawable ld = (LayerDrawable) progressDrawable;
|
||||
mProgressDrawable = ld.findDrawableByLayerId(android.R.id.progress);
|
||||
}
|
||||
mProgressThumb = mSeekBar.getThumb();
|
||||
mRedFilter = new LightingColorFilter(Color.BLACK,
|
||||
getContext().getResources().getColor(android.R.color.holo_red_light));
|
||||
|
||||
mOriginalValue = Utils.readOneLine(FILE_PATH);
|
||||
mOriginalPercent = strengthToPercent(Integer.parseInt(mOriginalValue));
|
||||
|
||||
mSeekBar.setOnSeekBarChangeListener(this);
|
||||
mSeekBar.setProgress(Integer.valueOf(mOriginalPercent));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showDialog(Bundle state) {
|
||||
super.showDialog(state);
|
||||
|
||||
// can't use onPrepareDialogBuilder for this as we want the dialog
|
||||
// to be kept open on click
|
||||
AlertDialog d = (AlertDialog) getDialog();
|
||||
Button defaultsButton = d.getButton(DialogInterface.BUTTON_NEUTRAL);
|
||||
defaultsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSeekBar.setProgress(strengthToPercent(DEFAULT_VALUE));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
Editor editor = getEditor();
|
||||
|
||||
int strength = percentToStrength(mSeekBar.getProgress());
|
||||
editor.putString(FILE_PATH, String.valueOf(strength));
|
||||
editor.commit();
|
||||
} else {
|
||||
Utils.writeValue(FILE_PATH, String.valueOf(mOriginalPercent));
|
||||
}
|
||||
}
|
||||
|
||||
public static void restore(Context context) {
|
||||
FILE_PATH = context.getResources().getString(R.string.vibrator_sysfs_file);
|
||||
|
||||
if (!isSupported(FILE_PATH)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final String value = prefs.getString(FILE_PATH, null);
|
||||
|
||||
if (value != null) {
|
||||
Log.d(TAG, "Restoring vibration setting: " + value);
|
||||
Utils.writeValue(FILE_PATH, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSupported(String filePath) {
|
||||
return Utils.fileExists(filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
boolean shouldWarn = progress >= strengthToPercent(WARNING_THRESHOLD);
|
||||
if (mProgressDrawable != null) {
|
||||
mProgressDrawable.setColorFilter(shouldWarn ? mRedFilter : null);
|
||||
}
|
||||
if (mProgressThumb != null) {
|
||||
mProgressThumb.setColorFilter(shouldWarn ? mRedFilter : null);
|
||||
}
|
||||
Utils.writeValue(FILE_PATH, String.valueOf(percentToStrength(progress)));
|
||||
mValue.setText(String.format("%d%%", progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
Vibrator vib = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vib.vibrate(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert vibrator strength to percent
|
||||
*/
|
||||
public static int strengthToPercent(int strength) {
|
||||
double maxValue = MAX_VALUE;
|
||||
double minValue = MIN_VALUE;
|
||||
|
||||
double percent = (strength - minValue) * (100 / (maxValue - minValue));
|
||||
|
||||
if (percent > 100)
|
||||
percent = 100;
|
||||
else if (percent < 0)
|
||||
percent = 0;
|
||||
|
||||
return (int) percent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert percent to vibrator strength
|
||||
*/
|
||||
public static int percentToStrength(int percent) {
|
||||
int strength = Math.round((((MAX_VALUE - MIN_VALUE) * percent) / 100) + MIN_VALUE);
|
||||
|
||||
if (strength > MAX_VALUE)
|
||||
strength = MAX_VALUE;
|
||||
else if (strength < MIN_VALUE)
|
||||
strength = MIN_VALUE;
|
||||
|
||||
return strength;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user