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:io.github.meness.easyintro.EasyIntroCarouselFragment.java

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

    mAdapter = new EasyIntroPagerAdapter(getChildFragmentManager());
    mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
}

From source file:com.example.bluetooth_faster_connection.MainActivity.java

public void cancel() {
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.cancel();
}

From source file:com.aimfire.gallery.cardboard.PhotoActivity.java

/**
 * Sets the view to our CardboardView and initializes the transformation matrices we will use
 * to render our scene.//from www. j  ava 2s. c  o  m
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo);

    loadDisplayPrefs();

    /*
     * show error message in case no photo to be displayed
     */
    mOverlayView = (CardboardOverlayView) findViewById(R.id.overlay);

    Intent intent = getIntent();
    mIsMyMedia = intent.getBooleanExtra(MainConsts.EXTRA_MSG, false);
    mAssetColor = intent.getBooleanExtra(MainConsts.EXTRA_COLOR, true);
    Uri uri = intent.getData();

    if (uri != null) {
        String filePath = getFilePathFromUri(uri);

        if (filePath == null) {
            Toast.makeText(this, "Please open downloaded file from a file manager/explorer.", Toast.LENGTH_LONG)
                    .show();
            finish();
            return;
        }

        File f = new File(filePath);
        String fileName = f.getName();

        if (!filePath.endsWith("jpg")) {
            /*
             * something's wrong. no point in continuing
             */
            Toast.makeText(this, R.string.error_no_media, Toast.LENGTH_LONG).show();
            finish();
            return;
        }

        if (!filePath.contains(MainConsts.MEDIA_3D_ROOT_PATH)) {
            /*
             * in case we got here directly without going thru MainActivity
             * first, it's possible we don't have storage initialized yet.
             */
            if (!FileUtils.initStorage()) {
                Toast.makeText(this, R.string.error_accessing_storage, Toast.LENGTH_LONG).show();
                finish();
                return;
            }

            /*
             * we are launched from external apps by host or file type. move the
             * file to our "shared with me" dir. if rename fails, we will have
             * to do the actual copy (rather than rename, as we may be copying
             * the file from internal to external storage; or we don't have
             * write permission on the source directory)
             */
            String newFilePath = MainConsts.MEDIA_3D_SHARED_PATH + fileName;

            boolean success = false;
            try {
                File from = (new File(filePath));
                File to = (new File(newFilePath));
                success = from.renameTo(to);
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (!success) {
                FileUtils.copyFile(filePath, newFilePath);
            }

            filePath = newFilePath;

            /*
             * make MediaScanner aware of the new file
             */
            MediaScanner.addItemMediaList(filePath);
        }

        mAssetList = MediaScanner.getNonEmptyPhotoList(
                mIsMyMedia ? MainConsts.MEDIA_3D_SAVE_DIR : MainConsts.MEDIA_3D_SHARED_DIR);

        if ((mAssetList != null) && (mAssetList.size() > 0)) {
            mAssetInd = mAssetList.indexOf(filePath);
            if (mAssetInd == -1) {
                if (BuildConfig.DEBUG)
                    Log.e(TAG, "onCreate: specified photo not found, path=" + filePath);
                mAssetInd = 0;
            }
            if (BuildConfig.DEBUG)
                Log.d(TAG, "onCreate: mMovieList size=" + mAssetList.size() + ", index=" + mAssetInd);
        } else {
            if (BuildConfig.DEBUG)
                Log.e(TAG, "onCreate: no photo found!");
            mOverlayView.show3DToast("no photo found!", 5000);
        }
    } else {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "onCreate: no file uri specified in intent, are we " + "directly envoked by daydream?");

        mAssetList = MediaScanner.getNonEmptyPhotoList(
                mIsMyMedia ? MainConsts.MEDIA_3D_SAVE_DIR : MainConsts.MEDIA_3D_SHARED_DIR);

        if ((mAssetList != null) && (mAssetList.size() > 0)) {
            mAssetInd = 0;
            if (BuildConfig.DEBUG)
                Log.d(TAG, "onCreate: mAssetList size=" + mAssetList.size() + ", index=" + mAssetInd);
        } else {
            if (BuildConfig.DEBUG)
                Log.e(TAG, "onCreate: no photo found!");
            mOverlayView.show3DToast("no photo found!", 5000);
        }
    }

    /*
     * initialize cardboard related stuff
     */
    mCardboardView = (GvrView) findViewById(R.id.cardboard_view);
    mCardboardView.setRenderer(this);
    mCardboardView.setOnTouchListener(otl);

    mCardboardView.setTransitionViewEnabled(true);

    // Enable Cardboard-trigger feedback with Daydream headsets. This is a simple way of supporting
    // Daydream controller input for basic interactions using the existing Cardboard trigger API.
    mCardboardView.enableCardboardTriggerEmulation();

    setGvrView(mCardboardView);

    //debug
    //ScreenParams sp = mCardboardView.getScreenParams();
    //if(BuildConfig.DEBUG) Log.i(TAG, "ScreenParams width=" + sp.getWidth() + ", height=" + sp.getHeight());

    //mPicRotation = new float[16];
    //mPicFrustum = new float[16];
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    mHgd = new HeadGestureDetector(this);
}

