Ejemplo n.º 1
0
 public void startChangeWholeHeaderViewPaddingTop(int distance) {
   ValueAnimator animator =
       ValueAnimator.ofInt(
           mWholeHeaderView.getPaddingTop(), mWholeHeaderView.getPaddingTop() - distance);
   animator.setDuration(mRefreshViewHolder.getTopAnimDuration());
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           int paddingTop = (int) animation.getAnimatedValue();
           mWholeHeaderView.setPadding(0, paddingTop, 0, 0);
         }
       });
   animator.start();
 }
Ejemplo n.º 2
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (null != mRefreshHeaderView) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          mWholeHeaderDownY = (int) event.getY();
          if (mCustomHeaderView != null) {
            mWholeHeaderViewDownPaddingTop = mWholeHeaderView.getPaddingTop();
          }

          if (mCustomHeaderView == null || !mIsCustomHeaderViewScrollable) {
            mRefreshDownY = (int) event.getY();
          }
          if (isWholeHeaderViewCompleteInvisible()) {
            mRefreshDownY = (int) event.getY();
            return true;
          }
          break;
        case MotionEvent.ACTION_MOVE:
          if (handleActionMove(event)) {
            return true;
          }
          break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
          if (handleActionUpOrCancel(event)) {
            return true;
          }
          break;
        default:
          break;
      }
    }
    return super.onTouchEvent(event);
  }
Ejemplo n.º 3
0
        public void handleMessage(android.os.Message msg) {
          switch (msg.what) {
            case REFRESH_BACKING: // 反弹中
              mHeaderLinearLayout.setPadding(
                  mHeaderLinearLayout.getPaddingLeft(),
                  (int) (mHeaderLinearLayout.getPaddingTop() * 0.75f),
                  mHeaderLinearLayout.getPaddingRight(),
                  mHeaderLinearLayout.getPaddingBottom());
              showProgressBar();
              break;

            case REFRESH_BACED: // 达到刷新界限,反弹结束后,加载数据
              headerInfo.setText("正在加载...");
              rotateArrow(ROTATE_DOWN);
              showProgressBar();
              mPullRefreshState = EXIT_PULL_REFRESH;
              new Thread() {
                public void run() {
                  if (mRefreshListener != null) {
                    mRefreshObject = mRefreshListener.refreshing();
                  }
                  Message msg = mHandler.obtainMessage();
                  msg.what = REFRESH_DONE;
                  msg.sendToTarget();
                };
              }.start();
              break;

            case REFRESH_RETURN: // 没有达到刷新界限,返回
              headerInfo.setText("下拉刷新");
              rotateArrow(ROTATE_DOWN);
              showArrow();
              mHeaderLinearLayout.setPadding(
                  mHeaderLinearLayout.getPaddingLeft(),
                  0,
                  mHeaderLinearLayout.getPaddingRight(),
                  mHeaderLinearLayout.getPaddingBottom());
              mPullRefreshState = NONE_PULL_REFRESH;
              setSelection(1);
              break;

            case REFRESH_DONE: // 加载数据结束
              headerInfo.setText("下拉刷新");
              headerTime.setText("更新时间为: " + mSimpleDateFormat.format(new Date()));
              rotateArrow(ROTATE_DOWN);
              showArrow();
              mHeaderLinearLayout.setPadding(
                  mHeaderLinearLayout.getPaddingLeft(),
                  0,
                  mHeaderLinearLayout.getPaddingRight(),
                  mHeaderLinearLayout.getPaddingBottom());
              mPullRefreshState = NONE_PULL_REFRESH;
              setSelection(1);
              if (mRefreshListener != null) {
                mRefreshListener.refreshed(mRefreshObject);
              }
              break;
          }
        };
 private int[] getDims(LinearLayout ll) {
   int[] diems = new int[4];
   diems[0] = ll.getPaddingLeft();
   diems[1] = ll.getPaddingTop();
   diems[2] = ll.getPaddingRight();
   diems[3] = ll.getPaddingBottom();
   return diems;
 }
  private void init(Context context) {
    // 设置滑动效果
    animation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(100);
    animation.setFillAfter(true);

    reverseAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(100);
    reverseAnimation.setFillAfter(true);

    inflater = LayoutInflater.from(context);
    headView = (LinearLayout) inflater.inflate(R.layout.pull_to_refresh_head, null);

    arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
    arrowImageView.setMinimumWidth(50);
    arrowImageView.setMinimumHeight(50);
    progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
    tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);

    headContentOriginalTopPadding = headView.getPaddingTop();

    measureView(headView);
    headContentHeight = headView.getMeasuredHeight();
    headContentWidth = headView.getMeasuredWidth();

    headView.setPadding(
        headView.getPaddingLeft(),
        -1 * headContentHeight,
        headView.getPaddingRight(),
        headView.getPaddingBottom());
    headView.invalidate();

    // System.out.println("初始高度�?+headContentHeight);
    // System.out.println("初始TopPad�?+headContentOriginalTopPadding);

    addHeaderView(headView);
    setOnScrollListener(this);
  }
