2011-03-23 21:36:37 +00:00
|
|
|
/*
|
2012-03-30 09:47:24 +00:00
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
2011-03-23 21:36:37 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-03-30 09:47:24 +00:00
|
|
|
package com.android.inputmethod.latin;
|
2011-03-23 21:36:37 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Vibrator;
|
|
|
|
|
2012-03-30 09:47:24 +00:00
|
|
|
public class VibratorUtils {
|
|
|
|
private static final VibratorUtils sInstance = new VibratorUtils();
|
2011-03-23 21:36:37 +00:00
|
|
|
private Vibrator mVibrator;
|
|
|
|
|
2012-03-30 09:47:24 +00:00
|
|
|
private VibratorUtils() {
|
|
|
|
// This utility class is not publicly instantiable.
|
2011-03-23 21:36:37 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 09:47:24 +00:00
|
|
|
public static VibratorUtils getInstance(Context context) {
|
2011-03-23 21:36:37 +00:00
|
|
|
if (sInstance.mVibrator == null) {
|
2012-03-30 09:47:24 +00:00
|
|
|
sInstance.mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
2011-03-23 21:36:37 +00:00
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasVibrator() {
|
2012-03-30 09:47:24 +00:00
|
|
|
if (mVibrator == null) {
|
2011-03-23 21:36:37 +00:00
|
|
|
return false;
|
2012-03-30 09:47:24 +00:00
|
|
|
}
|
|
|
|
return mVibrator.hasVibrator();
|
2011-03-23 21:36:37 +00:00
|
|
|
}
|
2011-09-19 05:51:31 +00:00
|
|
|
|
|
|
|
public void vibrate(long milliseconds) {
|
2012-03-30 09:47:24 +00:00
|
|
|
if (mVibrator == null) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-19 05:51:31 +00:00
|
|
|
mVibrator.vibrate(milliseconds);
|
|
|
|
}
|
2011-03-23 21:36:37 +00:00
|
|
|
}
|