android.os.Vibrator Java Examples
The following examples show how to use
android.os.Vibrator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaldConstraintLayoutButton.java From BaldPhone with Apache License 2.0 | 6 votes |
@SuppressLint("ClickableViewAccessibility") public BaldConstraintLayoutButton(Context context) { super(context); this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE); this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE); this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE); this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE); this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null; longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null; if (longPresses) if (longPressesShorter) { baldButtonTouchListener = new BaldButtonTouchListener(this); super.setOnTouchListener(baldButtonTouchListener); super.setOnClickListener(D.EMPTY_CLICK_LISTENER); } else { super.setOnLongClickListener(this); super.setOnClickListener(this); } else super.setOnClickListener(this); }
Example #2
Source File: ForceTouchListener.java From timecat with Apache License 2.0 | 6 votes |
/** * Handle progressive pressure on the screen */ private void progressiveForceTouch(){ runnable = new Runnable() { @Override public void run() { if(getPressure() >= pressureLimit && !alreadyExecuted && isProgressive) { if(isVibrate) { Vibrator vibr = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibr.vibrate(millisToVibrate); } forceTouchExecution.onForceTouch(); alreadyExecuted = true; } } }; timer.scheduleAtFixedRate(runnable, 1); }
Example #3
Source File: AlarmReceiver.java From fastnfitness with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onReceive(Context context, Intent arg1) { long[] pattern = { 0, // Start immediately 500, 500, 500, 500, 500}; Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createWaveform(pattern, -1)); } else { //deprecated in API 26 if (v != null) { v.vibrate(pattern, -1); } } }
Example #4
Source File: BaldButton.java From BaldPhone with Apache License 2.0 | 6 votes |
public BaldButton(Context context, @Nullable AttributeSet attrs) { super(context, attrs); this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE); this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE); this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE); this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE); this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null; longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null; if (longPresses) if (longPressesShorter) { baldButtonTouchListener = new BaldButtonTouchListener(this); super.setOnTouchListener(baldButtonTouchListener); super.setOnClickListener(D.EMPTY_CLICK_LISTENER); } else { super.setOnLongClickListener(this); super.setOnClickListener(this); } else super.setOnClickListener(this); }
Example #5
Source File: Receiver1.java From coursera-android with MIT License | 6 votes |
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "INTENT RECEIVED"); if (isOrderedBroadcast()) { Log.i(TAG, "Calling abortBroadcast()"); abortBroadcast(); } Vibrator v = (Vibrator) context .getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); Toast.makeText(context, "INTENT RECEIVED by Receiver1", Toast.LENGTH_LONG).show(); }
Example #6
Source File: SmoothieApplicationModule.java From toothpick with Apache License 2.0 | 6 votes |
private void bindSystemServices(Application application) { bindSystemService(application, LocationManager.class, LOCATION_SERVICE); bindSystemService(application, WindowManager.class, WINDOW_SERVICE); bindSystemService(application, ActivityManager.class, ACTIVITY_SERVICE); bindSystemService(application, PowerManager.class, POWER_SERVICE); bindSystemService(application, AlarmManager.class, ALARM_SERVICE); bindSystemService(application, NotificationManager.class, NOTIFICATION_SERVICE); bindSystemService(application, KeyguardManager.class, KEYGUARD_SERVICE); bindSystemService(application, Vibrator.class, VIBRATOR_SERVICE); bindSystemService(application, ConnectivityManager.class, CONNECTIVITY_SERVICE); bindSystemService(application, WifiManager.class, WIFI_SERVICE); bindSystemService(application, InputMethodManager.class, INPUT_METHOD_SERVICE); bindSystemService(application, SearchManager.class, SEARCH_SERVICE); bindSystemService(application, SensorManager.class, SENSOR_SERVICE); bindSystemService(application, TelephonyManager.class, TELEPHONY_SERVICE); bindSystemService(application, AudioManager.class, AUDIO_SERVICE); bindSystemService(application, DownloadManager.class, DOWNLOAD_SERVICE); bindSystemService(application, ClipboardManager.class, CLIPBOARD_SERVICE); }
Example #7
Source File: BaldLinearLayoutButton.java From BaldPhone with Apache License 2.0 | 6 votes |
public BaldLinearLayoutButton(Context context) { super(context); this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE); this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE); this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE); this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE); this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null; longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null; if (longPresses) if (longPressesShorter) { baldButtonTouchListener = new BaldButtonTouchListener(this); super.setOnTouchListener(baldButtonTouchListener); super.setOnClickListener(D.EMPTY_CLICK_LISTENER); } else { super.setOnLongClickListener(this); super.setOnClickListener(this); } else super.setOnClickListener(this); }
Example #8
Source File: FunctionButtonBar.java From alpha-wallet-android with MIT License | 6 votes |
@Override public void onLongTokenClick(View view, Token token, List<BigInteger> tokenIds) { //show radio buttons of all token groups if (adapter != null) adapter.setRadioButtons(true); selection = tokenIds; Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vb != null && vb.hasVibrator()) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { VibrationEffect vibe = VibrationEffect.createOneShot(200, DEFAULT_AMPLITUDE); vb.vibrate(vibe); } else { //noinspection deprecation vb.vibrate(200); } } //Wait for availability to complete waitForMapBuild(); populateButtons(token, getSelectedTokenId(tokenIds)); showButtons(); }
Example #9
Source File: App.java From ESeal with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); mApplicationContext = this; /*** * 初始化版本升级模块 */ UpdateConfig.initGet(this); /*** * 初始化定位sdk,建议在Application中创建 */ locationService = new LocationService(getApplicationContext()); mVibrator = (Vibrator) getApplicationContext().getSystemService(VIBRATOR_SERVICE); SDKInitializer.initialize(getApplicationContext()); }
Example #10
Source File: LoginActivity.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void onPasscodeError(boolean clear) { if (getParentActivity() == null) { return; } Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } if (clear) { codeField.setText(""); } AndroidUtilities.shakeView(confirmTextView, 2, 0); }
Example #11
Source File: EnjoyshopApplication.java From enjoyshop with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); mInstance = this; // 通过代码注册你的AppKey和AppSecret MobSDK.init(this, "201f8a7a91c30", "c63ec5c1eeac1f873ec78c1365120431"); sContext = getApplicationContext(); initUser(); Utils.init(this); locationService = new LocationService(getApplicationContext()); mVibrator = (Vibrator) getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE); setDatabase(); }
Example #12
Source File: BaldLinearLayoutButton.java From BaldPhone with Apache License 2.0 | 6 votes |
public BaldLinearLayoutButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE); this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE); this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE); this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE); this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null; longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null; if (longPresses) if (longPressesShorter) { baldButtonTouchListener = new BaldButtonTouchListener(this); super.setOnTouchListener(baldButtonTouchListener); super.setOnClickListener(D.EMPTY_CLICK_LISTENER); } else { super.setOnLongClickListener(this); super.setOnClickListener(this); } else super.setOnClickListener(this); }
Example #13
Source File: Haptics.java From OsmGo with MIT License | 6 votes |
@PluginMethod() @SuppressWarnings("MissingPermission") public void vibrate(PluginCall call) { Context c = this.getContext(); int duration = call.getInt("duration", 300); if(!hasPermission(Manifest.permission.VIBRATE)) { call.error("Can't vibrate: Missing VIBRATE permission in AndroidManifest.xml"); return; } if (Build.VERSION.SDK_INT >= 26) { ((Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibratePre26(duration); } call.success(); }
Example #14
Source File: EipFragment.java From bitmask_android with GNU General Public License v3.0 | 6 votes |
private void showToast(Activity activity, String message, boolean vibrateLong) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, activity.findViewById(R.id.custom_toast_container)); TextView text = layout.findViewById(R.id.text); text.setText(message); Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); if (vibrateLong) { v.vibrate(100); v.vibrate(200); } else { v.vibrate(100); } Toast toast = new Toast(activity.getApplicationContext()); toast.setGravity(Gravity.BOTTOM, 0, convertDimensionToPx(this.getContext(), R.dimen.stdpadding)); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
Example #15
Source File: MainActivityTestWear.java From goprohero with MIT License | 5 votes |
public void sendETNI15(View view) { Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE); v.vibrate(80); Toast.makeText(getApplicationContext(), "15sec", Toast.LENGTH_SHORT).show(); new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/31/4"); }
Example #16
Source File: VibrationHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
/** * Cancels the current vibration * * @param context any suitable context */ public static void cancel(@NonNull Context context) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator != null) { vibrator.cancel(); } }
Example #17
Source File: BubbleTrashLayout.java From bubbles-for-android with Apache License 2.0 | 5 votes |
void vibrate() { if (!isVibrateInThisSession){ final Vibrator vibrator = (Vibrator)getContext().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATION_DURATION_IN_MS); isVibrateInThisSession = true; } }
Example #18
Source File: MainActivity.java From goprohero with MIT License | 5 votes |
public void sendTrigger(View view) { Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE); v.vibrate(600); Toast.makeText(getApplicationContext(), "Trigger!", Toast.LENGTH_SHORT).show(); //GET("http://10.5.5.9/gp/gpControl/command/shutter?p=1"); new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/command/shutter?p=1"); // new HttpAsyncTask().execute("http://10.5.5.9/bacpac/SH?t=20161962&p=%01"); }
Example #19
Source File: BeepManager.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
synchronized void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
Example #20
Source File: DeviceUtils.java From ToolsFinal with Apache License 2.0 | 5 votes |
/** * 震动 * @param context * @param duration */ public static void vibrate(Context context, long duration) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, duration }; vibrator.vibrate(pattern, -1); }
Example #21
Source File: ContextUtils.java From openlauncher with Apache License 2.0 | 5 votes |
@SuppressWarnings("UnnecessaryReturnStatement") @SuppressLint("MissingPermission") public void vibrate(final int... ms) { int ms_v = ms != null && ms.length > 0 ? ms[0] : 50; Vibrator vibrator = ((Vibrator) _context.getSystemService(VIBRATOR_SERVICE)); if (vibrator == null) { return; } else if (Build.VERSION.SDK_INT >= 26) { vibrator.vibrate(VibrationEffect.createOneShot(ms_v, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibrator.vibrate(ms_v); } }
Example #22
Source File: ScanActivity.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@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(); cameraHandler = new Handler(cameraThread.getLooper()); }
Example #23
Source File: PhonkServerService.java From PHONK with GNU General Public License v3.0 | 5 votes |
private void vibrate() { int vWait = 20; int vTime = 80; long[] pattern = new long[]{vWait, vTime, vWait, vTime, vWait, vTime, vWait, vTime, vWait, vTime}; Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(pattern, -1); }
Example #24
Source File: ForceTouchListener.java From ForceTouch with Apache License 2.0 | 5 votes |
/** * Implemented ForceTouchListener * @param view VIew * @param motionEvent MotionEvent * @return boolean */ @Override public boolean onTouch(View view, MotionEvent motionEvent) { float pressure = motionEvent.getPressure(); checkParam(pressureLimit, millisToVibrate); setPressure(pressure); switch(motionEvent.getAction()){ case MotionEvent.ACTION_DOWN: if(pressure >= pressureLimit && !alreadyExecuted && !isProgressive) { if(isVibrate) { Vibrator vibr = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibr.vibrate(millisToVibrate); } forceTouchExecution.onForceTouch(); alreadyExecuted = true; }else if(isProgressive){ alreadyExecuted = false; progressiveForceTouch(); }else{ alreadyExecuted = false; forceTouchExecution.onNormalTouch(); timer.stop(runnable); } break; case MotionEvent.ACTION_CANCEL: if(isProgressive) { timer.stop(runnable); } alreadyExecuted = false; break; case MotionEvent.ACTION_UP: if(isProgressive) { timer.stop(runnable); } alreadyExecuted = false; break; } return true; }
Example #25
Source File: Toast.java From RobotHelper with GNU Affero General Public License v3.0 | 5 votes |
/** * 声音提示 */ public static void notice() { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(MainApplication.getInstance(), notification); r.play(); Vibrator vibrator = (Vibrator) MainApplication.getInstance().getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); }
Example #26
Source File: BeepManager.java From CodeScaner with MIT License | 5 votes |
synchronized void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
Example #27
Source File: OldCamActivity.java From goprohero with MIT License | 5 votes |
public void send120FPS(View view) { Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE); v.vibrate(600); Toast.makeText(getApplicationContext(), "120FPS", Toast.LENGTH_SHORT).show(); String yourFilePath = this.getFilesDir() + "/" + "camconfig.txt"; File yourFile = new File( yourFilePath ); try { String password = getFileContents(yourFile); new HttpAsyncTask ().execute("http://10.5.5.9/camera/FV?t=" + password + "&p=%09"); } catch (IOException e) { e.printStackTrace(); } }
Example #28
Source File: YTutils.java From YTPlayer with GNU General Public License v3.0 | 5 votes |
public static void Vibrate(Context context) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibrator.vibrate(100); } }
Example #29
Source File: TurnGameActivity.java From cloud-cup-android with Apache License 2.0 | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { SensorManager.getRotationMatrixFromVector(mRotationMatrix , event.values); SensorManager.getOrientation(mRotationMatrix, mOrientation); float zAngle = mOrientation[0]; //Log.d(LOG_TAG, "Turn z: " + zAngle); if(originalAngle == 0) { originalAngle = zAngle; } if( !halfTurn && Math.abs(zAngle - backtoRange(originalAngle + Math.PI)) < ANGLE_SENSIBILITY ) { halfTurn = true; demiTurns++; sendTurnValues(); } if( halfTurn && Math.abs(zAngle - originalAngle) < ANGLE_SENSIBILITY) { halfTurn = false; demiTurns++; ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(100); sendTurnValues(); } }
Example #30
Source File: VibrationHelperTest.java From android-card-form with MIT License | 5 votes |
@Test public void vibrate_doesNotCallVibrateIfHasVibratePermissionIsFalse() { PackageManager packageManager = mock(PackageManager.class); when(packageManager.checkPermission(eq(Manifest.permission.VIBRATE), anyString())) .thenReturn(PackageManager.PERMISSION_DENIED); Vibrator vibrator = mock(Vibrator.class); Context context = mock(Context.class); when(context.getPackageManager()).thenReturn(packageManager); when(context.getPackageName()).thenReturn("com.braintreepayments.cardform.test"); when(context.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(vibrator); VibrationHelper.vibrate(context, 1000); verifyZeroInteractions(vibrator); }