Java Code Examples for com.gcssloop.view.utils.DensityUtils

The following examples show how to use com.gcssloop.view.utils.DensityUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: diycode   Source File: UserActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initScrollAnimation(ViewHolder holder) {
    NestedScrollView scrollView = holder.get(R.id.scroll_view);
    ImageView avatar = holder.get(R.id.avatar);
    TextView username = holder.get(R.id.username);
    View backbground = holder.get(R.id.background);

    this.expectAnimMove = new ExpectAnim()
            .expect(avatar)
            .toBe(
                    topOfParent().withMarginDp(13),
                    leftOfParent().withMarginDp(13),
                    scale(0.5f, 0.5f)
            )
            .expect(username)
            .toBe(
                    toRightOf(avatar).withMarginDp(16),
                    sameCenterVerticalAs(avatar),
                    alpha(0.5f)
            )
            .expect(backbground)
            .toBe(
                    height(DensityUtils.dip2px(this, 60)).withGravity(Gravity.LEFT, Gravity.TOP)
            )
            .toAnimation();

    scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int
                oldScrollX, int oldScrollY) {
            final float percent = (scrollY * 1f) / v.getMaxScrollAmount();
            expectAnimMove.setPercent(percent);
        }
    });
}
 
Example 2
Source Project: PokeFaker   Source File: RockerView.java    License: MIT License 5 votes vote down vote up
private void initAttrs(Context context, AttributeSet attrs) {

        DEFAULT_AREA_RADIUS = DensityUtils.dip2px(context, 75);
        DEFAULT_ROCKER_RADIUS = DensityUtils.dip2px(context, 25);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.viewsupport);

        mAreaRadius = ta.getDimensionPixelOffset(R.styleable.viewsupport_area_radius, DEFAULT_AREA_RADIUS);
        mRockerRadius = ta.getDimensionPixelOffset(R.styleable.viewsupport_rocker_radius, DEFAULT_ROCKER_RADIUS);
        mRefreshCycle = ta.getInteger(R.styleable.viewsupport_refresh_cycle, DEFAULT_REFRESH_CYCLE);

        Drawable area_bg = ta.getDrawable(R.styleable.viewsupport_area_background);
        Drawable rocker_bg = ta.getDrawable(R.styleable.viewsupport_rocker_background);

        if (area_bg instanceof BitmapDrawable) {
            mAreaBitmap = ((BitmapDrawable) area_bg).getBitmap();
        } else if (area_bg instanceof ColorDrawable) {
            mAreaBitmap = null;
            mAreaColor = ((ColorDrawable) area_bg).getColor();
        } else {
            mAreaBitmap = null;
            mAreaColor = DEFAULT_AREA_COLOR;
        }

        if (rocker_bg instanceof BitmapDrawable) {
            mRockerBitmap = ((BitmapDrawable) rocker_bg).getBitmap();
        } else if (rocker_bg instanceof ColorDrawable) {
            mRockerBitmap = null;
            mRockerColor = ((ColorDrawable) rocker_bg).getColor();
        } else {
            mRockerBitmap = null;
            mRockerColor = DEFAULT_ROCKER_COLOR;
        }
    }
 
Example 3
Source Project: Rocker   Source File: RockerView.java    License: Apache License 2.0 5 votes vote down vote up
private void initAttrs(Context context, AttributeSet attrs) {

        DEFAULT_AREA_RADIUS = DensityUtils.dip2px(context, 75);
        DEFAULT_ROCKER_RADIUS = DensityUtils.dip2px(context, 25);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.viewsupport);

        mAreaRadius = ta.getDimensionPixelOffset(R.styleable.viewsupport_area_radius, DEFAULT_AREA_RADIUS);
        mRockerRadius = ta.getDimensionPixelOffset(R.styleable.viewsupport_rocker_radius, DEFAULT_ROCKER_RADIUS);

        mRefreshCycle = ta.getInteger(R.styleable.viewsupport_refresh_cycle, DEFAULT_REFRESH_CYCLE);
        mCallbackCycle = ta.getInteger(R.styleable.viewsupport_callback_cycle, DEFAULT_CALLBACK_CYCLE);

        Drawable area_bg = ta.getDrawable(R.styleable.viewsupport_area_background);
        Drawable rocker_bg = ta.getDrawable(R.styleable.viewsupport_rocker_background);

        if (area_bg instanceof BitmapDrawable) {
            mAreaBitmap = ((BitmapDrawable) area_bg).getBitmap();
        } else if (area_bg instanceof ColorDrawable) {
            mAreaBitmap = null;
            mAreaColor = ((ColorDrawable) area_bg).getColor();
        } else {
            mAreaBitmap = null;
            mAreaColor = DEFAULT_AREA_COLOR;
        }

        if (rocker_bg instanceof BitmapDrawable) {
            mRockerBitmap = ((BitmapDrawable) rocker_bg).getBitmap();
        } else if (rocker_bg instanceof ColorDrawable) {
            mRockerBitmap = null;
            mRockerColor = ((ColorDrawable) rocker_bg).getColor();
        } else {
            mRockerBitmap = null;
            mRockerColor = DEFAULT_ROCKER_COLOR;
        }
    }