FileDocCategorySizeDatePackage
FakeWebView.javaAPI DocAndroid 1.5 API3690Wed May 06 22:42:42 BST 2009com.android.browser

FakeWebView

public class FakeWebView extends android.widget.ImageView
This class is used by ImageAdapter to draw a representation of each tab. It overrides ImageView so it can be used for the new tab image as well.

Fields Summary
private TabControl.Tab
mTab
private android.graphics.Picture
mPicture
private boolean
mUsesResource
Constructors Summary
public FakeWebView(android.content.Context context)

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

        this(context, attrs, 0);
    
public FakeWebView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
    
Methods Summary
protected voidonDraw(android.graphics.Canvas canvas)

        if (mUsesResource) {
            super.onDraw(canvas);
        } else {
            // Always draw white behind the picture just in case the picture
            // draws nothing.
            // FIXME: We used to draw white only when the WebView was null but
            // sometimes the picture was empty. So now we always draw white. It
            // would be nice to know if the picture is empty so we can avoid
            // drawing white.
            canvas.drawColor(Color.WHITE);
            if (mTab != null) {
                final WebView w = mTab.getTopWindow();
                if (w != null) {
                    if (mPicture != null) {
                        canvas.save();
                        float scale = getWidth() * w.getScale() / w.getWidth();
                        canvas.scale(scale, scale);
                        canvas.translate(-w.getScrollX(), -w.getScrollY());
                        canvas.drawPicture(mPicture);
                        canvas.restore();
                    }
                }
            }
        }
    
public voidsetImageResource(int resId)

        mUsesResource = true;
        mTab = null;
        super.setImageResource(resId);
    
public voidsetTab(TabControl.Tab t)
Set a WebView for this FakeWebView to represent.

param
v WebView whose picture and other data will be used in onDraw.

        mUsesResource = false;
        mTab = t;
        if (t != null && t.getWebView() != null) {
            Listener l = new Listener();
            if (t.getSubWebView() != null) {
                t.getSubWebView().setPictureListener(l);
            } else {
                t.getWebView().setPictureListener(l);
            }
            mPicture = mTab.getTopWindow().capturePicture();
        }