Example usage for android.content Context VIBRATOR_SERVICE

List of usage examples for android.content Context VIBRATOR_SERVICE

Introduction

In this page you can find the example usage for android.content Context VIBRATOR_SERVICE.

Prototype

String VIBRATOR_SERVICE

To view the source code for android.content Context VIBRATOR_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.Vibrator for interacting with the vibration hardware.

Usage

From source file:com.digutsoft.metronome.DMFSetTempo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.settempo, container, false);

    sbTempo = (SeekBar) rootView.findViewById(R.id.sbTempo);
    tvTempo = (TextView) rootView.findViewById(R.id.tvTempo);
    final CircledImageView btStart = (CircledImageView) rootView.findViewById(R.id.btStart);
    final CircledImageView btPlus = (CircledImageView) rootView.findViewById(R.id.btPlus);
    final CircledImageView btMinus = (CircledImageView) rootView.findViewById(R.id.btMinus);

    mContext = getActivity().getApplicationContext();

    final Context mContext = getActivity();
    sharedPreferences = mContext.getSharedPreferences("dMetronome", 0);
    int defaultTempo = sharedPreferences.getInt("tempo", 80);
    setTempo(defaultTempo);//from w w w  .  j  av  a2s .c o m

    Intent viewIntent = new Intent(getActivity(), DMAMain.class);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(getActivity(), 0, viewIntent, 0);

    notificationBuilder = new NotificationCompat.Builder(getActivity()).setOngoing(true)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentIntent(viewPendingIntent);

    notificationManager = NotificationManagerCompat.from(getActivity());

    Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    metronome = new DMCMetronome(getActivity(), vibrator, rootView.findViewById(R.id.bilBackground));

    PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getString(R.string.app_name));

    sbTempo.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setTempo(i);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    btStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mTempo == 0) {
                Toast.makeText(getActivity(), R.string.tempo_zero, Toast.LENGTH_LONG).show();
                return;
            }

            if (DMCMetronome.mRunning) {
                metronome.stopTick();

                sbTempo.setEnabled(true);
                tvTempo.setText(Integer.toString(mTempo));
                btStart.setImageDrawable(getResources().getDrawable(R.drawable.ic_start));
                btStart.setCircleColor(getResources().getColor(R.color.green));
                btPlus.setVisibility(View.VISIBLE);
                btMinus.setVisibility(View.VISIBLE);

                wakeLock.release();

                notificationManager.cancel(1);
            } else {
                metronome.startTick(mTempo);

                sbTempo.setEnabled(false);
                btStart.setImageDrawable(getResources().getDrawable(R.drawable.ic_stop));
                btStart.setCircleColor(getResources().getColor(R.color.red));
                btPlus.setVisibility(View.GONE);
                btMinus.setVisibility(View.GONE);

                wakeLock.acquire();

                notificationBuilder
                        .setContentText(String.format(getString(R.string.notification_running), mTempo));
                notificationManager.notify(1, notificationBuilder.build());

                sharedPreferences.edit().putInt("tempo", mTempo).apply();
            }
        }
    });

    btPlus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setTempo(mTempo + 1);
        }
    });

    btMinus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setTempo(mTempo - 1);
        }
    });

    return rootView;
}

From source file:ua.com.spasetv.testintuitions.FragExerciseTwo.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    this.vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    this.contentValues = new ContentValues();
    this.dataBaseHelper = new DataBaseHelper(activity);

    try {//from   w  w w.  j a v  a 2 s .  c om
        onExerciseFinishListener = (OnExerciseFinishListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnExerciseFinishListener");
    }
}

From source file:org.peterbaldwin.vlcremote.fragment.NavigationFragment.java

private void vibrate() {
    Vibrator v = getSystemService(Context.VIBRATOR_SERVICE);
    if (v != null) {
        v.vibrate(100);
    }
}

From source file:ua.com.spasetv.testintuitions.FragExerciseOne.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    this.rndHelper = new RndHelper(ID_EXERCISE_ONE);
    this.arrayCorrectAnswers = rndHelper.getArrayAnswers();
    this.vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    this.contentValues = new ContentValues();
    this.dataBaseHelper = new DataBaseHelper(activity);

    try {/*from  ww w. j  a  v  a2s . c o m*/
        onExerciseFinishListener = (OnExerciseFinishListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnExerciseFinishListener");
    }
}

From source file:org.hansel.myAlert.ReminderService.java

@Override
public void onCreate() {
    super.onCreate();
    //obtenemos el "nmero de intentos"
    getApplicationContext().registerReceiver(alarmReceiver, new IntentFilter(CANCEL_ALARM_BROADCAST));
    int count = PreferenciasHancel.getReminderCount(getApplicationContext());
    count++;/*from w w w.  ja  v a 2  s .c om*/
    PreferenciasHancel.setReminderCount(getApplicationContext(), count);
    Log.v("Conteo: " + count);
    if (count >= 3) {
        //detenemos la alarma del servicio de recordatorios. y lanzamos el servicio de Tracking 
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);
        Log.v("Servicio de Rastreo....");
        Util.inicarServicio(getApplicationContext());

        startService(new Intent(getApplicationContext(), SendPanicService.class));
        stopSelf();
    } else {
        //mandamos una alerta de notificacin
        showNotifciation();
        playSound();
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        Vibra();
        Handler han = new Handler();
        run = new Runnable() {

            @Override
            public void run() {
                cancelAlarm();
                stopSelf();
            }
        };
        han.postDelayed(run, 1000 * 10);

        //alarma para "regresar" en caso que el usuario no de "click" en la notificacin
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        long due = System.currentTimeMillis() + (60000 * 3); // 3 minutos
        Log.v("Scheduling next update at " + new Date(due));
        am.set(AlarmManager.RTC_WAKEUP, due, Util.getReminderPendingIntennt(getApplicationContext()));

    }

}

