Ejemplo n.º 1
0
 /** Sets the current progress (must be between 0 and max). */
 public void setProgress(int progress) {
   if (progress > mMax || progress < 0) {
     throw new IllegalArgumentException(
         String.format("Progress (%d) must be between %d and %d", progress, 0, mMax));
   }
   mProgress = progress;
   if (null != mListener) {
     if (mProgress == mMax) {
       mListener.onProgressCompleted();
     } else {
       mListener.onProgressChanged(mProgress, mMax);
     }
   }
   invalidate();
 }
Ejemplo n.º 2
0
  private void attemptSignup() {
    if (mAuthTask != null) {
      return;
    }

    // Reset errors.
    mEmailView.setError(null);
    mPassword1View.setError(null);
    mPassword2View.setError(null);

    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String username = mUsername.getText().toString();
    String password = mPassword1View.getText().toString();
    String re_password = mPassword2View.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(re_password) && !isPasswordMatched(password, re_password)) {
      mPassword2View.setError(getString(R.string.error_incorrect_password));
      focusView = mPassword2View;
      cancel = true;
    }
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
      mPassword1View.setError(getString(R.string.error_invalid_password));
      focusView = mPassword1View;
      cancel = true;
    }

    // Check for a valid email address.
    if (!isEmailValid(email)) {
      mEmailView.setError(getString(R.string.error_invalid_email));
      focusView = mEmailView;
      cancel = true;
    } else if (TextUtils.isEmpty(email)) {
      mEmailView.setError(getString(R.string.error_field_required));
      focusView = mEmailView;
      cancel = true;
    }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a progress spinner, and kick off a background task to
      // perform the user login attempt.
      if (mProgressListener != null) {
        mProgressListener.onShowProgress(true);
      }
      mAuthTask = new UserSignupTask(email, username, password);
      mAuthTask.execute((Void) null);
    }
  }
Ejemplo n.º 3
0
  @Override
  public boolean send() {
    boolean isSuccess = false;

    HttpURLConnection conn = null;

    ByteArrayOutputStream output = null;

    InputStream input = null;
    String strNetTypeName = "";

    try {
      String sUrl = getUrl();
      if (sUrl == null) {
        throw new Exception("you have not set request url");
      }

      sUrl =
          sUrl
              + (getData() == null
                  ? ""
                  : ((sUrl.indexOf("?") > -1 ? (sUrl.endsWith("&") ? "" : "&") : "?")
                      + getParamString()));

      Log.d(LOG_TAG, getId() + ":" + sUrl);

      URL url = new URL(sUrl);

      conn = getConnect(mContext, url);
      checkCacnelStatus();
      conn.setConnectTimeout(getConnectTimeout());
      conn.setReadTimeout(getGetDataTimeout());

      final HashMap<String, String> header = getRequestHeader();
      if (null != header) {
        final Iterator<Entry<String, String>> inerator = header.entrySet().iterator();
        while (inerator.hasNext()) {
          Entry<String, String> entry = inerator.next();
          conn.setRequestProperty(entry.getKey(), entry.getValue());
          //	Log.d("||" + entry.getKey(), entry.getValue());
        }
      }

      if (mIfModifiedSince > 0) {
        conn.setIfModifiedSince(mIfModifiedSince);
      }

      requestStart = new Date().getTime();
      checkCacnelStatus();
      conn.connect();
      checkCacnelStatus();
      final int responseCode = conn.getResponseCode();

      mHttpStatus = responseCode;

      if (responseCode == HttpStatus.SC_NOT_MODIFIED) {
        setResponseHeader(conn);
        requestEnd = new Date().getTime();
        return true;
      }

      if (responseCode != HttpStatus.SC_OK) {
        Log.d(LOG_TAG, responseCode + "|||");
        throw new java.net.SocketException("http status is not 200 or 304");
      }

      if (conn.getContentType().contains("text/vnd.wap.wml") == true && tryCount < getTryLimit()) {
        tryCount++;
        return send();
      }

      output = new ByteArrayOutputStream();

      input = conn.getInputStream();

      final int totalSize = conn.getContentLength();

      int num = 0, downLoaded = 0;

      byte[] buf = new byte[BUFFERSIZE];
      while (mIsNeedResponse && !checkCacnelStatus() && (num = input.read(buf)) != -1) {
        output.write(buf, 0, num);
        downLoaded += num;
        if (mOnProgressListener != null) {
          long now = ToolUtil.getCurrentTime();
          if (now - lastProgressNotifyTime > PROGRESS_NOTIFY_OFFSET) {
            lastProgressNotifyTime = now;
            mOnProgressListener.onProgress(null, downLoaded, totalSize);
          }
        }
      }
      checkCacnelStatus();

      requestEnd = ToolUtil.getCurrentTime();
      checkCacnelStatus();
      setResult(conn, output);
      buf = null;
      isSuccess = true;
    } catch (CancelException ex) {
      Log.e(LOG_TAG, "HttpStatus = " + mHttpStatus + "\n" + ToolUtil.getStackTraceString(ex));
    } catch (java.net.ConnectException ex) {
      Log.e(
          LOG_TAG,
          "HttpStatus = " + mHttpStatus + "\n" + ToolUtil.getStackTraceString(ex) + " " + getId());
      strNetTypeName = HttpUtil.getNetTypeName();
      StatisticsEngine.trackEvent(
          IcsonApplication.app,
          "http_connect_exception",
          "network: " + strNetTypeName + ", HttpStatus = " + mHttpStatus);
    } catch (java.net.SocketException ex) {
      Log.e(
          LOG_TAG,
          "HttpStatus = " + mHttpStatus + "\n" + ToolUtil.getStackTraceString(ex) + " " + getId());
      strNetTypeName = HttpUtil.getNetTypeName();
      StatisticsEngine.trackEvent(
          IcsonApplication.app,
          "http_socket_exception",
          "network: " + strNetTypeName + ", HttpStatus = " + mHttpStatus);
    } catch (Exception ex) {
      Log.e(LOG_TAG, ToolUtil.getStackTraceString(ex));
      strNetTypeName = HttpUtil.getNetTypeName();
      StatisticsEngine.trackEvent(
          IcsonApplication.app,
          "http_other_exception",
          "network: " + strNetTypeName + ", HttpStatus = " + mHttpStatus);
    } finally {
      try {
        if (input != null) {
          input.close();
          input = null;
        }
        if (output != null) {
          output.close();
          output = null;
        }
        if (conn != null) {
          conn.disconnect();
          conn = null;
        }
      } catch (Exception ex) {
        Log.e(LOG_TAG, ToolUtil.getStackTraceString(ex));
      }
    }

    return isSuccess;
  }