コード例 #1
7
ファイル: CustomPopup.java プロジェクト: star-app/starcloud
  public void showLikeQuickAction(int x, int y) {
    preShow();

    mWindow.setAnimationStyle(android.R.style.Animation_Dialog);
    int[] location = new int[2];
    mAnchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + mAnchor.getWidth(),
            location[1] + mAnchor.getHeight());

    root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootW = root.getWidth(), rootH = root.getHeight();
    int screenW = mWManager.getDefaultDisplay().getWidth();

    int xpos = ((screenW - rootW) / 2) + x;
    int ypos = anchorRect.top - rootH + y;

    if (rootH > anchorRect.top) {
      ypos = anchorRect.bottom + y;
    }
    mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, xpos, ypos);
  }
コード例 #2
2
  @Override
  protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    Bitmap bitmap = getChildDrawingCache(child);
    // (top,left) is the pixel position of the child inside the list
    final int top = child.getTop();
    final int left = child.getLeft();
    // center point of child
    final int childCenterY = child.getHeight() / 2;
    final int childCenterX = child.getWidth() / 2;
    // center of list
    final int parentCenterY = -child.getHeight() / 2;
    // center point of child relative to list
    final int absChildCenterY = child.getTop() + childCenterY;
    // distance of child center to the list center
    final int distanceY = parentCenterY - absChildCenterY;
    // radius of imaginary circle
    final int r = getHeight() * 2;

    prepareMatrix(mMatrix, distanceY, r);

    mMatrix.preTranslate(-childCenterX, -childCenterY);
    mMatrix.postTranslate(childCenterX, childCenterY);
    mMatrix.postTranslate(left, top);

    canvas.drawBitmap(bitmap, mMatrix, mPaint);
    return false;
  }
コード例 #3
1
ファイル: TagImageView.java プロジェクト: XXZLMXX/RazerWidget
  private void setPosition(View v, int dx, int dy) {
    int parentWidth = this.getWidth();
    int parentHeight = this.getHeight();
    int l = v.getLeft() + dx;
    int t = v.getTop() + dy;

    if (l < 0) {
      l = 0;
    } else if ((l + v.getWidth()) >= parentWidth) {
      l = parentWidth - v.getWidth();
    }

    if (t < 0) {
      t = 0;
    } else if ((t + v.getHeight()) >= parentHeight) {
      t = parentHeight - v.getHeight();
    }

    int r = l + v.getWidth();
    int b = t + v.getHeight();

    v.layout(l, t, r, b);

    RelativeLayout.LayoutParams params =
        (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams();
    params.leftMargin = l;
    params.topMargin = t;
    v.setLayoutParams(params);
  }
コード例 #4
1
 @Override
 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
   int pos =
       mHeaderView.getHeight() - mHeaderView.getPaddingTop() + mTitleView.getHeight() / 2;
   mCustomAnimator.setStartPosition(pos);
   mHeaderView.getViewTreeObserver().removeOnGlobalFocusChangeListener(mChangeListener);
 }
コード例 #5
1
 private static void drawToast(View v, Rect vRect) {
   // TODO Auto-generated method stub
   if (mToast != null) {
     View tv = mToast.getView();
     if (tv.getWidth() > 0 && tv.isShown()) {
       if (LOGD_ENABLED) Log.i(LOG_TAG, "==== " + tv.getWidth() + " " + tv.getHeight());
       Bitmap second = Utils.createPngScreenshot(tv, tv.getWidth(), tv.getHeight(), 0);
       if (LOGD_ENABLED)
         Log.d(
             LOG_TAG,
             "====== gravity "
                 + mToast.getGravity()
                 + " x y "
                 + mToast.getXOffset()
                 + " "
                 + mToast.getYOffset()
                 + " "
                 + mToast.getHorizontalMargin()
                 + " "
                 + mToast.getVerticalMargin());
       PointF fromPoint =
           new PointF(
               (v.getWidth() - tv.getWidth()) / 2,
               v.getHeight() - vRect.top - mToast.getYOffset() - tv.getHeight());
       if (LOGD_ENABLED)
         Log.i(LOG_TAG, "======= prepare menu view2  ========" + fromPoint.x + " " + fromPoint.y);
       mCapture = Utils.mixtureBitmap2(mCapture, second, fromPoint, 0, (float) 1.0);
     }
   }
 }
