Settings: Add vibration patterns from OOS [3/3]

a rewrite of: c4560cafae

Change-Id: If5e776b622d603ed9c4022e23e6904b5c996e195
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
Ido Ben-Hur
2020-06-05 17:15:19 +03:00
committed by Joey
parent b893ae175e
commit 9b3c789826
5 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2020 Yet Another AOSP 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.notification;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
/**
* This class allows choosing a vibration pattern while ringing
*/
public class VibrationPatternPreferenceController extends AbstractPreferenceController
implements Preference.OnPreferenceChangeListener {
private static final String KEY_VIB_PATTERN = "vibration_pattern";
private ListPreference mVibPattern;
public VibrationPatternPreferenceController(Context context) {
super(context);
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY_VIB_PATTERN;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mVibPattern = (ListPreference) screen.findPreference(KEY_VIB_PATTERN);
int vibPattern = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.RINGTONE_VIBRATION_PATTERN, 0);
mVibPattern.setValueIndex(vibPattern);
mVibPattern.setSummary(mVibPattern.getEntries()[vibPattern]);
mVibPattern.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int vibPattern = Integer.valueOf((String) newValue);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.RINGTONE_VIBRATION_PATTERN, vibPattern);
mVibPattern.setSummary(mVibPattern.getEntries()[vibPattern]);
return true;
}
}