Java Code Examples for com.nineoldandroids.view.ViewHelper#getScaleX()

The following examples show how to use com.nineoldandroids.view.ViewHelper#getScaleX() . 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 File: ResideMenu.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
private float getTargetScale(float currentRawX){
    float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
    scaleFloatX = scaleDirection == DIRECTION_RIGHT ? - scaleFloatX : scaleFloatX;

    float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX;
    targetScale = targetScale > 1.0f ? 1.0f : targetScale;
    targetScale = targetScale < 0.5f ? 0.5f : targetScale;
    return targetScale;
}
 
Example 2
Source File: ResideMenu.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
private float getTargetScale(float currentRawX) {
	float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
	scaleFloatX = scaleDirection == DIRECTION_RIGHT ? -scaleFloatX
			: scaleFloatX;

	float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX;
	targetScale = targetScale > 1.0f ? 1.0f : targetScale;
	targetScale = targetScale < mScaleValue ? mScaleValue : targetScale; // 0.5
	return targetScale;
}
 
Example 3
Source File: ResideMenu.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
private float getTargetScale(float currentRawX) {
	float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
	scaleFloatX = scaleDirection == DIRECTION_RIGHT ? -scaleFloatX
			: scaleFloatX;

	float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX;
	targetScale = targetScale > 1.0f ? 1.0f : targetScale;
	targetScale = targetScale < mScaleValue ? mScaleValue : targetScale; // 0.5
	return targetScale;
}
 
Example 4
Source File: ResideMenu.java    From iSCAU-Android with GNU General Public License v3.0 5 votes vote down vote up
private float getTargetScale(float currentRawX){
    float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
    scaleFloatX = scaleDirection == DIRECTION_RIGHT ? - scaleFloatX : scaleFloatX;

    float targetScale = ViewHelper.getScaleX(view_activity) - scaleFloatX;
    targetScale = targetScale > 1.0f ? 1.0f : targetScale;
    targetScale = targetScale < 0.5f ? 0.5f : targetScale;
    return targetScale;
}
 
Example 5
Source File: ResideMenu.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private float getTargetScale(float currentRawX){
    float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
    scaleFloatX = scaleDirection == DIRECTION_RIGHT ? - scaleFloatX : scaleFloatX;

    float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX;
    targetScale = targetScale > 1.0f ? 1.0f : targetScale;
    targetScale = targetScale < 0.5f ? 0.5f : targetScale;
    return targetScale;
}
 
Example 6
Source File: CardView.java    From CardView with MIT License 5 votes vote down vote up
/**
 * 将下一个视图移到前边
 * 
 * @param view
 */
private void bringToTop(final View view) {
	topPosition++;
	float scaleX = ViewHelper.getScaleX(view) + ((float) 1 / mMaxVisible)
			* 0.2f;
	float tranlateY = ViewHelper.getTranslationY(view) + itemSpace;
	ViewPropertyAnimator.animate(view).translationY(tranlateY)
			.scaleX(scaleX).setDuration(200).alpha(1)
			.setInterpolator(new AccelerateInterpolator());
}
 
Example 7
Source File: ResideMenu.java    From AndroidResideMenu with MIT License 5 votes vote down vote up
private float getTargetScale(float currentRawX) {
    float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
    scaleFloatX = scaleDirection == DIRECTION_RIGHT ? -scaleFloatX : scaleFloatX;

    float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX;
    targetScale = targetScale > 1.0f ? 1.0f : targetScale;
    targetScale = targetScale < 0.5f ? 0.5f : targetScale;
    return targetScale;
}
 
