-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add haptic feedback toggle for code refresh
- Loading branch information
1 parent
9ab949a
commit 7197878
Showing
9 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
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
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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/beemdevelopment/aegis/VibrationPatterns.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.beemdevelopment.aegis; | ||
|
||
public class VibrationPatterns { | ||
private VibrationPatterns() {} | ||
|
||
public static final long[] EXPIRING = {475, 20, 5, 20, 965, 20, 5, 20, 965, 20, 5, 20, 420}; | ||
public static final long[] REFRESH_CODE = {0, 100}; | ||
} |
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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/beemdevelopment/aegis/helpers/VibrationHelper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.beemdevelopment.aegis.helpers; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import android.os.VibrationEffect; | ||
import android.os.Vibrator; | ||
import android.os.VibratorManager; | ||
|
||
import com.beemdevelopment.aegis.Preferences; | ||
|
||
import dagger.hilt.InstallIn; | ||
import dagger.hilt.android.EarlyEntryPoint; | ||
import dagger.hilt.android.EarlyEntryPoints; | ||
import dagger.hilt.components.SingletonComponent; | ||
|
||
public class VibrationHelper { | ||
public static void vibratePattern(Context context, long[] pattern) { | ||
if (!isHapticFeedbackEnabled(context)) { | ||
return; | ||
} | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
VibratorManager vibratorManager = (VibratorManager) context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE); | ||
if (vibratorManager != null) { | ||
Vibrator vibrator = vibratorManager.getDefaultVibrator(); | ||
VibrationEffect effect = VibrationEffect.createWaveform(pattern, -1); | ||
vibrator.vibrate(effect); | ||
} | ||
} else { | ||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); | ||
if (vibrator != null) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
VibrationEffect effect = VibrationEffect.createWaveform(pattern, -1); | ||
vibrator.vibrate(effect); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static boolean isHapticFeedbackEnabled(Context context) { | ||
Preferences _prefs = EarlyEntryPoints.get(context.getApplicationContext(), PrefEntryPoint.class).getPreferences(); | ||
|
||
return _prefs.isHapticFeedbackEnabled(); | ||
} | ||
|
||
@EarlyEntryPoint | ||
@InstallIn(SingletonComponent.class) | ||
public interface PrefEntryPoint { | ||
Preferences getPreferences(); | ||
} | ||
} |
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
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
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
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