Vibrator.java revision 0f49c28e7a3667e680002beb8c557d8b5e3ad1d3
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.os;
18
19import android.content.Context;
20
21/**
22 * Class that operates the vibrator on the device.
23 * <p>
24 * If your process exits, any vibration you started will stop.
25 * </p>
26 *
27 * To obtain an instance of the system vibrator, call
28 * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as the argument.
29 */
30public abstract class Vibrator {
31    /**
32     * @hide to prevent subclassing from outside of the framework
33     */
34    public Vibrator() {
35    }
36
37    /**
38     * Check whether the hardware has a vibrator.
39     *
40     * @return True if the hardware has a vibrator, else false.
41     */
42    public abstract boolean hasVibrator();
43
44    /**
45     * Vibrate constantly for the specified period of time.
46     * <p>This method requires the caller to hold the permission
47     * {@link android.Manifest.permission#VIBRATE}.
48     *
49     * @param milliseconds The number of milliseconds to vibrate.
50     */
51    public abstract void vibrate(long milliseconds);
52
53    /**
54     * Vibrate with a given pattern.
55     *
56     * <p>
57     * Pass in an array of ints that are the durations for which to turn on or off
58     * the vibrator in milliseconds.  The first value indicates the number of milliseconds
59     * to wait before turning the vibrator on.  The next value indicates the number of milliseconds
60     * for which to keep the vibrator on before turning it off.  Subsequent values alternate
61     * between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
62     * </p><p>
63     * To cause the pattern to repeat, pass the index into the pattern array at which
64     * to start the repeat, or -1 to disable repeating.
65     * </p>
66     * <p>This method requires the caller to hold the permission
67     * {@link android.Manifest.permission#VIBRATE}.
68     *
69     * @param pattern an array of longs of times for which to turn the vibrator on or off.
70     * @param repeat the index into pattern at which to repeat, or -1 if
71     *        you don't want to repeat.
72     */
73    public abstract void vibrate(long[] pattern, int repeat);
74
75    /**
76     * @hide
77     * Like {@link #vibrate(long)}, but allowing the caller to specify that
78     * the vibration is owned by someone else.
79     */
80    public abstract void vibrate(int owningUid, String owningPackage, long milliseconds);
81
82    /**
83     * @hide
84     * Like {@link #vibrate(long[], int)}, but allowing the caller to specify that
85     * the vibration is owned by someone else.
86     */
87    public abstract void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat);
88
89    /**
90     * Turn the vibrator off.
91     * <p>This method requires the caller to hold the permission
92     * {@link android.Manifest.permission#VIBRATE}.
93     */
94    public abstract void cancel();
95}
96