Exemplo n.º 1
0
  private void init() {
    header = LayoutInflater.from(context).inflate(R.layout.list_header, null);
    footer = LayoutInflater.from(context).inflate(R.layout.listfooter, null);

    arrowImageView = (ImageView) header.findViewById(R.id.head_arrowImageView);
    progressBar = (ImageView) header.findViewById(R.id.head_progressBar);
    tipsTextView = (TextView) header.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) header.findViewById(R.id.head_lastUpdatedTextView);

    Common.measureView(header);
    headerHeight = header.getMeasuredHeight();

    addHeaderView(header, null, false);

    addFooterView(footer, null, false);
    footer.setVisibility(View.GONE);
    header.setPadding(0, -1 * headerHeight, 0, 0);

    animation =
        new RotateAnimation(
            0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(250);
    animation.setFillAfter(true);

    reverseAnimation =
        new RotateAnimation(
            -180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(200);
    reverseAnimation.setFillAfter(true);
  }
Exemplo n.º 2
0
  private void changeHeaderViewByState() {
    lastUpdatedTextView.setText(
        context.getString(R.string.refresh_lasttime) + Common.howTimeAgo(context, lastRefreshTime));
    if (isRefreshable) {
      switch (state) {
        case RELEASE_TO_REFRESH:
          arrowImageView.setVisibility(View.VISIBLE);
          progressBar.setVisibility(View.GONE);
          tipsTextView.setVisibility(View.VISIBLE);
          arrowImageView.clearAnimation();
          arrowImageView.startAnimation(animation);
          tipsTextView.setText(context.getString(R.string.refresh_release));
          break;
        case PULL_TO_REFRESH:
          progressBar.setVisibility(View.GONE);
          tipsTextView.setVisibility(View.VISIBLE);
          arrowImageView.clearAnimation();
          arrowImageView.setVisibility(View.VISIBLE);
          // 是由RELEASE_To_REFRESH状态转变来的
          if (isBack) {
            isBack = false;
            arrowImageView.clearAnimation();
            arrowImageView.startAnimation(reverseAnimation);
          }
          // Log.v(TAG, "当前状态,下拉刷新");
          tipsTextView.setText(context.getString(R.string.refresh_pull));
          break;
        case REFRESHING:
          header.setPadding(0, 0, 0, 0);

          progressBar.setVisibility(View.VISIBLE);
          arrowImageView.clearAnimation();
          arrowImageView.setVisibility(View.GONE);
          // tipsTextview.setText(context.getString(R.string.loading));
          tipsTextView.setVisibility(View.GONE);
          lastUpdatedTextView.setVisibility(View.GONE);
          // Log.v(TAG, "当前状态,正在刷新...");
          break;
        case DONE:
          header.setPadding(0, -1 * headerHeight, 0, 0);

          progressBar.setVisibility(View.GONE);
          arrowImageView.clearAnimation();
          arrowImageView.setImageResource(R.drawable.arrow);
          tipsTextView.setText(context.getString(R.string.refresh_pull));
          tipsTextView.setVisibility(View.VISIBLE);
          lastUpdatedTextView.setVisibility(View.VISIBLE);
          // Log.v(TAG, "当前状态,done");
          break;
        default:
          break;
      }
    }
  }