Ejemplo n.º 6
0
  /**
   * 处理手指抬起事件
   *
   * @return true表示自己消耗掉该事件,false表示不消耗该事件
   */
  private boolean handleActionUpOrCancel(MotionEvent event) {
    boolean isReturnTrue = false;
    // 如果当前头部刷新控件没有完全隐藏,则需要返回true,自己消耗ACTION_UP事件
    if ((mCustomHeaderView == null || (mCustomHeaderView != null && !mIsCustomHeaderViewScrollable))
        && mWholeHeaderView.getPaddingTop() != mMinWholeHeaderViewPaddingTop) {
      isReturnTrue = true;
    }

    if (mCurrentRefreshStatus == RefreshStatus.PULL_DOWN
        || mCurrentRefreshStatus == RefreshStatus.IDLE) {
      // 处于下拉刷新状态,松手时隐藏下拉刷新控件
      if (mCustomHeaderView == null
          || (mCustomHeaderView != null
              && mWholeHeaderView.getPaddingTop() < 0
              && mWholeHeaderView.getPaddingTop() > mMinWholeHeaderViewPaddingTop)) {
        hiddenRefreshHeaderView();
      }
      mCurrentRefreshStatus = RefreshStatus.IDLE;
      handleRefreshStatusChanged();
    } else if (mCurrentRefreshStatus == RefreshStatus.RELEASE_REFRESH) {
      // 处于松开进入刷新状态,松手时完全显示下拉刷新控件,进入正在刷新状态
      beginRefreshing();
    }

    if (mRefreshDownY == -1) {
      mRefreshDownY = (int) event.getY();
    }
    int diffY = (int) event.getY() - mRefreshDownY;
    if (shouldHandleLoadingMore() && diffY <= 0) {
      // 处理上拉加载更多,需要返回true,自己消耗ACTION_UP事件
      isReturnTrue = true;
      beginLoadingMore();
    }

    mWholeHeaderDownY = -1;
    mRefreshDownY = -1;
    return isReturnTrue;
  }
    public void performValidation() {
      getEditText().setError(null);
      if (editTextValidator.isValidity()) {
        // Dismiss once everything is OK.
        theDialog.dismiss();
        ValidatingEditTextPreference.this.onClick(theDialog, AlertDialog.BUTTON_POSITIVE);

        // reset padding - for when dialog is used again
        if (originalBottomPadding != Integer.MIN_VALUE) {
          LinearLayout parentLayout = (LinearLayout) getEditText().getParent();

          if (originalBottomPadding == parentLayout.getPaddingBottom()) {
            parentLayout.setPadding(
                parentLayout.getPaddingLeft(),
                parentLayout.getPaddingTop(),
                parentLayout.getPaddingRight(),
                originalBottomPadding);
          }
        }
      } else {

        // increase padding so error message doesn't cover buttons
        if (originalBottomPadding != Integer.MIN_VALUE) {
          LinearLayout parentLayout = (LinearLayout) getEditText().getParent();

          if (originalBottomPadding == parentLayout.getPaddingBottom()) {
            parentLayout.setPadding(
                parentLayout.getPaddingLeft(),
                parentLayout.getPaddingTop(),
                parentLayout.getPaddingRight(),
                (int) (parentLayout.getPaddingBottom() + getEditText().getHeight() * 1.05));
          }
        }

        // don't dismiss the dialog
      }
    }
Ejemplo n.º 8
0
 public void bindSectionHeader(View view, int position, boolean displaySectionHeader) {
   TextView tv = (TextView) view.findViewById(R.id.information_header);
   LinearLayout layoutOther = (LinearLayout) view.findViewById(R.id.information_layout_other);
   if (topPadding == 0) {
     topPadding = layoutOther.getPaddingTop();
   }
   LinearLayout layoutTitle = (LinearLayout) view.findViewById(R.id.information_layout_title);
   if (displaySectionHeader) {
     layoutTitle.setVisibility(View.VISIBLE);
     tv.setText(getSections()[getSectionForPosition(position)]);
     layoutOther.setPadding(0, topPadding, 0, 0);
   } else {
     layoutTitle.setVisibility(View.GONE);
     layoutOther.setPadding(0, 0, 0, 0);
   }
 }
