summaryrefslogtreecommitdiffstats
path: root/core/java/android/view
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-04-13 17:34:20 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-13 17:34:20 -0700
commit90aba7caac78b407347b930cfb6ff7d6658ac90a (patch)
treea18918aeb2785b4ca801ee5319ed27973fdde49f /core/java/android/view
parent21e09bc4cbfd7d8f0e2f7ab5211a50339b1b8d20 (diff)
parenta47425a13c19f95057df78b8bb65bb25657e8753 (diff)
downloadframeworks_base-90aba7caac78b407347b930cfb6ff7d6658ac90a.zip
frameworks_base-90aba7caac78b407347b930cfb6ff7d6658ac90a.tar.gz
frameworks_base-90aba7caac78b407347b930cfb6ff7d6658ac90a.tar.bz2
Merge "Add support for input devices that have vibrators."
Diffstat (limited to 'core/java/android/view')
-rwxr-xr-xcore/java/android/view/InputDevice.java38
1 files changed, 37 insertions, 1 deletions
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java
index 4ebb679..4848a7a 100755
--- a/core/java/android/view/InputDevice.java
+++ b/core/java/android/view/InputDevice.java
@@ -16,9 +16,12 @@
package android.view;
+import android.content.Context;
import android.hardware.input.InputManager;
import android.os.Parcel;
import android.os.Parcelable;
+import android.os.Vibrator;
+import android.os.NullVibrator;
import java.util.ArrayList;
import java.util.List;
@@ -46,8 +49,11 @@ public final class InputDevice implements Parcelable {
private final int mSources;
private final int mKeyboardType;
private final KeyCharacterMap mKeyCharacterMap;
+ private final boolean mHasVibrator;
private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();
+ private Vibrator mVibrator; // guarded by mMotionRanges during initialization
+
/**
* A mask for input source classes.
*
@@ -304,7 +310,7 @@ public final class InputDevice implements Parcelable {
// Called by native code.
private InputDevice(int id, int generation, String name, String descriptor, int sources,
- int keyboardType, KeyCharacterMap keyCharacterMap) {
+ int keyboardType, KeyCharacterMap keyCharacterMap, boolean hasVibrator) {
mId = id;
mGeneration = generation;
mName = name;
@@ -312,6 +318,7 @@ public final class InputDevice implements Parcelable {
mSources = sources;
mKeyboardType = keyboardType;
mKeyCharacterMap = keyCharacterMap;
+ mHasVibrator = hasVibrator;
}
private InputDevice(Parcel in) {
@@ -322,6 +329,7 @@ public final class InputDevice implements Parcelable {
mSources = in.readInt();
mKeyboardType = in.readInt();
mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
+ mHasVibrator = in.readInt() != 0;
for (;;) {
int axis = in.readInt();
@@ -522,6 +530,31 @@ public final class InputDevice implements Parcelable {
}
/**
+ * Gets the vibrator service associated with the device, if there is one.
+ * Even if the device does not have a vibrator, the result is never null.
+ * Use {@link Vibrator#hasVibrator} to determine whether a vibrator is
+ * present.
+ *
+ * Note that the vibrator associated with the device may be different from
+ * the system vibrator. To obtain an instance of the system vibrator instead, call
+ * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
+ *
+ * @return The vibrator service associated with the device, never null.
+ */
+ public Vibrator getVibrator() {
+ synchronized (mMotionRanges) {
+ if (mVibrator == null) {
+ if (mHasVibrator) {
+ mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId);
+ } else {
+ mVibrator = NullVibrator.getInstance();
+ }
+ }
+ return mVibrator;
+ }
+ }
+
+ /**
* Provides information about the range of values for a particular {@link MotionEvent} axis.
*
* @see InputDevice#getMotionRange(int)
@@ -617,6 +650,7 @@ public final class InputDevice implements Parcelable {
out.writeInt(mSources);
out.writeInt(mKeyboardType);
mKeyCharacterMap.writeToParcel(out, flags);
+ out.writeInt(mHasVibrator ? 1 : 0);
final int numRanges = mMotionRanges.size();
for (int i = 0; i < numRanges; i++) {
@@ -657,6 +691,8 @@ public final class InputDevice implements Parcelable {
}
description.append("\n");
+ description.append(" Has Vibrator: ").append(mHasVibrator).append("\n");
+
description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");