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.mattprecious.notisync.profile.SecondaryCustomProfileActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void checkForVibrator() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) {
            vibrateCheckBox.setVisibility(View.GONE);
        }//from   www  .  j  ava  2  s. co  m
    }
}

From source file:io.jawg.osmcontributor.OsmTemplateApplication.java

public void notificationVibration() {
    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    // Vibrate for 500 milliseconds

    long[] pattern = { 100, 100 };
    v.vibrate(200);//w w  w  .j a  va 2 s  .com
}

From source file:com.android.camera2.its.ItsService.java

@Override
public void onCreate() {
    try {// w  ww .  j a  va  2  s  .  c om
        mThreadExitFlag = false;

        // Get handle to camera manager.
        mCameraManager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE);
        if (mCameraManager == null) {
            throw new ItsException("Failed to connect to camera manager");
        }
        mBlockingCameraManager = new BlockingCameraManager(mCameraManager);
        mCameraListener = new BlockingStateCallback();

        // Register for motion events.
        mEvents = new LinkedList<MySensorEvent>();
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
        mSensorManager.registerListener(this, mAccelSensor, SensorManager.SENSOR_DELAY_FASTEST);
        mSensorManager.registerListener(this, mMagSensor, SensorManager.SENSOR_DELAY_FASTEST);
        mSensorManager.registerListener(this, mGyroSensor, SensorManager.SENSOR_DELAY_FASTEST);

        // Get a handle to the system vibrator.
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

        // Create threads to receive images and save them.
        for (int i = 0; i < MAX_NUM_OUTPUT_SURFACES; i++) {
            mSaveThreads[i] = new HandlerThread("SaveThread" + i);
            mSaveThreads[i].start();
            mSaveHandlers[i] = new Handler(mSaveThreads[i].getLooper());
        }

        // Create a thread to handle object serialization.
        (new Thread(new SerializerRunnable())).start();
        ;

        // Create a thread to receive capture results and process them.
        mResultThread = new HandlerThread("ResultThread");
        mResultThread.start();
        mResultHandler = new Handler(mResultThread.getLooper());

        // Create a thread for the camera device.
        mCameraThread = new HandlerThread("ItsCameraThread");
        mCameraThread.start();
        mCameraHandler = new Handler(mCameraThread.getLooper());

        // Create a thread to process commands, listening on a TCP socket.
        mSocketRunnableObj = new SocketRunnable();
        (new Thread(mSocketRunnableObj)).start();
    } catch (ItsException e) {
        Logt.e(TAG, "Service failed to start: ", e);
    }
}

From source file:me.heron.safefoodscanner.activity.MainActivity.java

private void buzz() {
    Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(Constants.BUZZ_LENGTH_MILLISECOND);
}

From source file:dev.coatl.co.Urband_IMU_Recorder.presenter.fragments.FragmentMenuPanel.java

