List of usage examples for android.content Context VIBRATOR_SERVICE
String VIBRATOR_SERVICE
To view the source code for android.content Context VIBRATOR_SERVICE.
Click Source Link
From source file:org.ciasaboark.tacere.service.EventSilencerService.java
private void vibrate() { BetaPrefs betaPrefs = new BetaPrefs(this); if (betaPrefs.getDisableVibration()) { Log.d(TAG, "vibrations disabled"); } else {//from w w w. j a va2 s.co m Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 500, 200, 500 }; vibrator.vibrate(pattern, -1); } }
From source file:in.blogspot.anselmbros.torchie.ui.fragment.SettingsFragment.java
private void vibrate(long time) { Vibrator vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); if (vib.hasVibrator()) vib.vibrate(time);//from w ww . j a v a2 s . c o m }
From source file:com.daiv.android.twitter.services.SendTweet.java
public void finishedTweetingNotification() { // sometimes it just would keep making the notification for some reason... // so delay it to insure it clears everything correctly try {// www . j a v a 2 s . c om Thread.sleep(500); } catch (Exception e) { } try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (AppSettings.getInstance(getApplicationContext()).vibrate) { Log.v(TAG + "Test_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } stopForeground(true); NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); } catch (Exception e) { // not attached to activity } }
From source file:com.xortech.multipanic.PanicAddUpdate.java
/** * METHOD TO HANDLE INVALID USER INPUT - VIBRATE AND SHAKE * *///from www . j a va2 s .c o m public void VibrateError(EditText mEditText, EditText nEditText, EditText oEditText) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); Animation shake = AnimationUtils.loadAnimation(getBaseContext(), R.anim.shake); mEditText.startAnimation(shake); nEditText.startAnimation(shake); oEditText.startAnimation(shake); }
From source file:de.questmaster.fatremote.fragments.RemoteFragment.java
private void invokeSend() { // ring / vibrate if (!mSettings.isOverride() && mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) != 0 || (mSettings.isOverride() && mSettings.isTone())) { mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK, 0.5f); }//from ww w . ja v a 2 s.c o m if (mSettings.isVibrate()) { Vibrator vibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); } // Set sending image ImageView sending = (ImageView) c.findViewById(R.id.sendLED); sending.setImageResource(R.drawable.light_highlight); sending.invalidate(); // start sending NetworkProxy.getInstance(c).addRemoteEvent(new FATRemoteEvent(keyCode, keyModifier)); }
From source file:com.klinker.android.twitter.services.SendTweet.java
public void finishedTweetingNotification() { // sometimes it just would keep making the notification for some reason... // so delay it to insure it clears everything correctly try {/* ww w . j a va2 s .com*/ Thread.sleep(500); } catch (Exception e) { } try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (AppSettings.getInstance(getApplicationContext()).vibrate) { Log.v("talon_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } stopForeground(true); NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); } catch (Exception e) { // not attached to activity } }
From source file:cl.gisred.android.RepartoActivity.java
private void alertFail() { ToneGenerator tgFail = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); tgFail.startTone(ToneGenerator.TONE_CDMA_SOFT_ERROR_LITE, 200); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(1000);/* w w w . j a va2s.c o m*/ }
From source file:com.example.administrator.myapplication2._2_exercise._2_Status_heart.fragments.LeftFragment.java
public void warning() { alertCount++;/*w w w .j a v a 2s . co m*/ if (playBool == true && (alertCount % 5 == 0)) { MediaPlayer ss1; ss1 = MediaPlayer.create(getActivity(), R.raw.alertsound2); // ss1.setLooping(true); ss1.start(); Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(2000); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity(), R.style.AppCompatAlertDialogStyle); builder.setTitle("?? "); builder.setMessage( " ? \nMAXIMUM ?\n" + "5 ?? ??.\n" + "? \n?? ."); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { playBool = true; } }); builder.show(); playBool = false; } }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
/** * Sets the view to our CardboardView and initializes the transformation matrices we will use * to render our scene.//from w w w . j av a 2s. c o m * * @param savedInstanceState If the activity is being re-initialized after * previously being shut down then this Bundle contains the data it most * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent() != null) { mSearchTerm = getIntent().getStringExtra(EXTRA_SEARCH_TERM); } if (TextUtils.isEmpty(mSearchTerm) && savedInstanceState != null) { mSearchTerm = savedInstanceState.getString(EXTRA_SEARCH_TERM); } setContentView(R.layout.common_ui); CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboard_view); cardboardView.setRenderer(this); setCardboardView(cardboardView); cardboardView.setVRModeEnabled(true); mScaleTV = cardboardView.getVRMode() ? SCALE_TV_VR : SCALE_TV; mScaleTheater = cardboardView.getVRMode() ? SCALE_THEATER_VR : SCALE_THEATER; mImageRect = new float[NUM_TEXTURES][16]; mModelRect = new float[NUM_TEXTURES][16]; mCamera = new float[16]; mView = new float[16]; mModelViewProjection = new float[16]; mModelView = new float[16]; mModelFloor = new float[16]; mHeadView = new float[16]; mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mRectTextureIds = new int[NUM_TEXTURES]; for (int i = 0; i < NUM_TEXTURES; i++) { mRectTextureIds[i] = -1; } mTextureIds = new int[NUM_TEXTURES]; mGifResourceDecoder = new GifResourceDecoder(this); mTumblrClient = new TumblrClient(); mOverlayView = (CardboardOverlayView) findViewById(R.id.overlay); Glide.with(this).fromResource().asBitmap().load(R.drawable.ic_refresh_white_24dp) .transform(new FlipTransformation(this)) .into(new PhotoTexture.TextureTarget(STATIC_TEXTURE_ID_REFRESH, this)); Glide.with(this).fromResource().asBitmap().load(R.drawable.ic_play_circle_outline_white_24dp) .transform(new FlipTransformation(this)) .into(new PhotoTexture.TextureTarget(STATIC_TEXTURE_ID_PLAY, this)); Glide.with(this).fromResource().asBitmap().load(R.drawable.ic_pause_circle_outline_white_24dp) .transform(new FlipTransformation(this)) .into(new PhotoTexture.TextureTarget(STATIC_TEXTURE_ID_PAUSE, this)); }
From source file:com.googlecode.mindbell.MindBellPreferences.java
@SuppressWarnings("deprecation") // deprecation is because MindBell is not fragment-based @Override//from w ww . j a v a2s . c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check settings, delete any settings that are not valid final PrefsAccessor prefs = ContextAccessor.getInstance(this).getPrefs(); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences_1); addPreferencesFromResource(R.xml.preferences_2); // notifications depend on SDK addPreferencesFromResource(R.xml.preferences_3); final CheckBoxPreference preferenceUseAudioStreamVolumeSetting = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyUseAudioStreamVolumeSetting)); final CheckBoxPreference preferenceStatus = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyStatus)); final CheckBoxPreference preferenceShow = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyShow)); final CheckBoxPreference preferenceSound = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keySound)); final Preference preferenceReminderSoundLength = (Preference) getPreferenceScreen() .findPreference(getText(R.string.keyReminderSoundLength)); final ListPreferenceWithSummaryFix preferenceReminderBell = (ListPreferenceWithSummaryFix) getPreferenceScreen() .findPreference(getText(R.string.keyReminderBell)); final MediaVolumePreference preferenceVolume = (MediaVolumePreference) getPreferenceScreen() .findPreference(getText(R.string.keyVolume)); final RingtonePreference preferenceRingtone = (RingtonePreference) getPreferenceScreen() .findPreference(getText(R.string.keyRingtone)); final CheckBoxPreference preferenceVibrate = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyVibrate)); final ListPreferenceWithSummaryFix preferencePattern = (ListPreferenceWithSummaryFix) getPreferenceScreen() .findPreference(getText(R.string.keyPattern)); final CheckBoxPreference preferenceMuteOffHook = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyMuteOffHook)); final MinutesIntervalPickerPreference preferenceFrequency = (MinutesIntervalPickerPreference) getPreferenceScreen() .findPreference(getText(R.string.keyFrequency)); final CheckBoxPreference preferenceRandomize = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyRandomize)); final ListPreferenceWithSummaryFix preferenceNormalize = (ListPreferenceWithSummaryFix) getPreferenceScreen() .findPreference(getText(R.string.keyNormalize)); final MultiSelectListPreferenceWithSummary preferenceActiveOnDaysOfWeek = (MultiSelectListPreferenceWithSummary) getPreferenceScreen() .findPreference(getText(R.string.keyActiveOnDaysOfWeek)); final MediaVolumePreference preferenceMeditationVolume = (MediaVolumePreference) getPreferenceScreen() .findPreference(getText(R.string.keyMeditationVolume)); final CheckBoxPreference preferenceUseWorkaroundBell = (CheckBoxPreference) getPreferenceScreen() .findPreference(getText(R.string.keyUseWorkaroundBell)); final Preference preferenceFAQ = (Preference) getPreferenceScreen() .findPreference(getText(R.string.keyFAQ)); final Preference preferenceBatterySettings = (Preference) getPreferenceScreen() .findPreference(getText(R.string.keyBatterySettings)); final Preference preferenceSendMail = (Preference) getPreferenceScreen() .findPreference(getText(R.string.keySendMail)); preferenceUseAudioStreamVolumeSetting.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean isChecked = (Boolean) newValue; if (!isChecked && prefs.mustUseAudioStreamVolumeSetting()) { Toast.makeText(MindBellPreferences.this, R.string.mustUseAudioStreamSetting, Toast.LENGTH_SHORT) .show(); return false; } else { preferenceVolume.setEnabled(preferenceSound.isChecked() && !isChecked); preferenceMeditationVolume.setEnabled(!isChecked); return true; } } }); preferenceStatus.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { return mediateMuteOffHookAndStatus(preferenceMuteOffHook, newValue, REQUEST_CODE_STATUS); } }); preferenceShow.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { return mediateShowAndSoundAndVibrate(preferenceSound, preferenceVibrate, newValue); } }); preferenceSound.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (mediateShowAndSoundAndVibrate(preferenceShow, preferenceVibrate, newValue) && mediateSoundDurationRelatedSettings(preferenceFrequency, preferenceUseWorkaroundBell, preferenceReminderBell, preferenceRingtoneValue, newValue)) { boolean isChecked = (Boolean) newValue; preferenceReminderBell.setEnabled(isChecked); preferenceRingtone.setEnabled( isChecked && !PrefsAccessor.isUseStandardBell(preferenceReminderBell.getValue())); preferenceVolume.setEnabled(!preferenceUseAudioStreamVolumeSetting.isChecked() && isChecked); return true; } else { return false; } } }); preferenceReminderSoundLength.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { onPreferenceReminderSoundLength(preferenceUseWorkaroundBell.isChecked(), preferenceReminderBell.getValue(), preferenceRingtoneValue); return true; } }); preferenceReminderBell.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { String reminderBell = (String) newValue; boolean isChecked = PrefsAccessor.isUseStandardBell(reminderBell); if (PrefsAccessor.isUseStandardBell(reminderBell) || ContextCompat.checkSelfPermission(MindBellPreferences.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { if (mediateSoundDurationRelatedSettings(preferenceFrequency, preferenceUseWorkaroundBell, reminderBell, preferenceRingtoneValue, preferenceSound)) { // Allow setting this option to "off" if permission is granted preferenceRingtone.setEnabled(preferenceSound.isChecked() && !isChecked); // Weird, but ringtone cannot be retrieved from RingtonePreference, only from SharedPreference setPreferenceVolumeSoundUri(preferenceVolume, reminderBell, preferenceUseWorkaroundBell.isChecked(), preferenceRingtoneValue); return true; } else { return false; } } else { // Ask for permission if this option shall be set to "off" but permission is missing ActivityCompat.requestPermissions(MindBellPreferences.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_CODE_RINGTONE); // As the permission request is asynchronous we have to deny setting this option (to "off") return false; } } }); preferenceRingtone.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { String newRingtoneValue = (String) newValue; if (validatePreferenceRingtone(newRingtoneValue) && mediateSoundDurationRelatedSettings(preferenceFrequency, preferenceUseWorkaroundBell, preferenceReminderBell, newRingtoneValue, preferenceSound)) { setPreferenceRingtoneSummary(preferenceRingtone, newRingtoneValue); setPreferenceVolumeSoundUri(preferenceVolume, preferenceReminderBell.getValue(), preferenceUseWorkaroundBell.isChecked(), newRingtoneValue); preferenceRingtoneValue = newRingtoneValue; return true; } else { return false; } } }); preferenceVibrate.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { return mediateShowAndSoundAndVibrate(preferenceShow, preferenceSound, newValue); } }); preferencePattern.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { Vibrator vibrator = (Vibrator) MindBellPreferences.this.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(PrefsAccessor.getVibrationPattern((String) newValue), -1); return true; } }); preferenceMuteOffHook.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { return mediateMuteOffHookAndStatus(preferenceStatus, newValue, REQUEST_CODE_MUTE_OFF_HOOK); } }); preferenceRandomize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if ((Boolean) newValue) { // if interval deviation is selected, normalize is disabled on screen but it must be disabled in preferences, // too. Otherwise the following scenario could happen: set interval 1 h, de-select randomize, set normalize to // hh:00, select randomize, set interval 2 h, de-select randomize again ... hh:00 would be left in normalize // erroneously. preferenceNormalize.setValue(PrefsAccessor.NORMALIZE_NONE); } return true; } }); preferenceFrequency.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (!mediateSoundDurationRelatedSettings(newValue, preferenceUseWorkaroundBell, preferenceReminderBell, preferenceRingtoneValue, preferenceSound)) { return false; } else if (preferenceRandomize.isChecked()) { // if interval varies randomly, ringing on the minute is disabled and set to "no" anyway return true; } else if (isFrequencyDividesAnHour(new TimeOfDay((String) newValue))) { // if frequency is factor of an hour, ringing on the minute may be requested preferenceNormalize.setEnabled(true); } else { // if frequency is NOT factor of an hour, ringing on the minute may NOT be set if (preferenceNormalize.isEnabled() && isNormalize(preferenceNormalize.getValue())) { Toast.makeText(MindBellPreferences.this, R.string.frequencyDoesNotFitIntoAnHour, Toast.LENGTH_SHORT).show(); return false; } else { preferenceNormalize.setEnabled(false); } } return true; } }); preferenceNormalize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (!isNormalize((String) newValue)) { // if normalize - ringing on the minute - is not wanted, it's fine, no more to check here return true; } else if (isFrequencyDividesAnHour(preferenceFrequency.getTime())) { // if frequency is factor of an hour, requesting ringing on the minute is allowed return true; } else { // if frequency is NOT factor of an hour, ringing on the minute may NOT be set Toast.makeText(MindBellPreferences.this, R.string.frequencyDoesNotFitIntoAnHour, Toast.LENGTH_SHORT).show(); return false; } } }); preferenceActiveOnDaysOfWeek.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValues) { if (((Set<?>) newValues).isEmpty()) { Toast.makeText(MindBellPreferences.this, R.string.atLeastOneActiveDayNeeded, Toast.LENGTH_SHORT) .show(); return false; } return true; } }); preferenceFAQ.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Uri faqUri = Uri.parse(getText(R.string.faq_url).toString()); Intent browserIntent = new Intent(Intent.ACTION_VIEW, faqUri); startActivity(browserIntent); return true; } }); preferenceBatterySettings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { onPreferenceClickBatterySettings(); return true; } }); preferenceUseWorkaroundBell.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (mediateSoundDurationRelatedSettings(preferenceFrequency, newValue, preferenceReminderBell, preferenceRingtoneValue, preferenceSound)) { boolean isChecked = (Boolean) newValue; setPreferenceVolumeSoundUri(preferenceVolume, preferenceReminderBell.getValue(), isChecked, preferenceRingtoneValue); return true; } else { return false; } } }); preferenceSendMail.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(MindBellPreferences.this) // .setTitle(R.string.prefsSendMail) // .setMessage(R.string.mailInfo1) // .setIcon(R.mipmap.ic_launcher) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { onClickReallySendInfo(); } }) // .setNegativeButton(android.R.string.cancel, null) // .show(); return true; } }); // As no PreferenceChangeListener is called without change *BY USER*, some settings have to be made explicitly preferenceVolume .setEnabled(preferenceSound.isChecked() && !preferenceUseAudioStreamVolumeSetting.isChecked()); preferenceMeditationVolume.setEnabled(!preferenceUseAudioStreamVolumeSetting.isChecked()); preferenceReminderBell.setEnabled(preferenceSound.isChecked()); preferenceRingtone.setEnabled( preferenceSound.isChecked() && !PrefsAccessor.isUseStandardBell(preferenceReminderBell.getValue())); preferenceRingtoneValue = prefs.getRingtone(); // cannot be retrieved from preference setPreferenceRingtoneSummary(preferenceRingtone, preferenceRingtoneValue); setPreferenceVolumeSoundUri(preferenceVolume, preferenceReminderBell.getValue(), preferenceUseWorkaroundBell.isChecked(), preferenceRingtoneValue); }