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.google.android.apps.mytracks.util.Api11Adapter.java

@Override
public void configureMapViewContextualMenu(final SupportMapFragment fragment,
        final MapContextActionCallback callback) {

    fragment.getMap().setOnMarkerDragListener(new OnMarkerDragListener() {
        private LatLng position;
        private Marker currentMarker;
        private ActionMode actionMode;

        @Override//from  www .  ja  v  a2 s  .  c  o  m
        public void onMarkerDragStart(Marker marker) {
            if (null == currentMarker || !marker.getId().equals(currentMarker.getId())) {
                if (null != actionMode) {
                    actionMode.finish();
                }

                position = marker.getPosition();
                currentMarker = marker;
                marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
            }

            ((Vibrator) fragment.getActivity().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50);
        }

        @Override
        public void onMarkerDragEnd(final Marker marker) {
            if (actionMode != null) {
                if (null == currentMarker || !marker.getId().equals(currentMarker.getId())) {
                    actionMode.finish();
                } else {
                    ((Vibrator) fragment.getActivity().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50);
                    return;
                }
            }
            ((Vibrator) fragment.getActivity().getSystemService(Context.VIBRATOR_SERVICE))
                    .vibrate(new long[] { 0, 50, 100, 50, 100 }, -1);
            actionMode = fragment.getActivity().startActionMode(new ActionMode.Callback() {
                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    callback.onCreate(menu);
                    return true;
                }

                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    callback.onPrepare(menu, marker);
                    // Return true to indicate change
                    return true;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                    actionMode = null;
                    if (null != position) {
                        marker.setPosition(position);
                        position = null;
                        currentMarker = null;
                    }
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    mode.finish();

                    if (callback.onClick(item, marker)) {
                        position = null;
                        return true;
                    }

                    return false;
                }
            });

        }

        @Override
        public void onMarkerDrag(Marker paramMarker) {
        }
    });

    fragment.getMap().setOnMapLongClickListener(new OnMapLongClickListener() {
        private ActionMode actionMode;
        private Marker marker;

        @Override
        public void onMapLongClick(final LatLng point) {
            if (actionMode != null) {
                actionMode.finish();
            }

            marker = fragment.getMap().addMarker(new MarkerOptions().position(point).title("New location")
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));

            actionMode = fragment.getActivity().startActionMode(new ActionMode.Callback() {
                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    callback.onCreate(menu);
                    return true;
                }

                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    callback.onPrepare(menu, marker);
                    // Return true to indicate change
                    return true;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                    actionMode = null;
                    if (null != marker) {
                        marker.remove();
                    }
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    mode.finish();
                    return callback.onClick(item, marker);
                }
            });
        }
    });
}

From source file:se.erichansander.retrotimer.TimerKlaxon.java

