Java Code Examples for android.graphics.RectF#width()

The following examples show how to use android.graphics.RectF#width() . 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: CropOverlayView.java    From giffun with Apache License 2.0 6 votes vote down vote up
/**
 * Informs the CropOverlayView of the image's position relative to the ImageView. This is
 * necessary to call in order to draw the crop window.
 *
 * @param boundsPoints the image's bounding points
 * @param viewWidth The bounding image view width.
 * @param viewHeight The bounding image view height.
 */
public void setBounds(float[] boundsPoints, int viewWidth, int viewHeight) {
  if (boundsPoints == null || !Arrays.equals(mBoundsPoints, boundsPoints)) {
    if (boundsPoints == null) {
      Arrays.fill(mBoundsPoints, 0);
    } else {
      System.arraycopy(boundsPoints, 0, mBoundsPoints, 0, boundsPoints.length);
    }
    mViewWidth = viewWidth;
    mViewHeight = viewHeight;
    RectF cropRect = mCropWindowHandler.getRect();
    if (cropRect.width() == 0 || cropRect.height() == 0) {
      initCropWindow();
    }
  }
}
 
Example 2
Source File: ColorPickerView.java    From Atomic with GNU General Public License v3.0 6 votes vote down vote up
private int pointToAlpha(int x){
	
	final RectF rect = mAlphaRect;
	final int width = (int) rect.width();
	
	if(x < rect.left){
		x = 0;
	}
	else if(x > rect.right){
		x = width;
	}
	else{
		x = x - (int)rect.left;
	}
	
	return 0xff - (x * 0xff / width);
	
}
 
Example 3
Source File: CropOverlayView.java    From timecat with Apache License 2.0 6 votes vote down vote up
/**
 * Informs the CropOverlayView of the image's position relative to the
 * ImageView. This is necessary to call in order to draw the crop window.
 *
 * @param boundsPoints the image's bounding points
 * @param viewWidth    The bounding image view width.
 * @param viewHeight   The bounding image view height.
 */
public void setBounds(float[] boundsPoints, int viewWidth, int viewHeight) {
    if (boundsPoints == null || !Arrays.equals(mBoundsPoints, boundsPoints)) {
        if (boundsPoints == null) {
            Arrays.fill(mBoundsPoints, 0);
        } else {
            System.arraycopy(boundsPoints, 0, mBoundsPoints, 0, boundsPoints.length);
        }
        mViewWidth = viewWidth;
        mViewHeight = viewHeight;
        RectF cropRect = mCropWindowHandler.getRect();
        if (cropRect.width() == 0 || cropRect.height() == 0) {
            initCropWindow();
        }
    }
}
 
Example 4
Source File: ClipImageView.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
private void checkBorder() {
    RectF rect = getMatrixRectF();
    float deltaX = 0;
    float deltaY = 0;

    if (rect.width() >= mClipBorder.width()) {
        if (rect.left > mClipBorder.left) {
            deltaX = -rect.left + mClipBorder.left;
        }

        if (rect.right < mClipBorder.right) {
            deltaX = mClipBorder.right - rect.right;
        }
    }

    if (rect.height() >= mClipBorder.height()) {
        if (rect.top > mClipBorder.top) {
            deltaY = -rect.top + mClipBorder.top;
        }

        if (rect.bottom < mClipBorder.bottom) {
            deltaY = mClipBorder.bottom - rect.bottom;
        }
    }

    mScaleMatrix.postTranslate(deltaX, deltaY);
}
 
Example 5
Source File: BitmapManager.java    From XImageView with Apache License 2.0 5 votes vote down vote up
private RectF toViewCoordinate(RectF rect)
{
    if (rect == null) {
        return new RectF();
    }

    float left = rect.left - mViewBitmapRect.left;
    float right = left + rect.width();
    float top = rect.top - mViewBitmapRect.top;
    float bottom = top + rect.height();

    return new RectF(left, top, right, bottom);
}
 