Ejemplo n.º 9
0
  private void initViews() {
    logo = (ImageView) findViewById(R.id.img_login);
    et1 = (EditText) findViewById(R.id.et_login_account);
    et2 = (EditText) findViewById(R.id.et_login_password);

    sLayout = (LinearLayout) findViewById(R.id.layout_login);
    sLayPadRect =
        new Rect(
            sLayout.getPaddingLeft(),
            sLayout.getPaddingTop(),
            sLayout.getPaddingRight(),
            sLayout.getPaddingBottom());

    if (resizeLayout != null) {
      resizeLayout.setOnResizeListener(
          new JackResizeLayout.OnResizeListener() {

            @Override
            public void OnResize(int w, int h, int oldw, int oldh) {

              if (sLayout != null && sLayPadRect != null) {
                mHandler.sendEmptyMessage(oldh > h ? 1 : 2);
              }
            }
          });
    }

    sButton = (Button) findViewById(R.id.btn_log);
    JackButtonColorFilter.setButtonFocusChanged(sButton);
    sButton.setOnClickListener(this);

    tv1 = (TextView) findViewById(R.id.tv_register);
    tv2 = (TextView) findViewById(R.id.tv_guest);
    JackUtils.textpaint_underline(tv1);
    JackUtils.textpaint_underline(tv2);
    tv1.setOnClickListener(this);
    tv2.setOnClickListener(this);

    pref = getSharedPreferences(getString(R.string.preference), Context.MODE_PRIVATE);
    if (pref.contains(getString(R.string.pref_username)))
      et1.setText(pref.getString(getString(R.string.pref_username), "d"));
    if (!pref.contains(getString(R.string.notfirsttime))) {
      goSlide();
    }
  }
Ejemplo n.º 10
0
 private void setPreviewColor() {
   if (mView == null) return;
   ImageView iView = new ImageView(getContext());
   LinearLayout widgetFrameView = ((LinearLayout) mView.findViewById(android.R.id.widget_frame));
   if (widgetFrameView == null) return;
   widgetFrameView.setVisibility(View.VISIBLE);
   widgetFrameView.setPadding(
       widgetFrameView.getPaddingLeft(),
       widgetFrameView.getPaddingTop(),
       (int) (mDensity * 8),
       widgetFrameView.getPaddingBottom());
   // remove already create preview image
   int count = widgetFrameView.getChildCount();
   if (count > 0) {
     widgetFrameView.removeViews(0, count);
   }
   widgetFrameView.addView(iView);
   iView.setBackgroundDrawable(new AlphaPatternDrawable((int) (5 * mDensity)));
   iView.setImageBitmap(getPreviewBitmap());
 }
