This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.VIBRATE"/> | |
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); | |
if (vibrator.hasVibrator()) { | |
vibrator.vibrate(500); // for 500 ms | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiresApi(api = Build.VERSION_CODES.O) | |
private void createOneShotVibrationUsingVibrationEffect() { | |
// 1000 : Vibrate for 1 sec | |
// VibrationEffect.DEFAULT_AMPLITUDE - would perform vibration at full strength | |
VibrationEffect effect = VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE); | |
vibrator.vibrate(effect); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiresApi(api = Build.VERSION_CODES.O) | |
private void createWaveFormVibrationUsingVibrationEffectAndAmplitude() { | |
long[] mVibratePattern = new long[]{0, 400, 800, 600, 800, 800, 800, 1000}; | |
int[] mAmplitudes = new int[]{0, 255, 0, 255, 0, 255, 0, 255}; | |
// -1 : Play exactly once | |
if (vibrator.hasAmplitudeControl()) { | |
VibrationEffect effect = VibrationEffect.createWaveform(mVibratePattern, mAmplitudes, -1); | |
vibrator.vibrate(effect); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void customVibratePatternNoRepeat() { | |
// 0 : Start without a delay | |
// 400 : Vibrate for 400 milliseconds | |
// 200 : Pause for 200 milliseconds | |
// 400 : Vibrate for 400 milliseconds | |
long[] mVibratePattern = new long[]{0, 400, 200, 400}; | |
// -1 : Do not repeat this pattern | |
// pass 0 if you want to repeat this pattern from 0th index | |
vibrator.vibrate(mVibratePattern, -1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiresApi(api = Build.VERSION_CODES.O) | |
private void createOneShotVibrationUsingVibrationEffect() { | |
// 1000 : Vibrate for 1 sec | |
// VibrationEffect.DEFAULT_AMPLITUDE - would perform vibration at full strength | |
VibrationEffect effect = VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE); | |
vibrator.vibrate(effect); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SetAppUpdateAvailable { | |
private int mUpdateValue = 0; | |
private static final int UPDATE_AVAILABLE = 1; | |
private static final int UPDATE_COMPULSORY = 2; | |
public void setUpdateAvailable(){ | |
mUpdateValue = mUpdateValue | (1 << UPDATE_AVAILABLE); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nileshdeokar.healthapp; | |
public class GetAppUpdateAvailable { | |
private int updateValue = 0b0110; | |
private static final int UPDATE_AVAILABLE = 1; | |
private static final int UPDATE_COMPULSORY = 2; | |
public void getUpdateAvailable(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GetAppUpdateAvailable { | |
private int mUpdateValue = 0b0010; | |
private static final int UPDATE_AVAILABLE = 1; | |
private static final int UPDATE_COMPULSORY = 2; | |
public void getUpdateAvailable(){ | |
boolean result = false; | |
result = (mUpdateValue & (1 << UPDATE_AVAILABLE)) != 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppUpdateCheckerUsingBitwiseShiftOperation { | |
private int mUpdateValue = 0; | |
private static final int UPDATE_AVAILABLE = 1; | |
private static final int UPDATE_COMPULSORY = 2; | |
public void setValue(int position){ | |
mUpdateValue = mUpdateValue | (1 << position); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int myOriginalValue = 0b0010; | |
// STEP 1 : 0b0001 << 3 = 0b1000; | |
// STEP 2 : OR 0b0010; originalValue | |
// -------------- | |
// RESULT : 0b1010; // 3rd bit is set to true | |
// Formula for setting a bit : | |
// myOriginalValue = myOriginalValue | (1 << position); |
OlderNewer