Example usage for android.util FloatMath sqrt

List of usage examples for android.util FloatMath sqrt

Introduction

In this page you can find the example usage for android.util FloatMath sqrt.

Prototype

public static float sqrt(float value) 

Source Link

Document

Returns the closest float approximation of the square root of the argument.

Usage

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

private static void drawArc(Path p, float lastX, float lastY, float x, float y, float rx, float ry, float theta,
        int largeArc, int sweepArc) {
    // Log.d("drawArc", "from (" + lastX + "," + lastY + ") to (" + x + ","+
    // y + ") r=(" + rx + "," + ry +
    // ") theta=" + theta + " flags="+ largeArc + "," + sweepArc);

    // http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes

    if (rx == 0 || ry == 0) {
        p.lineTo(x, y);/*from   www . j av  a 2 s .  c  o m*/
        return;
    }

    if (x == lastX && y == lastY) {
        return; // nothing to draw
    }

    rx = Math.abs(rx);
    ry = Math.abs(ry);

    final float thrad = theta * (float) Math.PI / 180;
    final float st = FloatMath.sin(thrad);
    final float ct = FloatMath.cos(thrad);

    final float xc = (lastX - x) / 2;
    final float yc = (lastY - y) / 2;
    final float x1t = ct * xc + st * yc;
    final float y1t = -st * xc + ct * yc;

    final float x1ts = x1t * x1t;
    final float y1ts = y1t * y1t;
    float rxs = rx * rx;
    float rys = ry * ry;

    float lambda = (x1ts / rxs + y1ts / rys) * 1.001f; // add 0.1% to be
    // sure that no out
    // of range occurs
    // due to
    // limited precision
    if (lambda > 1) {
        float lambdasr = FloatMath.sqrt(lambda);
        rx *= lambdasr;
        ry *= lambdasr;
        rxs = rx * rx;
        rys = ry * ry;
    }

    final float R = FloatMath.sqrt((rxs * rys - rxs * y1ts - rys * x1ts) / (rxs * y1ts + rys * x1ts))
            * ((largeArc == sweepArc) ? -1 : 1);
    final float cxt = R * rx * y1t / ry;
    final float cyt = -R * ry * x1t / rx;
    final float cx = ct * cxt - st * cyt + (lastX + x) / 2;
    final float cy = st * cxt + ct * cyt + (lastY + y) / 2;

    final float th1 = angle(1, 0, (x1t - cxt) / rx, (y1t - cyt) / ry);
    float dth = angle((x1t - cxt) / rx, (y1t - cyt) / ry, (-x1t - cxt) / rx, (-y1t - cyt) / ry);

    if (sweepArc == 0 && dth > 0) {
        dth -= 360;
    } else if (sweepArc != 0 && dth < 0) {
        dth += 360;
    }

    // draw
    if ((theta % 360) == 0) {
        // no rotate and translate need
        arcRectf.set(cx - rx, cy - ry, cx + rx, cy + ry);
        p.arcTo(arcRectf, th1, dth);
    } else {
        // this is the hard and slow part :-)
        arcRectf.set(-rx, -ry, rx, ry);

        arcMatrix.reset();
        arcMatrix.postRotate(theta);
        arcMatrix.postTranslate(cx, cy);
        arcMatrix.invert(arcMatrix2);

        p.transform(arcMatrix2);
        p.arcTo(arcRectf, th1, dth);
        p.transform(arcMatrix);
    }
}

From source file:de.tlabs.ssr.g1.client.SourcesView.java

@Override
public boolean onDown(MotionEvent event) {
    scrolling = false;//from  ww  w.  j  a v  a  2  s  . co  m

    synchronized (GlobalData.audioScene) {
        // determine transformed coordinate of touch point
        touchPoint[0] = event.getX();
        touchPoint[1] = event.getY();
        inverseViewportTransformation.mapPoints(touchPoint);
        GlobalData.audioScene.inverseMapPoint(touchPoint);

        // try to find nearest sound source
        lastTouchSoundSource = GlobalData.audioScene.getNearestSoundSource(touchPoint);
        if (lastTouchSoundSource != null) {
            // get distance (touch point to source) in pixels
            selectionOffset[0] = lastTouchSoundSource.getX();
            selectionOffset[1] = lastTouchSoundSource.getY();
            GlobalData.audioScene.mapPoint(selectionOffset);
            viewportTransformation.mapPoints(selectionOffset);
            selectionOffset[0] -= event.getX();
            selectionOffset[1] -= event.getY();
            float distance = FloatMath
                    .sqrt(selectionOffset[0] * selectionOffset[0] + selectionOffset[1] * selectionOffset[1]);

            // select source?
            if (distance > SOURCE_SELECT_RADIUS) {
                lastTouchSoundSource = null;
            }
        }
    }

    return true;
}

