Skip to content

Helper Classes

Kaushik NP edited this page May 13, 2018 · 2 revisions

Standard displays shown after an action (FirstBackPress / DoubleBackPress)

  • ToastDisplay : standard Toast

    Example to show toast for Toast.LENGTH_SHORT period of time upon the first back button press, with a message reading "Press back button to confirm".

    FirstBackPressAction firstBackPressAction = new ToastDisplay()
                .standard(this);                                        //required
    
    DoubleBackPress doubleBackPress = new DoubleBackPress()
                .withFirstBackPressAction(firstBackPressAction)
                ...

    Example to show toast for Toast.LENGTH_SHORT period of time upon the first back button press, with a message reading "Press back button to Exit".

    FirstBackPressAction firstBackPressAction = new ToastDisplay()
                .standard(this, "Press back button to Exit");            //required
    
    DoubleBackPress doubleBackPress = new DoubleBackPress()
                .withFirstBackPressAction(firstBackPressAction)
                ...
  • SnackbarDisplay : standard Snackbar

    Note : Since Snackbar require the callers's parent view, the SnackbarDisplay class needs to be set and provided to the DoubleBackPress object after the View is set. Example, in an Activity, this would be inside the onCreate() function, after the setContentView() function is called.

    Example to show snackbar for Snackbar.LENGTH_SHORT period of time upon the first back button press, with a message reading "Press back button to confirm".

    //after the view is initialized
    FirstBackPressAction firstBackPressAction = new Snackbar()
                .standard(parentView);                                        //required
    
    doubleBackPress.setFirstBackPressAction(firstBackPressAction)

    Example to show snackbar for Snackbar.LENGTH_SHORT period of time upon the first back button press, with a message reading "Press back button to Exit".

    //after the view is initialized
    FirstBackPressAction firstBackPressAction = new Snackbar()
                .standard(parentView, "Press back button to Exit");            //required
    
    doubleBackPress.setFirstBackPressAction(firstBackPressAction)
Clone this wiki locally