コード例 #6
1
  @Override
  public boolean onDependentViewChanged(
      CoordinatorLayout parent, final LinearLayout child, View dependency) {

    shouldInitProperties(child, dependency);

    /* float distanceYToSubtract = ((mStartYPosition - mFinalYPosition)
     * (1f - expandedPercentageFactor)) + (child.getHeight()/2);*/

    /*float scrollDistance = mStartYPosition - mFinalYPosition;
    float scrollDistanceOfDependency = dependency.getHeight();

    float percentOfScroll =  scrollDistance / dependency.getY() * 100;

    Log.e("y",Float.toString(dependency.getY()));
    Log.e("scroll",Float.toString(percentOfScroll));
    float position = dependency.getY() / scrollDistance * 100;

    //float heightToSubtract = ((mStartHeight - finalHeight) * (1f - expandedPercentageFactor));*/

    // child.setY(mStartYPosition + dependency.getY();
    float scroll = dependency.getY() - (dependency.getHeight()) + mStartYPosition / 2;
    // Log.e("y",Float.toString(dependency.getY() - (dependency.getHeight()) + mStartYPosition /
    // 2));
    // Log.e("scroll",Float.toString(dependency.getHeight() / 2));

    if (scroll * -1 < dependency.getHeight() / 2) {
      child.setTranslationY(dependency.getY() - (dependency.getHeight()) + mStartYPosition / 2);
    } else {

    }

    return true;
  }
コード例 #7
1
ファイル: Maps2Activity.java プロジェクト: gebuh/wsandroid
  @Override
  /**
   * - Capture the clicked cluster so we can use it in custom infoWindow - Check overall bounds of
   * items in cluster - If the bounds are empty (all hosts at same place) then let it pop the info
   * window - Otherwise, move the camera to show the bounds of the map
   */
  public boolean onClusterClick(Cluster<HostBriefInfo> cluster) {
    mLastClickedCluster = cluster; // remember for use later in the Adapter

    // Find out the bounds of the hosts currently in cluster
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (HostBriefInfo host : cluster.getItems()) {
      builder.include(host.getLatLng());
    }
    LatLngBounds bounds = builder.build();

    // If the hosts are not all at the same location, then change bounds of map.
    if (!bounds.southwest.equals(bounds.northeast)) {
      // Offset from edge of map in pixels when exploding cluster
      View mapView = findViewById(R.id.map_fragment);
      int padding_percent = getResources().getInteger(R.integer.cluster_explode_padding_percent);
      int padding = Math.min(mapView.getHeight(), mapView.getWidth()) * padding_percent / 100;
      CameraUpdate cu =
          CameraUpdateFactory.newLatLngBounds(
              bounds, mapView.getWidth(), mapView.getHeight(), padding);
      mMap.animateCamera(cu);
      return true;
    }
    showMultihostSelectDialog((ArrayList<HostBriefInfo>) cluster.getItems());
    return true;
  }
コード例 #8
1
 public static Bitmap getViewBitmap(View v) {
   if (v.getWidth() == 0 || v.getHeight() == 0) return null;
   Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
   Canvas c = new Canvas(b);
   v.draw(c);
   return b;
 }