Example 8
Source File: ResideMenu.java    From GifAssistant with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
    if (currentActivityScaleX == 1.0f)
        setScaleDirectionByRawX(ev.getRawX());

    switch (ev.getAction()){
        case MotionEvent.ACTION_DOWN:
            lastActionDownX = ev.getX();
            lastActionDownY = ev.getY();
            isInIgnoredView = isInIgnoredView(ev) && !isOpened();
            pressedState    = PRESSED_DOWN;
            break;

        case MotionEvent.ACTION_MOVE:
            if (isInIgnoredView || isInDisableDirection(scaleDirection))
                break;

            if(pressedState != PRESSED_DOWN &&
                    pressedState != PRESSED_MOVE_HORIZANTAL)
                break;

            int xOffset = (int) (ev.getX() - lastActionDownX);
            int yOffset = (int) (ev.getY() - lastActionDownY);

            if(pressedState == PRESSED_DOWN) {
                if(yOffset > 25 || yOffset < -25) {
                    pressedState = PRESSED_MOVE_VERTICAL;
                    break;
                }
                if(xOffset < -50 || xOffset > 50) {
                    pressedState = PRESSED_MOVE_HORIZANTAL;
                    ev.setAction(MotionEvent.ACTION_CANCEL);
                    lastRawX = ev.getRawX();
                    return true;
                }
            } else if(pressedState == PRESSED_MOVE_HORIZANTAL) {
                if (currentActivityScaleX < 0.95)
                    scrollViewMenu.setVisibility(VISIBLE);

                float targetScale = getTargetScale(ev.getRawX());
                ViewHelper.setScaleX(viewActivity, targetScale);
                ViewHelper.setScaleY(viewActivity, targetScale);
                ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX);
                ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY);
                ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

                lastRawX = ev.getRawX();
                return true;
            }

            break;

        case MotionEvent.ACTION_UP:

            if (isInIgnoredView) break;
            if (pressedState != PRESSED_MOVE_HORIZANTAL) break;

            pressedState = PRESSED_DONE;
            if (isOpened()){
                if (currentActivityScaleX > 0.56f) {
                    closeMenu();
                } else {
                    openMenu(scaleDirection);
                }
            }else{
                if (currentActivityScaleX < 0.94f){
                    openMenu(scaleDirection);
                }else{
                    closeMenu();
                }
            }
            lastRawX = ev.getRawX();
            return true;

            //break;

    }
    lastRawX = ev.getRawX();
    return super.dispatchTouchEvent(ev);
}
 
Example 9
Source File: ResideMenu.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
	float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
	if (currentActivityScaleX == 1.0f)
		setScaleDirectionByRawX(ev.getRawX());

	switch (ev.getAction()) {
	case MotionEvent.ACTION_DOWN:
		lastActionDownX = ev.getX();
		lastActionDownY = ev.getY();
		isInIgnoredView = isInIgnoredView(ev) && !isOpened();
		pressedState = PRESSED_DOWN;
		break;

	case MotionEvent.ACTION_MOVE:
		if (isInIgnoredView || isInDisableDirection(scaleDirection))
			break;

		if (pressedState != PRESSED_DOWN
				&& pressedState != PRESSED_MOVE_HORIZANTAL)
			break;

		int xOffset = (int) (ev.getX() - lastActionDownX);
		int yOffset = (int) (ev.getY() - lastActionDownY);

		if (pressedState == PRESSED_DOWN) {
			if (yOffset > 50 || yOffset < -50) { // origin = 25
				pressedState = PRESSED_MOVE_VERTICAL;
				break;
			}
			if (xOffset < -50 || xOffset > 50) {
				pressedState = PRESSED_MOVE_HORIZANTAL;
				ev.setAction(MotionEvent.ACTION_CANCEL);
			}
		} else if (pressedState == PRESSED_MOVE_HORIZANTAL) {
			if (currentActivityScaleX < 0.90) // 0.95
				showScrollViewMenu(scrollViewMenu);

			float targetScale = getTargetScale(ev.getRawX());
			ViewHelper.setScaleX(viewActivity, targetScale);
			ViewHelper.setScaleY(viewActivity, targetScale);
			ViewHelper.setScaleX(imageViewShadow, targetScale
					+ shadowAdjustScaleX);
			ViewHelper.setScaleY(imageViewShadow, targetScale
					+ shadowAdjustScaleY);
			ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

			lastRawX = ev.getRawX();
			return true;
		}

		break;

	case MotionEvent.ACTION_UP:

		if (isInIgnoredView)
			break;
		if (pressedState != PRESSED_MOVE_HORIZANTAL)
			break;

		pressedState = PRESSED_DONE;
		if (isOpened()) {
			if (currentActivityScaleX > 0.65f) // 0.56
				closeMenu();
			else
				openMenu(scaleDirection);
		} else {
			if (currentActivityScaleX < 0.90f) { // 0.94
				openMenu(scaleDirection);
			} else {
				closeMenu();
			}
		}

		break;

	}
	lastRawX = ev.getRawX();
	return super.dispatchTouchEvent(ev);
}
 
