/** 截取scrollview的屏幕 * */
 public static Bitmap getBitmapByView(ScrollView scrollView) {
   int h = 0;
   Bitmap bitmap = null;
   // 获取listView实际高度
   for (int i = 0; i < scrollView.getChildCount(); i++) {
     h += scrollView.getChildAt(i).getHeight();
     //            scrollView.getChildAt(i).setBackgroundResource(R.drawable.bg3);
   }
   Log.d(TAG, "实际高度:" + h);
   Log.d(TAG, " 高度:" + scrollView.getHeight());
   // 创建对应大小的bitmap
   bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888);
   final Canvas canvas = new Canvas(bitmap);
   scrollView.draw(canvas);
   // 测试输出
   FileOutputStream out = null;
   try {
     out = new FileOutputStream("/sdcard/screen_test.png");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
   try {
     if (null != out) {
       bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
       out.flush();
       out.close();
     }
   } catch (IOException e) {
     // TODO: handle exception
   }
   return bitmap;
 }
  public void animateSubjectOut(final SubjectCard materia) {
    final List<View> toBeAnimated = new ArrayList<View>();
    boolean after = false;
    for (SubjectCard mtr : mSubjectCards) {
      if (after) toBeAnimated.add(mtr);
      if (mtr == materia) after = true;
    }
    toBeAnimated.add(mAddButton);
    final int numberToBeAnimated = toBeAnimated.size();

    int maxScroll = mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight(),
        materiaHeight = materia.getHeight();
    final int initScroll = mScrollView.getScrollY(),
        scrollBy =
            ((maxScroll < initScroll + materiaHeight)
                    ? Math.max(maxScroll - materiaHeight, 0)
                    : initScroll)
                - initScroll;
    ValueAnimator listAnimator = ValueAnimator.ofFloat(0, -materiaHeight);
    listAnimator.setInterpolator(new DecelerateInterpolator(3.2f));
    listAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            for (int i = 0; i < numberToBeAnimated; i++)
              ViewHelper.setTranslationY(toBeAnimated.get(i), value);
            ViewHelper.setScrollY(
                mScrollView, (int) (initScroll + scrollBy * animation.getAnimatedFraction()));
          }
        });
    listAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mSubjectCards.remove(materia);
            mSubjectsLayout.removeView(materia);
            mSqlHelper.remove(materia.getData().getSqlID());
            updateTotal();
            mScrollView.setVerticalScrollBarEnabled(true);
            mScrollView.setOnTouchListener(null);
            for (View mtr : toBeAnimated) ViewHelper.setTranslationY(mtr, 0);
          }
        });
    listAnimator.setDuration(700);
    mScrollView.setVerticalScrollBarEnabled(false);
    mScrollView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        }); // disable user scrolling during the animation

    if (ViewHelper.getTranslationX(materia) == 0) materia.swipeRight(0, 0);
    listAnimator.setStartDelay(500);
    listAnimator.start();
  }
 public final void aKY()
 {
   if (ipQ.iqA == 1)
   {
     izM.scrollTo(0, izM.getChildAt(0).getMeasuredHeight() - izM.getMeasuredHeight());
     return;
   }
   izM.scrollTo(0, 0);
 }
  @Override
  protected boolean isReadyForPullUp() {
    View scrollViewChild = mRefreshableView.getChildAt(0);
    if (null != scrollViewChild) {
      if (scrollViewChild instanceof ScrollView) {
        ScrollView mScrollView = (ScrollView) scrollViewChild;
        scrollViewChild = mScrollView.getChildAt(0);
        if (null != scrollViewChild)
          return mScrollView.getScrollY() >= (scrollViewChild.getHeight() - getHeight());
      }
      return mRefreshableView.getScrollY() >= (scrollViewChild.getHeight() - getHeight());
    }

    return false;
  }
  /**
   * Copy From ScrollView (API Level >= 14)
   *
   * <p>The scroll range of a scroll view is the overall height of all of its children.
   */
  private int computeVerticalScrollRange(ScrollView scrollView) {
    final int count = scrollView.getChildCount();
    final int contentHeight =
        scrollView.getHeight() - scrollView.getPaddingBottom() - scrollView.getPaddingTop();
    if (count == 0) {
      return contentHeight;
    }

    int scrollRange = scrollView.getChildAt(0).getBottom();
    final int scrollY = scrollView.getScrollY();
    final int overscrollBottom = Math.max(0, scrollRange - contentHeight);
    if (scrollY < 0) {
      scrollRange -= scrollY;
    } else if (scrollY > overscrollBottom) {
      scrollRange += scrollY - overscrollBottom;
    }

    return scrollRange;
  }
  /* (non-Javadoc)
   * @see br.com.mobgui4so.model.guigenerating.IDecodable#decode(br.com.mobgui4so.model.guigenerating.Genotype)
   */
  @Override
  public BasePhenotype decode(Genotype gen, Object context) {
    this.context = (Context) context;
    sv = new ScrollView(this.context);
    LinearLayout ll = new LinearLayout(this.context);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setPadding(0, 0, 10, 10);
    sv.addView(ll);

    preOrderTree(gen.getRoot(), ll);
    setLayoutOnUIThread();

    AndroidPhenotype phen = new AndroidPhenotype();
    phen.setMaxFrameHeight(ll.getHeight());
    phen.setMaxFrameWidth(ll.getWidth());
    this.framesArea = 0;
    this.badPhenotype = false;
    calculateFramesArea(sv.getChildAt(0));
    phen.setBadPhenotype(this.badPhenotype);
    phen.setFramesArea(this.framesArea);
    phen.setLayout(sv);

    return phen;
  }