Example 6
Source File: PhotoViewAttacher.java    From Matisse-Kotlin with Apache License 2.0 5 votes vote down vote up
public void fling(int viewWidth, int viewHeight, int velocityX,
                  int velocityY) {
    final RectF rect = getDisplayRect();
    if (rect == null) {
        return;
    }
    final int startX = Math.round(-rect.left);
    final int minX, maxX, minY, maxY;
    if (viewWidth < rect.width()) {
        minX = 0;
        maxX = Math.round(rect.width() - viewWidth);
    } else {
        minX = maxX = startX;
    }
    final int startY = Math.round(-rect.top);
    if (viewHeight < rect.height()) {
        minY = 0;
        maxY = Math.round(rect.height() - viewHeight);
    } else {
        minY = maxY = startY;
    }
    mCurrentX = startX;
    mCurrentY = startY;
    // If we actually can move, fling the scroller
    if (startX != maxX || startY != maxY) {
        mScroller.fling(startX, startY, velocityX, velocityY, minX,
                maxX, minY, maxY, 0, 0);
    }
}
 
Example 7
Source File: OC_Segblend3.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public List layOutComponents(List<OBPhoneme> comps,OBLabel mLabel,OBFont font)
{
    List<Float> rights = new ArrayList<>();
    String text = mLabel.text();
    int cumlength = 0;
    for(int i = 0;i < comps.size();i++)
    {
        cumlength += comps.get(i).text.length();
        String subtx = text.substring(0,cumlength);
        RectF r = boundingBoxForText(subtx,font);
        float f = r.width();
        rights.add(f);
    }
    List labs = new ArrayList<>();
    int idx = 0,i = 0;
    List syllableLefts = new ArrayList<>();
    for(OBPhoneme phoneme : comps)
    {
        OBLabel l = new OBLabel(phoneme.text,font);
        l.setColour(Color.BLACK);
        l.setPosition(mLabel.position());
        if (i == 0)
            syllableLefts.add(0f);
        else
            syllableLefts.add(rights.get(i-1));
        l.setRight(mLabel.left() + rights.get(i));
        l.setProperty("origpos",new PointF(l.position().x,l.position().y));
        labs.add(l);
        attachControl(l);
        i++;
    }
    leftOffsets = syllableLefts;
    return labs;
}
 
Example 8
Source File: DefaultOnDoubleTapListener.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    if (this.photoViewAttacher == null)
        return false;

    ImageView imageView = photoViewAttacher.getImageView();

    if (null != photoViewAttacher.getOnPhotoTapListener()) {
        final RectF displayRect = photoViewAttacher.getDisplayRect();

        if (null != displayRect) {
            final float x = e.getX(), y = e.getY();

            // Check to see if the user tapped on the photo
            if (displayRect.contains(x, y)) {

                float xResult = (x - displayRect.left)
                        / displayRect.width();
                float yResult = (y - displayRect.top)
                        / displayRect.height();

                photoViewAttacher.getOnPhotoTapListener().onPhotoTap(imageView, xResult, yResult);
                return true;
            }
        }
    }
    if (null != photoViewAttacher.getOnViewTapListener()) {
        photoViewAttacher.getOnViewTapListener().onViewTap(imageView, e.getX(), e.getY());
    }

    return false;
}
 
