-
-
Notifications
You must be signed in to change notification settings - Fork 511
Add haptic feedback toggle for code refresh #1599
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
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,12 @@ | ||
| package com.beemdevelopment.aegis; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class 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}; | ||
|
|
||
| public static long getLengthInMillis(long[] pattern) { | ||
| return Arrays.stream(pattern).sum(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| 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; | ||
|
|
||
| public class VibrationHelper { | ||
| private Preferences _preferences; | ||
|
|
||
| public VibrationHelper(Context context) { | ||
| _preferences = new Preferences(context); | ||
| } | ||
|
|
||
| public void vibratePattern(Context context, long[] pattern) { | ||
| if (!isHapticFeedbackEnabled()) { | ||
| 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 boolean isHapticFeedbackEnabled() { | ||
| return _preferences.isHapticFeedbackEnabled(); | ||
| } | ||
| } |
|
Member
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 see that the fix for the animation-related crash for entries that have a period of 7 is not included here. Do you want to create a separate PR for that? |
| 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; | ||
|
|
@@ -66,13 +68,13 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { | |
| private Listener _listener; | ||
| private SimpleItemTouchHelperCallback _touchCallback; | ||
| private ItemTouchHelper _touchHelper; | ||
| private VibrationHelper _vibrationHelper; | ||
|
|
||
| private RecyclerView _recyclerView; | ||
| private RecyclerView.ItemDecoration _itemDecoration; | ||
| private ViewPreloadSizeProvider<VaultEntry> _preloadSizeProvider; | ||
| private TotpProgressBar _progressBar; | ||
| private boolean _showProgress; | ||
| private boolean _showExpirationState; | ||
| private ViewMode _viewMode; | ||
| private LinearLayout _emptyStateView; | ||
|
|
||
|
|
@@ -95,6 +97,7 @@ public void onDestroy() { | |
| public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
| View view = inflater.inflate(R.layout.fragment_entry_list_view, container, false); | ||
| _progressBar = view.findViewById(R.id.progressBar); | ||
| _vibrationHelper = new VibrationHelper(getContext()); | ||
|
|
||
| // set up the recycler view | ||
| _recyclerView = view.findViewById(R.id.rvKeyProfiles); | ||
|
|
@@ -144,12 +147,23 @@ public int getSpanSize(int position) { | |
| @Override | ||
| public void onRefresh() { | ||
| refresh(false); | ||
| _vibrationHelper.vibratePattern(getContext(), VibrationPatterns.REFRESH_CODE); | ||
| } | ||
|
|
||
| @Override | ||
| public void onExpiring() { | ||
| _vibrationHelper.vibratePattern(getContext(), VibrationPatterns.EXPIRING); | ||
| } | ||
|
|
||
| @Override | ||
| public long getMillisTillNextRefresh() { | ||
| return TotpInfo.getMillisTillNextRotation(_adapter.getMostFrequentPeriod()); | ||
| } | ||
|
|
||
| @Override | ||
| public long getPeriodMillis() { | ||
| return _adapter.getMostFrequentPeriod() * 1000L; | ||
| } | ||
| }); | ||
|
|
||
| final int rvInitialPaddingLeft = _recyclerView.getPaddingLeft(); | ||
|
|
@@ -191,6 +205,16 @@ public void onDestroyView() { | |
| super.onDestroyView(); | ||
| } | ||
|
|
||
| public void onRefreshStop() { | ||
| _refresher.stop(); | ||
| } | ||
|
|
||
| public void onRefreshStart() { | ||
|
Member
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. Since we're now unconditionally starting the refresher from MainActivity, I think we need to check whether |
||
| if (_adapter.getMostFrequentPeriod() != -1){ | ||
| _refresher.start(); | ||
| } | ||
| } | ||
|
|
||
| public void setGroups(Collection<VaultGroup> groups) { | ||
| _adapter.setGroups(groups); | ||
| updateDividerDecoration(); | ||
|
|
@@ -353,11 +377,11 @@ public void onPeriodUniformityChanged(boolean isUniform, int period) { | |
| _progressBar.setVisibility(View.VISIBLE); | ||
| _progressBar.setPeriod(period); | ||
| _progressBar.start(); | ||
| _refresher.start(); | ||
| onRefreshStart(); | ||
| } else { | ||
| _progressBar.setVisibility(View.GONE); | ||
| _progressBar.stop(); | ||
| _refresher.stop(); | ||
| onRefreshStop(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -389,7 +413,6 @@ public void setShowNextCode(boolean showNextCode) { | |
| } | ||
|
|
||
| public void setShowExpirationState(boolean showExpirationState) { | ||
| _showExpirationState = showExpirationState; | ||
| _adapter.setShowExpirationState(showExpirationState); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.