@Override
public void onCreate() {
    TinyTracelog.trace("3");

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    // Listen for incoming calls to kill the alarm.
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    if (android.os.Build.VERSION.SDK_INT >= 8) {
        mAudioFocusHelper = new AudioFocusHelper(this);
    } else {// w  w  w .j  av  a2  s .c o m
        mAudioFocusHelper = null;
    }

    WakeLockHolder.acquireScreenCpuWakeLock(this);
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Vibrates the device for the specified amount of time.
 * //from ww  w  . j a va 2s . c o m
 * @param time
 *           Time to vibrate in ms.
 */
public void vibrate(long time) {
    // Start the vibration, 0 defaults to half a second.
    if (time == 0) {
        time = 500;
    }
    Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(time);
}

From source file:com.miljin.setminder.TimerService.java

public void broadcastDone() {
    //Activate alarm when timer is finished, depending on settings
    SharedPreferences settingsPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (settingsPrefs.getBoolean("enable_alarm_vibrate", false)) {
        vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        long[] vibratePattern = new long[] { 500, 500, 500, 500, 2500, 500, 500, 500, 2500, 500, 500, 500 };
        vibrator.vibrate(vibratePattern, -1);
    }/*from  w ww  .  ja  va2s  .  c  o m*/
    if (settingsPrefs.getBoolean("enable_alarm_sound", false)) {
        alarmPlayer = MediaPlayer.create(this, com.miljin.setminder.R.raw.alarm1);
        alarmPlayer.start();
    }

    notificationManager.cancelAll();

    //send broadcast
    Intent tickIntent = new Intent(MainActivity.ACTION_RECEIVE_TIMER_DONE);
    tickIntent.putExtra(EXTRA_TIMER_DONE, true);
    sendBroadcast(tickIntent);

    stopSelf();
}

From source file:javax.microedition.lcdui.Display.java

public static boolean vibrate(int duration) {
    try {/*from w ww .ja v a  2s  .  co  m*/
        if (vibrator == null) {
            vibrator = (Vibrator) ContextHolder.getContext().getSystemService(Context.VIBRATOR_SERVICE);
        }

        vibrator.vibrate(duration);

        return true;
    } catch (Throwable t) {
        return false;
    }
}

From source file:com.example.aaron.test.MyGLSurfaceView.java

public MyGLSurfaceView(Context context, float f[], turtle turtleList[]) {
    super(context);
    context1 = context;/*from  w ww  . j  a v  a2 s  .c o  m*/
    v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vor = new Voronoi(.001);
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    width1 = metrics.widthPixels;
    height1 = metrics.heightPixels;
    mapLeft = (width1 - 100) / height1;
    mapTop = (height1 - 5) / height1;
    mapBottom = -(height1 - 5) / height1;

    poseData = f;
    // Create an OpenGL ES 2.0 context.
    setEGLContextClientVersion(2);
    for (int i = 0; i < maxBots; i++) {
        tList[i] = new turtle();
        state[i] = 0;
    }

    // Set the Renderer for drawing on the GLSurfaceView
    mRenderer = new MyGLRenderer(context, f, tList, width1, height1);
    //float posTemp[]=f;
    setEGLConfigChooser(new MultisampleConfigChooser());
    setRenderer(mRenderer);

    // Render the view only when there is a change in the drawing data
    setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

}

From source file:com.phonegap.Notification.java

/**
 * Vibrates the device for the specified amount of time.
 * //from w w  w.ja  v a  2s. c  o  m
 * @param time         Time to vibrate in ms.
 */
public void vibrate(long time) {
    // Start the vibration, 0 defaults to half a second.
    if (time == 0) {
        time = 500;
    }
    Vibrator vibrator = (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(time);
}

From source file:de.dreier.mytargets.MainActivity.java

@Override
public void onEndFinished(final List<Shot> shotList, boolean remote) {
    confirm.setVisibility(View.VISIBLE);
    confirm.setTotalTimeMs(2500);//ww  w .j a v  a2  s  .c o m
    confirm.start();
    confirm.setListener(new DelayedConfirmationView.DelayedConfirmationListener() {
        @Override
        public void onTimerSelected(View view) {
            mTarget.setEnd(new End(round.shotsPerEnd, 0));
            confirm.setVisibility(View.INVISIBLE);
            confirm.reset();
        }

        @Override
        public void onTimerFinished(View view) {
            Intent intent = new Intent(MainActivity.this, ConfirmationActivity.class);
            intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.SUCCESS_ANIMATION);
            intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE, getString(R.string.saved));
            startActivity(intent);
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(200);
            finish();
            sendMessage(shotList);
        }
    });
}

From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java

public static void vibrate(Context context, int durationMS) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(durationMS);/*from  www.ja v  a2s  .co m*/
}

From source file:com.example.isaac.nileswestlitcenter.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/* w  w  w .  j a  v a  2 s . c o m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {

        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {

            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.

        }
        if (extras.getString("subject") != null) {
            if (intent.getExtras().getString("delete") != null) {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    //delete from arraylist
                    for (int i = 0; i < storeWhileScreenOff.size(); i++) {
                        if (storeWhileScreenOff.get(i)[1] == extras.getString("subject")
                                && storeWhileScreenOff.get(i)[2] == extras.getString("name")) {
                            storeWhileScreenOff.remove(i);
                            return;
                        }
                    }
                    //not in stored list, but on screen
                    storeWhileScreenOff.add(
                            new String[] { "true", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(true, extras.getString("subject"), extras.getString("name"));
                    //                    MainActivity.deleteStudentFromList(extras.getString("subject"),extras.getString("name"));
                    //                   or MainActivity.delete(extras.getInt("id"));
                }
            } else {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    storeWhileScreenOff.add(
                            new String[] { "false", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(false, extras.getString("subject"), extras.getString("name"));
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotification(extras.getString("subject"), extras.getString("name"));
                Vibrator v = (Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                // Vibrate for 500 milliseconds
                v.vibrate(1000);
                ((PowerManager) getSystemService(POWER_SERVICE))
                        .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                                "TAG")
                        .acquire();
                Log.i(TAG, "Received: " + extras.toString());

            }

        }
    }

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}