コード例 #9
0
  public void fixListViewHeight(ListView listView) {
    // 如果没有设置数据适配器,则ListView没有子项,返回。
    ListAdapter listAdapter = listView.getAdapter();
    int totalHeight = 0;
    if (listAdapter == null) {
      return;
    }
    for (int index = 0, len = listAdapter.getCount(); index < len; index++) {
      View listViewItem = listAdapter.getView(index, null, listView);
      // 计算子项View 的宽高
      // listViewItem.measure(0, 0);
      listViewItem.measure(
          View.MeasureSpec.makeMeasureSpec(
              getResources().getDisplayMetrics().widthPixels, View.MeasureSpec.EXACTLY),
          0);
      // 计算所有子项的高度和
      int height = 0;
      if (listViewItem.getHeight() > listViewItem.getMeasuredHeight())
        height = listViewItem.getHeight();
      else height = listViewItem.getMeasuredHeight();

      totalHeight += height;
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    // listView.getDividerHeight()获取子项间分隔符的高度
    // params.height设置ListView完全显示需要的高度
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
  }
コード例 #10
0
  public void showSearchBar() {
    mSearchViewContainer.animate().cancel();
    mSearchViewContainer.setAlpha(0);
    mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight());
    mSearchViewContainer
        .animate()
        .withLayer()
        .alpha(1)
        .translationY(0)
        .setDuration(200)
        .setListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationStart(Animator animation) {
                mSearchViewContainer.setVisibility(View.VISIBLE);
                mActionBar.setVisibility(View.VISIBLE);
              }
            });

    mFragmentsFrame.setTranslationY(-mSearchViewContainer.getHeight());
    mFragmentsFrame
        .animate()
        .withLayer()
        .translationY(0)
        .setDuration(200)
        .setListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationStart(Animator animation) {
                mBottomPaddingView.setVisibility(View.GONE);
              }
            });
  }
コード例 #11
0
ファイル: FlyEffect.java プロジェクト: Deki-Che/Sunday
 @Override
 public void initView(View item, int position, int scrollDirection) {
   ViewHelper.setPivotX(item, item.getWidth() / 2);
   ViewHelper.setPivotY(item, item.getHeight() / 2);
   ViewHelper.setRotationX(item, -INITIAL_ROTATION_ANGLE * scrollDirection);
   ViewHelper.setTranslationY(item, item.getHeight() * 2 * scrollDirection);
 }
コード例 #12
0
  private void trySlideAttachmentView(final ViewWrapper viewWrapper) {
    if (!(viewWrapper.attachment instanceof MediaPickerMessagePartData)) {
      return;
    }
    final View view = viewWrapper.view;

    final int xOffset = viewWrapper.prevLeft - view.getLeft();
    final int yOffset = viewWrapper.prevTop - view.getTop();
    final float scaleX = viewWrapper.prevWidth / (float) view.getWidth();
    final float scaleY = viewWrapper.prevHeight / (float) view.getHeight();

    if (xOffset == 0 && yOffset == 0 && scaleX == 1 && scaleY == 1) {
      // Layout hasn't changed
      return;
    }

    final AnimationSet animationSet = new AnimationSet(true /* shareInterpolator */);
    animationSet.addAnimation(new TranslateAnimation(xOffset, 0, yOffset, 0));
    animationSet.addAnimation(new ScaleAnimation(scaleX, 1, scaleY, 1));
    animationSet.setDuration(UiUtils.MEDIAPICKER_TRANSITION_DURATION);
    animationSet.setInterpolator(UiUtils.DEFAULT_INTERPOLATOR);
    view.startAnimation(animationSet);
    view.invalidate();
    viewWrapper.prevLeft = view.getLeft();
    viewWrapper.prevTop = view.getTop();
    viewWrapper.prevWidth = view.getWidth();
    viewWrapper.prevHeight = view.getHeight();
  }