Example 9
Source File: SparkView.java    From spark with Apache License 2.0 5 votes vote down vote up
public ScaleHelper(SparkAdapter adapter, RectF contentRect, float lineWidth, boolean fill) {
    final float leftPadding = contentRect.left;
    final float topPadding = contentRect.top;

    // subtract lineWidth to offset for 1/2 of the line bleeding out of the content box on
    // either side of the view
    final float lineWidthOffset = fill ? 0 : lineWidth;
    this.width = contentRect.width() - lineWidthOffset;
    this.height = contentRect.height() - lineWidthOffset;

    this.size = adapter.getCount();

    // get data bounds from adapter
    RectF bounds = adapter.getDataBounds();

    // if data is a line (which technically has no size), expand bounds to center the data
    bounds.inset(bounds.width() == 0 ? -1 : 0, bounds.height() == 0 ? -1 : 0);

    final float minX = bounds.left;
    final float maxX = bounds.right;
    final float minY = bounds.top;
    final float maxY = bounds.bottom;

    // xScale will compress or expand the min and max x values to be just inside the view
    this.xScale = width / (maxX - minX);
    // xTranslation will move the x points back between 0 - width
    this.xTranslation = leftPadding - (minX * xScale) + (lineWidthOffset / 2);
    // yScale will compress or expand the min and max y values to be just inside the view
    this.yScale = height / (maxY - minY);
    // yTranslation will move the y points back between 0 - height
    this.yTranslation = minY * yScale + topPadding + (lineWidthOffset / 2);
}
 
Example 10
Source File: CropImageView.java    From Android-CropView with Apache License 2.0 5 votes vote down vote up
private RectF calcFrameRect(RectF imageRect) {
    float frameW = getRatioX(imageRect.width());
    float frameH = getRatioY(imageRect.height());
    float imgRatio = imageRect.width() / imageRect.height();
    float frameRatio = frameW / frameH;
    float l = imageRect.left, t = imageRect.top, r = imageRect.right, b = imageRect.bottom;
    if (frameRatio >= imgRatio) {
        l = imageRect.left;
        r = imageRect.right;
        float hy = (imageRect.top + imageRect.bottom) * 0.5f;
        float hh = (imageRect.width() / frameRatio) * 0.5f;
        t = hy - hh;
        b = hy + hh;
    } else if (frameRatio < imgRatio) {
        t = imageRect.top;
        b = imageRect.bottom;
        float hx = (imageRect.left + imageRect.right) * 0.5f;
        float hw = imageRect.height() * frameRatio * 0.5f;
        l = hx - hw;
        r = hx + hw;
    }
    float w = r - l;
    float h = b - t;
    float cx = l + w / 2;
    float cy = t + h / 2;
    float sw = w * mInitialFrameScale;
    float sh = h * mInitialFrameScale;
    return new RectF(cx - sw / 2, cy - sh / 2, cx + sw / 2, cy + sh / 2);
}
 
Example 11
Source File: PhotoViewAttacher.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
public void fling(int viewWidth, int viewHeight, int velocityX, int velocityY) {
	final RectF rect = getDisplayRect();
	if (null == rect) {
		return;
	}

	final int startX = Math.round(-rect.left);
	final int minX, maxX, minY, maxY;

	if (viewWidth < rect.width()) {
		minX = 0;
		maxX = Math.round(rect.width() - viewWidth);
	} else {
		minX = maxX = startX;
	}

	final int startY = Math.round(-rect.top);
	if (viewHeight < rect.height()) {
		minY = 0;
		maxY = Math.round(rect.height() - viewHeight);
	} else {
		minY = maxY = startY;
	}

	mCurrentX = startX;
	mCurrentY = startY;

	if (DEBUG) {
		Log.d(LOG_TAG, "fling. StartX:" + startX + " StartY:" + startY + " MaxX:" + maxX + " MaxY:" + maxY);
	}

	// If we actually can move, fling the scroller
	if (startX != maxX || startY != maxY) {
		mScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY, 0, 0);
	}
}
 
Example 12
Source File: DefaultOnDoubleTapListener.java    From ZoomPreviewPicture with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    if (this.photoViewAttacher == null)
        return false;

    ImageView imageView = photoViewAttacher.getImageView();

    if (null != photoViewAttacher.getOnPhotoTapListener()) {
        final RectF displayRect = photoViewAttacher.getDisplayRect();

        if (null != displayRect) {
            final float x = e.getX(), y = e.getY();

            // Check to see if the user tapped on the photo
            if (displayRect.contains(x, y)) {

                float xResult = (x - displayRect.left)
                        / displayRect.width();
                float yResult = (y - displayRect.top)
                        / displayRect.height();

                photoViewAttacher.getOnPhotoTapListener().onPhotoTap(imageView, xResult, yResult);
                return true;
            }else{
                photoViewAttacher.getOnPhotoTapListener().onOutsidePhotoTap();
            }
        }
    }
    if (null != photoViewAttacher.getOnViewTapListener()) {
        photoViewAttacher.getOnViewTapListener().onViewTap(imageView, e.getX(), e.getY());
    }

    return false;
}
 
