Search in sources :

Example 1 with StoreHouseBarItem

use of com.scwang.smartrefresh.header.storehouse.StoreHouseBarItem in project SmartRefreshLayout by scwang90.

the class StoreHouseHeader method dispatchDraw.

@Override
protected void dispatchDraw(Canvas canvas) {
    final View thisView = this;
    final int c1 = canvas.save();
    final int len = mItemList.size();
    final float progress = thisView.isInEditMode() ? 1 : mProgress;
    for (int i = 0; i < len; i++) {
        canvas.save();
        StoreHouseBarItem storeHouseBarItem = mItemList.get(i);
        float offsetX = mOffsetX + storeHouseBarItem.midPoint.x;
        float offsetY = mOffsetY + storeHouseBarItem.midPoint.y;
        if (mIsInLoading) {
            storeHouseBarItem.getTransformation(thisView.getDrawingTime(), mTransformation);
            canvas.translate(offsetX, offsetY);
        } else {
            if (progress == 0) {
                storeHouseBarItem.resetPosition(mHorizontalRandomness);
                continue;
            }
            float startPadding = (1 - mInternalAnimationFactor) * i / len;
            float endPadding = 1 - mInternalAnimationFactor - startPadding;
            // done
            if (progress == 1 || progress >= 1 - endPadding) {
                canvas.translate(offsetX, offsetY);
                storeHouseBarItem.setAlpha(mBarDarkAlpha);
            } else {
                float realProgress;
                if (progress <= startPadding) {
                    realProgress = 0;
                } else {
                    realProgress = Math.min(1, (progress - startPadding) / mInternalAnimationFactor);
                }
                offsetX += storeHouseBarItem.translationX * (1 - realProgress);
                offsetY += -mDropHeight * (1 - realProgress);
                mMatrix.reset();
                mMatrix.postRotate(360 * realProgress);
                mMatrix.postScale(realProgress, realProgress);
                mMatrix.postTranslate(offsetX, offsetY);
                storeHouseBarItem.setAlpha(mBarDarkAlpha * realProgress);
                canvas.concat(mMatrix);
            }
        }
        storeHouseBarItem.draw(canvas);
        canvas.restore();
    }
    if (mIsInLoading) {
        thisView.invalidate();
    }
    canvas.restoreToCount(c1);
    super.dispatchDraw(canvas);
}
Also used : StoreHouseBarItem(com.scwang.smartrefresh.header.storehouse.StoreHouseBarItem) View(android.view.View)

Example 2 with StoreHouseBarItem

use of com.scwang.smartrefresh.header.storehouse.StoreHouseBarItem in project SmartRefreshLayout by scwang90.

the class StoreHouseHeader method initWithPointList.

public StoreHouseHeader initWithPointList(List<float[]> pointList) {
    float drawWidth = 0;
    float drawHeight = 0;
    boolean shouldLayout = mItemList.size() > 0;
    mItemList.clear();
    DensityUtil density = new DensityUtil();
    for (int i = 0; i < pointList.size(); i++) {
        float[] line = pointList.get(i);
        PointF startPoint = new PointF(density.dip2px(line[0]) * mScale, density.dip2px(line[1]) * mScale);
        PointF endPoint = new PointF(density.dip2px(line[2]) * mScale, density.dip2px(line[3]) * mScale);
        drawWidth = Math.max(drawWidth, startPoint.x);
        drawWidth = Math.max(drawWidth, endPoint.x);
        drawHeight = Math.max(drawHeight, startPoint.y);
        drawHeight = Math.max(drawHeight, endPoint.y);
        StoreHouseBarItem item = new StoreHouseBarItem(i, startPoint, endPoint, mTextColor, mLineWidth);
        item.resetPosition(mHorizontalRandomness);
        mItemList.add(item);
    }
    mDrawZoneWidth = (int) Math.ceil(drawWidth);
    mDrawZoneHeight = (int) Math.ceil(drawHeight);
    if (shouldLayout) {
        final View thisView = this;
        thisView.requestLayout();
    }
    return this;
}
Also used : DensityUtil(com.scwang.smartrefresh.layout.util.DensityUtil) StoreHouseBarItem(com.scwang.smartrefresh.header.storehouse.StoreHouseBarItem) PointF(android.graphics.PointF) View(android.view.View)

Aggregations

View (android.view.View)2 StoreHouseBarItem (com.scwang.smartrefresh.header.storehouse.StoreHouseBarItem)2 PointF (android.graphics.PointF)1 DensityUtil (com.scwang.smartrefresh.layout.util.DensityUtil)1