コード例 #13
0
ファイル: FlowLayout.java プロジェクト: lincbio/lincxmap
  private void drawDebugInfo(Canvas canvas, View child) {
    if (!debugDraw) {
      return;
    }

    Paint childPaint = this.createPaint(0xffffff00);
    Paint layoutPaint = this.createPaint(0xff00ff00);
    Paint newLinePaint = this.createPaint(0xffff0000);

    LayoutParams lp = (LayoutParams) child.getLayoutParams();

    if (lp.horizontalSpacing > 0) {
      float x = child.getRight();
      float y = child.getTop() + child.getHeight() / 2.0f;
      canvas.drawLine(x, y, x + lp.horizontalSpacing, y, childPaint);
      canvas.drawLine(
          x + lp.horizontalSpacing - 4.0f, y - 4.0f, x + lp.horizontalSpacing, y, childPaint);
      canvas.drawLine(
          x + lp.horizontalSpacing - 4.0f, y + 4.0f, x + lp.horizontalSpacing, y, childPaint);
    } else if (this.horizontalSpacing > 0) {
      float x = child.getRight();
      float y = child.getTop() + child.getHeight() / 2.0f;
      canvas.drawLine(x, y, x + this.horizontalSpacing, y, layoutPaint);
      canvas.drawLine(
          x + this.horizontalSpacing - 4.0f, y - 4.0f, x + this.horizontalSpacing, y, layoutPaint);
      canvas.drawLine(
          x + this.horizontalSpacing - 4.0f, y + 4.0f, x + this.horizontalSpacing, y, layoutPaint);
    }

    if (lp.verticalSpacing > 0) {
      float x = child.getLeft() + child.getWidth() / 2.0f;
      float y = child.getBottom();
      canvas.drawLine(x, y, x, y + lp.verticalSpacing, childPaint);
      canvas.drawLine(
          x - 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint);
      canvas.drawLine(
          x + 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint);
    } else if (this.verticalSpacing > 0) {
      float x = child.getLeft() + child.getWidth() / 2.0f;
      float y = child.getBottom();
      canvas.drawLine(x, y, x, y + this.verticalSpacing, layoutPaint);
      canvas.drawLine(
          x - 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint);
      canvas.drawLine(
          x + 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint);
    }

    if (lp.newLine) {
      if (orientation == HORIZONTAL) {
        float x = child.getLeft();
        float y = child.getTop() + child.getHeight() / 2.0f;
        canvas.drawLine(x, y - 6.0f, x, y + 6.0f, newLinePaint);
      } else {
        float x = child.getLeft() + child.getWidth() / 2.0f;
        float y = child.getTop();
        canvas.drawLine(x - 6.0f, y, x + 6.0f, y, newLinePaint);
      }
    }
  }
コード例 #14
0
ファイル: DragSortRecycler.java プロジェクト: jsveiga/Slide
  @Override
  public void getItemOffsets(Rect outRect, View view, RecyclerView rv, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, rv, state);

    debugLog("getItemOffsets");

    debugLog("View top = " + view.getTop());
    if (selectedDragItemPos != -1) {
      int itemPos = rv.getChildPosition(view);
      debugLog("itemPos =" + itemPos);

      if (!canDragOver(itemPos)) {
        return;
      }

      // Movement of finger
      float totalMovement = fingerY - fingerAnchorY;

      if (itemPos == selectedDragItemPos) {
        view.setVisibility(View.INVISIBLE);
      } else {
        // Make view visible incase invisible
        view.setVisibility(View.VISIBLE);

        // Find middle of the floatingItem
        float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2;

        // Moving down the list
        // These will auto-animate if the device continually sends touch motion events
        // if (totalMovment>0)
        {
          if ((itemPos > selectedDragItemPos) && (view.getTop() < floatMiddleY)) {
            float amountUp = (floatMiddleY - view.getTop()) / (float) view.getHeight();
            //  amountUp *= 0.5f;
            if (amountUp > 1) amountUp = 1;

            outRect.top = -(int) (floatingItemBounds.height() * amountUp);
            outRect.bottom = (int) (floatingItemBounds.height() * amountUp);
          }
        } // Moving up the list
        // else if (totalMovment < 0)
        {
          if ((itemPos < selectedDragItemPos) && (view.getBottom() > floatMiddleY)) {
            float amountDown = ((float) view.getBottom() - floatMiddleY) / (float) view.getHeight();
            //  amountDown *= 0.5f;
            if (amountDown > 1) amountDown = 1;

            outRect.top = (int) (floatingItemBounds.height() * amountDown);
            outRect.bottom = -(int) (floatingItemBounds.height() * amountDown);
          }
        }
      }
    } else {
      outRect.top = 0;
      outRect.bottom = 0;
      // Make view visible incase invisible
      view.setVisibility(View.VISIBLE);
    }
  }
