@Override public void onClick(View view) { switch (view.getId()) { case R.id.back: finish(); break; case R.id.button_djs: // 点击获得验证码 try { isMobileNet = HttpUtils.isMobileDataEnable(getApplicationContext()); isWifiNet = HttpUtils.isWifiDataEnable(getApplicationContext()); if (!isMobileNet && !isWifiNet) { Toast.makeText(this, R.string.network_error, Toast.LENGTH_SHORT).show(); return; } } catch (Exception e) { e.printStackTrace(); } mobile_str = mobile.getText().toString(); if (StringUtil.isNullOrEmpty(mobile_str)) { Toast.makeText(this, R.string.reg_error_one, Toast.LENGTH_SHORT).show(); return; } button_djs.setClickable(false); // 不可点击 MyTimer myTimer = new MyTimer(60000, 1000); myTimer.start(); getCard(); break; case R.id.next: // 下一步 try { isMobileNet = HttpUtils.isMobileDataEnable(getApplicationContext()); isWifiNet = HttpUtils.isWifiDataEnable(getApplicationContext()); if (!isMobileNet && !isWifiNet) { Toast.makeText(this, R.string.network_error, Toast.LENGTH_SHORT).show(); return; } } catch (Exception e) { e.printStackTrace(); } mobile_str = mobile.getText().toString(); card_str = card.getText().toString(); if (StringUtil.isNullOrEmpty(mobile_str)) { Toast.makeText(this, R.string.reg_error_one, Toast.LENGTH_SHORT).show(); return; } if (StringUtil.isNullOrEmpty(card_str)) { Toast.makeText(this, R.string.reg_error_five, Toast.LENGTH_SHORT).show(); return; } getReg(); break; case R.id.quest: // 问题 break; } }
@Override public void handleMessage(Message msg) { // 回弹速度随下拉距离moveDeltaY增大而增大 MOVE_SPEED = (float) (8 + 5 * Math.tan( Math.PI / 2 / getMeasuredHeight() * (pullDownY + Math.abs(pullUpY)))); if (!isTouch) { // 正在刷新,且没有往上推的话则悬停,显示"正在刷新..." if (stage == REFRESHING && pullDownY <= refreshDist) { pullDownY = refreshDist; timer.cancel(); } else if (stage == LOADING && -pullUpY <= loadMoreDist) { pullUpY = -loadMoreDist; timer.cancel(); } } if (pullDownY > 0) { pullDownY -= MOVE_SPEED; } else if (pullUpY < 0) { pullUpY += MOVE_SPEED; } if (pullDownY < 0) { // 已完成回弹 pullDownY = 0; refreshArrowImg.clearAnimation(); // 隐藏下拉头时有可能还在刷新,只有当前状态不是正在刷新时才改变状态 if (stage != REFRESHING && stage != LOADING) { changeStage(INIT); } timer.cancel(); requestLayout(); } if (pullUpY > 0) { // 已完成回弹 pullUpY = 0; loadArrowImg.clearAnimation(); // 隐藏上拉头时有可能还在刷新,只有当前状态不是正在刷新时才改变状态 if (stage != REFRESHING && stage != LOADING) { changeStage(INIT); } timer.cancel(); requestLayout(); } // 刷新布局,会自动调用onLayout requestLayout(); // 没有拖拉或者回弹完成 if (pullDownY + Math.abs(pullUpY) == 0) { timer.cancel(); } }
public void setLife(float time) { life = new MyTimer(time) { @Override protected void perform() { alive = false; } }; life.reset(); life.start(); }
@Override public void reset() { alive = false; setX(0); setY(0); setWidth(0); setHeight(0); wrapWidth = 0; text = ""; life.reset(); life.pause(); follow = false; followed = null; }
/** * (非 Javadoc)由父控件决定是否分发事件,防止事件冲突 * * @see android.view.ViewGroup#dispatchTouchEvent(android.view.MotionEvent) */ @Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: lastY = ev.getY(); timer.cancel(); mEvents = 0; releasePull(); break; case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_UP: // 过滤多点触碰 mEvents = -1; break; case MotionEvent.ACTION_MOVE: if (mEvents == 0) { if (pullDownY > 0 || (((Pullable) mPullableView).canPullDown() && canPullDown && stage != LOADING)) { // 可以下拉,正在加载时不能下拉 // 对实际滑动距离做缩小,造成用力拉的感觉 pullDownY = pullDownY + (ev.getY() - lastY) / radio; if (pullDownY < 0) { pullDownY = 0; canPullDown = false; canPullUp = true; } if (pullDownY > getMeasuredHeight()) { pullDownY = getMeasuredHeight(); } if (stage == REFRESHING) { // 正在刷新的时候触摸移动 isTouch = true; } } else if (pullUpY < 0 || (((Pullable) mPullableView).canPullUp() && canPullUp && stage != REFRESHING)) { // 可以上拉,正在刷新时不能上拉 pullUpY = pullUpY + (ev.getY() - lastY) / radio; if (pullUpY > 0) { pullUpY = 0; canPullDown = true; canPullUp = false; } if (pullUpY < -getMeasuredHeight()) { pullUpY = -getMeasuredHeight(); } if (stage == LOADING) { // 正在加载的时候触摸移动 isTouch = true; } } else { releasePull(); } } else { mEvents = 0; } lastY = ev.getY(); // 根据下拉距离改变比例 radio = (float) (2 + 2 * Math.tan( Math.PI / 2 / getMeasuredHeight() * (pullDownY + Math.abs(pullUpY)))); if (pullDownY > 0 || pullUpY < 0) { requestLayout(); } if (pullDownY > 0) { if (pullDownY <= refreshDist && (stage == RELEASE_TO_REFRESH || stage == DONE)) { // 如果下拉距离没达到刷新的距离且当前状态是释放刷新,改变状态为下拉刷新 changeStage(INIT); } if (pullDownY >= refreshDist && stage == INIT) { // 如果下拉距离达到刷新的距离且当前状态是初始状态刷新,改变状态为释放刷新 changeStage(RELEASE_TO_REFRESH); } } else if (pullUpY < 0) { // 下面是判断上拉加载的,同上,注意pullUpY是负值 if (-pullUpY <= loadMoreDist && (stage == RELEASE_TO_LOAD || stage == DONE)) { changeStage(INIT); } // 上拉操作 if (-pullUpY >= loadMoreDist && stage == INIT) { changeStage(RELEASE_TO_LOAD); } } // 因为刷新和加载操作不能同时进行,所以pullDownY和pullUpY不会同时不为0,因此这里用(pullDownY + // Math.abs(pullUpY))就可以不对当前状态作区分了 if ((pullDownY + Math.abs(pullUpY)) > 8) { // 防止下拉过程中误触发长按事件和点击事件 ev.setAction(MotionEvent.ACTION_CANCEL); } break; case MotionEvent.ACTION_UP: if (pullDownY > refreshDist || -pullUpY > loadMoreDist) // 正在刷新时往下拉(正在加载时往上拉),释放后下拉头(上拉头)不隐藏 { isTouch = false; } if (stage == RELEASE_TO_REFRESH) { changeStage(REFRESHING); // 刷新操作 if (mOnRefreshListener != null) mOnRefreshListener.onRefresh(this); } else if (stage == RELEASE_TO_LOAD) { changeStage(LOADING); // 加载操作 if (mOnRefreshListener != null) mOnRefreshListener.onLoadMore(this); } hide(); default: break; } // TODO 事件分发交给父类 super.dispatchTouchEvent(ev); return true; }
private void hide() { timer.schedule(5); }
@Override public void act(float delta) { super.act(delta); life.update(delta); checkBounds(); }
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mUpdateHandler.removeCallbacksAndMessages(null); timer.cancel(); }
/** Call this method when you're done using the monitor. */ public void release() { if (handlerRegistration != null) { handlerRegistration.removeHandler(); } timer.cancel(); }
/** * Schedule a check changes after a key down a short way into the future, to reduce UI stress. * Only call from onKeyDown, because it assumes the monitored object implements HasAllKeyHandlers. */ private void scheduleCheckChanges() { handlerRegistration.removeHandler(); handlerRegistration = null; timer.start(); }