From source file:eu.dirtyharry.androidopsiadmin.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (vibrate) {
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(50);/*from w  w w . j  av a2 s  .co  m*/
    }
    switch (item.getItemId()) {
    case R.id.menu_preferences:
        Log.d("Barcode", "display preferences");

        new Functions().displayPreferences(Main.this);
        break;
    case R.id.menu_changelog:
        cl.getFullLogDialog().show();
        // case R.id.menu_close:
        break;
    case R.id.menu_donate:
        Intent browse = new Intent(Intent.ACTION_VIEW, Uri
                .parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LJAYM3ND7MUQE"));
        startActivity(browse);
        //         Toast.makeText(Main.this, "Spenden!", Toast.LENGTH_LONG).show();
        // case R.id.menu_close:
        break;
    case R.id.menu_about:
        Intent about = new Intent(Main.this, ShowAbout.class);
        startActivity(about);
        //         Toast.makeText(Main.this, "ber", Toast.LENGTH_LONG).show();
        // case R.id.menu_close:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.rebo.app.TileMap.java

public void toggleCompass(Compass.Mode mode) {
    if (mode == null) {
        switch (mCompass.getMode()) {
        case OFF:
            mode = Compass.Mode.C2D;/*  ww  w  . j a va  2  s.  c o m*/
            break;
        default:
            mode = Compass.Mode.OFF;
            break;
        }
    }
    ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50);

    mCompass.setMode(mode);
    switch (mode) {
    case NAV:
        mCompassFab.setBackgroundTintList(ColorStateList
                .valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.colorAccent), 0.4f)));
        break;
    case C2D:
        mCompassFab.setBackgroundTintList(ColorStateList
                .valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.colorAccent), 0.4f)));
        //App.activity.showToastOnUiThread("Compass 2D");
        break;
    case C3D:
        mCompassFab.setBackgroundTintList(ColorStateList
                .valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.colorSecondAccent), 0.4f)));
        //App.activity.showToastOnUiThread("Compass 3D");
        break;
    case OFF:
        mCompassFab.setBackgroundTintList(
                ColorStateList.valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.white), 0.4f)));
        mCompass.setRotation(0);
        mCompass.setTilt(0);
        //App.activity.showToastOnUiThread("Manual");
        break;
    default:
        break;
    }

    App.map.updateMap(true);
}

From source file:com.skyousuke.ivtool.windows.MainWindow.java

private void showAppraisal() {
    appraisalButton.setOnClickListener(new OnClickListener() {
        @Override//from w ww .  j av a 2 s .  co  m
        public void onClick(View v) {
            Toast.makeText(context, "Long Press to Disable Appraisal", Toast.LENGTH_SHORT).show();
            Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            vb.vibrate(100);
        }
    });
    appraisalButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            lostFocus(500);
            if (hasAppraisalShow())
                hideAppraisal();
            return true;
        }
    });
    showTeamSelect();
    appraisalButton.setText(R.string.no_appraisal);
}

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  a 2  s .  c  o m*/
                    .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.skyousuke.ivtool.windows.MainWindow.java