Example 13
Source File: GridTextMarker.java    From InteractiveChart with Apache License 2.0 5 votes vote down vote up
@Override public void onMarkerViewMeasure(RectF viewRect, Matrix matrix, float highlightPointX,
    float highlightPointY, String[] markerText, @Size(min = 4) @NonNull float[] markerViewInfo) {
  if (viewRect.top > highlightPointY || highlightPointY > viewRect.bottom) {
    return;
  }
  markerTextPaint.getTextBounds(markerText[1], 0, markerText[1].length(), textRect);
  width = Math.max(width,
      textRect.width() + (attribute.markerBorderLRPadding - attribute.markerBorderWidth) * 2);
  height = Math.max(height,
      textRect.height() + (attribute.markerBorderTBPadding - attribute.markerBorderWidth) * 2);
  highlightPointY = highlightPointY - height / 2;
  if (highlightPointY < viewRect.top) {
    highlightPointY = viewRect.top + inset;
  }
  if (highlightPointY > viewRect.bottom - height) {
    highlightPointY = viewRect.bottom - height - inset;
  }

  if (yMarkerAlign == GridMarkerAlign.LEFT) {
    markerInsets.left = viewRect.left + inset;
  } else if (yMarkerAlign == GridMarkerAlign.RIGHT) {
    markerInsets.left = viewRect.right - width - inset;
  } else if (highlightPointX > viewRect.left + viewRect.width() / 2) {
    markerInsets.left = viewRect.right - width - inset;
  } else {
    markerInsets.left = viewRect.left + inset;
  }

  markerInsets.top = highlightPointY;
  markerInsets.right = markerInsets.left + width;
  markerInsets.bottom = markerInsets.top + height;

  markerViewInfo[0] = markerInsets.left - inset;
  markerViewInfo[2] = markerInsets.right + inset;
}
 
Example 14
Source File: PhotoViewAttacher.java    From ZoomPreviewPicture with Apache License 2.0 4 votes vote down vote up
public void fling(int viewWidth, int viewHeight, int velocityX,
                  int velocityY) {
    final RectF rect = getDisplayRect();
    if (null == rect) {
        return;
    }

    final int startX = Math.round(-rect.left);
    final int minX, maxX, minY, maxY;

    if (viewWidth < rect.width()) {
        minX = 0;
        maxX = Math.round(rect.width() - viewWidth);
    } else {
        minX = maxX = startX;
    }

    final int startY = Math.round(-rect.top);
    if (viewHeight < rect.height()) {
        minY = 0;
        maxY = Math.round(rect.height() - viewHeight);
    } else {
        minY = maxY = startY;
    }

    mCurrentX = startX;
    mCurrentY = startY;

    if (DEBUG) {
        LogManager.getLogger().d(
                LOG_TAG,
                "fling. StartX:" + startX + " StartY:" + startY
                        + " MaxX:" + maxX + " MaxY:" + maxY);
    }

    // If we actually can move, fling the scroller
    if (startX != maxX || startY != maxY) {
        mScroller.fling(startX, startY, velocityX, velocityY, minX,
                maxX, minY, maxY, 0, 0);
    }
}
 