From source file:de.tlabs.ssr.g1.client.SourcesView.java

@Override
public boolean onScroll(MotionEvent firstEvent, MotionEvent thisEvent, float distanceX, float distanceY) {

    // transform sound source or surface?
    if (lastTouchSoundSource != null) { // transform sound source
        synchronized (GlobalData.audioScene) {
            // is lastTouchSoundSource selected?
            if (!lastTouchSoundSource.isSelected()) {
                // select only this source
                GlobalData.audioScene.deselectAllSoundSources();
                GlobalData.audioScene.selectSoundSource(lastTouchSoundSource);
            }/*from  ww  w.j  ava 2 s .  c  o m*/

            // save positions of sources if this is first scroll event
            if (!scrolling) {
                scrolling = true;
                firstScrollPoint[0] = firstEvent.getX();
                firstScrollPoint[1] = firstEvent.getY();
                ArrayList<SoundSource> selectedSources = GlobalData.audioScene.getSelectedSoundSources();
                int numSources = selectedSources.size();
                for (int i = 0; i < numSources; i++) { // loop through all currently selected sources
                    selectedSources.get(i).getXY(point);
                    GlobalData.audioScene.mapPoint(point);
                    viewportTransformation.mapPoints(point);
                    selectedSources.get(i).savePosition(point);
                }
            }

            // enough time elapsed to do next position update?
            long currentTime = SystemClock.uptimeMillis();
            if (currentTime - lastSendTime < MAX_POSITION_UPDATE_FREQ)
                return true;
            lastSendTime = currentTime;

            // translate or rotate?
            if (transformationMode == TransformationMode.TRANSLATE) { // translate
                // generate server request string
                String strMsg = "<request>";
                ArrayList<SoundSource> selectedSources = GlobalData.audioScene.getSelectedSoundSources();
                int numSources = selectedSources.size();
                SoundSource soundSource;
                for (int i = 0; i < numSources; i++) { // loop through all currently selected sources
                    soundSource = selectedSources.get(i);

                    // if source is fixed, skip it
                    if (soundSource.isPositionFixed())
                        continue;

                    strMsg += "<source id='" + soundSource.getId() + "'>";
                    // transform screen coords into object coords, consider offset
                    point[0] = soundSource.getSavedX() + thisEvent.getX() - firstScrollPoint[0];
                    point[1] = soundSource.getSavedY() + thisEvent.getY() - firstScrollPoint[1];
                    inverseViewportTransformation.mapPoints(point);

                    if (soundSource.getSourceModel() == SoundSource.SourceModel.PLANE) { // recalculate orientation for plane waves
                        float norm = FloatMath.sqrt(point[0] * point[0] + point[1] * point[1]); // for plane waves, if source is movable
                        if (norm != 0.0f) {
                            float newAzimuth;
                            if (point[1] >= 0.0f)
                                newAzimuth = (float) (Math.acos(point[0] / norm) / Math.PI * 180.0f) - 180.0f
                                        + GlobalData.audioScene.getReference().getAzimuth();
                            else
                                newAzimuth = (float) -(Math.acos(point[0] / norm) / Math.PI * 180.0f) - 180.0f
                                        + GlobalData.audioScene.getReference().getAzimuth();
                            strMsg += "<orientation azimuth='" + String.valueOf(newAzimuth) + "'/>";
                        }
                    }

                    GlobalData.audioScene.inverseMapPoint(point);
                    strMsg += "<position x='" + String.valueOf(point[0]) + "' y='" + String.valueOf(point[1])
                            + "'/>";
                    strMsg += "</source>";
                }
                strMsg += "</request>\0";

                // send changes to server
                sendToServer(strMsg);
            } else { // rotate
                // not implemented
            }
        }
    } else { // transform surface
        if (!scrolling) {
            scrolling = true;
            firstScrollPoint[0] = thisEvent.getX();
            firstScrollPoint[1] = thisEvent.getY();
            currentSavedTranslation[0] = currentTranslation[0];
            currentSavedTranslation[1] = currentTranslation[1];
        }

        // translate or rotate?
        if (transformationMode == TransformationMode.TRANSLATE) { // translate
            if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
                point[0] = thisEvent.getX() - firstScrollPoint[0];
                point[1] = thisEvent.getY() - firstScrollPoint[1];
            } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
                point[0] = thisEvent.getY() - firstScrollPoint[1];
                point[1] = -(thisEvent.getX() - firstScrollPoint[0]);
            }
            setCurrentTranslation(currentSavedTranslation[0] + point[0], currentSavedTranslation[1] + point[1]);
        } else { // rotate
            // not implemented
        }
    }

    return true;
}