Ejemplo n.º 11
0
  public void setupWidget() {
    Log.i(TAG, "Clearing any old widget stuffs");
    // remove all views from the layout
    removeAllViews();

    // unregister our content receiver
    if (mBroadcastReceiver != null) {
      mContext.unregisterReceiver(mBroadcastReceiver);
    }
    // unobserve our content
    if (mObserver != null) {
      mObserver.unobserve();
    }

    // clear the button instances
    PowerButton.unloadAllButtons();

    Log.i(TAG, "Setting up widget");

    String buttons =
        Settings.System.getString(mContext.getContentResolver(), Settings.System.WIDGET_BUTTONS);
    if (buttons == null) {
      Log.i(TAG, "Default buttons being loaded");
      buttons = BUTTONS_DEFAULT;
      // Add the WiMAX button if it's supported
      /* TODO: Fix after WiMax Fixed
      if (WimaxHelper.isWimaxSupported(mContext)) {
          buttons += BUTTON_DELIMITER + PowerButton.BUTTON_WIMAX;
      }
      */
    }
    Log.i(TAG, "Button list: " + buttons);

    // create a linearlayout to hold our buttons
    LinearLayout ll = new LinearLayout(mContext);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    ll.setGravity(Gravity.CENTER_HORIZONTAL);

    int buttonCount = 0;
    for (String button : buttons.split("\\|")) {
      Log.i(TAG, "Setting up button: " + button);
      // inflate our button, we don't add it to a parent and don't do any layout shit yet
      View buttonView = mInflater.inflate(R.layout.power_widget_button, null, false);

      if (PowerButton.loadButton(button, buttonView)) {
        // add the button here
        ll.addView(buttonView, BUTTON_LAYOUT_PARAMS);
        buttonCount++;
      } else {
        Log.e(TAG, "Error setting up button: " + button);
      }
    }

    // we determine if we're using a horizontal scroll view based on a threshold of button counts
    if (buttonCount > LAYOUT_SCROLL_BUTTON_THRESHOLD) {
      // we need our horizontal scroll view to wrap the linear layout
      mScrollView = new HorizontalScrollView(mContext);
      // make the fading edge the size of a button (makes it more noticible that we can scroll
      mScrollView.setFadingEdgeLength(
          mContext.getResources().getDisplayMetrics().widthPixels / LAYOUT_SCROLL_BUTTON_THRESHOLD);
      mScrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
      mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
      // set the padding on the linear layout to the size of our scrollbar, so we don't have them
      // overlap
      ll.setPadding(
          ll.getPaddingLeft(),
          ll.getPaddingTop(),
          ll.getPaddingRight(),
          mScrollView.getVerticalScrollbarWidth());
      mScrollView.addView(ll, WIDGET_LAYOUT_PARAMS);
      updateScrollbar();
      addView(mScrollView, WIDGET_LAYOUT_PARAMS);
    } else {
      // not needed, just add the linear layout
      addView(ll, WIDGET_LAYOUT_PARAMS);
    }

    // set up a broadcast receiver for our intents, based off of what our power buttons have been
    // loaded
    setupBroadcastReceiver();
    IntentFilter filter = PowerButton.getAllBroadcastIntentFilters();
    // we add this so we can update views and such if the settings for our widget change
    filter.addAction(Settings.SETTINGS_CHANGED);
    // we need to detect orientation changes and update the static button width value appropriately
    filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    // register the receiver
    mContext.registerReceiver(mBroadcastReceiver, filter);
    // register our observer
    if (mObserver != null) {
      mObserver.observe();
    }
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // isDragging = true;
        startY = ev.getY();
        if (topRowIndex > 1) {
          showRefreshButton = false;
        } else {
          showRefreshButton = true;
        }
        break;
      case MotionEvent.ACTION_MOVE:
        if (!isLoading && showRefreshButton) {
          deltaY = ev.getY() - startY;

          Log.d("debug", String.valueOf(deltaY));

          headerRelativeLayout.setPadding(
              headerRelativeLayout.getPaddingLeft(),
              -1 * HEADER_HEIGHT + (int) deltaY,
              0,
              headerRelativeLayout.getPaddingBottom());

          if (headerRelativeLayout.getPaddingTop() >= HEADER_HEIGHT
              && currentState == STATE_PULL_TO_REFRESH) {
            // change state
            currentState = STATE_RELEASE_TO_UPDATE;
            arrowImage.clearAnimation();
            arrowImage.startAnimation(rotateAnimation);
            headerTextView.setText(R.string.release_to_refresh);
          } else if (headerRelativeLayout.getPaddingTop() < HEADER_HEIGHT
              && currentState == STATE_RELEASE_TO_UPDATE) {
            currentState = STATE_PULL_TO_REFRESH;
            arrowImage.clearAnimation();
            arrowImage.startAnimation(reverseRotateAnimation);
            headerTextView.setText(R.string.pull_to_refresh);
          }
        }
        break;
      case MotionEvent.ACTION_UP:
        // isDragging = false;

        if (!isLoading && showRefreshButton) {
          if (headerRelativeLayout.getPaddingTop() < HEADER_HEIGHT) {
            // come back
            headerRelativeLayout.setPadding(
                headerRelativeLayout.getPaddingLeft(),
                -1 * HEADER_HEIGHT,
                0,
                headerRelativeLayout.getPaddingBottom());
          } else {
            // come to HEADER_HEIGHT and start the trigger
            headerRelativeLayout.setPadding(
                headerRelativeLayout.getPaddingLeft(),
                HEADER_TOP,
                0,
                headerRelativeLayout.getPaddingBottom());
            headerTextView.setText(R.string.loading);
            progressBar.setVisibility(View.VISIBLE);
            arrowImage.clearAnimation();
            arrowImage.setVisibility(View.GONE);

            // START LOADING
            isLoading = true;
            if (refreshDelegate != null) {
              refreshDelegate.startFresh();
            }
          }
        }
        break;
      default:
        break;
    }

    return super.onTouchEvent(ev);
  }
