Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    // 设定状态栏的颜色,当版本大于4.4时起作用
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      SystemBarTintManager tintManager = new SystemBarTintManager(this);
      tintManager.setStatusBarTintEnabled(true);
      // 此处可以重新指定状态栏颜色
      tintManager.setStatusBarTintResource(R.color.material_blue);
    }

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle("用户注册"); // 标题的文字需在setSupportActionBar之前,不然会无效
    mToolbar.setTitleTextColor(Color.WHITE);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    etUserName = (MaterialEditText) findViewById(R.id.etUserName);
    etPassword = (MaterialEditText) findViewById(R.id.etPassword);
    etEmail = (MaterialEditText) findViewById(R.id.etEmail);

    cpbtnSignUp = (CircularProgressButton) findViewById(R.id.cpbtnSignUp);
    cpbtnSignUp.setIndeterminateProgressMode(true);
    cpbtnSignUp.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            cpbtnSignUp.setProgress(0);
            cpbtnSignUp.setProgress(50); // 注册按钮开始显示进度

            user = new StudentUser();
            user.setUsername(etUserName.getText().toString());
            user.setPassword(etPassword.getText().toString());
            user.setEmail(etEmail.getText().toString());
            user.signUp(
                SignUpActivity.this,
                new SaveListener() {
                  @Override
                  public void onSuccess() {
                    cpbtnSignUp.setProgress(100);
                    // Toast.makeText(SignUpActivity.this, "注册成功!", Toast.LENGTH_SHORT).show();
                    final int activityFinishDelay = 2000;
                    new Handler()
                        .postDelayed(
                            new Runnable() {
                              @Override
                              public void run() {
                                SignUpActivity.this.finish();
                              }
                            },
                            activityFinishDelay);
                  }

                  @Override
                  public void onFailure(int i, String s) {

                    // Toast.makeText(SignUpActivity.this, "错误码:"+ i +"注册失败:" + s,
                    // Toast.LENGTH_SHORT).show();
                    switch (i) {
                      case 202:
                        cpbtnSignUp.setErrorText("注册失败,用户名已存在");
                        break;
                      case 203:
                        cpbtnSignUp.setErrorText("注册失败,邮箱已使用");
                        break;
                      case 305:
                        cpbtnSignUp.setErrorText("注册失败,用户名或密码为空");
                        break;
                      case 9016:
                        cpbtnSignUp.setErrorText("无网络连接,请检查您的手机网络");
                        break;
                      case 9010:
                        cpbtnSignUp.setErrorText("网络连接超时");
                        break;
                      default:
                        cpbtnSignUp.setErrorText("注册失败");
                        break;
                    }
                    cpbtnSignUp.setProgress(-1);
                  }
                });
          }
        });
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_details);

    Intent i = getIntent();
    String style = i.getStringExtra("style");

    // 设定状态栏的颜色,当版本大于4.4时起作用
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      SystemBarTintManager tintManager = new SystemBarTintManager(this);
      tintManager.setStatusBarTintEnabled(true);
      // 此处可以重新指定状态栏颜色
      if (style != null) {
        tintManager.setStatusBarTintColor(Color.parseColor(style));
      } else {
        tintManager.setStatusBarTintResource(R.color.colorPrimaryDark);
      }
    }

    url = i.getStringExtra("url");

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitleTextColor(Color.WHITE);
    String title = i.getStringExtra("title");
    if (title != null) {
      mToolbar.setTitle(title);
    } else {
      mToolbar.setTitle("正在加载...");
    }

    if (style != null) {
      mToolbar.setBackgroundColor(Color.parseColor(style));
    }

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final ProgressBar pbBar = (ProgressBar) findViewById(R.id.pbWebView);

    wvNews = (WebView) findViewById(R.id.webViewNews);
    WebSettings settings = wvNews.getSettings();
    // 适应屏幕
    settings.setUseWideViewPort(true);
    //        settings.setSupportZoom(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    //      settings.setLoadWithOverviewMode(true);
    //      settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    wvNews.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
              pbBar.setVisibility(View.INVISIBLE);
              LinearLayout.LayoutParams linearParams =
                  (LinearLayout.LayoutParams) pbBar.getLayoutParams(); // 取控件pbBar当前的布局参数
              linearParams.height = 0; // 当控件的高强制设成0象素
              pbBar.setLayoutParams(linearParams);
            } else {
              if (View.INVISIBLE == pbBar.getVisibility()) {
                pbBar.setVisibility(View.VISIBLE);
              }
              pbBar.setProgress(newProgress);
            }
            super.onProgressChanged(view, newProgress);
          }

          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            getSupportActionBar().setTitle(title);
          }
        });

    // wvNews.loadDataWithBaseURL("about:blank", newsHtml.toString(), "text/html", "utf-8", null);
    wvNews.loadUrl(url);
    // wvNews.loadDataWithBaseURL("about:blank", i.getStringExtra("context"), "text/html", "utf-8",
    // null);//读取intent传过来的本地网页数据

  }