From source file:com.slushpupie.deskclock.DeskClock.java

private float spacing(MotionEvent event) {
    try {/*from w w w . j  av  a  2 s.co m*/
        float x0 = ((Float) getXMethod.invoke(event, 0)).floatValue();
        float x1 = ((Float) getXMethod.invoke(event, 1)).floatValue();
        float x = x0 - x1;
        float y0 = ((Float) getYMethod.invoke(event, 0)).floatValue();
        float y1 = ((Float) getYMethod.invoke(event, 1)).floatValue();
        float y = y0 - y1;
        return FloatMath.sqrt(x * x + y * y);
    } catch (IllegalArgumentException iae) {
        return 0;
    } catch (IllegalAccessException e) {
        return 0;
    } catch (InvocationTargetException e) {
        return 0;
    }
}

From source file:com.androidex.volley.ui.PhotoView.java

/**
 * Returns the currently applied scale factor for the image.
 * <p>//from   w  ww  . j  ava  2 s .co m
 * NOTE: This method overwrites any values stored in {@link #mValues}.
 */
private float getScale() {
    return FloatMath.sqrt((float) Math.pow(getValue(mMatrix, Matrix.MSCALE_X), 2)
            + (float) Math.pow(getValue(mMatrix, Matrix.MSKEW_Y), 2));
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

public boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId,
        final int remoteTypedArrayIndex) {
    try {/*from   w ww  . j  a v a 2s .c om*/

        if (localAttrId == android.R.attr.background) {
            Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_android_background " + (keyboardBackground != null));
            super.setBackgroundDrawable(keyboardBackground);
        } else if (localAttrId == android.R.attr.paddingLeft) {
            padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingLeft " + padding[0]);
        } else if (localAttrId == android.R.attr.paddingTop) {
            padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingTop " + padding[1]);
        } else if (localAttrId == android.R.attr.paddingRight) {
            padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingRight " + padding[2]);
        } else if (localAttrId == android.R.attr.paddingBottom) {
            padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingBottom " + padding[3]);
        } else if (localAttrId == R.attr.keyBackground) {
            mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_keyBackground " + (mKeyBackground != null));
        } else if (localAttrId == R.attr.keyHysteresisDistance) {
            mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyHysteresisDistance " + mKeyHysteresisDistance);
        } else if (localAttrId == R.attr.verticalCorrection) {
            mVerticalCorrection = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_verticalCorrection " + mVerticalCorrection);
        } else if (localAttrId == R.attr.keyPreviewBackground) {
            mPreviewKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewBackground " + (mPreviewKeyBackground != null));
        } else if (localAttrId == R.attr.keyPreviewTextColor) {
            mPreviewKeyTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewTextColor " + mPreviewKeyTextColor);
        } else if (localAttrId == R.attr.keyPreviewTextSize) {
            mPreviewKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewTextSize " + mPreviewKeyTextSize);
        } else if (localAttrId == R.attr.keyPreviewLabelTextSize) {
            mPreviewLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewLabelTextSize " + mPreviewLabelTextSize);
        } else if (localAttrId == R.attr.keyPreviewOffset) {
            mPreviewOffset = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewOffset " + mPreviewOffset);
        } else if (localAttrId == R.attr.keyTextSize) {
            mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 18);
            // you might ask yourself "why did Menny sqrt root the factor?"
            // I'll tell you; the factor is mostly for the height, not the
            // font size,
            // but I also factorize the font size because I want the text to
            // be a little like
            // the key size.
            // the whole factor maybe too much, so I ease that a bit.
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mKeyTextSize = mKeyTextSize
                        * FloatMath.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape());
            else
                mKeyTextSize = mKeyTextSize
                        * FloatMath.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait());
            Log.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize);
        } else if (localAttrId == R.attr.keyTextColor) {
            mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mKeyTextColor == null) {
                Log.d(TAG, "Creating an empty ColorStateList for mKeyTextColor");
                mKeyTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) });
            }
            Log.d(TAG, "AnySoftKeyboardTheme_keyTextColor " + mKeyTextColor);
        } else if (localAttrId == R.attr.labelTextSize) {
            mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 14);
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            Log.d(TAG, "AnySoftKeyboardTheme_labelTextSize " + mLabelTextSize);
        } else if (localAttrId == R.attr.keyboardNameTextSize) {
            mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 10);
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mKeyboardNameTextSize = mKeyboardNameTextSize
                        * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mKeyboardNameTextSize = mKeyboardNameTextSize
                        * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            Log.d(TAG, "AnySoftKeyboardTheme_keyboardNameTextSize " + mKeyboardNameTextSize);
        } else if (localAttrId == R.attr.keyboardNameTextColor) {
            mKeyboardNameTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mKeyboardNameTextColor == null) {
                Log.d(TAG, "Creating an empty ColorStateList for mKeyboardNameTextColor");
                mKeyboardNameTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFAAAAAA) });
            }
            Log.d(TAG, "AnySoftKeyboardTheme_keyboardNameTextColor " + mKeyboardNameTextColor);
        } else if (localAttrId == R.attr.shadowColor) {
            mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowColor " + mShadowColor);
        } else if (localAttrId == R.attr.shadowRadius) {
            mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowRadius " + mShadowRadius);
        } else if (localAttrId == R.attr.shadowOffsetX) {
            mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowOffsetX " + mShadowOffsetX);
        } else if (localAttrId == R.attr.shadowOffsetY) {
            mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowOffsetY " + mShadowOffsetY);
        } else if (localAttrId == R.attr.backgroundDimAmount) {
            mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, 0.5f);
            Log.d(TAG, "AnySoftKeyboardTheme_backgroundDimAmount " + mBackgroundDimAmount);
        } else if (localAttrId == R.attr.keyTextStyle) {
            int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0);
            switch (textStyle) {
            case 0:
                mKeyTextStyle = Typeface.DEFAULT;
                break;
            case 1:
                mKeyTextStyle = Typeface.DEFAULT_BOLD;
                break;
            case 2:
                mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC);
                break;
            default:
                mKeyTextStyle = Typeface.defaultFromStyle(textStyle);
                break;
            }
            Log.d(TAG, "AnySoftKeyboardTheme_keyTextStyle " + mKeyTextStyle);
        } else if (localAttrId == R.attr.symbolColorScheme) {
            mSymbolColorScheme = remoteTypedArray.getInt(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_symbolColorScheme " + mSymbolColorScheme);
        } else if (localAttrId == R.attr.keyHorizontalGap) {
            float themeHorizotalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setHorizontalKeyGap(themeHorizotalKeyGap);
            Log.d(TAG, "AnySoftKeyboardTheme_keyHorizontalGap " + themeHorizotalKeyGap);
        } else if (localAttrId == R.attr.keyVerticalGap) {
            float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap);
            Log.d(TAG, "AnySoftKeyboardTheme_keyVerticalGap " + themeVerticalRowGap);
        } else if (localAttrId == R.attr.keyNormalHeight) {
            float themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight);
            Log.d(TAG, "AnySoftKeyboardTheme_keyNormalHeight " + themeNormalKeyHeight);
        } else if (localAttrId == R.attr.keyLargeHeight) {
            float themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight);
            Log.d(TAG, "AnySoftKeyboardTheme_keyLargeHeight " + themeLargeKeyHeight);
        } else if (localAttrId == R.attr.keySmallHeight) {
            float themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight);
            Log.d(TAG, "AnySoftKeyboardTheme_keySmallHeight " + themeSmallKeyHeight);
        } else if (localAttrId == R.attr.hintTextSize) {
            mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_hintTextSize " + mHintTextSize);
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            Log.d(TAG, "AnySoftKeyboardTheme_hintTextSize with factor " + mHintTextSize);
        } else if (localAttrId == R.attr.hintTextColor) {
            mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mHintTextColor == null) {
                Log.d(TAG, "Creating an empty ColorStateList for mHintTextColor");
                mHintTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) });
            }
            Log.d(TAG, "AnySoftKeyboardTheme_hintTextColor " + mHintTextColor);
        } else if (localAttrId == R.attr.hintLabelVAlign) {
            mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM);
            Log.d(TAG, "AnySoftKeyboardTheme_hintLabelVAlign " + mHintLabelVAlign);
        } else if (localAttrId == R.attr.hintLabelAlign) {
            mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT);
            Log.d(TAG, "AnySoftKeyboardTheme_hintLabelAlign " + mHintLabelAlign);
        } else if (localAttrId == R.attr.hintOverflowLabel) {
            mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_hintOverflowLabel " + mHintOverflowLabel);
        }

        return true;
    } catch (Exception e) {
        // on API changes, so the incompatible themes wont crash me..
        e.printStackTrace();
        return false;
    }
}