Example 15
Source File: SvgBrush.java    From Svg-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
public void setupPaint(Paint paint, RectF box, float scale, float opacity) {
  float height = box.height();
  float width = box.width();
  float midX = box.centerX();
  float midY = box.centerY();
  float offsetX = (midX - width / 2);
  float offsetY = (midY - height / 2);

  int[] stopsColors = mStopColors;
  float[] stops = mStops;
  //parseGradientStops(mColors, stopsCount, stops, stopsColors, opacity);

  if (mType == GradientType.LINEAR_GRADIENT) {
    float x1 = ParserHelper.fromPercentageToFloat(mPoints.get(0), width, offsetX, scale);
    float y1 = ParserHelper.fromPercentageToFloat(mPoints.get(1), height, offsetY, scale);
    float x2 = ParserHelper.fromPercentageToFloat(mPoints.get(2), width, offsetX, scale);
    float y2 = ParserHelper.fromPercentageToFloat(mPoints.get(3), height, offsetY, scale);
    paint.setShader(
        new LinearGradient(
            x1,
            y1,
            x2,
            y2,
            stopsColors,
            stops,
            Shader.TileMode.CLAMP));
  } else {
    float rx = ParserHelper.fromPercentageToFloat(mPoints.get(2), width, 0f, scale);
    float ry = ParserHelper.fromPercentageToFloat(mPoints.get(3), height, 0f, scale);

    float cx = ParserHelper.fromPercentageToFloat(mPoints.get(4), width, offsetX, scale);
    float cy = ParserHelper.fromPercentageToFloat(mPoints.get(5), height, offsetY, scale) / (ry / rx);
    // TODO: support focus point.
    float fx = ParserHelper.fromPercentageToFloat(mPoints.get(0), width, offsetX, scale);
    float fy = ParserHelper.fromPercentageToFloat(mPoints.get(1), height, offsetY, scale) / (ry / rx);
    Shader radialGradient = new RadialGradient(
        cx,
        cy,
        rx,
        stopsColors,
        stops,
        Shader.TileMode.CLAMP
    );

    Matrix radialMatrix = new Matrix();
    radialMatrix.preScale(1f, ry / rx);
    radialGradient.setLocalMatrix(radialMatrix);
    paint.setShader(radialGradient);
  }
}
 
Example 16
Source File: ImageViewTouchBase.java    From YiBo with Apache License 2.0 4 votes vote down vote up
public void center(boolean horizontal, boolean vertical) {
    if (mBitmapDisplayed == null) {
        return;
    }

    Matrix m = getImageViewMatrix();

    RectF rect = new RectF(0, 0,
            mBitmapDisplayed.getWidth(),
            mBitmapDisplayed.getHeight());

    m.mapRect(rect);

    float height = rect.height();
    float width  = rect.width();

    float deltaX = 0, deltaY = 0;

    if (vertical) {
        int viewHeight = getHeight();
        if (height < viewHeight) {
            deltaY = (viewHeight - height) / 2 - rect.top;
        } else if (rect.top > 0) {
            deltaY = -rect.top;
        } else if (rect.bottom < viewHeight) {
            deltaY = getHeight() - rect.bottom;
        }
    }

    if (horizontal) {
        int viewWidth = getWidth();
        if (width < viewWidth) {
            deltaX = (viewWidth - width) / 2 - rect.left;
        } else if (rect.left > 0) {
            deltaX = -rect.left;
        } else if (rect.right < viewWidth) {
            deltaX = viewWidth - rect.right;
        }
    }

    postTranslate(deltaX, deltaY);
    setImageMatrix(getImageViewMatrix());
}
 
