コード例 #1
0
  private void featchData() {

    progressBar.startIntro();
    progressBar.setProgress(0);
    if (!MyApplication.instance.isNetworkAvailable()) {
      try {
        Snackbar snackbar =
            Snackbar.make(relativeLayout, "لا يوجد اتصال بالانترنت", Snackbar.LENGTH_INDEFINITE)
                .setAction(
                    "اعد المحاولة",
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        featchData();
                      }
                    });
        snackbar.setActionTextColor(Color.RED);

        View sbView = snackbar.getView();
        TextView textView =
            (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setTextColor(Color.YELLOW);

        snackbar.show();
      } catch (Exception e) {

      }
    } else {

      webView.stopLoading();
      webView.loadUrl(MyApplication.BASE_URL + urlExtention);
    }
  }
コード例 #2
0
  /* 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();
  }
コード例 #3
0
ファイル: RecentFragment.java プロジェクト: bkromhout/Minerva
  /**
   * 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();
  }
コード例 #4
0
  private void updateCatagory() {

    final Dao<CatagoryModel, Integer> catagoryDoa;

    try {
      catagoryDoa = getHelper().getCatagoryDao();

      UpdateBuilder<CatagoryModel, Integer> updateBuilder = catagoryDoa.updateBuilder();
      updateBuilder.updateColumnValue("catagoryName", catagoryEditText.getText().toString());

      updateBuilder
          .where()
          .eq("categoryId", Integer.valueOf(catagoryModel.getCategoryId()))
          .and()
          .eq("catagoryName", catagoryModel.getCatagoryName());
      ;
      updateBuilder.update();

      Snackbar snackbar =
          Snackbar.make(view, "Catagory updated sucessfully!!", Snackbar.LENGTH_LONG);

      snackbar.show();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
 @Override
 public void showSnackbar(String message) {
   CoordinatorLayout coordinator =
       (CoordinatorLayout) getActivity().findViewById(R.id.coordinator);
   Snackbar snackbar = Snackbar.make(coordinator, message, Snackbar.LENGTH_LONG);
   snackbar.show();
 }
コード例 #6
0
 private void onFabClicked() {
   Snackbar testSnackbar =
       Snackbar.make(
           findViewById(android.R.id.content), "Snackbar clicked", Snackbar.LENGTH_SHORT);
   testSnackbar.show();
   /** Managing the {@link Snackbar} is not that hard either */
   RxSnackbar.dismisses(testSnackbar).subscribe(this::onSnackbarDismissed);
 }
コード例 #7
0
  private void onSwipeDelete(RecyclerView.ViewHolder viewHolder, final View rootView) {
    billId = ((TextView) viewHolder.itemView.findViewById(R.id.tvPayID)).getText().toString();
    getSingleBill();

    Snackbar snackbar =
        Snackbar.make(rootView, AppConfig.BILL_DELETED, Snackbar.LENGTH_LONG)
            .setAction(AppConfig.UNDO, mOnClickListener);
    snackbar.show();
  }
コード例 #8
0
ファイル: SnackbarHelper.java プロジェクト: natix643/uome
  private void show(int stringId, int colorId, int length) {
    Snackbar snackbar = Snackbar.make(contentView, stringId, length);
    dismissOnClick(snackbar);

    TextView text =
        (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
    text.setTextColor(activity.getResources().getColor(colorId));

    snackbar.show();
  }
コード例 #9
0
 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();
 }
コード例 #10
0
 public void showProgressBar(boolean isShow) throws Exception {
   if (isShow) {
     progressBar.setVisibility(View.VISIBLE);
     if (snackbar != null) {
       snackbar.show();
     }
   } else {
     progressBar.setVisibility(View.GONE);
     if (snackbar != null) {
       snackbar.dismiss();
     }
   }
 }
コード例 #11
0
ファイル: AppInfoActivity.java プロジェクト: Dairowu/TiTa
  @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;
    }
  }
コード例 #12
0
  protected void showToast(String message, boolean isLong) {

    @LayoutRes int rootView = getRootView();
    View view = this.findViewById(rootView);

    if (view == null) {
      Timber.e("view is null, cannot show toast");
      Timber.d("View id: '" + getLayoutResource() + "'");
      return;
    }

    Snackbar snackbar =
        Snackbar.make(view, message, isLong ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT);
    snackbar.show();
  }
