本文整理汇总了Java中android.os.Vibrator.hasVibrator方法的典型用法代码示例。如果您正苦于以下问题:Java Vibrator.hasVibrator方法的具体用法?Java Vibrator.hasVibrator怎么用?Java Vibrator.hasVibrator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Vibrator
的用法示例。
在下文中一共展示了Vibrator.hasVibrator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNonIndexableKeys
import android.os.Vibrator; //导入方法依赖的package包/类
public List<String> getNonIndexableKeys(Context context) {
final ArrayList<String> rt = new ArrayList<String>();
if (Utils.isVoiceCapable(context)) {
rt.add(KEY_NOTIFICATION_VOLUME);
} else {
rt.add(KEY_RING_VOLUME);
rt.add(KEY_PHONE_RINGTONE);
rt.add(KEY_WIFI_DISPLAY);
rt.add(KEY_VIBRATE_WHEN_RINGING);
}
Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vib == null || !vib.hasVibrator()) {
rt.add(KEY_VIBRATE);
}
CMHardwareManager hardware = CMHardwareManager.getInstance(context);
if (!hardware.isSupported(CMHardwareManager.FEATURE_VIBRATOR)) {
rt.add(KEY_VIBRATION_INTENSITY);
}
return rt;
}
示例2: shouldVibrateNew
import android.os.Vibrator; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean shouldVibrateNew(Context context, int ringerMode) {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
return false;
}
boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;
if (vibrateWhenRinging) {
return ringerMode != AudioManager.RINGER_MODE_SILENT;
} else {
return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
}
}
示例3: shouldVibrateNew
import android.os.Vibrator; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean shouldVibrateNew(Context context, int ringerMode) {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
return false;
}
boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;
if (vibrateWhenRinging) {
return ringerMode != AudioManager.RINGER_MODE_SILENT;
} else {
return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
}
}
示例4: hasVibrator
import android.os.Vibrator; //导入方法依赖的package包/类
public static boolean hasVibrator(Context con) {
if (mHasVibrator != null) return mHasVibrator;
try {
Vibrator v = (Vibrator) con.getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = v.hasVibrator();
return mHasVibrator;
} catch (Throwable t) {
mHasVibrator = null;
return false;
}
}
示例5: playRingtone
import android.os.Vibrator; //导入方法依赖的package包/类
public void playRingtone() {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
// Honour silent mode
switch (audioManager.getRingerMode()) {
case AudioManager.RINGER_MODE_NORMAL:
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_RING);
try {
if(hasSIM())
mPlayer.setDataSource(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
else
mPlayer.setDataSource(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
mPlayer.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "Could not setup media player for ringtone");
mPlayer = null;
return;
}
mPlayer.setLooping(true);
mPlayer.start();
break;
case AudioManager.RINGER_MODE_VIBRATE:
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
if(mVibrator.hasVibrator()) {
long[] pattern = {0, 500, 200};
// The '0' here means to repeat indefinitely
// '0' is actually the index at which the pattern keeps repeating from (the start)
// To repeat the pattern from any other point, you could increase the index, e.g. '1'
mVibrator.vibrate(pattern, 0);
}
break;
}
}
示例6: onCreate
import android.os.Vibrator; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.other_sound_settings);
mContext = getActivity();
// power state change notification sounds
mPowerSoundsVibrate = (SwitchPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
mPowerSoundsVibrate.setChecked(CMSettings.Global.getInt(getContentResolver(),
CMSettings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) != 0);
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
removePreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
}
mPowerSoundsRingtone = findPreference(KEY_POWER_NOTIFICATIONS_RINGTONE);
String currentPowerRingtonePath = CMSettings.Global.getString(getContentResolver(),
CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE);
// set to default notification if we don't yet have one
if (currentPowerRingtonePath == null) {
currentPowerRingtonePath = System.DEFAULT_NOTIFICATION_URI.toString();
CMSettings.Global.putString(getContentResolver(),
CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE, currentPowerRingtonePath);
}
// is it silent ?
if (currentPowerRingtonePath.equals(POWER_NOTIFICATIONS_SILENT_URI)) {
mPowerSoundsRingtone.setSummary(
getString(R.string.power_notifications_ringtone_silent));
} else {
final Ringtone ringtone =
RingtoneManager.getRingtone(getActivity(), Uri.parse(currentPowerRingtonePath));
if (ringtone != null) {
mPowerSoundsRingtone.setSummary(ringtone.getTitle(getActivity()));
}
}
for (SettingPref pref : PREFS) {
pref.init(this);
}
}
示例7: vibrate
import android.os.Vibrator; //导入方法依赖的package包/类
private void vibrate() {
if (mDontVibrate) return;
Vibrator vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (!vi.hasVibrator()) return;
vi.vibrate(VIBRATION);
}
示例8: onReceive
import android.os.Vibrator; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.i(TAG, "Received " + intent);
Util.logExtras(intent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Cancel set alarm
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(INTENT_ON), PendingIntent.FLAG_UPDATE_CURRENT);
if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction()))
am.cancel(pi);
// Vibrate
Vibrator vs = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vs.hasVibrator())
vs.vibrate(50);
try {
if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction())) {
boolean enabled = INTENT_ON.equals(intent.getAction());
prefs.edit().putBoolean("enabled", enabled).apply();
if (enabled)
ServiceSinkhole.start("widget", context);
else
ServiceSinkhole.stop("widget", context);
// Auto enable
int auto = Integer.parseInt(prefs.getString("auto_enable", "0"));
if (!enabled && auto > 0) {
Log.i(TAG, "Scheduling enabled after minutes=" + auto);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
else
am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
}
} else if (INTENT_LOCKDOWN_ON.equals(intent.getAction()) || INTENT_LOCKDOWN_OFF.equals(intent.getAction())) {
boolean lockdown = INTENT_LOCKDOWN_ON.equals(intent.getAction());
prefs.edit().putBoolean("lockdown", lockdown).apply();
ServiceSinkhole.reload("widget", context);
WidgetLockdown.updateWidgets(context);
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
}
示例9: giveTactileFeedbackForKeyPress
import android.os.Vibrator; //导入方法依赖的package包/类
/**
* Run the vibrator to give tactile feedback for 50ms when any key is pressed.
*/
static void giveTactileFeedbackForKeyPress(@NonNull Context context) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (v.hasVibrator()) v.vibrate(50);
}
示例10: giveTactileFeedbackForAuthFail
import android.os.Vibrator; //导入方法依赖的package包/类
/**
* Run the vibrator to give tactile feedback for 350ms when yser authentication is successful.
*/
static void giveTactileFeedbackForAuthFail(@NonNull Context context) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (v.hasVibrator()) v.vibrate(350);
}
示例11: giveTactileFeedbackForAuthSuccess
import android.os.Vibrator; //导入方法依赖的package包/类
/**
* Run the vibrator to give tactile feedback for 100ms at difference of 50ms for two times when
* user authentication is failed.
*/
static void giveTactileFeedbackForAuthSuccess(@NonNull Context context) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (v.hasVibrator()) v.vibrate(new long[]{50, 100, 50, 100}, -1);
}
示例12: startCallNotification
import android.os.Vibrator; //导入方法依赖的package包/类
public void startCallNotification() {
Log.d(TAG, "startCallNotification()");
ringtonePlayer.play(false);
vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
long[] vibrationCycle = {0, 1000, 1000};
if (vibrator.hasVibrator()) {
vibrator.vibrate(vibrationCycle, 1);
}
}