Vibrator.java revision c2346134bb519a54d50655cbef940fc3fdec60a9
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 with 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 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     *
47     * @param milliseconds The number of milliseconds to vibrate.
48     */
49    public abstract void vibrate(long milliseconds);
50
51    /**
52     * Vibrate with a given pattern.
53     *
54     * <p>
55     * Pass in an array of ints that are the durations for which to turn on or off
56     * the vibrator in milliseconds.  The first value indicates the number of milliseconds
57     * to wait before turning the vibrator on.  The next value indicates the number of milliseconds
58     * for which to keep the vibrator on before turning it off.  Subsequent values alternate
59     * between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
60     * </p><p>
61     * To cause the pattern to repeat, pass the index into the pattern array at which
62     * to start the repeat, or -1 to disable repeating.
63     * </p>
64     *
65     * @param pattern an array of longs of times for which to turn the vibrator on or off.
66     * @param repeat the index into pattern at which to repeat, or -1 if
67     *        you don't want to repeat.
68     */
69    public abstract void vibrate(long[] pattern, int repeat);
70
71    /**
72     * Turn the vibrator off.
73     */
74    public abstract void cancel();
75}
76