Example 17
Source File: KenBurnsView.java    From RxAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    Drawable d = getDrawable();
    if (!mPaused && d != null) {
        if (mDrawableRect.isEmpty()) {
            updateDrawableBounds();
        } else if (hasBounds()) {
            if (mCurrentTrans == null) { // Starting the first transition.
                startNewTransition();
            }

            if (mCurrentTrans.getDestinyRect() != null) { // If null, it's supposed to stop.
                mElapsedTime += System.currentTimeMillis() - mLastFrameTime;
                RectF currentRect = mCurrentTrans.getInterpolatedRect(mElapsedTime);

                float widthScale = mDrawableRect.width() / currentRect.width();
                float heightScale = mDrawableRect.height() / currentRect.height();
                // Scale to make the current rect match the smallest drawable dimension.
                float currRectToDrwScale = Math.min(widthScale, heightScale);
                // Scale to make the current rect match the viewport bounds.
                float currRectToVpScale = mViewportRect.width() / currentRect.width();
                // Combines the two scales to fill the viewport with the current rect.
                float totalScale = currRectToDrwScale * currRectToVpScale;

                float translX = totalScale * (mDrawableRect.centerX() - currentRect.left);
                float translY = totalScale * (mDrawableRect.centerY() - currentRect.top);

                /* Performs matrix transformations to fit the content
                   of the current rect into the entire view. */
                mMatrix.reset();
                mMatrix.postTranslate(-mDrawableRect.width() / 2, -mDrawableRect.height() / 2);
                mMatrix.postScale(totalScale, totalScale);
                mMatrix.postTranslate(translX, translY);

                setImageMatrix(mMatrix);

                // Current transition is over. It's time to start a new one.
                if (mElapsedTime >= mCurrentTrans.getDuration()) {
                    fireTransitionEnd(mCurrentTrans);
                    startNewTransition();
                }
            } else { // Stopping? A stop event has to be fired.
                fireTransitionEnd(mCurrentTrans);
            }
        }
        mLastFrameTime = System.currentTimeMillis();
        postInvalidateDelayed(FRAME_DELAY);
    }
    super.onDraw(canvas);
}
 
Example 18
Source File: PhotoViewAttacher.java    From jmessage-android-uikit with MIT License 4 votes vote down vote up
public final boolean onSingleTapConfirmed(MotionEvent e) {
//        Activity activity = (Activity) mContext;
//        if(mFromChatActivity){
//            activity.finish();
//        }else {
//            RelativeLayout titleRl = (RelativeLayout) activity.findViewById(R.id.title_bar_rl);
//            RelativeLayout checkBoxRl = (RelativeLayout) activity.findViewById(R.id.check_box_rl);
//            WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
//            //如果标题栏,菜单栏可见,单击后隐藏并设置全屏模式
//            if(mTitleBarVisible){
//                attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//                activity.getWindow().setAttributes(attrs);
//                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//                titleRl.setVisibility(View.GONE);
//                checkBoxRl.setVisibility(View.GONE);
//                mTitleBarVisible = false;
//                //否则显示标题栏、菜单栏,并取消全屏
//            }else {
//                attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
//                activity.getWindow().setAttributes(attrs);
//                activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//                titleRl.setVisibility(View.VISIBLE);
//                checkBoxRl.setVisibility(View.VISIBLE);
//                mTitleBarVisible = true;
//            }
//        }

        ImageView imageView = getImageView();
		if (null != imageView) {
			if (null != mPhotoTapListener) {
				final RectF displayRect = getDisplayRect();

				if (null != displayRect) {
					final float x = e.getX(), y = e.getY();

					// Check to see if the user tapped on the photo
					if (displayRect.contains(x, y)) {

						float xResult = (x - displayRect.left) / displayRect.width();
						float yResult = (y - displayRect.top) / displayRect.height();

						mPhotoTapListener.onPhotoTap(imageView, xResult, yResult);
						return true;
					}
				}
			}
			if (null != mViewTapListener) {
				mViewTapListener.onViewTap(imageView, e.getX(), e.getY());
			}
		}

		return false;
	}
 
