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:biz.bokhorst.bpt.BPTService.java

@Override
public IBinder onBind(Intent intent) {
    // Start foreground service
    startForeground(1, getNotification(getString(R.string.Running)));

    // Instantiate helpers
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    databaseHelper = new DatabaseHelper(this);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    taskHandler = new Handler();
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BPT");
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Intent alarmIntent = new Intent("BPT_ALARM");
    pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmReceiver = new BPTAlarmReceiver();
    registerReceiver(alarmReceiver, new IntentFilter("BPT_ALARM"));

    bound = true;/*from   w  w w.  j  ava  2s .c  o  m*/
    return serverMessenger.getBinder();
}

From source file:nth.com.ares.utils.Utils.java

public static void vibrate(long[] pattern, Context context) {
    // Start without a delay
    // Vibrate for 100 milliseconds
    // Sleep for 1000 milliseconds
    // long[] pattern = {0, 100, 1000};

    // The first value indicates the number of milliseconds to wait before turning the vibrator ON: 0=Start without a delay
    // Each element then alternates between vibrate, sleep, vibrate, sleep...
    // long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100};
    Vibrator v1 = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    // The '-1' here means to vibrate once, as '-1' is out of bounds in the pattern array
    //     '0' here means to repeat indefinitely
    //     '0' is actually the index at which the pattern keeps repeating from (the start)
    //     To repeat the pattern from any other point, you could increase the index, e.g. '1'
    v1.vibrate(pattern, -1);//from ww w  . j ava  2s .c o m
}

From source file:com.nextgis.maplibui.fragment.CompassFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (null == getParentFragment()) {
        setRetainInstance(true);/* w w w.  j  ava  2 s .co  m*/
    }

    // reference to vibrator service
    mDeclination = 0;
    mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    if (!PermissionUtil.hasPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
            || !PermissionUtil.hasPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION))
        return;

    if (mCurrentLocation == null) {
        LocationManager locationManager = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);
        mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        if (mCurrentLocation == null) {
            mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }

    if (mCurrentLocation != null)
        mDeclination = getDeclination(mCurrentLocation, System.currentTimeMillis());
}

From source file:mirko.android.datetimepicker.date.DatePickerDialogSupport.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (savedInstanceState != null) {
        mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR));
        mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
        mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));
        mEnableClearButton = savedInstanceState.getBoolean(KEY_ENABLE_CLEAR_BUTTON, false);
    }/*  w w w. j  a va 2  s  .  c o  m*/
}

From source file:com.klinker.android.twitter.services.SendQueue.java

public void finishedTweetingNotification() {
    try {//from  w  w  w  . ja v  a 2 s .  c o  m
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext)
                .setSmallIcon(R.drawable.ic_stat_icon)
                .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false)
                .setTicker(getResources().getString(R.string.tweet_success));

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

        stopForeground(true);

        NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext
                .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 to activity
    }
}

From source file:de.pixart.messenger.ui.ScanActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    setContentView(R.layout.activity_scan);
    scannerView = findViewById(R.id.scan_activity_mask);
    previewView = findViewById(R.id.scan_activity_preview);
    previewView.setSurfaceTextureListener(this);

    cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND);
    cameraThread.start();/*from   w  w w  . j  av a 2  s. co  m*/
    cameraHandler = new Handler(cameraThread.getLooper());
}

From source file:com.intel.xdk.notification.Notification.java

public void vibrate() {
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(500);
}

From source file:de.ub0r.android.websms.WebSMSReceiver.java

/**
 * Handle result of message sending.//  www  .  j a  va 2  s .c o m
 *
 * @param context context
 * @param specs   {@link de.ub0r.android.websms.connector.common.ConnectorSpec}
 * @param command {@link de.ub0r.android.websms.connector.common.ConnectorCommand}
 */
static void handleSendCommand(final Context context, final ConnectorSpec specs,
        final ConnectorCommand command) {

    boolean isHandled = false;
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);

    if (!specs.hasStatus(ConnectorSpec.STATUS_ERROR)) {
        // Sent successfully
        saveMessage(context, specs, command, MESSAGE_TYPE_SENT);
        if (p.getBoolean(WebSMS.PREFS_SEND_VIBRATE, false)) {
            final Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            if (v != null) {
                v.vibrate(VIBRATOR_SEND);
                v.cancel();
            }
        }
        isHandled = true;
        messageCompleted(context, command);
    }

    if (!isHandled) {
        // Resend if possible (network might be down temporarily or an odd
        // failure on the provider's web side)
        final int maxResendCount = de.ub0r.android.lib.Utils
                .parseInt(p.getString(WebSMS.PREFS_MAX_RESEND_COUNT, "0"), 0);
        if (maxResendCount > 0) {
            int wasResendCount = command.getResendCount();

            if (wasResendCount < maxResendCount && !isResendCancelled(command.getMsgId())) {

                // schedule resend
                command.setResendCount(wasResendCount + 1);
                displayResendingNotification(context, command);
                scheduleMessageResend(context, specs, command);

                isHandled = true;
            }
        }
    }

    if (!isHandled) {
        // Display notification if sending failed
        displaySendingFailedNotification(context, specs, command);
        messageCompleted(context, command);
    }
}

From source file:com.google.android.gms.location.sample.locationupdates.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    httpQueue = Volley.newRequestQueue(this);

    // Locate the UI widgets.
    mStartUpdatesButton = (ImageView) findViewById(R.id.start_updates_button);
    mStopUpdatesButton = (ImageView) findViewById(R.id.stop_updates_button);
    mLatitudeTextView = (TextView) findViewById(R.id.latitude_text);
    mLongitudeTextView = (TextView) findViewById(R.id.longitude_text);
    mLastUpdateTimeTextView = (TextView) findViewById(R.id.last_update_time_text);
    myMainLayout = (LinearLayout) findViewById(R.id.myMainLayout);
    // Set labels.
    mLatitudeLabel = getResources().getString(R.string.latitude_label);
    mLongitudeLabel = getResources().getString(R.string.longitude_label);
    mLastUpdateTimeLabel = getResources().getString(R.string.last_update_time_label);

    mDetector = new GestureDetectorCompat(this, this);
    mDetector.setOnDoubleTapListener(this);

    mRequestingLocationUpdates = false;//from  w  w w.  j a  v  a 2  s  . com
    mLastUpdateTime = "";

    // Update values using data stored in the Bundle.
    updateValuesFromBundle(savedInstanceState);

    // Kick off the process of building a GoogleApiClient and requesting the LocationServices
    // API.
    buildGoogleApiClient();

    myVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
}

From source file:org.thoughtcrime.securesms.VerifyIdentityActivity.java

@Override
public void onQrDataFound(final String data) {
    Util.runOnMain(new Runnable() {
        @Override//from   w ww . j  av a  2 s  . c om
        public void run() {
            ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50);

            getSupportFragmentManager().popBackStack();
            displayFragment.setScannedFingerprint(data);
        }
    });
}