FileDocCategorySizeDatePackage
ImageGrid.javaAPI DocAndroid 1.5 API7643Wed May 06 22:42:42 BST 2009com.android.browser

ImageGrid

public class ImageGrid extends android.widget.GridView implements android.widget.AdapterView.OnItemClickListener, android.view.View.OnCreateContextMenuListener
This class implements a Grid layout of Views for the Tab picker.

Fields Summary
private Listener
mListener
private ImageAdapter
mAdapter
private boolean
mIsLive
private static final int
SPACING
public static final int
CANCEL
public static final int
NEW_TAB
Constructors Summary
public ImageGrid(android.content.Context context, boolean live, Listener l)
Constructor

param
context Context to use when inflating resources.
param
live TRUE if the view can accept touch or click
param
l Listener to respond to clicks etc.


                                          
           
        super(context);

        mIsLive = live;
        if (live) {
            setFocusable(true);
            setFocusableInTouchMode(true);
            setOnItemClickListener(this);
            setOnCreateContextMenuListener(this);
        }
        mListener = l;

        mAdapter = new ImageAdapter(context, this, live);
        setAdapter(mAdapter);

        setBackgroundColor(0xFF000000);

        setVerticalSpacing(SPACING);
        setHorizontalSpacing(SPACING);
        setNumColumns(2);
        setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        setSelector(android.R.drawable.gallery_thumb);
    
Methods Summary
public voidadd(TabControl.Tab t)
Called by BrowserActivity to add a new window to the tab picker. This does not happen dynamically, this only happens during view setup.

param
v Webview of the tab to add
param
name Web page title
param
url URL of the webpage

        mAdapter.add(t);
    
public voidclear()
Do some internal cleanup of the ImageGrid's adapter.

        mAdapter.clear();
    
public booleandispatchKeyEvent(android.view.KeyEvent event)

        // We always consume the BACK key even if mListener is null or the
        // ImageGrid is not "live." This prevents crashes during tab animations
        // if the user presses BACK.
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                (event.getKeyCode() == KeyEvent.KEYCODE_BACK)) {
            if (mListener != null && mIsLive) {
                mListener.onClick(CANCEL);
                invalidate();
            }
            return true;
        }
        return super.dispatchKeyEvent(event);
    
public intgetContextMenuPosition(android.view.MenuItem menu)

        AdapterView.AdapterContextMenuInfo info =
                (AdapterView.AdapterContextMenuInfo) menu.getMenuInfo();
        int pos = info.position;
        if (!mAdapter.maxedOut()) {
            pos--;
        }
        return pos;
    
public com.android.browser.ImageGrid$ListenergetListener()

        return mListener;
    
public booleanisLive()
Return true if the ImageGrid is live. This means that tabs can be chosen and the menu can be invoked.

        return mIsLive;
    
public voidonCreateContextMenu(android.view.ContextMenu menu, android.view.View v, android.view.ContextMenu.ContextMenuInfo menuInfo)

        // Do not create the context menu if there is no listener or the Tab
        // overview is not "live."
        if (mListener == null || !mIsLive) {
            return;
        }
        AdapterView.AdapterContextMenuInfo info = 
                (AdapterView.AdapterContextMenuInfo) menuInfo;
        boolean maxed = mAdapter.maxedOut();
        if (info.position > 0 || maxed) {
            MenuInflater inflater = new MenuInflater(mContext);
            inflater.inflate(R.menu.tabscontext, menu);
            int position = info.position;
            if (!maxed) {
                position--;
            }
            menu.setHeaderTitle(mAdapter.mItems.get(position).getTitle());
        }
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View v, int position, long id)

        if (!mAdapter.maxedOut()) {
            position--;
        }
        // Position will be -1 for the "New Tab" cell.
        if (mListener != null) {
            mListener.onClick(position);
        }
    
protected voidonSizeChanged(int w, int h, int oldw, int oldh)

        // Called when our orientation changes. Tell the adapter about the new
        // size. Compute the individual tab height by taking the grid height
        // and subtracting the SPACING. Then subtract the list padding twice
        // (once for each tab on screen) and divide the remaining height by 2.
        int tabHeight = (h - SPACING
                - 2 * (getListPaddingTop() + getListPaddingBottom())) / 2;
        mAdapter.heightChanged(tabHeight);
        super.onSizeChanged(w, h, oldw, oldh);
    
public voidremove(int index)
Called by BrowserActivity when a window has been removed from the tab list.

param
index Window to remove, from 0 to MAX_TABS-1

        if (Config.DEBUG && (index < 0 || index >= TabControl.MAX_TABS)) {
            throw new AssertionError();
        }
        mAdapter.remove(index);
    
public voidsetCurrentIndex(int startingIndex)
Request focus to initially set to a particular tab.

param
startingIndex This is a Tab index from 0 - MAX_TABS-1 and does not include the "New Tab" cell.

        if (!mAdapter.maxedOut()) {
            startingIndex++;
        }
        setSelection(startingIndex);
    
public voidsetListener(com.android.browser.ImageGrid$Listener l)

        mListener = l;