コード例 #15
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   if (DEBUG) {
     Log.d(LOG_TAG, String.format("getView: %s, reused: %s", position, convertView == null));
   }
   // Header (negative positions will throw an ArrayIndexOutOfBoundsException)
   int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
   if (position < numHeadersAndPlaceholders) {
     View headerViewContainer = mHeaderViewInfos.get(position / mNumColumns).viewContainer;
     if (position % mNumColumns == 0) {
       return headerViewContainer;
     } else {
       if (convertView == null) {
         convertView = new View(parent.getContext());
       }
       // We need to do this because GridView uses the height of the last item
       // in a row to determine the height for the entire row.
       convertView.setVisibility(View.INVISIBLE);
       convertView.setMinimumHeight(headerViewContainer.getHeight());
       return convertView;
     }
   }
   // Adapter
   final int adjPosition = position - numHeadersAndPlaceholders;
   int adapterCount = 0;
   if (mAdapter != null) {
     adapterCount = getAdapterAndPlaceHolderCount();
     if (adjPosition < adapterCount) {
       if (adjPosition < mAdapter.getCount()) {
         return mAdapter.getView(adjPosition, convertView, parent);
       } else {
         if (convertView == null) {
           convertView = new View(parent.getContext());
         }
         convertView.setVisibility(View.INVISIBLE);
         convertView.setMinimumHeight(mRowHeight);
         return convertView;
       }
     }
   }
   // Footer
   final int footerPosition = adjPosition - adapterCount;
   if (footerPosition < getCount()) {
     View footViewContainer = mFooterViewInfos.get(footerPosition / mNumColumns).viewContainer;
     if (position % mNumColumns == 0) {
       return footViewContainer;
     } else {
       if (convertView == null) {
         convertView = new View(parent.getContext());
       }
       // We need to do this because GridView uses the height of the last item
       // in a row to determine the height for the entire row.
       convertView.setVisibility(View.INVISIBLE);
       convertView.setMinimumHeight(footViewContainer.getHeight());
       return convertView;
     }
   }
   throw new ArrayIndexOutOfBoundsException(position);
 }
コード例 #16
0
  protected void animateView(final int durationMs, final boolean isClosing) {

    boolean is_valid = mHiddenView != null && mImageView != null;

    if (!is_valid) return;

    if (mHiddenView.getHeight() == 0) {
      postAnimateView(durationMs, isClosing);
    }

    final long startTime = System.currentTimeMillis();
    final float startHeight = 0;
    final float endHeight = isClosing ? mImageView.getPaddingBottom() : mHiddenView.getHeight();

    final Easing easing = new Linear();

    if (null != mHiddenView && null != getParent() && null != getHandler()) {

      getHandler()
          .post(
              new Runnable() {

                @Override
                public void run() {

                  if (null != mHiddenView) {
                    long now = System.currentTimeMillis();

                    float currentMs = Math.min(durationMs, now - startTime);
                    float newHeight =
                        (float) easing.easeOut(currentMs, startHeight, endHeight, durationMs);

                    int height = isClosing ? (int) (endHeight - newHeight) : (int) newHeight;

                    LayoutParams params = (LayoutParams) mImageView.getLayoutParams();
                    params.bottomMargin = height;
                    mImageView.setLayoutParams(params);

                    if (currentMs < durationMs) {
                      if (null != getHandler()) {
                        getHandler().post(this);
                        invalidate();
                      }
                    } else {
                      opened = !isClosing;
                      if (null != getParent()) {

                        if (!opened) mHiddenView.setVisibility(View.INVISIBLE);

                        requestLayout();
                      }
                      postInvalidate();
                    }
                  }
                }
              });
    }
  }
 public CardComponent$ExpandAnimatorListener(View paramView, boolean paramBoolean) {
   a = paramView;
   b = ((ViewGroup.MarginLayoutParams) paramView.getLayoutParams());
   c = b.topMargin;
   d = b.bottomMargin;
   e = (paramView.getHeight() + c + d);
   f = new Rect(0, 0, paramView.getWidth(), paramView.getHeight());
   g = paramBoolean;
 }
