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:org.lyricue.android.Lyricue.java

/**
 * Called when the activity is first created.
 *///from www.  j av  a2 s . c o  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate()");
    activity = this;
    setContentView(R.layout.main);
    FragmentManager fragman = getSupportFragmentManager();
    vib = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);

    if (savedInstanceState != null) {
        for (Fragment frag : fragman.getFragments()) {
            if (frag != null) {
                Log.d(TAG, frag.toString());
                Log.d(TAG, frag.getClass().getName());
                fragments.put(frag.getClass().getName(), frag);
            }
        }
        hosts = (HostItem[]) savedInstanceState.getParcelableArray("hosts");
        profile = savedInstanceState.getString("profile");
        playlistid = savedInstanceState.getLong("playlistid");
        playlists_text = savedInstanceState.getStringArray("playlists_text");
        playlists_id = savedInstanceState.getLongArray("playlists_id");
        bibles_text = savedInstanceState.getStringArray("bibles_text");
        bibles_id = savedInstanceState.getStringArray("bibles_id");
        bibles_type = savedInstanceState.getStringArray("bibles_type");
        ld = new LyricueDisplay(hosts);
    }

    LyricuePagerAdapter adapter = new LyricuePagerAdapter(fragman, activity, activity);
    pager = (ViewPager) findViewById(R.id.viewpager);
    pager.setAdapter(adapter);

    actionBar = getSupportActionBar();
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // When the tab is selected, switch to the
            // corresponding page in the ViewPager.
            pager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
        }

        @Override
        public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
        }
    };

    Tab controlTab = actionBar.newTab().setText("Control").setTabListener(tabListener);
    actionBar.addTab(actionBar.newTab().setText(R.string.playlist).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.available).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.bible).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.display).setTabListener(tabListener));
    actionBar.addTab(controlTab);

    pager.setOffscreenPageLimit(actionBar.getTabCount());

    Resources res = getResources();
    Configuration conf = res.getConfiguration();
    boolean isLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE);
    boolean isLarge = (conf.screenLayout & 0x4) == 0x4;
    Log.d(TAG, "Status:" + isLarge + ":" + isLandscape);
    if (isLarge && isLandscape) {
        activity.setQuickBar(false);
        actionBar.removeTab(controlTab);
        pager.setCurrentItem(0);
    } else {
        pager.setCurrentItem(4);
    }
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getSupportActionBar().setSelectedNavigationItem(position);
        }
    });

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.RED);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    thumbnail_width = Math.min(displaymetrics.widthPixels, displaymetrics.heightPixels) / 2;
    if (profile.equals("")) {
        getPrefs();
    }
}

From source file:de.schildbach.wallet.ui.ScanActivity.java

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

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

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

    cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND);
    cameraThread.start();//  w  ww .j  a  v a2 s . c o  m
    cameraHandler = new Handler(cameraThread.getLooper());

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 0);
}

From source file:com.nextgis.mobile.forms.CompassFragment.java

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

    // reference to vibrator service
    vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);

    // vibrate or not?
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    vibrationOn = prefs.getBoolean("compass_vibration", true);

    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);
        }/*w w  w  .j a va  2 s  .c o  m*/
    }
    mDeclination = 0;

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

    sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_NORMAL);

    getActivity().registerReceiver(compassBroadcastReceiver, new IntentFilter(ACTION_COMPASS_UPDATES));

    Log.d(TAG, "CompassActivity: onCreate");
}

From source file:com.google.mist.plot.MainActivity.java

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

    mDecorView = getWindow().getDecorView();
    mVRPlotView = new VRPlotView(this, null);
    addContentView(mVRPlotView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    mSensorData = new ArrayList<float[]>();
    mSensorTime = new ArrayList<Long>();
    mSensorAccuracy = new ArrayList<Integer>();

    mAccuracyData = new ArrayList<Integer>();
    mAccuracyTime = new ArrayList<Long>();

    mRotationData = new ArrayList<float[]>();
    mRotationTime = new ArrayList<Long>();

    mPullDetector = new MagnetPullDetector(this);
    mPullDetector.setOnPullListener(this);

    mPositivesTime = new ArrayList<Long>();
    mPositivesData = new ArrayList<Integer>();

    mVibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);

    mRecordRotation = false; // You can record rotation here in addition to magnetometer readings.
    if (mRecordRotation) {
        mRotationDetector = new RotationDetector(this);
        mRotationDetector.setRotationListener(this);
    }/*from   www.j  a  v a2 s .co m*/

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