コード例 #13
0
  // 加载更多
  private void loadMore(final String url) {
    isLoading = true; // 正在加载
    if (HttpUtils.isNetworkConnected(mActivity)) {
      XUtil.GetJson(
          url,
          new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
              //                    PreUtils.putStringTo(Constant.CACHE, mActivity, url,
              // responseString);
              SQLiteDatabase db =
                  ((MainActivity) mActivity).getCacheDbHelper().getWritableDatabase();
              db.execSQL(
                  "replace into CacheList(date,json) values(" + date + ",' " + result + "')");
              db.close();
              parseBeforeJson(result);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
              //                    UIUtils.showToastSafe("解析失败: "+ex.toString());
            }
          });

    } else {
      SQLiteDatabase db = ((MainActivity) mActivity).getCacheDbHelper().getReadableDatabase();
      Cursor cursor = db.rawQuery("select * from CacheList where date = " + date, null);
      if (cursor.moveToFirst()) {
        String json = cursor.getString(cursor.getColumnIndex("json"));
        parseBeforeJson(json);
      } else {
        db.delete("CacheList", "date < " + date, null);
        isLoading = false;
        Snackbar sb = Snackbar.make(lv_news, "没有更多的离线内容了~", Snackbar.LENGTH_SHORT);
        sb.getView()
            .setBackgroundColor(
                mActivity
                    .getResources()
                    .getColor(
                        ((MainActivity) mActivity).isLight()
                            ? android.R.color.holo_blue_dark
                            : android.R.color.black));
        sb.show();
      }
      cursor.close();
      db.close();
    }
  }
コード例 #14
0
 protected void showColorfulSnackbar(
     String text,
     String action,
     View.OnClickListener actionListener,
     int bgColor,
     int textColor,
     int actionTextColor) {
   Snackbar snackbar =
       Snackbar.make(findViewById(android.R.id.content), text, Snackbar.LENGTH_SHORT)
           .setAction(action, actionListener);
   snackbar.setActionTextColor(actionTextColor);
   View bgView = snackbar.getView();
   bgView.setBackgroundColor(bgColor);
   TextView textView = (TextView) bgView.findViewById(android.support.design.R.id.snackbar_text);
   textView.setTextColor(textColor);
   snackbar.show();
 }
コード例 #15
0
    public void onEventMainThread(Events.StateChanged.ServiceBroker e) {
      Log.v(TAG, "onEventMainThread StateChanged.ServiceBroker -> " + e.getState());
      if (cachedState != null) {
        Snackbar snackbar = null;
        if (e.getState() == ServiceBroker.State.CONNECTED) {
          snackbar =
              Snackbar.make(
                  getActivity().findViewById(R.id.content_frame),
                  R.string.snackbarConnected,
                  Snackbar.LENGTH_LONG); // Don’t forget to show!
        } else if (e.getState() == ServiceBroker.State.CONNECTING) {
          snackbar =
              Snackbar.make(
                  getActivity().findViewById(R.id.content_frame),
                  R.string.snackbarConnecting,
                  Snackbar.LENGTH_LONG); // Don’t forget to show!

        } else if (e.getState() == ServiceBroker.State.DISCONNECTED
            || e.getState() == ServiceBroker.State.DISCONNECTED_USERDISCONNECT) {
          snackbar =
              Snackbar.make(
                  getActivity().findViewById(R.id.content_frame),
                  R.string.snackbarDisconnected,
                  Snackbar.LENGTH_LONG); // Don’t forget to show!
        } else if (e.getState() == ServiceBroker.State.DISCONNECTED_ERROR) {
          snackbar =
              Snackbar.make(
                  getActivity().findViewById(R.id.content_frame),
                  R.string.snackbarDisconnectedError,
                  Snackbar.LENGTH_LONG); // Don’t forget to show!
        }

        // Fix snackbar text color and show
        if (snackbar != null) {
          View view = snackbar.getView();
          TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
          tv.setTextColor(Color.WHITE);
          snackbar.show();
        }
      }
      cachedState =
          e
              .getState(); // this event might arrive before options menu is ready. In this case
                           // onCreateOptionsmenu updates the button from the cachedState
      updateDisconnectButton(e.getState());
    }