@Override
public void onClick(View v) {
    /* Gets the ID of the clicked object */
    int id = v.getId();
    Log.i(TAG, Integer.toString(id));
    /* Gets the activity of running */
    ActivityHomePanel activity = (ActivityHomePanel) getActivity();

    /* Determines what to do according to the ID */
    final String actualUser_str = Urband_Preferences
            .getActualUser(getActivity(), Urband_Preferences.USER_NUMBER).toString();
    final String actualSession_actNum_str = Urband_Preferences
            .getActualSession(getActivity(), Urband_Preferences.ACTIVITY_NUMBER).toString();
    if (id == R.id.button_recording) {
        /* Gets USER_NUM, ACTIVITY_NUM and GESTURE_NUM from preferences and store them as strings for file creation */
        miActualUser = actualUser_str;/*from   w  ww .j av  a  2s.  c  om*/
        miActivitySession = actualSession_actNum_str;
        miGestureSession = Urband_Preferences.getActualSession(getActivity(), Urband_Preferences.GESTURE_NUMBER)
                .toString();

        /* Generates a vibrator object to control the device vibration */
        Vibrator vib = (Vibrator) activity.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);

        /* Determines if starting or ending recording */
        if (!Urband_Preferences.getConfig(getActivity(), Urband_Preferences.isRecordingSession)) {
            /* Generates a file name according to session type selected */
            Toast.makeText(activity, "Se graba una actividad", Toast.LENGTH_LONG).show();
            file = new File(dir, "Urband_U" + miActualUser + "_A" + miActivitySession + ".txt");

            /* Creates the file acording to actual user and type of session */
            try {
                miFile = new FileWriter(file, true);
            } catch (IOException e) {
                e.printStackTrace();
            }

            /* Generates a vibration pattern before start recording to notify the user */
            try {
                vib.vibrate(100);
                Thread.sleep(900);
                vib.vibrate(100);
                Thread.sleep(900);
                vib.vibrate(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            /* Enable recordNow flag */
            recordNow = true;
        } else /* ending recording */
        {
            /* Disable recordNow flag */
            recordNow = false;

            /* Vibrates to notify the user */
            vib.vibrate(300);

            /* Writes last data and closes the file */
            try {
                if (miFile != null) {
                    miFile.flush();
                    miFile.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        Urband_Preferences.setConfig(getActivity(), Urband_Preferences.isRecordingSession,
                !Urband_Preferences.getConfig(getActivity(), Urband_Preferences.isRecordingSession));
        Log.v("Esta grabando?: ",
                Urband_Preferences.getConfig(getActivity(), Urband_Preferences.isRecordingSession) ? "Si"
                        : "No");
        recordingMovementSession();
    } else if (id == R.id.button_plus_actividad) /* Button adds one to the count of activities */
    {
        /* Gets ACTIVITY_NUM from preferences and adds one to the result */
        BluetoothGattService batteryService = BluetoothService.mBluetoothGatt
                .getService(UUID.fromString(BluetoothGattAttributes.GESTURE_SERVICE));
        if (batteryService == null) {
            Log.i("TAG", "fifo service not found! FRAGMENTMENUPANEL");
            return;
        }
        BluetoothGattCharacteristic FIFO = batteryService
                .getCharacteristic(UUID.fromString(BluetoothGattAttributes.GESTURE_DEBUG_CHAR09));
        if (FIFO == null) {
            Log.i("TAG", "fifo level not found! FRAGMENTMENUPANEL");
            return;
        }
        BluetoothService.mBluetoothGatt.readCharacteristic(FIFO);
        cuenta_actividades = Urband_Preferences.getActualSession(getActivity(),
                Urband_Preferences.ACTIVITY_NUMBER) + 1;

        if (cuenta_actividades > 40) {
            cuenta_actividades = 40;
        }
        /* Updates ACTIVITY_NUM into preferences */
        Urband_Preferences.setActualSession(getActivity(), Urband_Preferences.ACTIVITY_NUMBER,
                cuenta_actividades);
        /* Set textView with the new value */
        Actividades.setText(actualSession_actNum_str + " de 40");
        Log.i("Session de Actividad: ", actualSession_actNum_str);
    }

    else if (id == R.id.button_minus_actividad) {
        cuenta_actividades = Urband_Preferences.getActualUser(getActivity(), Urband_Preferences.ACTIVITY_NUMBER)
                - 1;
        if (cuenta_actividades <= 0) {
            cuenta_actividades = 1;
        }
        Urband_Preferences.setActualUser(getActivity(), Urband_Preferences.ACTIVITY_NUMBER, cuenta_actividades);
        final String actualUser_actnum = Urband_Preferences
                .getActualUser(getActivity(), Urband_Preferences.ACTIVITY_NUMBER).toString();
        Actividades.setText(actualUser_actnum + " de 40");
        Log.v("Session de Actividad: ", actualUser_actnum);
    }

    else if (id == R.id.button_plus_user) {
        cuenta_usuarios = Urband_Preferences.getActualUser(getActivity(), Urband_Preferences.USER_NUMBER) + 1;
        Urband_Preferences.setActualUser(getActivity(), Urband_Preferences.USER_NUMBER, cuenta_usuarios);
        Usuarios.setText(actualUser_str);
        Log.v("Usuario: ", actualUser_str);
    }

    else if (id == R.id.button_minus_user) {
        cuenta_usuarios = Urband_Preferences.getActualUser(getActivity(), Urband_Preferences.USER_NUMBER) - 1;
        if (cuenta_usuarios == 0) {
            cuenta_usuarios = 1;
        }
        Urband_Preferences.setActualUser(getActivity(), Urband_Preferences.USER_NUMBER, cuenta_usuarios);
        Usuarios.setText(actualUser_str);
        Log.v("Usuario: ", actualUser_str);
    }

    /* Determines which is the actual session and display description on TextView sessionDescription */
    int indexActivity = Urband_Preferences.getActualSession(getActivity(), Urband_Preferences.ACTIVITY_NUMBER)
            - 1;
    sessionDescription.setText(ActivitySessionsDescription[indexActivity]);
}

From source file:com.nextgis.mobile.fragment.MapFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//w ww  .j  a  va  2  s .com
    mActivity = (MainActivity) getActivity();
    mTolerancePX = mActivity.getResources().getDisplayMetrics().density * ConstantsUI.TOLERANCE_DP;

    mPreferences = PreferenceManager.getDefaultSharedPreferences(mActivity);
    mApp = (MainApplication) mActivity.getApplication();
    mVibrator = (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE);
    mGpsEventSource = mApp.getGpsEventSource();

    mMap = new MapViewOverlays(mActivity, (MapDrawable) mApp.getMap());
    mMap.setId(R.id.map_view);

    mEditLayerOverlay = new EditLayerOverlay(mActivity, mMap);
}

From source file:com.ght.cerberus.StatusFragment.java

private void raiseAlarm() {
    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
    // Vibrate for 500 milliseconds
    v.vibrate(500);
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void handleChild(View child, int columnCount, LinearLayout keyContainer, int keyHeight) {
    child.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.amharic_key_bg));
    child.setOnTouchListener(new OnTouchListener() {
        @Override//from  w  w  w  .jav a 2 s  .c om
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (shouldVibrate) {
                    Vibrator vb = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    if (vb != null) {
                        vb.vibrate(20);
                    }
                }
                mPressedKeyView = v;
                mHandler.removeCallbacks(mKeyPressRunnable);
                mHandler.postAtTime(mKeyPressRunnable, mPressedKeyView,
                        SystemClock.uptimeMillis() + INITIAL_INTERVAL);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_OUTSIDE:
                mHandler.removeCallbacksAndMessages(mPressedKeyView);
                mPressedKeyView = null;
                mNormalInterval = 100;
                break;
            }
            return false;
        }
    });
    child.setOnClickListener(mKeyClickListener);
    int margin = getCustomSize(1.5f);
    int tempKeyHeight = keyHeight - (margin * 2);
    LayoutParams params = new LayoutParams(0, tempKeyHeight, columnCount);
    params.setMargins(margin, margin, margin, margin);
    keyContainer.addView(child, params);
}

From source file:com.nxp.nfc_demo.activities.MainActivity.java

@Override
protected void onNewIntent(Intent nfc_intent) {
    super.onNewIntent(nfc_intent);
    // Set the pattern for vibration
    long pattern[] = { 0, 100 };

    // Set the initial auth parameters
    mAuthStatus = AuthStatus.Disabled.getValue();
    mPassword = null;// ww w .ja va  2  s.c om

    // Vibrate on new Intent
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(pattern, -1);
    doProcess(nfc_intent);
}

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
    }// ww  w  .  j a v  a  2 s.c om
}