From source file:org.hansel.myAlert.AlarmFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    getActivity().getWindow().addFlags(LayoutParams.FLAG_TURN_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD);
    mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    alarmManager = (AlarmManager) getActivity().getSystemService(Activity.ALARM_SERVICE);
    usuarioDao = new UsuarioDAO(getActivity().getApplicationContext());
    usuarioDao.open();// ww  w . j  a va2  s. c o m
    setAlarm();
    Vibra();
    // tocamos la alarma:
    String _uri = Util.getRingtone(getActivity().getApplicationContext());
    if (_uri != null && _uri.length() > 0) {

        //handler.post(vibrate);
        playSound(getActivity().getApplicationContext(), Uri.parse(_uri));
    }
    //preparamos handler para terminar alarma;
    handler.postDelayed(stop, 1000 * 60 * 2);
    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    alert.setTitle("Contrasea para cancelar...");
    alert.setMessage("Contrasea:");

    // Set an EditText view to get user input   
    final EditText input = new EditText(getActivity());
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();
            //encriptamos el password y lo comparamos con el guardado
            /*  String hash = SimpleCrypto.md5(SimpleCrypto.MD5_KEY);
            if(hash.length()>0)
            {
             String encrypted= SimpleCrypto.encrypt(value, hash);
             if(encrypted.length()>0)
             {
                value = encrypted;
             }
            }*/
            if (usuarioDao.getPassword(value.trim())) //buscar en la BD la contrasea
            {
                Log.v("Detener Rastreo");
                getActivity().stopService(
                        new Intent(getActivity().getApplicationContext(), LocationManagement.class));

                alarmManager.cancel(Util.getPendingAlarmPanicButton(getActivity().getApplicationContext()));

                Toast.makeText(getActivity(), "Rastreo Detenido", Toast.LENGTH_SHORT).show();
                getActivity().finish();
                return;
            } else {
                Toast.makeText(getActivity(), "Contrasea Incorrecta", Toast.LENGTH_SHORT).show();
                return;
            }
        }
    });

    alert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {

            getActivity().finish();
            return;
        }
    });

    return alert.create();

}

From source file:ca.psiphon.ploggy.ActivitySendIdentityByNfc.java

@Override
public void onNdefPushComplete(NfcEvent nfcEvent) {
    final Context finalContext = this;
    runOnUiThread(new Runnable() {
        @Override/*w  w  w  . j  av  a 2 s  . com*/
        public void run() {
            Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            vibe.vibrate(100);
            Toast.makeText(finalContext, R.string.prompt_nfc_push_complete, Toast.LENGTH_LONG).show();
        }
    });
}

From source file:sintef.android.gravity.AlarmFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    sVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    sPhoneStateListener = new StatePhoneReceiver();
    sManager = ((TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE));

}

From source file:nortti.ru.gomoscow.GeofenceTransitionsIntentService.java

/**
 * Handles incoming intents./* w ww.  ja  v a2s .  c om*/
 * @param intent sent by Location Services. This Intent is provided to Location
 *               Services (inside a PendingIntent) when addGeofences() is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this, geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }

    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER
            || geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {

        // Get the geofences that were triggered. A single event can trigger multiple geofences.
        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();

        // Get the transition details as a String.
        String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geofenceTransition,
                triggeringGeofences);

        // Send notification and log the transition details.
        sendNotification(geofenceTransitionDetails);
        Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(500);
        Log.i(TAG, geofenceTransitionDetails);
    } else {
        // Log the error.
        Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition));
    }
}

From source file:org.frb.sf.frbn.GCMIntentService.java

@Override
protected void onMessage(Context context, Intent intent) {
    Log.i(TAG, "Received message");
    //String message = getString(R.string.gcm_message);
    //String message = getString(R.string.gcm_message) + ": " + intent.getExtras().getString("message");        

    String message = intent.getExtras().getString("message");
    String title = intent.getExtras().getString("title");
    String district = intent.getExtras().getString("district");
    String category = intent.getExtras().getString("category");
    String timestamp = intent.getExtras().getString("timestamp");

    //Date dt = new Date(Long.parseLong(timestamp, 10));

    MessageManager manager = new MessageManager(context);
    Message messageObj = new Message(message, title, category, district, Long.parseLong(timestamp));
    manager.addMessageItem(messageObj);/*from ww w .j  a v  a  2  s .com*/

    displayMessage(context, message);
    // notifies user
    generateNotification(context, messageObj);

    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(300);
}