コード例 #18
0
  @Test
  public void layout_shouldAffectWidthAndHeight() throws Exception {
    assertThat(view.getWidth(), equalTo(0));
    assertThat(view.getHeight(), equalTo(0));

    view.layout(100, 200, 303, 404);
    assertThat(view.getWidth(), equalTo(303 - 100));
    assertThat(view.getHeight(), equalTo(404 - 200));
  }
コード例 #19
0
 @Override
 public void initView(View item, int position, int scrollDirection) {
   ViewHelper.setPivotX(item, item.getWidth() / 2);
   ViewHelper.setPivotY(item, item.getHeight() / 2);
   ViewHelper.setScaleX(item, INITIAL_SCALE_FACTOR);
   ViewHelper.setScaleY(item, INITIAL_SCALE_FACTOR);
   ViewHelper.setTranslationY(item, item.getHeight() / 2 * scrollDirection);
   ViewHelper.setAlpha(item, JazzyHelper.OPAQUE / 2);
 }
コード例 #20
0
 private int b() {
   ViewGroup.LayoutParams localLayoutParams = a.getLayoutParams();
   if (a(a.getHeight())) {
     return a.getHeight();
   }
   if (localLayoutParams != null) {
     return a(height, true);
   }
   return 0;
 }
コード例 #21
0
ファイル: GrabIt.java プロジェクト: raizal/android-flip
  public static Bitmap takeScreenshot(View view) {
    if (view == null) return null;
    assert view.getWidth() > 0 && view.getHeight() > 0;
    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), config);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);

    return bitmap;
  }
コード例 #22
0
ファイル: ViewTarget.java プロジェクト: hegazy/glide
 private int getViewHeightOrParam() {
   final LayoutParams layoutParams = view.getLayoutParams();
   if (isSizeValid(view.getHeight())) {
     return view.getHeight();
   } else if (layoutParams != null) {
     return getSizeForParam(layoutParams.height, true /*isHeight*/);
   } else {
     return PENDING_SIZE;
   }
 }
コード例 #23
0
 @Override
 public void animate(View view) {
   f = pickScale();
   f2 = pickScale();
   f3 = pickTranslation(view.getWidth(), f);
   f4 = pickTranslation(view.getHeight(), f);
   f5 = pickTranslation(view.getWidth(), f2);
   f6 = pickTranslation(view.getHeight(), f2);
   start(view, Image_Animation_Duration, f, f2, f3, f4, f5, f6);
 }
コード例 #24
0
 @Override
 public void onGlobalLayout() {
   if (waitingForExactHeaderHeight && dummyHeader.getHeight() > 0) {
     headerHeight = dummyHeader.getHeight();
     waitingForExactHeaderHeight = false;
     LayoutParams params = dummyHeader.getLayoutParams();
     params.height = headerHeight;
     dummyHeader.setLayoutParams(params);
   }
 }
コード例 #25
0
  @SuppressLint("NewApi")
  private void moveHandlebar(final float where) {
    float move = where;
    if (move < mScrollbarMargin) move = mScrollbarMargin;
    else if (move > getHeight() - mHandlebar.getHeight() - mScrollbarMargin)
      move = getHeight() - mHandlebar.getHeight() - mScrollbarMargin;

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
      mHandlebar.startAnimation(moveCompat(move));
    else mHandlebar.setTranslationY(move);
  }
