-
-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add haptic feedback toggle for code refresh #1599
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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}; | ||
} |
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really what |
||
|
||
return _prefs.isHapticFeedbackEnabled(); | ||
} | ||
|
||
@EarlyEntryPoint | ||
@InstallIn(SingletonComponent.class) | ||
public interface PrefEntryPoint { | ||
Preferences getPreferences(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.beemdevelopment.aegis.ui.views; | ||
|
||
import android.animation.Animator; | ||
import android.animation.AnimatorListenerAdapter; | ||
import android.animation.AnimatorSet; | ||
import android.animation.ArgbEvaluator; | ||
import android.animation.ObjectAnimator; | ||
|
@@ -25,11 +27,13 @@ | |
import com.beemdevelopment.aegis.AccountNamePosition; | ||
import com.beemdevelopment.aegis.Preferences; | ||
import com.beemdevelopment.aegis.R; | ||
import com.beemdevelopment.aegis.VibrationPatterns; | ||
import com.beemdevelopment.aegis.ViewMode; | ||
import com.beemdevelopment.aegis.helpers.AnimationsHelper; | ||
import com.beemdevelopment.aegis.helpers.CenterVerticalSpan; | ||
import com.beemdevelopment.aegis.helpers.SimpleAnimationEndListener; | ||
import com.beemdevelopment.aegis.helpers.UiRefresher; | ||
import com.beemdevelopment.aegis.helpers.VibrationHelper; | ||
import com.beemdevelopment.aegis.otp.HotpInfo; | ||
import com.beemdevelopment.aegis.otp.OtpInfo; | ||
import com.beemdevelopment.aegis.otp.OtpInfoException; | ||
|
@@ -67,6 +71,7 @@ public class EntryHolder extends RecyclerView.ViewHolder { | |
|
||
private boolean _hidden; | ||
private boolean _paused; | ||
private boolean _nonUniform; | ||
|
||
private TotpProgressBar _progressBar; | ||
private MaterialCardView _view; | ||
|
@@ -118,12 +123,13 @@ public long getMillisTillNextRefresh() { | |
}); | ||
} | ||
|
||
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMode viewMode, AccountNamePosition accountNamePosition, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed, boolean showExpirationState, boolean showNextCode) { | ||
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMode viewMode, AccountNamePosition accountNamePosition, boolean showIcon, boolean nonUniform, boolean hidden, boolean paused, boolean dimmed, boolean showExpirationState, boolean showNextCode) { | ||
_entry = entry; | ||
_hidden = hidden; | ||
_paused = paused; | ||
_codeGrouping = groupSize; | ||
_viewMode = viewMode; | ||
_nonUniform = nonUniform; | ||
|
||
_accountNamePosition = accountNamePosition; | ||
if (viewMode.equals(ViewMode.TILES) && _accountNamePosition == AccountNamePosition.END) { | ||
|
@@ -140,7 +146,7 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMo | |
_favoriteIndicator.setVisibility(_entry.isFavorite() ? View.VISIBLE : View.INVISIBLE); | ||
|
||
// only show the progress bar if there is no uniform period and the entry type is TotpInfo | ||
setShowProgress(showProgress); | ||
setShowProgress(nonUniform); | ||
|
||
// only show the button if this entry is of type HotpInfo | ||
_buttonRefresh.setVisibility(entry.getInfo() instanceof HotpInfo ? View.VISIBLE : View.GONE); | ||
|
@@ -457,6 +463,16 @@ public void startExpirationAnimation() { | |
final int blinkDuration = 3000; | ||
ValueAnimator delayAnim2 = ValueAnimator.ofFloat(0f, 0f); | ||
delayAnim2.setDuration((long) ((totalStateDuration - blinkDuration) / durationScale)); | ||
delayAnim2.addListener(new AnimatorListenerAdapter() { | ||
@Override | ||
public void onAnimationEnd(Animator animation) { | ||
if (!_nonUniform) { | ||
if (itemView.isShown()) { | ||
VibrationHelper.vibratePattern(itemView.getContext(), VibrationPatterns.EXPIRING); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This results in starting a vibration for every single entry. Since we're not relying on repeated animation callbacks for the "ticks" of the vibration, I don't think we need to link this to the animation. Perhaps a second |
||
} | ||
} | ||
} | ||
}); | ||
|
||
ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(_profileCode, "alpha", 1f, .5f); | ||
alphaAnim.setDuration((long) (500 / durationScale)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,11 +33,13 @@ | |
import com.beemdevelopment.aegis.Preferences; | ||
import com.beemdevelopment.aegis.R; | ||
import com.beemdevelopment.aegis.SortCategory; | ||
import com.beemdevelopment.aegis.VibrationPatterns; | ||
import com.beemdevelopment.aegis.ViewMode; | ||
import com.beemdevelopment.aegis.helpers.AnimationsHelper; | ||
import com.beemdevelopment.aegis.helpers.MetricsHelper; | ||
import com.beemdevelopment.aegis.helpers.SimpleItemTouchHelperCallback; | ||
import com.beemdevelopment.aegis.helpers.UiRefresher; | ||
import com.beemdevelopment.aegis.helpers.VibrationHelper; | ||
import com.beemdevelopment.aegis.otp.TotpInfo; | ||
import com.beemdevelopment.aegis.ui.glide.GlideHelper; | ||
import com.beemdevelopment.aegis.ui.models.ErrorCardInfo; | ||
|
@@ -144,6 +146,10 @@ public int getSpanSize(int position) { | |
@Override | ||
public void onRefresh() { | ||
refresh(false); | ||
|
||
if (_recyclerView.isShown()) { | ||
VibrationHelper.vibratePattern(getContext(), VibrationPatterns.REFRESH_CODE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is only the case on my device, but I don't feel this vibration. |
||
} | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we can remove this?