Exemple #7
0
 private static boolean canScrollViewScroll(ScrollView sv) {
   if (sv.getChildCount() == 0) return false;
   final int childHeight = sv.getChildAt(0).getMeasuredHeight();
   return sv.getMeasuredHeight() - sv.getPaddingTop() - sv.getPaddingBottom() < childHeight;
 }
 /** Write a string to the output window */
 private void log(String string) {
   output.append(string + "\n");
   int height = scrollView.getChildAt(0).getHeight();
   Log.d(TAG, "scroll view height: " + height);
   scrollView.scrollTo(0, height + 2000);
 }
  /**
   * 子控件为ListView等时,ACTION_MOVE执行几次后this.disallowIntercept=true;
   * 造成的影响:用户体验不好!(如果从中间滑到顶部或底部是不会进入onInterceptTouchEvent方法的,拦截不到事件,不能执行刷新加载相关功能)
   * 解决办法:重写requestDisallowInterceptTouchEvent,过滤disallowIntercept=true。
   * 缺点:这样会导致子控件调用parent.requestDisallowInterceptTouchEvent(true)失效。
   *
   * <p>ViewGroup类dispatchTouchEvent方法关键代码: final boolean disallowIntercept = (mGroupFlags &
   * FLAG_DISALLOW_INTERCEPT) != 0; if (!disallowIntercept) { intercepted =
   * onInterceptTouchEvent(ev); }
   *
   * @param ev
   * @return
   */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    printLog("parent onInterceptTouchEvent:" + ev.getAction());
    int action = ev.getAction();
    if (pullView.doMainType == pullView.NONE && action == MotionEvent.ACTION_DOWN) {
      reset();
    }
    if (pullView.doMainType == pullView.REFRESHING || pullView.doMainType == pullView.LOADING) {
      printLog("parent onInterceptTouchEvent result:" + !refreshingOrLoadingOverScrollEnabled);
      return !refreshingOrLoadingOverScrollEnabled;
    }
    printLog("parent onInterceptTouchEvent result:" + isGetFinalDirection);
    if (isGetFinalDirection) {
      //            getParent().requestDisallowInterceptTouchEvent(true);
      return true;
    }
    // 得到可能的方向
    if (this.direction.type == Direction.NONE && this.directionEnable.type != Direction.NONE) {
      this.startY = ev.getY();
      printLog("startY:" + startY);
      for (View view : conditionChildViews) {
        printLog(view.getClass().getSimpleName());
        if (view instanceof AbsListView) {
          AbsListView absListView = (AbsListView) view;
          Direction direction = new Direction();
          View firstView = absListView.getChildAt(0);
          View lastView = absListView.getChildAt(absListView.getChildCount() - 1);
          if (firstView == null
              || (absListView.getFirstVisiblePosition() == 0
                  && firstView.getTop() >= view.getTop())) {
            printLog("顶部");
            direction.addDirection(Direction.DOWN_PULL);
          }
          if (lastView == null
              || (absListView.getLastVisiblePosition() == (absListView.getCount() - 1)
                  && lastView.getBottom() <= view.getBottom())) {
            printLog("底部");
            direction.addDirection(Direction.UP_PULL);
          }
          if (direction.type == Direction.NONE) {
            this.direction.type = Direction.NONE;
            printLog("NONE");
            break;
          }
          this.direction.configDirection(direction.type);
        } else if (view instanceof ScrollView) {
          ScrollView scrollView = (ScrollView) view;
          Direction direction = new Direction();
          int scrollY = view.getScrollY();
          int height = view.getHeight();
          int scrollViewMeasuredHeight = scrollView.getChildAt(0).getMeasuredHeight();
          if (scrollY == 0) {
            printLog("顶部");
            direction.addDirection(Direction.DOWN_PULL);
          }
          if ((scrollY + height) == scrollViewMeasuredHeight) {
            printLog("底部");
            direction.addDirection(Direction.UP_PULL);
          }
          if (direction.type == Direction.NONE) {
            this.direction.type = Direction.NONE;
            printLog("NONE");
            break;
          }
          this.direction.configDirection(direction.type);
        } else {
          if (view.getScrollY() == 0) {
            printLog("顶部");
            direction.addDirection(Direction.DOWN_PULL);
          }
          if (true) { // TODO 哈哈(待修改)
            printLog("底部");
            direction.addDirection(Direction.UP_PULL);
          }
          if (direction.type == Direction.NONE) {
            this.direction.type = Direction.NONE;
            printLog("NONE");
            break;
          }
          this.direction.configDirection(direction.type);
        }
      }
      this.direction.takeIntersection(this.directionEnable);
    }
    // 得到最终方向
    else if (this.direction.type != Direction.NONE) {
      findFinalDirection(ev);
    }

    return false;
  }