Example 10
Source File: ResideMenu.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
	float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
	if (currentActivityScaleX == 1.0f)
		setScaleDirectionByRawX(ev.getRawX());

	switch (ev.getAction()) {
	case MotionEvent.ACTION_DOWN:
		lastActionDownX = ev.getX();
		lastActionDownY = ev.getY();
		isInIgnoredView = isInIgnoredView(ev) && !isOpened();
		pressedState = PRESSED_DOWN;
		break;

	case MotionEvent.ACTION_MOVE:
		if (isInIgnoredView || isInDisableDirection(scaleDirection))
			break;

		if (pressedState != PRESSED_DOWN
				&& pressedState != PRESSED_MOVE_HORIZANTAL)
			break;

		int xOffset = (int) (ev.getX() - lastActionDownX);
		int yOffset = (int) (ev.getY() - lastActionDownY);

		if (pressedState == PRESSED_DOWN) {
			if (yOffset > 50 || yOffset < -50) { // origin = 25
				pressedState = PRESSED_MOVE_VERTICAL;
				break;
			}
			if (xOffset < -50 || xOffset > 50) {
				pressedState = PRESSED_MOVE_HORIZANTAL;
				ev.setAction(MotionEvent.ACTION_CANCEL);
			}
		} else if (pressedState == PRESSED_MOVE_HORIZANTAL) {
			if (currentActivityScaleX < 0.90) // 0.95
				showScrollViewMenu(scrollViewMenu);

			float targetScale = getTargetScale(ev.getRawX());
			ViewHelper.setScaleX(viewActivity, targetScale);
			ViewHelper.setScaleY(viewActivity, targetScale);
			ViewHelper.setScaleX(imageViewShadow, targetScale
					+ shadowAdjustScaleX);
			ViewHelper.setScaleY(imageViewShadow, targetScale
					+ shadowAdjustScaleY);
			ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

			lastRawX = ev.getRawX();
			return true;
		}

		break;

	case MotionEvent.ACTION_UP:

		if (isInIgnoredView)
			break;
		if (pressedState != PRESSED_MOVE_HORIZANTAL)
			break;

		pressedState = PRESSED_DONE;
		if (isOpened()) {
			if (currentActivityScaleX > 0.65f) // 0.56
				closeMenu();
			else
				openMenu(scaleDirection);
		} else {
			if (currentActivityScaleX < 0.90f) { // 0.94
				openMenu(scaleDirection);
			} else {
				closeMenu();
			}
		}

		break;

	}
	lastRawX = ev.getRawX();
	return super.dispatchTouchEvent(ev);
}
 
