/* Shows notification for a running sleep timer */
  private void showSleepTimerNotification(long remainingTime) {

    // set snackbar message
    String message;
    if (remainingTime > 0) {
      message = mSleepTimerNotificationMessage + getReadableTime(remainingTime);
    } else {
      message = mSleepTimerNotificationMessage;
    }

    // show snackbar
    mSleepTimerNotification = Snackbar.make(mRootView, message, Snackbar.LENGTH_INDEFINITE);
    mSleepTimerNotification.setAction(
        R.string.dialog_generic_button_cancel,
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            // stop sleep timer service
            mSleepTimerService.startActionStop(mActivity);
            mSleepTimerRunning = false;
            saveAppState(mActivity);
            // notify user
            Toast.makeText(
                    mActivity,
                    mActivity.getString(R.string.toastmessage_timer_cancelled),
                    Toast.LENGTH_SHORT)
                .show();
            LogHelper.v(LOG_TAG, "Sleep timer cancelled.");
          }
        });
    mSleepTimerNotification.show();
  }
Beispiel #2
0
  /**
   * Called when one of the cards is swiped away. Removes the associated book from the recents list.
   *
   * @param uniqueId The unique ID of the item so that the correct {@link RBook} can be retrieved.
   */
  @Override
  public void handleSwiped(long uniqueId) {
    // Remove from recents.
    realm.executeTransactionAsync(
        bgRealm ->
            bgRealm.where(RBook.class).equalTo("uniqueId", uniqueId).findFirst().isInRecents =
                false);

    // Show snackbar with "Undo" button.
    Snackbar undoSnackbar = Snackbar.make(coordinator, R.string.book_removed, Snackbar.LENGTH_LONG);
    undoSnackbar.setAction(
        R.string.undo,
        view -> {
          // Put back in recents if undo button is clicked.
          try (Realm realm = Realm.getDefaultInstance()) {
            realm.executeTransactionAsync(
                bgRealm ->
                    bgRealm
                            .where(RBook.class)
                            .equalTo("uniqueId", uniqueId)
                            .findFirst()
                            .isInRecents =
                        true);
          }
        });
    undoSnackbar.show();
  }
Beispiel #3
0
  public void Gain50Exp(View view) {
    user.gain_exp(50);
    mProgress.incrementProgressBy(50);

    Snackbar snackbar = Snackbar.make(view, "You got 50 EXP!", Snackbar.LENGTH_LONG);
    snackbar.setAction("Action", null).show();

    if (mProgress.getProgress() >= mProgress.getMax()) {
      LevelUp(view);
    }
  }
  public static Snackbar showSnackbar(
      View container, @StringRes int text, View.OnClickListener click) {
    if (container == null) {
      L.e("container == null, return null");
      return null;
    }

    Snackbar snackbar = Snackbar.make(container, text, Snackbar.LENGTH_INDEFINITE);
    snackbar.setAction(R.string.action_enable, click).show();

    return snackbar;
  }
 private void showErrorMessage(
     @StringRes int messageResId,
     @StringRes int actionLabelResid,
     View.OnClickListener actionListener) {
   Snackbar instance = Snackbar.make(getView(), messageResId, Snackbar.LENGTH_LONG);
   if (actionLabelResid != 0 && actionListener != null) {
     instance.setAction(actionLabelResid, actionListener);
     int colorRes = ViewUtils.getThemeColorAccent(getActivity().getTheme());
     instance.setActionTextColor(colorRes);
   }
   instance.show();
 }
Beispiel #6
0
  @Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.bnAppinfoBack:
        Intent intent = new Intent(AppInfoActivity.this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
        break;

      case R.id.bnAppinfoParner:
        final Snackbar snackbar =
            Snackbar.make(view, " 制作成员:吴德永" + "、邓贺文、陈俊均 、李振初", Snackbar.LENGTH_LONG);
        snackbar.setAction(
            "滑动消失",
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                snackbar.dismiss();
              }
            });
        snackbar.show();
        break;

      case R.id.bnAppinfoUpdate:
        final Snackbar snackbar2 = Snackbar.make(view, "暂无更新哦", Snackbar.LENGTH_LONG);
        snackbar2.setAction(
            "滑动消失",
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                snackbar2.dismiss();
              }
            });
        snackbar2.show();
        break;
    }
  }
Beispiel #7
0
 @Override
 protected void showError(@StringRes int errorStringRes) {
   if (isContextValid()) {
     if (getView() != null) {
       Snackbar snackbar = Snackbar.make(getView(), errorStringRes, Snackbar.LENGTH_INDEFINITE);
       snackbar.setAction(
           R.string.retry,
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               fetchChapters();
             }
           });
       ColoredSnackBar.alert(snackbar).show();
     } else {
       Toast.makeText(getActivity(), errorStringRes, Toast.LENGTH_SHORT).show();
     }
   }
 }
 private void eliminarAlumno(int position) {
   // Se obtiene la referencia al alumno.
   Firebase refAlumno = mAdaptador.getRef(position);
   final String key = refAlumno.getKey();
   final Alumno alumno = mAdaptador.getItem(position);
   // Se borra de la base de datos.
   refAlumno.removeValue();
   lblNuevoAlumno.setVisibility(mAdaptador.isEmpty() ? View.VISIBLE : View.INVISIBLE);
   Snackbar snackbar =
       Snackbar.make(lblNuevoAlumno, R.string.alumno_eliminado, Snackbar.LENGTH_LONG);
   snackbar.setAction(
       R.string.deshacer,
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           agregarAlumno(key, alumno);
         }
       });
   snackbar.show();
 }
