Example usage for android.os Vibrator vibrate

List of usage examples for android.os Vibrator vibrate

Introduction

In this page you can find the example usage for android.os Vibrator vibrate.

Prototype

@RequiresPermission(android.Manifest.permission.VIBRATE)
    public void vibrate(VibrationEffect vibe, AudioAttributes attributes) 

Source Link

Usage

From source file:com.sean.takeastand.alarmprocess.AlarmService.java

private void sendNotification() {
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent[] pendingIntents = makeNotificationIntents();
    RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification);
    rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]);
    notificationClockTime = Utils.getFormattedCalendarTime(Calendar.getInstance(), this);
    rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime);
    NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this);
    alarmNotificationBuilder.setContent(rvRibbon).setContentIntent(pendingIntents[0]).setAutoCancel(false)
            .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small)
            .setContentTitle("Take A Stand ").setContentText(
                    "Mark Stood")
            .extend(new NotificationCompat.WearableExtender().addAction(
                    new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[2])
                            .build())/* w  w w . j  a  v  a2  s .c om*/
                    .setContentAction(0).setHintHideIcon(true)
    //                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed))
    );

    //Purpose of below is to figure out what type of user alert to give with the notification
    //If scheduled, check settings for that schedule
    //If unscheduled, check user defaults
    if (mCurrentAlarmSchedule != null) {
        boolean[] alertType = mCurrentAlarmSchedule.getAlertType();
        if ((alertType[0])) {
            alarmNotificationBuilder.setLights(238154000, 1000, 4000);
        }
        if (alertType[1]) {
            alarmNotificationBuilder.setVibrate(mVibrationPattern);
            AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) {
                Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(mVibrationPattern, -1);
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    } else {
        boolean[] alertType = Utils.getDefaultAlertType(this);
        if ((alertType[0])) {
            alarmNotificationBuilder.setLights(238154000, 1000, 4000);
        }
        if (alertType[1]) {
            alarmNotificationBuilder.setVibrate(mVibrationPattern);
            AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) {
                Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(mVibrationPattern, -1);
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    }
    Notification alarmNotification = alarmNotificationBuilder.build();
    notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification);

    if (getSharedPreferences(Constants.USER_SHARED_PREFERENCES, 0).getBoolean(Constants.STANDDTECTORTM_ENABLED,
            false)) {
        Intent standSensorIntent = new Intent(this, StandDtectorTM.class);
        standSensorIntent.setAction(com.heckbot.standdtector.Constants.STANDDTECTOR_START);
        standSensorIntent.putExtra("MILLISECONDS", (long) 60000);

        standSensorIntent.putExtra("pendingIntent", pendingIntents[1]);

        startService(standSensorIntent);
    }
}

From source file:com.example.SmartBoard.MQTTHandler.java