コード例 #26
0
  @Override
  public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Translate overlay and image
    float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
    int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
    ViewHelper.setTranslationY(
        mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
    ViewHelper.setTranslationY(
        mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

    // Scale title text
    float scale =
        1
            + ScrollUtils.getFloat(
                (flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);

    // Translate title text
    int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
    int titleTranslationY = maxTitleTranslationY - scrollY;
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);

    // Translate FAB
    int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
    float fabTranslationY =
        ScrollUtils.getFloat(
            -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2,
            mActionBarSize - mFab.getHeight() / 2,
            maxFabTranslationY);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin,
      // which causes FAB's OnClickListener not working.
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams();
      lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth();
      lp.topMargin = (int) fabTranslationY;
      mFab.requestLayout();
    } else {
      ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
      ViewHelper.setTranslationY(mFab, fabTranslationY);
    }

    // Show/hide FAB
    if (fabTranslationY < mFlexibleSpaceShowFabOffset) {
      hideFab();
    } else {
      showFab();
    }
  }
  @Override
  public void onPageSelected(int position) {
    SparseArrayCompat<ScrollTabHolder> scrollTabHolders = mAdapter.getScrollTabHolders();

    if (scrollTabHolders == null || scrollTabHolders.size() != mNumFragments) {
      return;
    }

    ScrollTabHolder currentHolder = scrollTabHolders.valueAt(position);
    currentHolder.adjustScroll(
        (int) (mHeader.getHeight() + mHeader.getTranslationY()), mHeader.getHeight());
  }
コード例 #28
0
  public static void expandOrCollapse(View view2Expand, View view2Measure, int collapsedHeight) {
    if (view2Expand.getHeight() < collapsedHeight) return;

    int measuredHeight = measureViewHeight(view2Expand, view2Measure);

    if (measuredHeight < collapsedHeight) measuredHeight = collapsedHeight;

    final int startHeight = view2Expand.getHeight();
    final int finishHeight = startHeight <= collapsedHeight ? measuredHeight : collapsedHeight;

    view2Expand.startAnimation(new ExpandAnimation(view2Expand, startHeight, finishHeight));
  }
 private static int c(View paramView)
 {
   Object localObject = paramView.getLayoutParams();
   if ((localObject instanceof ViewGroup.MarginLayoutParams))
   {
     localObject = (ViewGroup.MarginLayoutParams)localObject;
     int i1 = paramView.getHeight();
     int i2 = topMargin;
     return bottomMargin + (i1 + i2);
   }
   return paramView.getHeight();
 }
コード例 #30
0
ファイル: DisplayActivity.java プロジェクト: BoD/bikey
  private void hideControls() {
    mControlsVisible = false;
    int duration = getResources().getInteger(R.integer.animation_controls_showHide);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
      // Landscape: tab containers slide to left / right
      mConTabsA
          .animate()
          .alpha(0)
          .translationX(-mConTabsA.getWidth())
          .setInterpolator(new AccelerateInterpolator())
          .setDuration(duration);
      mConTabsB
          .animate()
          .alpha(0)
          .translationX(mConTabsB.getWidth())
          .setInterpolator(new AccelerateInterpolator())
          .setDuration(duration);
    } else {
      // Portrait: tab containers slide to top / bottom
      mConTabsA
          .animate()
          .alpha(0)
          .translationY(-mConTabsA.getHeight())
          .setInterpolator(new AccelerateInterpolator())
          .setDuration(duration);
      mConTabsB
          .animate()
          .alpha(0)
          .translationY(mConTabsB.getHeight())
          .setInterpolator(new AccelerateInterpolator())
          .setDuration(duration);
    }

    // 'Uncompress' the main fragment
    mConFragments
        .animate()
        .scaleX(1f)
        .scaleY(1f)
        .setInterpolator(new AccelerateInterpolator())
        .setDuration(duration);

    // Record button
    mChkRecord
        .animate()
        .alpha(0)
        .translationY(-mChkRecord.getHeight())
        .setInterpolator(new AccelerateInterpolator())
        .setDuration(duration);

    // Show the title
    mTxtTitle.animate().alpha(1f).setDuration(duration).setStartDelay(duration);
  }