Java 类com.facebook.rebound.ui.Util 实例源码

项目:Hipster-Visualization    文件:SpringyFontFitTextView.java   
@Override
public void onSpringUpdate(Spring spring) {
    Resources resources = getResources();
    double value = spring.getCurrentValue();

    float selectedTitleScale = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 0,
            1);
    float titleTranslateY = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1,
            Util.dpToPx(-150f, resources), 0);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setScaleX(selectedTitleScale);
        setScaleY(selectedTitleScale);
        setTranslationY(titleTranslateY);
    }
}
项目:SpringFloatingActionMenu    文件:SpringFloatingActionMenu.java   
private void layoutMenuItemsAsGrid(int left, int top, int right, int bottom) {
    Resources resources = getResources();

    int edgeGap = Util.dpToPx(24, resources);

    int colCount = 3;
    int rowCount = mMenuItemCount % colCount == 0 ? mMenuItemCount / colCount : mMenuItemCount / colCount + 1;
    Log.d(TAG, "row count:" + rowCount);

    int itemHeight = mMenuItemViews.get(0).getMeasuredHeight();
    int itemWidth = mMenuItemViews.get(0).getMeasuredWidth();

    int containerWidth = getMeasuredWidth();
    int containerHeight = getMeasuredHeight();

    int itemGap = (containerWidth - 2 * edgeGap - colCount * itemWidth) / (colCount - 1);
    //top and bottom gap
    int tbGap = (containerHeight - rowCount * itemHeight - itemGap * (rowCount - 1)) / 2;

    for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
        for (int colIdx = 0; colIdx < colCount; colIdx++) {
            int idxInItem = rowIdx * colCount + colIdx;
            if (idxInItem < mMenuItemCount) {
                View item = mMenuItemViews.get(rowIdx * colCount + colIdx);
                Log.d(TAG, "menu item index:" + (rowIdx * colCount + colIdx));
                int itemLeft = edgeGap + colIdx * itemWidth + colIdx * itemGap;
                int itemTop = tbGap + rowIdx * itemGap + rowIdx * itemHeight;
                item.layout(itemLeft, itemTop, itemLeft + itemWidth, itemTop + itemHeight);
            } else {
                break;
            }
        }
    }
}
项目:SpringFloatingActionMenu    文件:MenuItemView.java   
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    measureChildren(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(
            Math.max(mBtn.getMeasuredWidth(), mLabel.getMeasuredWidth()),
            mBtn.getMeasuredHeight() + mLabel.getMeasuredHeight() + Util.dpToPx(4, getResources())
    );
}
项目:test4XXX    文件:OrigamiExample.java   
/**
 * This method takes the current state of the spring and maps it to all the values for each UI
 * element that is animated on this spring. This allows the Spring to act as a common timing
 * function for the animation ensuring that all element transitions are synchronized.
 *
 * You can think of these mappings as similiar to Origami transitions.
 * SpringUtil#mapValueFromRangeToRange converts the spring's 0 to 1 transition and maps it to the
 * range of animation for a property on a view such as translation, scale, rotation, and alpha.
 */
private void render() {
  Resources resources = getResources();
  // Get the current spring value.
  double value = mSpring.getCurrentValue();

  // Map the spring to the feedback bar position so that its hidden off screen and bounces in on tap.
  float barPosition =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, mFeedbackBar.getHeight(), 0);
  mFeedbackBar.setTranslationY(barPosition);

  // Map the spring to the selected photo scale as it moves into and out of the grid.
  float selectedPhotoScale =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 0.33, 1);
  selectedPhotoScale = Math.max(selectedPhotoScale, 0); // Clamp the value so we don't go below 0.
  mSelectedPhoto.setScaleX(selectedPhotoScale);
  mSelectedPhoto.setScaleY(selectedPhotoScale);

  // Map the spring to the selected photo translation from its position in the grid
  float selectedPhotoTranslateX = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, Util.dpToPx(-106.667f, resources), 0);
  float selectedPhotoTranslateY = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, Util.dpToPx(46.667f, resources), 0);
  mSelectedPhoto.setTranslationX(selectedPhotoTranslateX);
  mSelectedPhoto.setTranslationY(selectedPhotoTranslateY);

  // Map the spring to the photo grid alpha as it fades to black when the photo is selected.
  float gridAlpha =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0);
  mPhotoGrid.setAlpha(gridAlpha);


  // Map the spring to the photo grid scale so that it scales down slightly as the selected photo // zooms in.
  float gridScale =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0.95);
  gridScale = Math.max(gridScale, 0); // Clamp the value so we don't go below 0.
  mPhotoGrid.setScaleX(gridScale);
  mPhotoGrid.setScaleY(gridScale);
}
项目:Green    文件:OrigamiExample.java   
/**
 * This method takes the current state of the spring and maps it to all the values for each UI
 * element that is animated on this spring. This allows the Spring to act as a common timing
 * function for the animation ensuring that all element transitions are synchronized.
 *
 * You can think of these mappings as similiar to Origami transitions.
 * SpringUtil#mapValueFromRangeToRange converts the spring's 0 to 1 transition and maps it to the
 * range of animation for a property on a view such as translation, scale, rotation, and alpha.
 */