public void messageArrived(String topic, MqttMessage message) {
    MyActivity drawingActivity = (MyActivity) drawingContext;
    JSONObject recvMessage = null;/*from   w ww  . j  a va 2 s.com*/

    if (message.toString().compareTo("") == 0) {
        //user went offline
        String[] topicStruct = topic.split("/");
        // System.out.println("user to be removed: "+topicStruct[2]);

        if (topicStruct[2].compareTo("users") == 0) {
            usersListHistory.remove(new OnlineStateMessage(null, topicStruct[3]));
            usersAdapter.notifyDataSetChanged();

        } else if (topicStruct[2].compareTo("objects") == 0) {
            drawingActivity.drawer.removeObject(topicStruct[3]);
        }
        return;
    }

    try {
        recvMessage = new JSONObject(message.toString());
    } catch (JSONException j) {
        j.printStackTrace();
    }

    if (recvMessage.optString("status").compareTo("online") == 0) {

        OnlineStateMessage newUser = new OnlineStateMessage(recvMessage.optString("selfie"),
                recvMessage.optString("userId"));
        // System.out.println("user added: "+ recvMessage.optString("userId"));
        usersListHistory.add(newUser);
        usersAdapter.notifyDataSetChanged();
        return;

    }

    String clientId = recvMessage.optString("clientId");

    if (clientId.compareTo(client.getClientId()) != 0) {

        switch (type.valueOf(recvMessage.optString("type"))) {

        case Point:
            drawingActivity.drawer.drawPoint((float) recvMessage.optDouble("mX"),
                    (float) recvMessage.optDouble("mY"), recvMessage.optInt("drawActionFlag"),
                    recvMessage.optInt("color"), recvMessage.optString("mode"), recvMessage.optInt("brushSize"),
                    recvMessage.optString("clientId"));
            break;
        case Eraser:
            float eSize = (float) recvMessage.optDouble("size");
            drawingActivity.drawer.updateEraseSize(eSize);
            break;
        case Pencil: //shares topic with Eraser
            float size = (float) recvMessage.optDouble("size");
            drawingActivity.drawer.updateBrushSize(size);
            break;

        case ColorChange:
            drawingActivity.drawer.updateColor(recvMessage.optInt("code"));
            break;

        case ClearScreen:
            drawingActivity.drawer.updateClearScreen();
            break;
        case Chat:
            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(new long[] { 3, 100 }, -1);

            String[] nameMessage = recvMessage.optString("message").split(":");
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
                    .setLargeIcon(stringToBitmap(recvMessage.optString("selfie")))
                    .setSmallIcon(R.drawable.smart2).setContentTitle(nameMessage[0])
                    .setContentText(nameMessage[1]).setTicker("New Message Arrived").setAutoCancel(true)
                    .setNumber(++numMessages);

            NotificationManager mNotificationManager = (NotificationManager) ctx
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            // mId allows you to update the notification later on.
            mNotificationManager.notify(1000, mBuilder.build());

            ChatMessageWithSelfie mChatMessage = new ChatMessageWithSelfie(recvMessage.optBoolean("direction"),
                    recvMessage.optString("message"), recvMessage.optString("selfie"),
                    recvMessage.optString("imageSent"), null);
            sessionHistory.add(mChatMessage);
            Chat.chatAdapter.add(mChatMessage);
            break;

        case Image:
            Vibrator v2 = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v2.vibrate(new long[] { 3, 100 }, -1);
            Toast.makeText(ctx, recvMessage.optString("username") + " has sent you a message!",
                    Toast.LENGTH_SHORT).show();
            ChatMessageWithSelfie mChatImageMessage = new ChatMessageWithSelfie(
                    recvMessage.optBoolean("direction"), null, recvMessage.optString("selfie"),
                    recvMessage.optString("image"), null);
            sessionHistory.add(mChatImageMessage);
            Chat.chatAdapter.add(mChatImageMessage);
            break;
        case Rectangle:
            drawingActivity.drawer.onDrawReceivedRectangle(recvMessage);
            break;
        case Circle:
            drawingActivity.drawer.onDrawReceivedCircle(recvMessage);
            break;
        case Line:
            drawingActivity.drawer.onDrawReceivedLine(recvMessage);
            break;
        case Text:
            drawingActivity.drawer.onDrawReceivedText(recvMessage);
            break;
        default:
            //ignore the message
        }
    }
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public void vibrateDefaultPattern(Context context, ActionResponse ar) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(new long[] { 0, 200, 400, 200, 400, 200 }, -1);
    //      vibrator.vibrate(1000);
    ar.action_resp = ActionResponse.ACTION_SUCCESS;
    ar.resp_msg_text = "";
}

From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java

private void vibrate() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    //vibrate for 300 milliseconds and then stop for 500 ms and repeat the same style. You can change the pattern and
    //long pattern[]={0,300,200,300,500};
    //start vibration with repeated count, use -1 if you don't want to repeat the vibration
    long pattern[] = { 0, 500, 2500, 500, 2500, 500, 2500, 500, 2500, 500, 2500, 500, 2500, 500, 2500, 500,
            2500, 500, 2500, 500, 2500, 500, 2500, 500, 2500 };
    vibrator.vibrate(pattern, 0);
}

From source file:no.barentswatch.fiskinfo.MapActivity.java

/**
 * Notifies the user through vibration and sound that he is on collision
 * course with a object./* w w  w  . java  2s .  co  m*/
 * TODO: show dialog and allow user to turn off alarm. Until then, only make phone vibrate.
 * 
 */
private void notifyUserOfProximityAlert() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = { 0, // Start immediately
            500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200,
            500, 200, 500, 200 };

    vibrator.vibrate(pattern, -1);

    //      MediaPlayer mediaPlayer = MediaPlayer.create(getContext(), R.raw.terran_2);
    //      if (mediaPlayer == null) {
    //         return;
    //      }
    //      mediaPlayer.start();

}

