2323import android .view .MenuInflater ;
2424import android .view .MenuItem ;
2525import android .view .View ;
26+ import android .view .ViewGroup ;
2627import android .view .inputmethod .InputMethodManager ;
2728import android .widget .AutoCompleteTextView ;
2829import android .widget .Button ;
4647import com .beemdevelopment .aegis .SortCategory ;
4748import com .beemdevelopment .aegis .helpers .BitmapHelper ;
4849import com .beemdevelopment .aegis .helpers .DropdownHelper ;
50+ import com .beemdevelopment .aegis .helpers .FabMenuHelper ;
4951import com .beemdevelopment .aegis .helpers .FabScrollHelper ;
5052import com .beemdevelopment .aegis .helpers .PermissionHelper ;
5153import com .beemdevelopment .aegis .helpers .ViewHelper ;
6971import com .beemdevelopment .aegis .vault .VaultGroup ;
7072import com .beemdevelopment .aegis .vault .VaultRepository ;
7173import com .beemdevelopment .aegis .vault .VaultRepositoryException ;
72- import com .google .android .material .bottomsheet .BottomSheetDialog ;
7374import com .google .android .material .chip .Chip ;
7475import com .google .android .material .chip .ChipGroup ;
7576import com .google .android .material .color .MaterialColors ;
8485import java .util .Collections ;
8586import java .util .Date ;
8687import java .util .HashSet ;
88+ import java .util .LinkedHashMap ;
8789import java .util .List ;
8890import java .util .Map ;
8991import java .util .Objects ;
92+ import java .util .SequencedMap ;
9093import java .util .Set ;
9194import java .util .UUID ;
9295import java .util .concurrent .atomic .AtomicReference ;
@@ -117,13 +120,15 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
117120 private Set <UUID > _prefGroupFilter ;
118121
119122 private FabScrollHelper _fabScrollHelper ;
123+ private FabMenuHelper _fabMenuHelper ;
120124
121125 private ActionMode _actionMode ;
122126 private ActionMode .Callback _actionModeCallbacks = new ActionModeCallbacks ();
123127
124128 private LockBackPressHandler _lockBackPressHandler ;
125129 private SearchViewBackPressHandler _searchViewBackPressHandler ;
126130 private ActionModeBackPressHandler _actionModeBackPressHandler ;
131+ private FabMenuBackPressHandler _fabMenuBackPressHandler ;
127132
128133 private final ActivityResultLauncher <Intent > authResultLauncher =
129134 registerForActivityResult (new StartActivityForResult (), activityResult -> {
@@ -207,6 +212,8 @@ protected void onCreate(Bundle savedInstanceState) {
207212 getOnBackPressedDispatcher ().addCallback (this , _searchViewBackPressHandler );
208213 _actionModeBackPressHandler = new ActionModeBackPressHandler ();
209214 getOnBackPressedDispatcher ().addCallback (this , _actionModeBackPressHandler );
215+ _fabMenuBackPressHandler = new FabMenuBackPressHandler ();
216+ getOnBackPressedDispatcher ().addCallback (this , _fabMenuBackPressHandler );
210217
211218 _entryListView = (EntryListView ) getSupportFragmentManager ().findFragmentById (R .id .key_profiles );
212219 _entryListView .setListener (this );
@@ -226,27 +233,29 @@ protected void onCreate(Bundle savedInstanceState) {
226233 _entryListView .setSearchBehaviorMask (_prefs .getSearchBehaviorMask ());
227234 _prefGroupFilter = _prefs .getGroupFilter ();
228235
229- FloatingActionButton fab = findViewById (R .id .fab );
230- fab .setOnClickListener (v -> {
231- View view = getLayoutInflater ().inflate (R .layout .dialog_add_entry , null );
232- BottomSheetDialog dialog = new BottomSheetDialog (this );
233- dialog .setContentView (view );
234-
235- view .findViewById (R .id .fab_enter ).setOnClickListener (v1 -> {
236- dialog .dismiss ();
237- startEditEntryActivityForManual ();
238- });
239- view .findViewById (R .id .fab_scan_image ).setOnClickListener (v2 -> {
240- dialog .dismiss ();
241- startScanImageActivity ();
242- });
243- view .findViewById (R .id .fab_scan ).setOnClickListener (v3 -> {
244- dialog .dismiss ();
245- startScanActivity ();
246- });
247-
248- Dialogs .showSecureDialog (dialog );
249- });
236+ View scrimOverlayLayout = LayoutInflater .from (this ).inflate (R .layout .scrim_layout , null );
237+ View scrimOverlay = scrimOverlayLayout .findViewById (R .id .scrim );
238+ addContentView (scrimOverlayLayout , new ViewGroup .LayoutParams (
239+ ViewGroup .LayoutParams .MATCH_PARENT ,
240+ ViewGroup .LayoutParams .MATCH_PARENT
241+ ));
242+
243+ View fabMenuLayout = LayoutInflater .from (this ).inflate (R .layout .fab_menu , null );
244+ addContentView (fabMenuLayout , new ViewGroup .LayoutParams (
245+ ViewGroup .LayoutParams .MATCH_PARENT ,
246+ ViewGroup .LayoutParams .MATCH_PARENT
247+ ));
248+
249+ ViewGroup menuItemsContainer = fabMenuLayout .findViewById (R .id .fab_menu_items_container );
250+ FloatingActionButton fab = fabMenuLayout .findViewById (R .id .fab );
251+
252+ LinkedHashMap <View , Runnable > actions = new LinkedHashMap <>();
253+ actions .put (fabMenuLayout .findViewById (R .id .fab_menu_item_scan ), this ::startScanActivity );
254+ actions .put (fabMenuLayout .findViewById (R .id .fab_menu_item_scan_image ), this ::startScanImageActivity );
255+ actions .put (fabMenuLayout .findViewById (R .id .fab_menu_item_enter ), this ::startEditEntryActivityForManual );
256+
257+ _fabMenuHelper = new FabMenuHelper (scrimOverlay , menuItemsContainer , fab , actions );
258+ _fabMenuHelper .setOnFabMenuStateChangeListener (_fabMenuBackPressHandler ::setEnabled );
250259
251260 _groupChip = findViewById (R .id .groupChipGroup );
252261 _fabScrollHelper = new FabScrollHelper (fab );
@@ -1314,6 +1323,9 @@ public void onLocked(boolean userInitiated) {
13141323 if (_searchView != null && !_searchView .isIconified ()) {
13151324 collapseSearchView ();
13161325 }
1326+ if (_fabMenuHelper != null && _fabMenuHelper .isOpen ()) {
1327+ _fabMenuHelper .close ();
1328+ }
13171329
13181330 _entryListView .clearEntries ();
13191331 _loaded = false ;
@@ -1399,6 +1411,19 @@ public void handleOnBackPressed() {
13991411 }
14001412 }
14011413
1414+ private class FabMenuBackPressHandler extends OnBackPressedCallback {
1415+ public FabMenuBackPressHandler () {
1416+ super (false );
1417+ }
1418+
1419+ @ Override
1420+ public void handleOnBackPressed () {
1421+ if (_fabMenuHelper != null && _fabMenuHelper .isOpen ()) {
1422+ _fabMenuHelper .close ();
1423+ }
1424+ }
1425+ }
1426+
14021427 private class ActionModeCallbacks implements ActionMode .Callback {
14031428 @ Override
14041429 public boolean onCreateActionMode (ActionMode mode , Menu menu ) {
0 commit comments