Search in sources :

Example 76 with Vibrator

use of android.os.Vibrator in project QLibrary by DragonsQC.

the class VibratorUtils method vibrate.

/**
     * @param context      Context
     * @param milliseconds 震动的时长,单位是毫秒
     */
public static void vibrate(final Context context, long milliseconds) {
    Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
    vib.vibrate(milliseconds);
}
Also used : Vibrator(android.os.Vibrator)

Example 77 with Vibrator

use of android.os.Vibrator in project QLibrary by DragonsQC.

the class VibratorUtils method vibrate.

/**
     * @param context  Context
     * @param pattern  自定义震动模式 。数组中数字的含义依次是[静止时长,震动时长,静止时长,震动时长。。。]时长的单位是毫秒
     * @param isRepeat 是否反复震动,如果是true,反复震动,如果是false,只震动一次
     */
public static void vibrate(final Context context, long[] pattern, boolean isRepeat) {
    Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
    vib.vibrate(pattern, isRepeat ? 1 : -1);
}
Also used : Vibrator(android.os.Vibrator)

Example 78 with Vibrator

use of android.os.Vibrator in project Etar-Calendar by Etar-Group.

the class GeneralPreferences method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Activity activity = getActivity();
    // Make sure to always use the same preferences file regardless of the package name
    // we're running under
    final PreferenceManager preferenceManager = getPreferenceManager();
    final SharedPreferences sharedPreferences = getSharedPreferences(activity);
    preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.general_preferences);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
    mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
        PreferenceCategory mAlertGroup = (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
        mAlertGroup.removePreference(mVibrate);
    }
    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
    String ringToneUri = Utils.getRingTonePreference(activity);
    // Set the ringToneUri to the backup-able shared pref only so that
    // the Ringtone dialog will open up with the correct value.
    final Editor editor = preferenceScreen.getEditor();
    editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();
    String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
    mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);
    mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
    mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
    mTheme = (ListPreference) preferenceScreen.findPreference(KEY_THEME_PREF);
    mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
    mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
    mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
    mDayWeek = (ListPreference) preferenceScreen.findPreference(KEY_DAYS_PER_WEEK);
    mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
    mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
    mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
    buildSnoozeDelayEntries();
    mTheme.setSummary(mTheme.getEntry());
    mWeekStart.setSummary(mWeekStart.getEntry());
    mDayWeek.setSummary(mDayWeek.getEntry());
    mDefaultReminder.setSummary(mDefaultReminder.getEntry());
    mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
    mDefaultStart.setSummary(mDefaultStart.getEntry());
    // This triggers an asynchronous call to the provider to refresh the data in shared pref
    mTimeZoneId = Utils.getTimeZone(activity, null);
    SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);
    // off, we will explicitly read it.
    if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
        mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
    }
    mHomeTZ.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showTimezoneDialog();
            return true;
        }
    });
    if (mTzPickerUtils == null) {
        mTzPickerUtils = new TimeZonePickerUtils(getActivity());
    }
    CharSequence timezoneName = mTzPickerUtils.getGmtDisplayName(getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
    mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);
    TimeZonePickerDialog tzpd = (TimeZonePickerDialog) activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
        tzpd.setOnTimeZoneSetListener(this);
    }
    migrateOldPreferences(sharedPreferences);
    updateChildPreferences();
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Activity(android.app.Activity) PreferenceManager(android.preference.PreferenceManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) TimeZonePickerUtils(com.android.timezonepicker.TimeZonePickerUtils) TimeZonePickerDialog(com.android.timezonepicker.TimeZonePickerDialog) Vibrator(android.os.Vibrator) Editor(android.content.SharedPreferences.Editor)

Example 79 with Vibrator

use of android.os.Vibrator in project android-common by litesuits.

the class VibrateUtil method vibrate.

/**
     * Vibrate constantly for the specified period of time.
     * <p>This method requires the caller to hold the permission
     * {@link android.Manifest.permission#VIBRATE}.
     *
     * @param milliseconds The number of milliseconds to vibrate.
     */
public static void vibrate(Context context, long milliseconds) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(milliseconds);
}
Also used : Vibrator(android.os.Vibrator)

Example 80 with Vibrator

use of android.os.Vibrator in project BarcodeEye by BarcodeEye.

the class BeepManager method playBeepSoundAndVibrate.

public synchronized void playBeepSoundAndVibrate() {
    if (playBeep && mediaPlayer != null) {
        mediaPlayer.start();
    }
    if (vibrate) {
        Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(VIBRATE_DURATION);
    }
}
Also used : Vibrator(android.os.Vibrator)

Aggregations

Vibrator (android.os.Vibrator)88 IOException (java.io.IOException)10 RemoteException (android.os.RemoteException)8 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 InputDevice (android.view.InputDevice)6 NotificationManager (android.app.NotificationManager)5 Intent (android.content.Intent)5 Bitmap (android.graphics.Bitmap)5 SystemVibrator (android.os.SystemVibrator)5 FileOutputStream (java.io.FileOutputStream)5 Activity (android.app.Activity)4 Context (android.content.Context)4 AudioManager (android.media.AudioManager)4 PowerManager (android.os.PowerManager)4 NotificationCompat (android.support.v4.app.NotificationCompat)4 ErrnoException (android.system.ErrnoException)4 Uri (android.net.Uri)3 AlarmManager (android.app.AlarmManager)2 PendingIntent (android.app.PendingIntent)2 SearchManager (android.app.SearchManager)2