From source file:com.rickendirk.rsgwijzigingen.ZoekService.java

private void vibrate() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator.hasVibrator()) {
        //Eerste waarde vertraging, 2e duur, 3e vertraging, 4e duur, etc
        long[] pattern = { 0, 250, 600, 250 };
        vibrator.vibrate(pattern, -1); // -1 betekent geen herhaling
    }/*from   w w w . j a  v a 2s .  c o  m*/
}

From source file:com.googlecode.mindbell.MindBellPreferences.java

@SuppressWarnings("deprecation") // deprecation is because MindBell is not fragment-based
@Override//  w ww . j  a  v  a2  s  .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);

}

From source file:com.klinker.android.twitter.activities.compose.Compose.java

public void finishedTweetingNotification() {
    new Handler().postDelayed(new Runnable() {
        @Override// w  ww  .j  a va2 s  . co m
        public void run() {
            try {
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_stat_icon)
                        .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false)
                        .setTicker(getResources().getString(R.string.tweet_success));

                if (settings.vibrate) {
                    Log.v("talon_vibrate", "vibrate on compose");
                    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                    long[] pattern = { 0, 50, 500 };
                    v.vibrate(pattern, -1);
                }

                NotificationManager mNotificationManager = (NotificationManager) 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?
            }
        }
    }, 500);

}

From source file:com.daiv.android.twitter.ui.compose.Compose.java

public void finishedTweetingNotification() {
    new Handler().postDelayed(new Runnable() {
        @Override/* w w w .  j a  v a  2  s . c o m*/
        public void run() {
            try {
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_stat_icon)
                        .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false)
                        .setTicker(getResources().getString(R.string.tweet_success));

                if (settings.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);
                }

                NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                mNotificationManager.notify(6, mBuilder.build());
                // cancel it immediately, the ticker will just go off
                mNotificationManager.cancel(6);

                sendMessage();
            } catch (Exception e) {
                // not attached?
            }
        }
    }, 500);

}

From source file:ar.com.martinrevert.argenteam.GcmIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from ww w.j ava 2s  .  c  o  m*/
private void generarNotification(Context context, String message, String urlimagen, String urlarticulo,
        String tipo, String fecha) {
    SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean vib = preferencias.getBoolean("vibraoff", false);
    boolean movieoff = preferencias.getBoolean("movieoff", false);
    boolean tvoff = preferencias.getBoolean("tvoff", false);
    String ringmovie = preferencias.getString("prefRingtonemovie", "");
    String ringtv = preferencias.getString("prefRingtonetv", "");
    //Todo traducir ticker
    String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM";

    Random randomGenerator = new Random();
    int randomInt = randomGenerator.nextInt(100);

    Bitmap bitmap = getRemoteImage(urlimagen, tipo);

    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    int dash = 500;
    int short_gap = 200;

    long[] pattern = { 0, // Start immediately
            dash, short_gap, dash, short_gap, dash };

    Intent notificationIntent;
    String ringtone;
    int ledlight;

    if (tipo.equalsIgnoreCase("Movie")) {
        ringtone = ringmovie;
        notificationIntent = new Intent(context, Peli.class);
        ledlight = preferencias.getInt("ledMovie", 0);

    } else {
        notificationIntent = new Intent(context, Tv.class);
        ringtone = ringtv;
        ledlight = preferencias.getInt("ledTV", 0);
        System.out.println(ledlight);
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("passed", urlarticulo);

    PendingIntent pendingIntent;

    pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0);

    Notification myNotification;
    myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message)
            .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews views;
        views = new RemoteViews(getPackageName(), R.layout.custom_notification);
        views.setImageViewBitmap(R.id.big_picture, bitmap);
        views.setImageViewBitmap(R.id.big_icon,
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm));
        views.setTextViewText(R.id.title, message);
        myNotification.bigContentView = views;
    }

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if (movieoff && tipo.equalsIgnoreCase("Movie")) {
        if (vib) {
            v.vibrate(pattern, -1);
        }
        notificationManager.notify(randomInt, myNotification);

    }

    if (tvoff && tipo.equalsIgnoreCase("Serie TV")) {
        if (vib) {
            v.vibrate(pattern, -1);
        }
        notificationManager.notify(randomInt, myNotification);

    }

}