Beispiel #9
0
  public static void show(View view, String msg, int flag) {

    if (flag == 0) { // 短时显示
      mSnackbar = Snackbar.make(view, msg, Snackbar.LENGTH_SHORT);
    } else if (flag == 1) { // 长时显示
      mSnackbar = Snackbar.make(view, msg, Snackbar.LENGTH_LONG);
    } else {
      mSnackbar = Snackbar.make(view, msg, flag);
    }

    mSnackbar.show();
    // Snackbar中有一个可点击的文字,这里设置点击所触发的操作。
    mSnackbar.setAction(
        "关了吧",
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Snackbar在点击“关闭”后消失
            mSnackbar.dismiss();
          }
        });
  }
  private void initRest() {
    loadWebViewData();
    setupLanguagesButton();
    setMorePageDetails(mPage);

    if (mPage.isAutoTranslated() && !mTranslatedDismissed) {
      final Snackbar snackBar =
          Snackbar.make(mToolbar, R.string.auto_translated, Snackbar.LENGTH_INDEFINITE);
      snackBar.getView().setBackgroundColor(mPrefUtilities.getCurrentColor());
      snackBar.setAction(
          R.string.auto_translated_snackbar_close,
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              snackBar.dismiss();
              mTranslatedDismissed = true;
            }
          });
      snackBar.show();
    }
    sendEvent("Page", mPage.getTitle());
  }
Beispiel #11
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       return true;
     case R.id.action_credits:
       final Snackbar snackbar =
           Snackbar.make(mLayout, "Made by Dhruv, Bharat, Ankit, Kirti", Snackbar.LENGTH_LONG);
       snackbar.setAction(
           R.string.dismiss,
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               snackbar.dismiss();
             }
           });
       snackbar.setActionTextColor(getResources().getColor(R.color.white));
       snackbar.show();
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.submit) {
      final EditText highBlock = (EditText) findViewById(R.id.high_block);
      if (highBlock.getText().toString().equals("")) {
        FrameLayout layoutRoot = (FrameLayout) findViewById(R.id.layout_root);
        final Snackbar snackbar =
            Snackbar.make(
                layoutRoot,
                getResources().getString(R.string.empty_high_password),
                Snackbar.LENGTH_LONG);
        View snackBarView = snackbar.getView();
        TextView text =
            (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text);
        text.setTextColor(getResources().getColor(R.color.icons));
        snackBarView.setBackgroundColor(getResources().getColor(R.color.primary));
        snackbar.setActionTextColor(getResources().getColor(R.color.snack_action));
        snackbar.setAction(
            getString(R.string.i_know),
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                snackbar.dismiss();
              }
            });
        snackbar.show();
        return false;
      }

      final EditText deviceSeed = (EditText) findViewById(R.id.user_input);
      if (deviceSeed.getText().toString().length() == 6) {
        AlertDialog.Builder builder = new AlertDialog.Builder(SetDeviceActivity.this);
        builder
            .setTitle(getString(R.string.submit_warning_title))
            .setMessage(getString(R.string.submit_warning))
            .setPositiveButton(
                getString(R.string.alert_yes),
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences sharedPreferences =
                        getSharedPreferences("user_data", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString("device_id", deviceSeed.getText().toString());
                    editor.putString(
                        "md5_password", Md5Utils.getMd5(highBlock.getText().toString()));
                    editor.apply();

                    Intent intent = new Intent(SetDeviceActivity.this, MainActivity.class);
                    SetDeviceActivity.this.startActivity(intent);
                    SetDeviceActivity.this.finish();
                  }
                })
            .setNegativeButton(getString(R.string.alert_cancel), null)
            .show();
      } else {
        FrameLayout layoutRoot = (FrameLayout) findViewById(R.id.layout_root);
        final Snackbar snackbar =
            Snackbar.make(
                layoutRoot,
                getResources().getString(R.string.incorrect_seed),
                Snackbar.LENGTH_LONG);
        View snackBarView = snackbar.getView();
        TextView text =
            (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text);
        text.setTextColor(getResources().getColor(R.color.icons));
        snackBarView.setBackgroundColor(getResources().getColor(R.color.primary));
        snackbar.setActionTextColor(getResources().getColor(R.color.snack_action));
        snackbar.setAction(
            getString(R.string.i_know),
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                snackbar.dismiss();
              }
            });
        snackbar.show();
      }
    }
    return super.onOptionsItemSelected(item);
  }