summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/hardware
diff options
context:
space:
mode:
authorScott Mertz <scott@cyngn.com>2015-02-09 12:55:55 -0800
committerAdnan Begovic <adnan@cyngn.com>2015-10-29 17:36:31 -0700
commitba4c43f77699721dff7c2536ee61c0f8c18ea446 (patch)
treedbdb89b6dbf9d21f58574956256f7a3048c18460 /src/com/android/settings/hardware
parent306c2881c045ccf0e1afc4494fe9e50781f88818 (diff)
downloadpackages_apps_Settings-ba4c43f77699721dff7c2536ee61c0f8c18ea446.zip
packages_apps_Settings-ba4c43f77699721dff7c2536ee61c0f8c18ea446.tar.gz
packages_apps_Settings-ba4c43f77699721dff7c2536ee61c0f8c18ea446.tar.bz2
Settings: Change to CmHardwareService
Change-Id: Iab392aefa9476a2e956a697210f3f7e6426ff815
Diffstat (limited to 'src/com/android/settings/hardware')
-rw-r--r--src/com/android/settings/hardware/VibratorIntensity.java68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/com/android/settings/hardware/VibratorIntensity.java b/src/com/android/settings/hardware/VibratorIntensity.java
index 88f1298..6c00cde 100644
--- a/src/com/android/settings/hardware/VibratorIntensity.java
+++ b/src/com/android/settings/hardware/VibratorIntensity.java
@@ -25,6 +25,7 @@ import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
+import android.hardware.CmHardwareManager;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.DialogPreference;
@@ -37,7 +38,6 @@ import android.widget.TextView;
import android.widget.Button;
import com.android.settings.R;
-import org.cyanogenmod.hardware.VibratorHW;
public class VibratorIntensity extends DialogPreference implements
SeekBar.OnSeekBarChangeListener {
@@ -46,6 +46,11 @@ public class VibratorIntensity extends DialogPreference implements
private TextView mValue;
private TextView mWarning;
private int mOriginalValue;
+ private int mMinValue;
+ private int mMaxValue;
+ private int mDefaultValue;
+ private int mWarningValue;
+ private CmHardwareManager mCmHardwareManager;
private Drawable mProgressDrawable;
private Drawable mProgressThumb;
@@ -54,7 +59,9 @@ public class VibratorIntensity extends DialogPreference implements
public VibratorIntensity(Context context, AttributeSet attrs) {
super(context, attrs);
- if (!isSupported()) {
+ mCmHardwareManager = (CmHardwareManager) context.getSystemService(Context.CMHW_SERVICE);
+
+ if (!mCmHardwareManager.isSupported(CmHardwareManager.FEATURE_VIBRATOR)) {
return;
}
@@ -79,10 +86,16 @@ public class VibratorIntensity extends DialogPreference implements
mValue = (TextView) view.findViewById(R.id.value);
mWarning = (TextView) view.findViewById(R.id.warning_text);
- int warningThreshold = VibratorHW.getWarningThreshold();
- if (warningThreshold > 0) {
+ // Read the current value in case user wants to dismiss his changes
+ mOriginalValue = mCmHardwareManager.getVibratorIntensity();
+ mWarningValue = mCmHardwareManager.getVibratorWarningIntensity();
+ mMinValue = mCmHardwareManager.getVibratorMinIntensity();
+ mMaxValue = mCmHardwareManager.getVibratorMaxIntensity();
+ mDefaultValue = mCmHardwareManager.getVibratorDefaultIntensity();
+ if (mWarningValue > 0) {
String message = getContext().getResources().getString(
- R.string.vibrator_warning, intensityToPercent(warningThreshold));
+ R.string.vibrator_warning, intensityToPercent(mMinValue, mMaxValue,
+ mWarningValue));
mWarning.setText(message);
} else if (mWarning != null) {
mWarning.setVisibility(View.GONE);
@@ -97,12 +110,9 @@ public class VibratorIntensity extends DialogPreference implements
mRedFilter = new LightingColorFilter(Color.BLACK,
getContext().getResources().getColor(android.R.color.holo_red_light));
- // Read the current value in case user wants to dismiss his changes
- mOriginalValue = VibratorHW.getCurIntensity();
-
// Restore percent value from SharedPreferences object
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
- int defaultValue = intensityToPercent(VibratorHW.getDefaultIntensity());
+ int defaultValue = intensityToPercent(mMinValue, mMaxValue, mDefaultValue);
int percent = prefs.getInt(PREF_NAME, defaultValue);
mSeekBar.setOnSeekBarChangeListener(this);
@@ -120,7 +130,7 @@ public class VibratorIntensity extends DialogPreference implements
defaultsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- mSeekBar.setProgress(intensityToPercent(VibratorHW.getDefaultIntensity()));
+ mSeekBar.setProgress(intensityToPercent(mMinValue, mMaxValue, mDefaultValue));
}
});
}
@@ -134,35 +144,32 @@ public class VibratorIntensity extends DialogPreference implements
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putInt(PREF_NAME, mSeekBar.getProgress()).commit();
} else {
- VibratorHW.setIntensity(mOriginalValue);
- }
- }
-
- public static boolean isSupported() {
- try {
- return VibratorHW.isSupported();
- } catch (NoClassDefFoundError e) {
- // Hardware abstraction framework isn't installed
- return false;
+ mCmHardwareManager.setVibratorIntensity(mCmHardwareManager.getVibratorIntensity());
}
}
public static void restore(Context context) {
- if (!isSupported()) {
+ CmHardwareManager cmHardwareManager =
+ (CmHardwareManager) context.getSystemService(Context.CMHW_SERVICE);
+ if (!cmHardwareManager.isSupported(CmHardwareManager.FEATURE_VIBRATOR)) {
return;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- int defaultValue = intensityToPercent(VibratorHW.getDefaultIntensity());
+ int vibrator = cmHardwareManager.getVibratorIntensity();
+ int min = cmHardwareManager.getVibratorMinIntensity();
+ int max = cmHardwareManager.getVibratorMaxIntensity();
+ int defaultValue = intensityToPercent(min, max,
+ cmHardwareManager.getVibratorDefaultIntensity());
int percent = prefs.getInt(PREF_NAME, defaultValue);
- VibratorHW.setIntensity(percentToIntensity(percent));
+ cmHardwareManager.setVibratorIntensity(percentToIntensity(min, max, percent));
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- int warningThreshold = VibratorHW.getWarningThreshold();
boolean shouldWarn =
- warningThreshold > 0 && progress >= intensityToPercent(warningThreshold);
+ mWarningValue > 0 && progress >= intensityToPercent(mMinValue, mMaxValue,
+ mWarningValue);
if (mProgressDrawable != null) {
mProgressDrawable.setColorFilter(shouldWarn ? mRedFilter : null);
@@ -171,7 +178,8 @@ public class VibratorIntensity extends DialogPreference implements
mProgressThumb.setColorFilter(shouldWarn ? mRedFilter : null);
}
- VibratorHW.setIntensity(percentToIntensity(progress));
+ mCmHardwareManager.setVibratorIntensity(percentToIntensity(mMinValue, mMaxValue,
+ progress));
mValue.setText(String.format("%d%%", progress));
}
@@ -186,9 +194,7 @@ public class VibratorIntensity extends DialogPreference implements
vib.vibrate(200);
}
- private static int intensityToPercent(int value) {
- double maxValue = VibratorHW.getMaxIntensity();
- double minValue = VibratorHW.getMinIntensity();
+ private static int intensityToPercent(double minValue, double maxValue, int value) {
double percent = (value - minValue) * (100 / (maxValue - minValue));
if (percent > 100) {
@@ -200,9 +206,7 @@ public class VibratorIntensity extends DialogPreference implements
return (int) percent;
}
- private static int percentToIntensity(int percent) {
- int maxValue = VibratorHW.getMaxIntensity();
- int minValue = VibratorHW.getMinIntensity();
+ private static int percentToIntensity(int minValue, int maxValue, int percent) {
int value = Math.round((((maxValue - minValue) * percent) / 100) + minValue);
if (value > maxValue) {