Example 11
Source File: ResideMenu.java    From iSCAU-Android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    float currentActivityScaleX = ViewHelper.getScaleX(view_activity);
    if (currentActivityScaleX == 1.0f)
        setScaleDirectionByRawX(ev.getRawX());

    switch (ev.getAction()){
        case MotionEvent.ACTION_DOWN:
            canScale = !isInIgnoredView(ev);
            break;

        case MotionEvent.ACTION_MOVE:
            if (!canScale || isInDisableDirection(scaleDirection))
                break;
            if (currentActivityScaleX < 0.95)
                sv_menu.setVisibility(VISIBLE);

            float targetScale = getTargetScale(ev.getRawX());
            ViewHelper.setScaleX(view_activity, targetScale);
            ViewHelper.setScaleY(view_activity, targetScale);
            ViewHelper.setScaleX(iv_shadow, targetScale + shadow_AdjustScaleX);
            ViewHelper.setScaleY(iv_shadow, targetScale + shadow_AdjustScaleY);
            ViewHelper.setAlpha(sv_menu, (1 - targetScale) * 2.0f);
            break;

        case MotionEvent.ACTION_UP:
            if (!canScale)
                break;
            if (isOpened()){
                if (currentActivityScaleX > 0.55f)
                    closeMenu();
                else
                    openMenu(scaleDirection);
            }else if (!isOpened()){
                if (currentActivityScaleX < 0.95f)
                    openMenu(scaleDirection);
                else
                    closeMenu();
            }
            break;
    }
    lastRawX = ev.getRawX();
    return super.onInterceptTouchEvent(ev);
}
 
Example 12
Source File: ResideMenu.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
    if (currentActivityScaleX == 1.0f)
        setScaleDirectionByRawX(ev.getRawX());

    switch (ev.getAction()){
        case MotionEvent.ACTION_DOWN:
            lastActionDownX = ev.getX();
            lastActionDownY = ev.getY();
            isInIgnoredView = isInIgnoredView(ev) && !isOpened();
            pressedState    = PRESSED_DOWN;
            break;

        case MotionEvent.ACTION_MOVE:
            if (isInIgnoredView || isInDisableDirection(scaleDirection))
                break;

            if(pressedState != PRESSED_DOWN &&
                    pressedState != PRESSED_MOVE_HORIZANTAL)
                break;

            int xOffset = (int) (ev.getX() - lastActionDownX);
            int yOffset = (int) (ev.getY() - lastActionDownY);

            if(pressedState == PRESSED_DOWN) {
                if(yOffset > 25 || yOffset < -25) {
                    pressedState = PRESSED_MOVE_VERTICAL;
                    break;
                }
                if(xOffset < -50 || xOffset > 50) {
                    pressedState = PRESSED_MOVE_HORIZANTAL;
                    ev.setAction(MotionEvent.ACTION_CANCEL);
                }
            } else if(pressedState == PRESSED_MOVE_HORIZANTAL) {
                if (currentActivityScaleX < 0.95)
                    showScrollViewMenu();

                float targetScale = getTargetScale(ev.getRawX());
                ViewHelper.setScaleX(viewActivity, targetScale);
                ViewHelper.setScaleY(viewActivity, targetScale);
                ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX);
                ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY);
                ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

                lastRawX = ev.getRawX();
                return true;
            }

            break;

        case MotionEvent.ACTION_UP:

            if (isInIgnoredView) break;
            if (pressedState != PRESSED_MOVE_HORIZANTAL) break;

            pressedState = PRESSED_DONE;
            if (isOpened()){
                if (currentActivityScaleX > 0.56f)
                    closeMenu();
                else
                    openMenu(scaleDirection);
            }else{
                if (currentActivityScaleX < 0.94f){
                    openMenu(scaleDirection);
                }else{
                    closeMenu();
                }
            }

            break;

    }
    lastRawX = ev.getRawX();
    return super.dispatchTouchEvent(ev);
}
 
