FileDocCategorySizeDatePackage
ImageAdapter.javaAPI DocAndroid 1.5 API8128Wed May 06 22:42:42 BST 2009com.android.browser

ImageAdapter

public class ImageAdapter extends Object implements android.widget.ListAdapter
Adapter used by ImageGrid.

Fields Summary
ArrayList
mItems
private ArrayList
mDataObservers
private android.content.Context
mContext
private boolean
mMaxedOut
private ImageGrid
mImageGrid
private boolean
mIsLive
private int
mTabHeight
Constructors Summary
ImageAdapter(android.content.Context context, ImageGrid grid, boolean live)

        mContext = context;
        mIsLive = live;
        mItems = new ArrayList<TabControl.Tab>();
        mImageGrid = grid;
        mDataObservers = new ArrayList<DataSetObserver>();
    
Methods Summary
public voidadd(TabControl.Tab t)
Add a new window web page to the grid

param
t The tab to display

        if (mMaxedOut) {
            return;
        }
        mItems.add(t);
        notifyObservers();
        if (mItems.size() == TabControl.MAX_TABS) {
            mMaxedOut = true;
        }
    
public booleanareAllItemsEnabled()

        return true;
    
public voidclear()
Clear the internal WebViews and remove their picture listeners.

        for (TabControl.Tab t : mItems) {
            clearPictureListeners(t);
        }
        mItems.clear();
        notifyObservers();
    
private voidclearPictureListeners(TabControl.Tab t)

        if (t.getWebView() != null) {
            t.getWebView().setPictureListener(null);
            if (t.getSubWebView() != null) {
                t.getSubWebView().setPictureListener(null);
            }
        }
    
private voidconfirmClose(int position)

        final ImageGrid.Listener l = mImageGrid.getListener();
        if (l == null) {
            return;
        }
        l.remove(position);
    
public intgetCount()

        // Include the New Window button if we have not reached the tab limit
        if (!mMaxedOut) {
            return mItems.size()+1;
        }
        return mItems.size();
    
public java.lang.ObjectgetItem(int position)

        if (!mMaxedOut) {
            if (0 == position) {
                return null;
            }
            return mItems.get(position);
        }
        return mItems.get(position);
    
public longgetItemId(int position)

        return position;
    
public intgetItemViewType(int position)

        return 0;
    
public android.view.ViewgetView(int position, android.view.View convertView, android.view.ViewGroup parent)

        View v = null;
        if (convertView != null) {
            v = convertView;
        } else {
            LayoutInflater factory = LayoutInflater.from(mContext);
            v = factory.inflate(R.layout.tabitem, null);
        }
        FakeWebView img = (FakeWebView) v.findViewById(R.id.icon);
        ImageView close = (ImageView) v.findViewById(R.id.close);
        TextView tv = (TextView) v.findViewById(R.id.label);

        // position needs to be in the range of Tab indices.
        if (!mMaxedOut) {
            position--;
        }

        // Create the View for actual tabs
        if (position != ImageGrid.NEW_TAB) {
            TabControl.Tab t = mItems.get(position);
            img.setTab(t);
            tv.setText(t.getTitle());
            // Do not put the 'X' if the tab picker isn't "live" (meaning the
            // user cannot click on a tab)
            if (!mIsLive) {
                close.setVisibility(View.GONE);
            } else {
                close.setVisibility(View.VISIBLE);
                final int pos = position;
                close.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            ImageAdapter.this.confirmClose(pos);
                        }
                    });
            }
        } else {
            img.setBackgroundColor(Color.BLACK);
            img.setImageResource(R.drawable.ic_new_window);
            img.setScaleType(ImageView.ScaleType.CENTER);
            img.setPadding(0, 0, 0, 34);
            tv.setText(R.string.new_window);
            close.setVisibility(View.GONE);
        }
        ViewGroup.LayoutParams lp = img.getLayoutParams();
        if (lp.height != mTabHeight) {
            lp.height = mTabHeight;
            img.requestLayout();
        }
        return v;
    
public intgetViewTypeCount()

        return 1;
    
public booleanhasStableIds()

        return true;
    
voidheightChanged(int newHeight)

        mTabHeight = newHeight;
    
public booleanisEmpty()

        return getCount() == 0;
    
public booleanisEnabled(int position)

        if (position >= 0 && position <= mItems.size()) {
            return true;
        }
        return false;
    
public booleanmaxedOut()
Whether the adapter is at its limit, determined by TabControl.MAX_TABS

return
True if the number of Tabs represented in this Adapter is at its maximum.

        return mMaxedOut;
    
voidnotifyObservers()
Notify all the observers that a change has happened.

        for (DataSetObserver observer : mDataObservers) {
            observer.onChanged();
        }
    
public voidregisterDataSetObserver(android.database.DataSetObserver observer)

        mDataObservers.add(observer);
    
public voidremove(int index)
Remove a window from the list. At this point, the window has already gone. It just needs to be removed from the screen

param
index window to remove

        if (index >= 0 && index < mItems.size()) {
            clearPictureListeners(mItems.remove(index));
            notifyObservers();
            mMaxedOut = false;
        }
    
public voidunregisterDataSetObserver(android.database.DataSetObserver observer)

        mDataObservers.remove(observer);