From source file:com.wordpress.httpstheredefiningproductions.phonefinder.recorder.java

@Override
public void onCreate() {
    super.onCreate();
    //get the things above linked up to actual things in the app
    v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
    mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());

}

From source file:com.zuluindia.watchpresenter.MonitorVolumeKeyPress.java

public void onCreate() {
    super.onCreate();
    settings = getSharedPreferences(Constants.SETTINGS_NAME, MODE_PRIVATE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    Log.d(LOGCAT, "Service Started!");
    objPlayer = MediaPlayer.create(this, com.zuluindia.watchpresenter.R.raw.silence);
    objPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    objPlayer.setLooping(true);// www.  j  av a2  s.  c o m
    timer = new Timer();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    midVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 2;
    resetVolume();
}

From source file:jorge.tolentino.empty.Empty.java

/**
 * Vibrates the device with a given pattern.
 *
 * @param pattern     Pattern with which to vibrate the device.
 *                    Pass in an array of longs that
 *                    are the durations for which to
 *                    turn on or off the vibrator in
 *                    milliseconds. The first value
 *                    indicates the number of milliseconds
 *                    to wait before turning the vibrator
 *                    on. The next value indicates the
 *                    number of milliseconds for which
 *                    to keep the vibrator on before
 *                    turning it off. Subsequent values
 *                    alternate between durations in
 *                    milliseconds to turn the vibrator
 *                    off or to turn the vibrator on.
 *
 * @param repeat      Optional index into the pattern array at which
 *                    to start repeating, or -1 for no repetition (default).
 *///from   w  w w  . j  a  va2  s  .co m
public void vibrateWithPattern(long[] pattern, int repeat) {
    Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(pattern, repeat);
}

From source file:com.cybrosys.currency.CurrencyMain.java

public void vibrate() {
    Boolean isVibe = sharedPrefs.getBoolean("prefVibe", false);
    Vibrator vibe = (Vibrator) PalmCalcActivity.ctx.getSystemService(Context.VIBRATOR_SERVICE);
    if (isVibe) {
        vibe.vibrate(100);/*from  w w  w  .ja  v a  2  s  .  c  o  m*/
    }
}

From source file:org.schabi.terminightor.NightKillerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent != null) {
        Log.d(TAG, "get data from intent");
        try {/*from  w  w w.jav  a 2 s .  c o m*/
            alarm = Alarm.getFromCursorItem(AlarmDBOpenHelper.getAlarmDBOpenHelper(this)
                    .getReadableItem(intent.getLongExtra(Alarm.ID, -1)));
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (!alarm.isRepeatEnabled()) {
            alarm.setEnabled(false);
            AlarmDBOpenHelper.getAlarmDBOpenHelper(this).update(alarm);
        }

        indicator.saveAlarm(alarm);
    } else {
        Log.d(TAG, "get data from indicator");
        try {
            alarm = indicator.restoreAlarm(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = { 1000, 200, 200, 200 };
    if (alarm.isVibrate()) {
        vibrator.vibrate(pattern, 0);
    }

    mediaPlayer = setupNewMediaPlayer(alarm);
    mediaPlayer.start();

    alarmActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
            | Intent.FLAG_FROM_BACKGROUND);
    alarmActivityIntent.putExtra(Alarm.ID, alarm.getId());
    alarmActivityIntent.putExtra(Alarm.NAME, alarm.getName());
    alarmActivityIntent.putExtra(Alarm.NFC_TAG_ID, alarm.getNfcTagId());
    this.startActivity(alarmActivityIntent);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification n = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.alarm))
            .setContentText(alarm.getName()).setSmallIcon(R.drawable.terminightor_notify_small).setOngoing(true)
            .build();
    n.contentIntent = PendingIntent.getActivity(this.getApplicationContext(),
            SpecialPendingIds.OPEN_ALARM_ACTIVITY, alarmActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    nm.notify(NOTIFICATION_ID, n);

    return START_STICKY;
}

From source file:nl.endran.scrumpoker.fragments.cardselection.QuickSettingsFragment.java

private void installShakeListener() {
    shakeManager.start(new ShakeManager.Listener() {
        @Override//  ww  w .  j av  a 2s.com
        public void onShake() {
            Context context = getContext();
            if (context != null && tracking != null) {
                Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(500);
                tracking.logCustom(new CustomEvent("Reveal").putCustomAttribute("Type", "Shake"));
                informListener();
            }
        }
    });
}