Example 13
Source File: SafeDrawOverlay.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void draw(final Canvas c, final MapView mapView, final boolean shadow) {

    sSafeCanvas.setCanvas(c);

    if (this.mUseSafeCanvas) {

        // Find the screen offset
        Rect screenRect = mapView.getProjection().getScreenRect();
        sSafeCanvas.xOffset = -screenRect.left;
        sSafeCanvas.yOffset = -screenRect.top;

        // Save the canvas state
        c.save();

        if (mapView.getMapOrientation() != 0) {
            // Un-rotate the maps so we can rotate them accurately using the safe canvas
            c.rotate(-mapView.getMapOrientation(), screenRect.exactCenterX(),
                    screenRect.exactCenterY());
        }

        // Since the translate calls still take a float, there can be rounding errors
        // Let's calculate the error, and adjust for it.
        final int floatErrorX = screenRect.left - (int) (float) screenRect.left;
        final int floatErrorY = screenRect.top - (int) (float) screenRect.top;

        // Translate the coordinates
        final float scaleX = ViewHelper.getScaleX(mapView);
        final float scaleY = ViewHelper.getScaleY(mapView);
        c.translate(screenRect.left * scaleX, screenRect.top * scaleY);
        c.translate(floatErrorX, floatErrorY);

        if (mapView.getMapOrientation() != 0) {
            // Safely re-rotate the maps
            sSafeCanvas.rotate(mapView.getMapOrientation(), (double) screenRect.exactCenterX(),
                    (double) screenRect.exactCenterY());
        }
    } else {
        sSafeCanvas.xOffset = 0;
        sSafeCanvas.yOffset = 0;
    }

    this.drawSafe(sSafeCanvas, mapView, shadow);

    if (this.mUseSafeCanvas) {
        c.restore();
    }
}
 
Example 14
Source File: ResideMenu.java    From AndroidResideMenu with MIT License 4 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
    if (currentActivityScaleX == 1.0f)
        setScaleDirectionByRawX(ev.getRawX());

    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            lastActionDownX = ev.getX();
            lastActionDownY = ev.getY();
            isInIgnoredView = isInIgnoredView(ev) && !isOpened();
            pressedState = PRESSED_DOWN;
            break;

        case MotionEvent.ACTION_MOVE:
            if (isInIgnoredView || isInDisableDirection(scaleDirection))
                break;

            if (pressedState != PRESSED_DOWN &&
                    pressedState != PRESSED_MOVE_HORIZONTAL)
                break;

            int xOffset = (int) (ev.getX() - lastActionDownX);
            int yOffset = (int) (ev.getY() - lastActionDownY);

            if (pressedState == PRESSED_DOWN) {
                if (yOffset > 25 || yOffset < -25) {
                    pressedState = PRESSED_MOVE_VERTICAL;
                    break;
                }
                if (xOffset < -50 || xOffset > 50) {
                    pressedState = PRESSED_MOVE_HORIZONTAL;
                    ev.setAction(MotionEvent.ACTION_CANCEL);
                }
            } else if (pressedState == PRESSED_MOVE_HORIZONTAL) {
                if (currentActivityScaleX < 0.95)
                    showScrollViewMenu(scrollViewMenu);

                float targetScale = getTargetScale(ev.getRawX());
                if (mUse3D) {
                    int angle = scaleDirection == DIRECTION_LEFT ? -ROTATE_Y_ANGLE : ROTATE_Y_ANGLE;
                    angle *= (1 - targetScale) * 2;
                    ViewHelper.setRotationY(viewActivity, angle);

                    ViewHelper.setScaleX(imageViewShadow, targetScale - shadowAdjustScaleX);
                    ViewHelper.setScaleY(imageViewShadow, targetScale - shadowAdjustScaleY);
                } else {
                    ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX);
                    ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY);
                }
                ViewHelper.setScaleX(viewActivity, targetScale);
                ViewHelper.setScaleY(viewActivity, targetScale);
                ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

                lastRawX = ev.getRawX();
                return true;
            }

            break;

        case MotionEvent.ACTION_UP:

            if (isInIgnoredView) break;
            if (pressedState != PRESSED_MOVE_HORIZONTAL) break;

            pressedState = PRESSED_DONE;
            if (isOpened()) {
                if (currentActivityScaleX > 0.56f)
                    closeMenu();
                else
                    openMenu(scaleDirection);
            } else {
                if (currentActivityScaleX < 0.94f) {
                    openMenu(scaleDirection);
                } else {
                    closeMenu();
                }
            }

            break;

    }
    lastRawX = ev.getRawX();
    return super.dispatchTouchEvent(ev);
}