Example #1
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);
  }
    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
      }
    }
  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();
    }
  }
Example #6
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();
    }
  }
  // 当状态改变时候,调用该方法,以更新界�?
  private void changeHeaderViewByState() {
    switch (state) {
      case RELEASE_To_REFRESH:
        arrowImageView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        tipsTextview.setVisibility(View.VISIBLE);
        lastUpdatedTextView.setVisibility(View.VISIBLE);

        arrowImageView.clearAnimation();
        arrowImageView.startAnimation(animation);

        tipsTextview.setText(R.string.pull_to_refresh_release_label);

        // Log.v(TAG, "当前状�?,松�?���?);
        break;
      case PULL_To_REFRESH:
        progressBar.setVisibility(View.GONE);
        tipsTextview.setVisibility(View.VISIBLE);
        lastUpdatedTextView.setVisibility(View.VISIBLE);
        arrowImageView.clearAnimation();
        arrowImageView.setVisibility(View.VISIBLE);
        if (isBack) {
          isBack = false;
          arrowImageView.clearAnimation();
          arrowImageView.startAnimation(reverseAnimation);
        }
        tipsTextview.setText(R.string.pull_to_refresh_pull_label);

        // Log.v(TAG, "当前状�?,下拉刷�?);
        break;

      case REFRESHING:
        // System.out.println("刷新REFRESHING-TopPad�?+headContentOriginalTopPadding);
        headView.setPadding(
            headView.getPaddingLeft(),
            headContentOriginalTopPadding,
            headView.getPaddingRight(),
            headView.getPaddingBottom());
        headView.invalidate();

        progressBar.setVisibility(View.VISIBLE);
        arrowImageView.clearAnimation();
        arrowImageView.setVisibility(View.GONE);
        tipsTextview.setText(R.string.pull_to_refresh_refreshing_label);
        lastUpdatedTextView.setVisibility(View.GONE);

        // Log.v(TAG, "当前状�?,正在刷新...");
        break;
      case DONE:
        // System.out.println("完成DONE-TopPad�?+(-1 * headContentHeight));
        headView.setPadding(
            headView.getPaddingLeft(),
            -1 * headContentHeight,
            headView.getPaddingRight(),
            headView.getPaddingBottom());
        headView.invalidate();

        progressBar.setVisibility(View.GONE);
        arrowImageView.clearAnimation();
        // 此处更换图标
        arrowImageView.setImageResource(R.drawable.ic_pulltorefresh_arrow);

        tipsTextview.setText(R.string.pull_to_refresh_pull_label);
        lastUpdatedTextView.setVisibility(View.VISIBLE);

        // Log.v(TAG, "当前状�?,done");
        break;
    }
  }
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        if (firstItemIndex == 0 && !isRecored) {
          startY = (int) event.getY();
          isRecored = true;
          // System.out.println("当前-按下高度-ACTION_DOWN-Y�?+startY);
        }
        break;

      case MotionEvent.ACTION_CANCEL: // 失去焦点&取消动作
      case MotionEvent.ACTION_UP:
        if (state != REFRESHING) {
          if (state == DONE) {
            // System.out.println("当前-抬起-ACTION_UP:DONE�?��都不�?);
          } else if (state == PULL_To_REFRESH) {
            state = DONE;
            changeHeaderViewByState();
            // System.out.println("当前-抬起-ACTION_UP:PULL_To_REFRESH-->DONE-由下拉刷新状态到刷新完成状�?");
          } else if (state == RELEASE_To_REFRESH) {
            state = REFRESHING;
            changeHeaderViewByState();
            onRefresh();
            // System.out.println("当前-抬起-ACTION_UP:RELEASE_To_REFRESH-->REFRESHING-由松�?��新状态,到刷新完成状�?);
          }
        }

        isRecored = false;
        isBack = false;

        break;

      case MotionEvent.ACTION_MOVE:
        int tempY = (int) event.getY();
        // System.out.println("当前-滑动-ACTION_MOVE Y�?+tempY);
        if (!isRecored && firstItemIndex == 0) {
          // System.out.println("当前-滑动-记录拖拽时的位置 Y�?+tempY);
          isRecored = true;
          startY = tempY;
        }
        if (state != REFRESHING && isRecored) {
          // 可以松开刷新�?
          if (state == RELEASE_To_REFRESH) {
            // �?��推,推到屏幕足够掩盖head的程度,但还没有全部掩盖
            if ((tempY - startY < headContentHeight + 20) && (tempY - startY) > 0) {
              state = PULL_To_REFRESH;
              changeHeaderViewByState();
              // System.out.println("当前-滑动-ACTION_MOVE:RELEASE_To_REFRESH--》PULL_To_REFRESH-由松�?��新状态转变到下拉刷新状�?");
            }
            // �?��子推到顶
            else if (tempY - startY <= 0) {
              state = DONE;
              changeHeaderViewByState();
              // System.out.println("当前-滑动-ACTION_MOVE:RELEASE_To_REFRESH--》DONE-由松�?��新状态转变到done状�?");
            }
            // �?��拉,或�?还没有上推到屏幕顶部掩盖head
            else {
              // 不用进行特别的操作,只用更新paddingTop的�?就行�?
            }
          }
          // 还没有到达显示松�?��新的时�?,DONE或�?是PULL_To_REFRESH状�?
          else if (state == PULL_To_REFRESH) {
            // 下拉到可以进入RELEASE_TO_REFRESH的状�?
            if (tempY - startY >= headContentHeight + 20
                && currentScrollState == SCROLL_STATE_TOUCH_SCROLL) {
              state = RELEASE_To_REFRESH;
              isBack = true;
              changeHeaderViewByState();
              // System.out.println("当前-滑动-PULL_To_REFRESH--》RELEASE_To_REFRESH-由done或�?下拉刷新状�?转变到松�?���?);
            }
            // 上推到顶�?
            else if (tempY - startY <= 0) {
              state = DONE;
              changeHeaderViewByState();
              // System.out.println("当前-滑动-PULL_To_REFRESH--》DONE-由Done或�?下拉刷新状�?转变到done状�?");
            }
          }
          // done状�?�?
          else if (state == DONE) {
            if (tempY - startY > 0) {
              state = PULL_To_REFRESH;
              changeHeaderViewByState();
              // System.out.println("当前-滑动-DONE--》PULL_To_REFRESH-由done状�?转变到下拉刷新状�?);
            }
          }

          // 更新headView的size
          if (state == PULL_To_REFRESH) {
            int topPadding = (int) ((-1 * headContentHeight + (tempY - startY)));
            headView.setPadding(
                headView.getPaddingLeft(),
                topPadding,
                headView.getPaddingRight(),
                headView.getPaddingBottom());
            headView.invalidate();
            // System.out.println("当前-下拉刷新PULL_To_REFRESH-TopPad�?+topPadding);
          }

          // 更新headView的paddingTop
          if (state == RELEASE_To_REFRESH) {
            int topPadding = (int) ((tempY - startY - headContentHeight));
            headView.setPadding(
                headView.getPaddingLeft(),
                topPadding,
                headView.getPaddingRight(),
                headView.getPaddingBottom());
            headView.invalidate();
            // System.out.println("当前-释放刷新RELEASE_To_REFRESH-TopPad�?+topPadding);
          }
        }
        break;
    }
    return super.onTouchEvent(event);
  }
