FileDocCategorySizeDatePackage
TiledImageView.javaAPI DocAndroid 5.1 API12291Thu Mar 12 22:22:42 GMT 2015com.android.photos.views

TiledImageView

public class TiledImageView extends android.widget.FrameLayout
Shows an image using {@link TiledImageRenderer} using either {@link GLSurfaceView} or {@link BlockingGLTextureView}.

Fields Summary
private static final boolean
USE_TEXTURE_VIEW
private static final boolean
IS_SUPPORTED
private static final boolean
USE_CHOREOGRAPHER
private BlockingGLTextureView
mTextureView
private android.opengl.GLSurfaceView
mGLSurfaceView
private boolean
mInvalPending
private android.view.Choreographer.FrameCallback
mFrameCallback
private float[]
mValues
protected Object
mLock
protected ImageRendererWrapper
mRenderer
private Runnable
mFreeTextures
private android.graphics.RectF
mTempRectF
Constructors Summary
public TiledImageView(android.content.Context context)

        this(context, null);
    
public TiledImageView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
        if (!IS_SUPPORTED) {
            return;
        }

        mRenderer = new ImageRendererWrapper();
        mRenderer.image = new TiledImageRenderer(this);
        View view;
        if (USE_TEXTURE_VIEW) {
            mTextureView = new BlockingGLTextureView(context);
            mTextureView.setRenderer(new TileRenderer());
            view = mTextureView;
        } else {
            mGLSurfaceView = new GLSurfaceView(context);
            mGLSurfaceView.setEGLContextClientVersion(2);
            mGLSurfaceView.setRenderer(new TileRenderer());
            mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
            view = mGLSurfaceView;
        }
        addView(view, new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        //setTileSource(new ColoredTiles());
    
Methods Summary
public voiddestroy()

        if (!IS_SUPPORTED) {
            return;
        }
        if (USE_TEXTURE_VIEW) {
            mTextureView.destroy();
        } else {
            mGLSurfaceView.queueEvent(mFreeTextures);
        }
    
protected voiddispatchDraw(android.graphics.Canvas canvas)

        if (!IS_SUPPORTED) {
            return;
        }
        if (USE_TEXTURE_VIEW) {
            mTextureView.render();
        }
        super.dispatchDraw(canvas);
    
private voidinvalOnVsync()

        if (!mInvalPending) {
            mInvalPending = true;
            if (mFrameCallback == null) {
                mFrameCallback = new FrameCallback() {
                    @Override
                    public void doFrame(long frameTimeNanos) {
                        mInvalPending = false;
                        mGLSurfaceView.requestRender();
                    }
                };
            }
            Choreographer.getInstance().postFrameCallback(mFrameCallback);
        }
    
public voidinvalidate()

        if (!IS_SUPPORTED) {
            return;
        }
        if (USE_TEXTURE_VIEW) {
            super.invalidate();
            mTextureView.invalidate();
        } else {
            if (USE_CHOREOGRAPHER) {
                invalOnVsync();
            } else {
                mGLSurfaceView.requestRender();
            }
        }
    
public static booleanisTilingSupported()


        
        return IS_SUPPORTED;
    
protected voidonLayout(boolean changed, int left, int top, int right, int bottom)

        super.onLayout(changed, left, top, right, bottom);
        if (!IS_SUPPORTED) {
            return;
        }
        synchronized (mLock) {
            updateScaleIfNecessaryLocked(mRenderer);
        }
    
public voidonPause()


       
        if (!IS_SUPPORTED) {
            return;
        }
        if (!USE_TEXTURE_VIEW) {
            mGLSurfaceView.onPause();
        }
    
public voidonResume()

        if (!IS_SUPPORTED) {
            return;
        }
        if (!USE_TEXTURE_VIEW) {
            mGLSurfaceView.onResume();
        }
    
public voidpositionFromMatrix(android.graphics.Matrix matrix)

        
        if (!IS_SUPPORTED) {
            return;
        }
        if (mRenderer.source != null) {
            final int rotation = mRenderer.source.getRotation();
            final boolean swap = !(rotation % 180 == 0);
            final int width = swap ? mRenderer.source.getImageHeight()
                    : mRenderer.source.getImageWidth();
            final int height = swap ? mRenderer.source.getImageWidth()
                    : mRenderer.source.getImageHeight();
            mTempRectF.set(0, 0, width, height);
            matrix.mapRect(mTempRectF);
            matrix.getValues(mValues);
            int cx = width / 2;
            int cy = height / 2;
            float scale = mValues[Matrix.MSCALE_X];
            int xoffset = Math.round((getWidth() - mTempRectF.width()) / 2 / scale);
            int yoffset = Math.round((getHeight() - mTempRectF.height()) / 2 / scale);
            if (rotation == 90 || rotation == 180) {
                cx += (mTempRectF.left / scale) - xoffset;
            } else {
                cx -= (mTempRectF.left / scale) - xoffset;
            }
            if (rotation == 180 || rotation == 270) {
                cy += (mTempRectF.top / scale) - yoffset;
            } else {
                cy -= (mTempRectF.top / scale) - yoffset;
            }
            mRenderer.scale = scale;
            mRenderer.centerX = swap ? cy : cx;
            mRenderer.centerY = swap ? cx : cy;
            invalidate();
        }
    
public voidsetTileSource(com.android.photos.views.TiledImageRenderer.TileSource source, java.lang.Runnable isReadyCallback)

        if (!IS_SUPPORTED) {
            return;
        }
        synchronized (mLock) {
            mRenderer.source = source;
            mRenderer.isReadyCallback = isReadyCallback;
            mRenderer.centerX = source != null ? source.getImageWidth() / 2 : 0;
            mRenderer.centerY = source != null ? source.getImageHeight() / 2 : 0;
            mRenderer.rotation = source != null ? source.getRotation() : 0;
            mRenderer.scale = 0;
            updateScaleIfNecessaryLocked(mRenderer);
        }
        invalidate();
    
public voidsetTranslationX(float translationX)

        if (!IS_SUPPORTED) {
            return;
        }
        super.setTranslationX(translationX);
    
private voidupdateScaleIfNecessaryLocked(com.android.photos.views.TiledImageView$ImageRendererWrapper renderer)

        if (renderer == null || renderer.source == null
                || renderer.scale > 0 || getWidth() == 0) {
            return;
        }
        renderer.scale = Math.min(
                (float) getWidth() / (float) renderer.source.getImageWidth(),
                (float) getHeight() / (float) renderer.source.getImageHeight());