Example 19
Source File: OC_Spell2.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
public void demob()throws Exception
{
    setStatus(STATUS_DOING_DEMO);
    RectF botrect = objectDict.get("bottomrect") .frame();
    PointF destpt = new PointF(rightMostLabelX()  + botrect.width() / 2,botrect.centerY());
    PointF startpt = pointForDestPoint(destpt,45);
    loadPointerStartPoint(startpt,destpt);
    movePointerToPoint(destpt,-1,true);
    waitForSecs(0.3f);
    playAudioQueuedScene("DEMO",true);
    waitForSecs(0.4f);

    for(OBLabel sl : staticLabels)
    {
        String tx = sl.text();
        OBLabel targetlab = candidateLabelWithText(tx);
        movePointerToPoint(OB_Maths.locationForRect(0.5f, 0.7f, targetlab.frame()),-1,true);
        waitForSecs(0.2f);
        moveObjects(Arrays.asList(targetlab,thePointer),sl.position(),-0.7f,OBAnim.ANIM_EASE_IN_EASE_OUT);
        targetlab.setProperty("staticLabelIndex",letterIdx);
        playSfxAudio("letterin",false);
        dashes.get(letterIdx).hide();
        movePointerForwards(applyGraphicScale(-100),-1);
        waitSFX();
        waitForSecs(0.2f);
        if(letterAudio != OCSP_LETTER_AUDIO_NONE)
        {
            int col = targetlab.colour();
            targetlab.setColour(Color.RED);
            playLetterAudio(sl.text() );
            waitForSecs(0.2f);
            waitAudio();
            targetlab.setColour(col);
            waitForSecs(0.2f);
        }

        highlightDash(++letterIdx);
        waitForSecs(0.4f);
    }

    blendWord();
    waitForSecs(0.3f);
    speakWord(currWordID);
    waitForSecs(0.3f);
    thePointer.hide();
    waitForSecs(0.3f);
    flyWordToBottom();
    showDashes();
    waitForSecs(0.3f);
    letterIdx = 0;
    highlightMarker();
    waitForSecs(0.4f);

    playAudioQueuedScene("DEMO2",true);
    waitForSecs(0.2f);

    if(RADemo)
    {
        buttonDemo();
    }
    nextScene();
}
 
Example 20
Source File: KenBurnsView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    Drawable d = getDrawable();
    if (!mPaused && d != null) {
        if (mDrawableRect.isEmpty()) {
            updateDrawableBounds();
        } else if (!mViewportRect.isEmpty()) {
            if (mCurrentTrans == null) { // Starting the first transition.
                startNewTransition();
            }

            if (mCurrentTrans.getDestinyRect() != null) { // If null, it's supposed to stop.
                mElapsedTime += System.currentTimeMillis() - mLastFrameTime;
                RectF currentRect = mCurrentTrans.getInterpolatedRect(mElapsedTime);

                float widthScale = mDrawableRect.width() / currentRect.width();
                float heightScale = mDrawableRect.height() / currentRect.height();
                // Scale to make the current rect match the smallest drawable dimension.
                float currRectToDrwScale = Math.min(widthScale, heightScale);
                // Scale to make the current rect match the viewport bounds.
                float currRectToVpScale = mViewportRect.width() / currentRect.width();
                // Combines the two scales to fill the viewport with the current rect.
                float totalScale = currRectToDrwScale * currRectToVpScale;

                float translX = totalScale * (mDrawableRect.centerX() - currentRect.left);
                float translY = totalScale * (mDrawableRect.centerY() - currentRect.top);

                /* Performs matrix transformations to fit the content
                   of the current rect into the entire view. */
                mMatrix.reset();
                mMatrix.postTranslate(-mDrawableRect.width() / 2, -mDrawableRect.height() / 2);
                mMatrix.postScale(totalScale, totalScale);
                mMatrix.postTranslate(translX, translY);

                setImageMatrix(mMatrix);

                // Current transition is over. It's time to start a new one.
                if (mElapsedTime >= mCurrentTrans.getDuration()) {
                    fireTransitionEnd(mCurrentTrans);
                    startNewTransition();
                }
            } else { // Stopping? A stop event has to be fired.
                fireTransitionEnd(mCurrentTrans);
            }
        }
        mLastFrameTime = System.currentTimeMillis();
        postInvalidateDelayed(FRAME_DELAY);
    }
    super.onDraw(canvas);
}