Example #9
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {

    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mDownY = ev.getY();
        break;

      case MotionEvent.ACTION_MOVE:
        mMoveY = ev.getY();
        if (mCurrScrollState == ENTER_PULL_REFRESH && mMoveY - mDownY > 0) {
          if (((mMoveY - mDownY) / 4) < 111) {
            mHeaderLinearLayout.setPadding(
                mHeaderLinearLayout.getPaddingLeft(),
                (int) ((mMoveY - mDownY) / 4),
                mHeaderLinearLayout.getPaddingRight(),
                mHeaderLinearLayout.getPaddingBottom());
          } else {
            mHeaderLinearLayout.setPadding(
                mHeaderLinearLayout.getPaddingLeft(),
                111,
                mHeaderLinearLayout.getPaddingRight(),
                mHeaderLinearLayout.getPaddingBottom());
          }
        } else {
          mCurrScrollState = NONE_PULL_REFRESH;
        }
        break;

      case MotionEvent.ACTION_UP:
        // when you action up, it will do these:
        // 1. roll back util header topPadding is 0
        // 2. hide the header by setSelection(1)
        if (mCurrScrollState == OVER_PULL_REFRESH || mCurrScrollState == ENTER_PULL_REFRESH) {
          new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      Message _msg;
                      while (mHeaderLinearLayout.getPaddingTop() > 1) {
                        _msg = mHandler.obtainMessage();
                        _msg.what = REFRESH_BACKING;
                        _msg.sendToTarget();
                        try {
                          Thread.sleep(10);
                        } catch (InterruptedException e) {
                          e.printStackTrace();
                        }
                      }
                      _msg = mHandler.obtainMessage();
                      if (mPullRefreshState == OVER_PULL_REFRESH) {
                        _msg.what = REFRESH_BACED;
                      } else {
                        _msg.what = REFRESH_RETURN;
                      }
                      _msg.sendToTarget();
                    }
                  })
              .start();
        }
        break;
    }
    return super.onTouchEvent(ev);
  }