private void render() {
  Resources resources = getResources();
  // Get the current spring value.
  double value = mSpring.getCurrentValue();

  // Map the spring to the feedback bar position so that its hidden off screen and bounces in on tap.
  float barPosition =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, mFeedbackBar.getHeight(), 0);
  mFeedbackBar.setTranslationY(barPosition);

  // Map the spring to the selected photo scale as it moves into and out of the grid.
  float selectedPhotoScale =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 0.33, 1);
  selectedPhotoScale = Math.max(selectedPhotoScale, 0); // Clamp the value so we don't go below 0.
  mSelectedPhoto.setScaleX(selectedPhotoScale);
  mSelectedPhoto.setScaleY(selectedPhotoScale);

  // Map the spring to the selected photo translation from its position in the grid
  float selectedPhotoTranslateX = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, Util.dpToPx(-106.667f, resources), 0);
  float selectedPhotoTranslateY = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, Util.dpToPx(46.667f, resources), 0);
  mSelectedPhoto.setTranslationX(selectedPhotoTranslateX);
  mSelectedPhoto.setTranslationY(selectedPhotoTranslateY);

  // Map the spring to the photo grid alpha as it fades to black when the photo is selected.
  float gridAlpha =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0);
  mPhotoGrid.setAlpha(gridAlpha);


  // Map the spring to the photo grid scale so that it scales down slightly as the selected photo // zooms in.
  float gridScale =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0.95);
  gridScale = Math.max(gridScale, 0); // Clamp the value so we don't go below 0.
  mPhotoGrid.setScaleX(gridScale);
  mPhotoGrid.setScaleY(gridScale);
}
项目:rebound    文件:OrigamiExample.java   
/**
 * This method takes the current state of the spring and maps it to all the values for each UI
 * element that is animated on this spring. This allows the Spring to act as a common timing
 * function for the animation ensuring that all element transitions are synchronized.
 *
 * You can think of these mappings as similiar to Origami transitions.
 * SpringUtil#mapValueFromRangeToRange converts the spring's 0 to 1 transition and maps it to the
 * range of animation for a property on a view such as translation, scale, rotation, and alpha.
 */
private void render() {
  Resources resources = getResources();
  // Get the current spring value.
  double value = mSpring.getCurrentValue();

  // Map the spring to the feedback bar position so that its hidden off screen and bounces in on tap.
  float barPosition =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, mFeedbackBar.getHeight(), 0);
  mFeedbackBar.setTranslationY(barPosition);

  // Map the spring to the selected photo scale as it moves into and out of the grid.
  float selectedPhotoScale =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 0.33, 1);
  selectedPhotoScale = Math.max(selectedPhotoScale, 0); // Clamp the value so we don't go below 0.
  mSelectedPhoto.setScaleX(selectedPhotoScale);
  mSelectedPhoto.setScaleY(selectedPhotoScale);

  // Map the spring to the selected photo translation from its position in the grid
  float selectedPhotoTranslateX = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, Util.dpToPx(-106.667f, resources), 0);
  float selectedPhotoTranslateY = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, Util.dpToPx(46.667f, resources), 0);
  mSelectedPhoto.setTranslationX(selectedPhotoTranslateX);
  mSelectedPhoto.setTranslationY(selectedPhotoTranslateY);

  // Map the spring to the photo grid alpha as it fades to black when the photo is selected.
  float gridAlpha =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0);
  mPhotoGrid.setAlpha(gridAlpha);


  // Map the spring to the photo grid scale so that it scales down slightly as the selected photo // zooms in.
  float gridScale =
      (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0.95);
  gridScale = Math.max(gridScale, 0); // Clamp the value so we don't go below 0.
  mPhotoGrid.setScaleX(gridScale);
  mPhotoGrid.setScaleY(gridScale);
}
项目:SpringFloatingActionMenu    文件:MenuItemView.java   
private void init(Context context) {

        Resources resources = getResources();
        int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources);
        this.mDiameter = diameterPX;
        mBtn = new ImageButton(context);
        LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX);
        btnLp.gravity = Gravity.CENTER_HORIZONTAL;
        btnLp.bottomMargin = Util.dpToPx(mGapSize, resources);
        mBtn.setLayoutParams(btnLp);
        OvalShape ovalShape = new OvalShape();
        ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
        shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor()));
        mBtn.setBackgroundDrawable(shapeDrawable);
        mBtn.setImageResource(mMenuItem.getIcon());
        mBtn.setClickable(false);
        addView(mBtn);

        mLabel = new TextView(context);
        LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        labelLp.gravity = Gravity.CENTER_HORIZONTAL;
        mLabel.setLayoutParams(labelLp);
        mLabel.setText(mMenuItem.getLabel());
        mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor()));
        mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
        addView(mLabel);

        setOrientation(LinearLayout.VERTICAL);
        if(mAlphaAnimation) {
            setAlpha(0);
        }

        getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
                applyPressAnimation();
                ViewGroup parent = (ViewGroup) getParent();
                parent.setClipChildren(false);
                parent.setClipToPadding(false);
                setClipChildren(false);
                setClipToPadding(false);
            }
        });


    }