Exemplo n.º 1
0
 @Override
 protected void onRestoreInstanceState(Bundle loadState) {
   super.onRestoreInstanceState(loadState);
   // use this to load your snacks for later
   mSnackBar.onRestoreInstanceState(loadState.getBundle(SAVED_SNACKBAR));
   // might as well load the counter too
   mSnackIndex = loadState.getInt(SAVED_COUNT);
 }
Exemplo n.º 2
0
 @Override
 protected void onSaveInstanceState(Bundle saveState) {
   super.onSaveInstanceState(saveState);
   // use this to save your snacks for later
   saveState.putBundle(SAVED_SNACKBAR, mSnackBar.onSaveInstanceState());
   // just for saving the number of times the button has been pressed
   saveState.putInt(SAVED_COUNT, mSnackIndex);
 }
Exemplo n.º 3
0
  public void onCreateClicked(View view) {
    String message = "";
    short duration = 0;
    SnackBar.Style style = SnackBar.Style.DEFAULT;

    int selectedMessageLength = mMsgLengthOptions.getSelectedItemPosition();
    switch (selectedMessageLength) {
      case SHORT_MSG:
        message = "This is a one-line message.";
        break;
      case LONG_MSG:
        message = "This message is a lot longer, it should stretch at least two lines. ";
        break;
    }

    int selectedDuration = mDurationOptions.getSelectedItemPosition();
    switch (selectedDuration) {
      case SHORT_SNACK:
        duration = SnackBar.SHORT_SNACK;
        break;
      case MED_SNACK:
        duration = SnackBar.MED_SNACK;
        break;
      case LONG_SNACK:
        duration = SnackBar.LONG_SNACK;
        break;
    }

    int selectedActionBtnColor = mActionBtnColorOptions.getSelectedItemPosition();
    switch (selectedActionBtnColor) {
      case RED:
        style = SnackBar.Style.RED;
        break;
      case ORANGE:
        style = SnackBar.Style.ORANGE;
        break;
      case YELLOW:
        style = SnackBar.Style.YELLOW;
        break;
      case GREEN:
        style = SnackBar.Style.GREEN;
        break;
      case BLUE:
        style = SnackBar.Style.BLUE;
        break;
      case PURPLE:
        style = SnackBar.Style.PURPLE;
        break;
      case PINK:
        style = SnackBar.Style.PINK;
        break;
      case DEFAULT:
        style = SnackBar.Style.DEFAULT;
        break;
      case ALERT:
        style = SnackBar.Style.ALERT;
        break;
      case CONFIRM:
        style = SnackBar.Style.CONFIRM;
        break;
      case INFO:
        style = SnackBar.Style.INFO;
        break;
    }

    int selectedActionBtnExistance = mActionBtnOptions.getSelectedItemPosition();
    switch (selectedActionBtnExistance) {
      case ACTION_BTN:
        mSnackBar.show(message, "Action", style, duration);
        break;
      case NO_ACTION_BTN:
        mSnackBar.show(message, duration);
        break;
    }
  }