private void hideAppraisal() {
    hideTeamSelect();//from w ww .j  a v  a  2 s  . c  o m
    hideRangePhraseSelect();
    hideBestStatSelect();
    hideMatchedStatSelect();
    hideStatSelect();

    appraisalButton.setText(R.string.appraisal);
    appraisalButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            lostFocus(500);
            if (!hasAppraisalShow())
                showAppraisal();
            return true;
        }
    });
    appraisalButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            lostFocus(500);
            Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            vb.vibrate(25);
            if (!hasAppraisalShow())
                showAppraisal();
        }
    });
}

From source file:system.info.reader.java

public String refresh() {
    //wifi//from w w  w . j  a  v  a2  s .c  o m
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null))
        Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress());
    else
        Properties.setInfo((String) propertyItems[4], "not avaiable");

    //String tmpsdcard = runCmd("df", "");
    //if (tmpsdcard != null) result += tmpsdcard + "\n\n";

    //setMap("dpi", dpi);

    //location
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    List ll = lm.getProviders(true);
    Boolean foundLoc = false;
    for (int i = 0; i < ll.size(); i++) {
        Location lo = lm.getLastKnownLocation((String) ll.get(i));
        if (lo != null) {
            Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude());
            foundLoc = true;
            break;
        }
    }
    if (!foundLoc)
        Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint));

    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List serviceList = am.getRunningServices(10000);
    serviceInfo = "";
    for (int i = 0; i < serviceList.size(); i++) {
        RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i);
        serviceInfo += rs.service.flattenToShortString() + "\n";
    }
    //result += getString(R.string.nService) + serviceList.size() + "\n";//service number

    psInfo = "";
    List appList = am.getRunningAppProcesses();
    for (int i = 0; i < appList.size(); i++) {
        RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i);
        psInfo += as.processName + "\n";
    }
    //result += getString(R.string.nProcess) + appList.size() + "\n";//process number

    taskInfo = "";
    List taskList = am.getRunningTasks(10000);
    for (int i = 0; i < taskList.size(); i++) {
        RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i);
        taskInfo += ts.baseActivity.flattenToShortString() + "\n";
    }
    //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number

    //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number

    //setMap(getString(R.string.nApk), nApk);

    //send message to let view redraw.
    Message msg = mRedrawHandler.obtainMessage();
    mRedrawHandler.sendMessage(msg);
    //properListItemAdapter.notifyDataSetChanged();//no use?

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(400);
    return "";
}

From source file:net.ustyugov.jtalk.Notify.java

public static void subscribtionNotify(Context context, String account, String from) {
    String soundPath = "";

    Intent i = new Intent(context, RosterActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra("subscribtion", true);
    i.putExtra("account", account);
    i.putExtra("jid", from);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String vibration = prefs.getString("vibrationMode", "1");
    if (!prefs.getBoolean("soundDisabled", false)) {
        if (vibration.equals("1") || vibration.equals("2") || vibration.equals("3")) {
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(200);//from www .  ja  v a 2 s .  co  m
        }
        soundPath = prefs.getString("ringtone", "");
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setAutoCancel(true);
    mBuilder.setOngoing(false);
    mBuilder.setSmallIcon(R.drawable.noface);
    mBuilder.setLights(0xFF0000FF, 2000, 3000);
    mBuilder.setContentTitle(from);
    mBuilder.setContentText("Subscription request");
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setTicker("Subscription request from " + from);
    if (!soundPath.isEmpty())
        mBuilder.setSound(Uri.parse(soundPath));

    NotificationManager mng = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mng.notify(Integer.parseInt((System.currentTimeMillis() + "").substring(7)), mBuilder.build());
}