コード例 #16
0
        @Override
        public void run() {
          if (Build.VERSION.SDK_INT >= 23) {
            String permissionLabel = "";
            try {
              PackageManager pm = mContext.getPackageManager();
              PermissionGroupInfo pg =
                  pm.getPermissionGroupInfo(
                      Manifest.permission_group.STORAGE, PackageManager.GET_META_DATA);
              permissionLabel = pg.loadLabel(pm).toString();
            } catch (Exception e) {

            }
            if (!permissionLabel.isEmpty()) {
              permissionLabel = "(" + permissionLabel + ")";
            }
            permissionLabel =
                getString(R.string.guide_feature_permission)
                    + " "
                    + getString(R.string.allow_permission)
                    + permissionLabel;
            Snackbar snackbar =
                Snackbar.make(mLayout.getRootView(), permissionLabel, Snackbar.LENGTH_LONG)
                    .setAction(
                        getString(R.string.permission_setting),
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            intent.setData(Uri.parse("package:" + mContext.getPackageName()));
                            mContext.startActivity(intent);
                          }
                        });
            // snackbar.setActionTextColor(Color.MAGENTA);
            View snackbarView = snackbar.getView();
            TextView textView =
                (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
            textView.setMaxLines(5);
            snackbar.show();
          }
        }
コード例 #17
0
 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();
 }
コード例 #18
0
  public void checkInternet() {
    if (!MyApplication.instance.isNetworkAvailable()) {
      Snackbar snackbar =
          Snackbar.make(relativeLayout, "لا يوجد اتصال بالانترنت", Snackbar.LENGTH_INDEFINITE)
              .setAction(
                  "اعد المحاولة",
                  new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      checkInternet();
                    }
                  });
      snackbar.setActionTextColor(Color.RED);

      View sbView = snackbar.getView();
      TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
      textView.setTextColor(Color.YELLOW);

      snackbar.show();
    }
  }
コード例 #19
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();
          }
        });
  }
コード例 #20
0
  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());
  }
コード例 #21
0
 /**
  * Helper method that shows that specified {@link Snackbar} and waits until it has been fully
  * shown. Note that calling this method will reset the currently set {@link Snackbar.Callback}.
  */
 public static void showSnackbarAndWaitUntilFullyShown(Snackbar snackbar) {
   SnackbarShownCallback snackbarCallback = new SnackbarShownCallback();
   snackbar.setCallback(snackbarCallback);
   try {
     // Register our listener as idling resource so that Espresso waits until the
     // the snackbar has been fully shown
     Espresso.registerIdlingResources(snackbarCallback);
     // Show the snackbar
     snackbar.show();
     // Mark the callback to require waiting for idle state
     snackbarCallback.mNeedsIdle = true;
     // Perform a dummy Espresso action that loops until the UI thread is idle. This
     // effectively blocks us until the Snackbar has completed its sliding animation.
     onView(isRoot()).perform(waitUntilIdle());
     snackbarCallback.mNeedsIdle = false;
   } finally {
     // Unregister our idling resource
     Espresso.unregisterIdlingResources(snackbarCallback);
     // And remove our tracker listener from Snackbar
     snackbar.setCallback(null);
   }
 }
コード例 #22
0
  private void deleteCatagory() {

    final Dao<CatagoryModel, Integer> catagoryDoa;

    try {
      catagoryDoa = getHelper().getCatagoryDao();

      DeleteBuilder<CatagoryModel, Integer> deleteBuilder = catagoryDoa.deleteBuilder();
      deleteBuilder
          .where()
          .eq("categoryId", Integer.valueOf(catagoryModel.getCategoryId()))
          .and()
          .eq("catagoryName", catagoryModel.getCatagoryName());
      deleteBuilder.delete();

      Snackbar snackbar =
          Snackbar.make(view, "Catagory deleted sucessfully!!", Snackbar.LENGTH_LONG);
      snackbar.show();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
コード例 #23
0
ファイル: MainActivity.java プロジェクト: sourabhv/Stopwatch
 @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);
   }
 }
コード例 #24
0
 // TODO: unused
 public void onFabButtonClick(View view) {
   final Snackbar bar =
       Snackbar.make(findViewById(R.id.action_bar_root), "Connected", Snackbar.LENGTH_LONG);
   bar.show();
 }
コード例 #25
0
  private void showSnackbar(String text, int duration) {
    Snackbar snackbar = Snackbar.make(coordinatorLayout, text, duration);

    snackbar.show();
  }
コード例 #26
0
ファイル: SnackbarHelper.java プロジェクト: natix643/uome
 public void info(int stringId) {
   Snackbar snackbar = Snackbar.make(contentView, stringId, LENGTH_SHORT);
   dismissOnClick(snackbar);
   snackbar.show();
 }
コード例 #27
0
  @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);
  }