From source file:org.medcare.Dicom.DicomActivity.java

/** Determine the space between the first two fingers */
private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
}

From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java

/**
 * Pythagoras distance between two points.
 *//*from w w  w . j av  a2  s .c  o m*/
private float distance(float x0, float x1, float y0, float y1) {
    float x = x0 - x1;
    float y = y0 - y1;
    return FloatMath.sqrt(x * x + y * y);
}

From source file:com.wb.launcher3.Page.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    mPointCount = ev.getPointerCount();//added by zxa 1018 for adjust brightness

    //Log.i("zwb", "zhangwuba ------ luancher dispatchTouchEvent");

    boolean enable = (Settings.Secure.getInt(mContext.getContentResolver(), "tyd_gesture_launcher", 1) == 1);
    boolean gesture = false;

    if (mPointCount == 2) {
        int x1 = (int) ev.getX(0);
        int y1 = (int) ev.getY(0);

        int x2 = (int) ev.getX(1);
        int y2 = (int) ev.getY(1);

        x1Down = x1;/*from   w w  w. j  av a  2s  . c o  m*/
        x2Down = x2;
        y1Down = y1;
        y2Down = y2;

        xyD = (int) FloatMath.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        //Log.i("zwb", "zhangwuba ------  xyD = " + xyD);
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        //Log.i("xyz", "ACTION_DOWN");
        tempX = 0;
        tempY = 0;
        mOldY = ev.getY();
        mOldX = ev.getX();

        // mMode = DRAG;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        mLastMultiDownDistance = getDistance(ev);
        //mMode = ZOOM;
        break;
    case MotionEvent.ACTION_UP:
        //added by zxa 1018 for multi touch panel  adjust screen light  start
        if (enable) {
            closebrightnessDialog();
        }
        //added by zxa 1018 for multi touch panel  adjust screen light  end
        //mMode = NONE;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        //added by zxa 1018 for multi touch panel  adjust screen light  start
        if (enable) {
            closebrightnessDialog();
        }
        //mMode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        int scrollLength = xyD - temp;
        temp = xyD;
        if (enable && Math.abs(scrollLength) < 5 && y1Down != (int) mOldY) {
            adjustBrightness(ev, mPointCount);
        }
        /* if (mMode == ZOOM) {
        double currentLength = getDistance(ev);
        float length = (float) (currentLength - mLastMultiDownDistance);
        if (length < SHOW_WORKSPACE_PREVIEW_THRESHOLD) {
            onMultiZoomIn(length);
        } else {
            onMultiZoomOut(length);
        }
         }*/
        break;
    }

    /*  if (mMode == ZOOM) {
    return true;
      }*/

    return super.dispatchTouchEvent(ev);
}