コード例 #1
0
  @Override
  protected final void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
      Bundle bundle = (Bundle) state;

      setMode(Mode.mapIntToValue(bundle.getInt(STATE_MODE, 0)));
      mCurrentMode = Mode.mapIntToValue(bundle.getInt(STATE_CURRENT_MODE, 0));

      mScrollingWhileRefreshingEnabled =
          bundle.getBoolean(STATE_SCROLLING_REFRESHING_ENABLED, false);
      mShowViewWhileRefreshing = bundle.getBoolean(STATE_SHOW_REFRESHING_VIEW, true);

      // Let super Restore Itself
      super.onRestoreInstanceState(bundle.getParcelable(STATE_SUPER));

      State viewState = State.mapIntToValue(bundle.getInt(STATE_STATE, 0));
      if (viewState == State.REFRESHING || viewState == State.MANUAL_REFRESHING) {
        setState(viewState, true);
      }

      // Now let derivative classes restore their state
      onPtrRestoreInstanceState(bundle);
      return;
    }

    super.onRestoreInstanceState(state);
  }
コード例 #2
0
  @SuppressWarnings("deprecation")
  private void init(Context context, AttributeSet attrs) {
    switch (getPullToRefreshScrollDirection()) {
      case HORIZONTAL:
        setOrientation(LinearLayout.HORIZONTAL);
        break;
      case VERTICAL:
      default:
        setOrientation(LinearLayout.VERTICAL);
        break;
    }

    setGravity(Gravity.CENTER);

    ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();

    // Styleables from XML
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);

    if (a.hasValue(R.styleable.PullToRefresh_ptrMode)) {
      mMode = Mode.mapIntToValue(a.getInteger(R.styleable.PullToRefresh_ptrMode, 0));
    }

    if (a.hasValue(R.styleable.PullToRefresh_ptrAnimationStyle)) {
      mLoadingAnimationStyle =
          AnimationStyle.mapIntToValue(
              a.getInteger(R.styleable.PullToRefresh_ptrAnimationStyle, 0));
    }

    // Refreshable View
    // By passing the attrs, we can add ListView/GridView params via XML
    mRefreshableView = createRefreshableView(context, attrs);
    addRefreshableView(context, mRefreshableView);

    // We need to create now layouts now
    mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
    mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);

    /** Styleables from XML */
    if (a.hasValue(R.styleable.PullToRefresh_ptrRefreshableViewBackground)) {
      Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrRefreshableViewBackground);
      if (null != background) {
        mRefreshableView.setBackgroundDrawable(background);
      }
    } else if (a.hasValue(R.styleable.PullToRefresh_ptrAdapterViewBackground)) {
      Utils.warnDeprecation("ptrAdapterViewBackground", "ptrRefreshableViewBackground");
      Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrAdapterViewBackground);
      if (null != background) {
        mRefreshableView.setBackgroundDrawable(background);
      }
    }

    if (a.hasValue(R.styleable.PullToRefresh_ptrOverScroll)) {
      mOverScrollEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrOverScroll, true);
    }

    if (a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
      mScrollingWhileRefreshingEnabled =
          a.getBoolean(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled, false);
    }

    // Let the derivative classes have a go at handling attributes, then
    // recycle them...
    handleStyledAttributes(a);
    a.recycle();

    // Finally update the UI for the modes
    updateUIForMode();
  }