Settings: Allow choosing a custom vibration pattern [3/3]
Change-Id: I574da771ae90321f65d8ffddecd59db430105bb2 Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -292,4 +292,6 @@
|
|||||||
<string name="pattern_da_da_dzzz" translatable="false">da-da-dzzz</string>
|
<string name="pattern_da_da_dzzz" translatable="false">da-da-dzzz</string>
|
||||||
<string name="pattern_da_dzzz_da" translatable="false">da-dzzz-da</string>
|
<string name="pattern_da_dzzz_da" translatable="false">da-dzzz-da</string>
|
||||||
<string name="pattern_custom">Custom</string>
|
<string name="pattern_custom">Custom</string>
|
||||||
|
<string name="custom_vibration_pattern_title">Custom pattern</string>
|
||||||
|
<string name="custom_vibration_pattern_summary">Set a custom vibration pattern</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -181,11 +181,50 @@
|
|||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="vibration_pattern"
|
android:key="vibration_pattern"
|
||||||
android:title="@string/vibration_pattern_title"
|
android:title="@string/vibration_pattern_title"
|
||||||
android:order="-125"
|
android:order="-85"
|
||||||
android:entries="@array/vibration_pattern_entries"
|
android:entries="@array/vibration_pattern_entries"
|
||||||
android:entryValues="@array/vibration_pattern_values"
|
android:entryValues="@array/vibration_pattern_values"
|
||||||
android:dependency="vibrate_for_calls"/>
|
android:dependency="vibrate_for_calls"/>
|
||||||
|
|
||||||
|
<!-- Custom ringtone vibration pattern category -->
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="custom_vibration_pattern"
|
||||||
|
android:title="@string/custom_vibration_pattern_title"
|
||||||
|
android:order="-84"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<!-- Custom ringtone vibration pattern 1 -->
|
||||||
|
<org.evolution.settings.preferences.CustomSeekBarPreference
|
||||||
|
android:key="custom_vibration_pattern1"
|
||||||
|
android:order="-83"
|
||||||
|
android:max="1000"
|
||||||
|
settings:min="0"
|
||||||
|
settings:interval="100"
|
||||||
|
settings:units="ms"
|
||||||
|
android:dependency="vibrate_for_calls"/>
|
||||||
|
|
||||||
|
<!-- Custom ringtone vibration pattern 2 -->
|
||||||
|
<org.evolution.settings.preferences.CustomSeekBarPreference
|
||||||
|
android:key="custom_vibration_pattern2"
|
||||||
|
android:order="-82"
|
||||||
|
android:max="1000"
|
||||||
|
settings:min="0"
|
||||||
|
settings:interval="100"
|
||||||
|
settings:units="ms"
|
||||||
|
android:dependency="vibrate_for_calls"/>
|
||||||
|
|
||||||
|
<!-- Custom ringtone vibration pattern 3 -->
|
||||||
|
<org.evolution.settings.preferences.CustomSeekBarPreference
|
||||||
|
android:key="custom_vibration_pattern3"
|
||||||
|
android:order="-81"
|
||||||
|
android:max="1000"
|
||||||
|
settings:min="0"
|
||||||
|
settings:interval="100"
|
||||||
|
settings:units="ms"
|
||||||
|
android:dependency="vibrate_for_calls"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settingslib.PrimarySwitchPreference
|
<com.android.settingslib.PrimarySwitchPreference
|
||||||
android:key="gesture_prevent_ringing_sound"
|
android:key="gesture_prevent_ringing_sound"
|
||||||
android:title="@string/gesture_prevent_ringing_sound_title"
|
android:title="@string/gesture_prevent_ringing_sound_title"
|
||||||
|
|||||||
@@ -16,16 +16,20 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
import org.evolution.settings.preferences.CustomSeekBarPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class allows choosing a vibration pattern while ringing
|
* This class allows choosing a vibration pattern while ringing
|
||||||
*/
|
*/
|
||||||
@@ -33,8 +37,16 @@ public class VibrationPatternPreferenceController extends AbstractPreferenceCont
|
|||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String KEY_VIB_PATTERN = "vibration_pattern";
|
private static final String KEY_VIB_PATTERN = "vibration_pattern";
|
||||||
|
private static final String KEY_CUSTOM_VIB_CATEGORY = "custom_vibration_pattern";
|
||||||
|
private static final String KEY_CUSTOM_VIB1 = "custom_vibration_pattern1";
|
||||||
|
private static final String KEY_CUSTOM_VIB2 = "custom_vibration_pattern2";
|
||||||
|
private static final String KEY_CUSTOM_VIB3 = "custom_vibration_pattern3";
|
||||||
|
|
||||||
private ListPreference mVibPattern;
|
private ListPreference mVibPattern;
|
||||||
|
private PreferenceCategory mCustomVibCategory;
|
||||||
|
private CustomSeekBarPreference mCustomVib1;
|
||||||
|
private CustomSeekBarPreference mCustomVib2;
|
||||||
|
private CustomSeekBarPreference mCustomVib3;
|
||||||
|
|
||||||
public VibrationPatternPreferenceController(Context context) {
|
public VibrationPatternPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -59,14 +71,70 @@ public class VibrationPatternPreferenceController extends AbstractPreferenceCont
|
|||||||
mVibPattern.setValueIndex(vibPattern);
|
mVibPattern.setValueIndex(vibPattern);
|
||||||
mVibPattern.setSummary(mVibPattern.getEntries()[vibPattern]);
|
mVibPattern.setSummary(mVibPattern.getEntries()[vibPattern]);
|
||||||
mVibPattern.setOnPreferenceChangeListener(this);
|
mVibPattern.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mCustomVibCategory = (PreferenceCategory) screen.findPreference(KEY_CUSTOM_VIB_CATEGORY);
|
||||||
|
mCustomVib1 = (CustomSeekBarPreference) screen.findPreference(KEY_CUSTOM_VIB1);
|
||||||
|
mCustomVib2 = (CustomSeekBarPreference) screen.findPreference(KEY_CUSTOM_VIB2);
|
||||||
|
mCustomVib3 = (CustomSeekBarPreference) screen.findPreference(KEY_CUSTOM_VIB3);
|
||||||
|
updateCustomVibVisibility(vibPattern == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
int vibPattern = Integer.valueOf((String) newValue);
|
if (preference == mVibPattern) {
|
||||||
Settings.System.putInt(mContext.getContentResolver(),
|
int vibPattern = Integer.valueOf((String) newValue);
|
||||||
Settings.System.RINGTONE_VIBRATION_PATTERN, vibPattern);
|
Settings.System.putInt(mContext.getContentResolver(),
|
||||||
mVibPattern.setSummary(mVibPattern.getEntries()[vibPattern]);
|
Settings.System.RINGTONE_VIBRATION_PATTERN, vibPattern);
|
||||||
return true;
|
mVibPattern.setSummary(mVibPattern.getEntries()[vibPattern]);
|
||||||
|
updateCustomVibVisibility(vibPattern == 5);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mCustomVib1) {
|
||||||
|
updateCustomVib(0, (Integer) newValue);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mCustomVib2) {
|
||||||
|
updateCustomVib(1, (Integer) newValue);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mCustomVib3) {
|
||||||
|
updateCustomVib(2, (Integer) newValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCustomVibVisibility(boolean show) {
|
||||||
|
mCustomVibCategory.setVisible(show);
|
||||||
|
mCustomVib1.setVisible(show);
|
||||||
|
mCustomVib2.setVisible(show);
|
||||||
|
mCustomVib3.setVisible(show);
|
||||||
|
if (show) updateCustomVibPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCustomVibPreferences() {
|
||||||
|
String value = Settings.System.getString(mContext.getContentResolver(),
|
||||||
|
Settings.System.CUSTOM_RINGTONE_VIBRATION_PATTERN);
|
||||||
|
if (value != null) {
|
||||||
|
String[] customPattern = value.split(",", 3);
|
||||||
|
mCustomVib1.setValue(Integer.parseInt(customPattern[0]));
|
||||||
|
mCustomVib2.setValue(Integer.parseInt(customPattern[1]));
|
||||||
|
mCustomVib3.setValue(Integer.parseInt(customPattern[2]));
|
||||||
|
} else { // set default
|
||||||
|
mCustomVib1.setValue(0);
|
||||||
|
mCustomVib2.setValue(800);
|
||||||
|
mCustomVib3.setValue(800);
|
||||||
|
Settings.System.putString(mContext.getContentResolver(),
|
||||||
|
Settings.System.CUSTOM_RINGTONE_VIBRATION_PATTERN, "0,800,800");
|
||||||
|
}
|
||||||
|
mCustomVib1.setOnPreferenceChangeListener(this);
|
||||||
|
mCustomVib2.setOnPreferenceChangeListener(this);
|
||||||
|
mCustomVib3.setOnPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCustomVib(int index, int value) {
|
||||||
|
String[] customPattern = Settings.System.getString(mContext.getContentResolver(),
|
||||||
|
Settings.System.CUSTOM_RINGTONE_VIBRATION_PATTERN).split(",", 3);
|
||||||
|
customPattern[index] = String.valueOf(value);
|
||||||
|
Settings.System.putString(mContext.getContentResolver(),
|
||||||
|
Settings.System.CUSTOM_RINGTONE_VIBRATION_PATTERN, String.join(
|
||||||
|
",", customPattern[0], customPattern[1], customPattern[2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user