Ejemplo n.º 13
0
  /**
   * 处理手指滑动事件
   *
   * @param event
   * @return true表示自己消耗掉该事件,false表示不消耗该事件
   */
  private boolean handleActionMove(MotionEvent event) {
    if (mCurrentRefreshStatus == RefreshStatus.REFRESHING || mIsLoadingMore) {
      return false;
    }

    if ((mCustomHeaderView == null || !mIsCustomHeaderViewScrollable) && mRefreshDownY == -1) {
      mRefreshDownY = (int) event.getY();
    }
    if (mCustomHeaderView != null
        && mIsCustomHeaderViewScrollable
        && isCustomHeaderViewCompleteVisible()
        && mRefreshDownY == -1) {
      mRefreshDownY = (int) event.getY();
    }

    int refreshDiffY = (int) event.getY() - mRefreshDownY;
    refreshDiffY = (int) (refreshDiffY / mRefreshViewHolder.getPaddingTopScale());

    // 如果是向下拉,并且当前可见的第一个条目的索引等于0,才处理整个头部控件的padding
    if (refreshDiffY > 0 && shouldHandleRefresh() && isCustomHeaderViewCompleteVisible()) {
      int paddingTop = mMinWholeHeaderViewPaddingTop + refreshDiffY;
      if (paddingTop > 0 && mCurrentRefreshStatus != RefreshStatus.RELEASE_REFRESH) {
        // 下拉刷新控件完全显示,并且当前状态没有处于释放开始刷新状态
        mCurrentRefreshStatus = RefreshStatus.RELEASE_REFRESH;
        handleRefreshStatusChanged();

        mRefreshViewHolder.handleScale(1.0f, refreshDiffY);
      } else if (paddingTop < 0) {
        // 下拉刷新控件没有完全显示,并且当前状态没有处于下拉刷新状态
        if (mCurrentRefreshStatus != RefreshStatus.PULL_DOWN) {
          boolean isPreRefreshStatusNotIdle = mCurrentRefreshStatus != RefreshStatus.IDLE;
          mCurrentRefreshStatus = RefreshStatus.PULL_DOWN;
          if (isPreRefreshStatusNotIdle) {
            handleRefreshStatusChanged();
          }
        }
        float scale = 1 - paddingTop * 1.0f / mMinWholeHeaderViewPaddingTop;
        /**
         * 往下滑 paddingTop mMinWholeHeaderViewPaddingTop 到 0 scale 0 到 1 往上滑 paddingTop 0 到
         * mMinWholeHeaderViewPaddingTop scale 1 到 0
         */
        mRefreshViewHolder.handleScale(scale, refreshDiffY);
      }
      paddingTop = Math.min(paddingTop, mMaxWholeHeaderViewPaddingTop);
      mWholeHeaderView.setPadding(0, paddingTop, 0, 0);

      if (mRefreshViewHolder.canChangeToRefreshingStatus()) {
        mWholeHeaderDownY = -1;
        mRefreshDownY = -1;

        beginRefreshing();
      }

      return true;
    }

    if (mCustomHeaderView != null && mIsCustomHeaderViewScrollable) {
      if (mWholeHeaderDownY == -1) {
        mWholeHeaderDownY = (int) event.getY();

        if (mCustomHeaderView != null) {
          mWholeHeaderViewDownPaddingTop = mWholeHeaderView.getPaddingTop();
        }
      }

      int wholeHeaderDiffY = (int) event.getY() - mWholeHeaderDownY;
      if ((mPullDownRefreshEnable && !isWholeHeaderViewCompleteInvisible())
          || (wholeHeaderDiffY > 0 && shouldInterceptToMoveCustomHeaderViewDown())
          || (wholeHeaderDiffY < 0 && shouldInterceptToMoveCustomHeaderViewUp())) {

        int paddingTop = mWholeHeaderViewDownPaddingTop + wholeHeaderDiffY;
        if (paddingTop < mMinWholeHeaderViewPaddingTop - mCustomHeaderView.getMeasuredHeight()) {
          paddingTop = mMinWholeHeaderViewPaddingTop - mCustomHeaderView.getMeasuredHeight();
        }
        mWholeHeaderView.setPadding(0, paddingTop, 0, 0);

        return true;
      }
    }

    return false;
  }