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);
    }
  }
Esempio n. 2
0
  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();
  }
Esempio n. 3
0
 private void dismissOnClick(final Snackbar snackbar) {
   snackbar
       .getView()
       .setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               snackbar.dismiss();
             }
           });
 }
  // 加载更多
  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();
    }
  }
Esempio n. 5
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();
 }
    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());
    }
        @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();
          }
        }
  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();
    }
  }
  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());
  }
Esempio n. 10
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);
  }