FileDocCategorySizeDatePackage
LayoutModel.javaAPI DocAndroid 1.5 API9165Wed May 06 22:42:46 BST 2009com.android.mms.model

LayoutModel

public class LayoutModel extends Model

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
LOCAL_LOGV
public static final String
IMAGE_REGION_ID
public static final String
TEXT_REGION_ID
public static final int
LAYOUT_BOTTOM_TEXT
public static final int
LAYOUT_TOP_TEXT
public static final int
DEFAULT_LAYOUT_TYPE
private int
mLayoutType
private RegionModel
mRootLayout
private RegionModel
mImageRegion
private RegionModel
mTextRegion
private ArrayList
mNonStdRegions
private com.android.mms.layout.LayoutParameters
mLayoutParams
Constructors Summary
public LayoutModel()


      
        mLayoutParams = LayoutManager.getInstance().getLayoutParameters();
        // Create default root-layout and regions.
        createDefaultRootLayout();
        createDefaultImageRegion();
        createDefaultTextRegion();
    
public LayoutModel(ArrayList layouts)

        mLayoutParams = LayoutManager.getInstance().getLayoutParameters();
        // Root-Layout must be always provided as the first element.
        mRootLayout = layouts.get(0);
        mNonStdRegions = new ArrayList<RegionModel>();

        int size = layouts.size();
        if (size > 1) {
            for (int i = 1; i < size; i++) {
                RegionModel r = layouts.get(i);
                String rId = r.getRegionId();
                if (rId.equals(IMAGE_REGION_ID)) {
                    mImageRegion = r;
                } else if (rId.equals(TEXT_REGION_ID)) {
                    mTextRegion = r;
                } else {
                    if (LOCAL_LOGV) {
                        Log.v(TAG, "Found non-standard region: " + rId);
                    }
                    mNonStdRegions.add(r);
                }
            }
        }

        validateLayouts();
    
public LayoutModel(RegionModel rootLayout, ArrayList regions)

        mLayoutParams = LayoutManager.getInstance().getLayoutParameters();
        mRootLayout = rootLayout;
        mNonStdRegions = new ArrayList<RegionModel>();

        for (RegionModel r : regions) {
            String rId = r.getRegionId();
            if (rId.equals(IMAGE_REGION_ID)) {
                mImageRegion = r;
            } else if (rId.equals(TEXT_REGION_ID)) {
                mTextRegion = r;
            } else {
                if (LOCAL_LOGV) {
                    Log.v(TAG, "Found non-standard region: " + rId);
                }
                mNonStdRegions.add(r);
            }
        }

        validateLayouts();
    
Methods Summary
public voidchangeTo(int layout)

        if (mRootLayout == null) {
            throw new IllegalStateException("Root-Layout uninitialized.");
        }

        if (mLayoutParams == null) {
            mLayoutParams = LayoutManager.getInstance().getLayoutParameters();
        }

        if (mLayoutType != layout) {
            switch (layout) {
                case LAYOUT_BOTTOM_TEXT: {
                    mImageRegion.setTop(0);
                    mTextRegion.setTop(mLayoutParams.getImageHeight());
                    mLayoutType = layout;
                    notifyModelChanged(true);
                }
                break;
                case LAYOUT_TOP_TEXT: {
                    mImageRegion.setTop(mLayoutParams.getTextHeight());
                    mTextRegion.setTop(0);
                    mLayoutType = layout;
                    notifyModelChanged(true);
                }
                break;
                default: {
                    Log.w(TAG, "Unknown layout type: " + layout);
                }
            }
        } else {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Skip changing layout.");
            }
        }
    
private voidcreateDefaultImageRegion()

        if (mRootLayout == null) {
            throw new IllegalStateException("Root-Layout uninitialized.");
        }

        mImageRegion = new RegionModel(IMAGE_REGION_ID, 0, 0,
                mRootLayout.getWidth(), mLayoutParams.getImageHeight());
    
private voidcreateDefaultRootLayout()

        mRootLayout = new RegionModel(null, 0, 0, mLayoutParams.getWidth(),
                                                  mLayoutParams.getHeight());
    
private voidcreateDefaultTextRegion()

        if (mRootLayout == null) {
            throw new IllegalStateException("Root-Layout uninitialized.");
        }

        mTextRegion = new RegionModel(
                TEXT_REGION_ID, 0, mLayoutParams.getImageHeight(),
                mRootLayout.getWidth(), mLayoutParams.getTextHeight());
    
public RegionModelfindRegionById(java.lang.String rId)

        if (IMAGE_REGION_ID.equals(rId)) {
            return mImageRegion;
        } else if (TEXT_REGION_ID.equals(rId)) {
            return mTextRegion;
        } else {
            for (RegionModel r : mNonStdRegions) {
                if (r.getRegionId().equals(rId)) {
                    return r;
                }
            }

            if (LOCAL_LOGV) {
                Log.v(TAG, "Region not found: " + rId);
            }
            return null;
        }
    
public java.lang.StringgetBackgroundColor()

        return mRootLayout.getBackgroundColor();
    
public RegionModelgetImageRegion()

        return mImageRegion;
    
public intgetLayoutHeight()

        return mRootLayout.getHeight();
    
public intgetLayoutType()

        return mLayoutType;
    
public intgetLayoutWidth()

        return mRootLayout.getWidth();
    
public java.util.ArrayListgetRegions()
Get all regions except root-layout. The result is READ-ONLY.

        ArrayList<RegionModel> regions = new ArrayList<RegionModel>();
        if (mImageRegion != null) {
            regions.add(mImageRegion);
        }
        if (mTextRegion != null) {
            regions.add(mTextRegion);
        }
        return regions;
    
public RegionModelgetRootLayout()

        return mRootLayout;
    
public RegionModelgetTextRegion()

        return mTextRegion;
    
public booleanhasNonStdRegions()

        return mNonStdRegions.size() > 0;
    
protected voidregisterModelChangedObserverInDescendants(IModelChangedObserver observer)

        if (mRootLayout != null) {
            mRootLayout.registerModelChangedObserver(observer);
        }

        if (mImageRegion != null) {
            mImageRegion.registerModelChangedObserver(observer);
        }

        if (mTextRegion != null) {
            mTextRegion.registerModelChangedObserver(observer);
        }
    
public voidsetImageRegion(RegionModel imageRegion)

        mImageRegion = imageRegion;
    
public voidsetRootLayout(RegionModel rootLayout)

        mRootLayout = rootLayout;
    
public voidsetTextRegion(RegionModel textRegion)

        mTextRegion = textRegion;
    
protected voidunregisterAllModelChangedObserversInDescendants()

        if (mRootLayout != null) {
            mRootLayout.unregisterAllModelChangedObservers();
        }

        if (mImageRegion != null) {
            mImageRegion.unregisterAllModelChangedObservers();
        }

        if (mTextRegion != null) {
            mTextRegion.unregisterAllModelChangedObservers();
        }
    
protected voidunregisterModelChangedObserverInDescendants(IModelChangedObserver observer)

        if (mRootLayout != null) {
            mRootLayout.unregisterModelChangedObserver(observer);
        }

        if (mImageRegion != null) {
            mImageRegion.unregisterModelChangedObserver(observer);
        }

        if (mTextRegion != null) {
            mTextRegion.unregisterModelChangedObserver(observer);
        }
    
private voidvalidateLayouts()

        if (mRootLayout == null) {
            createDefaultRootLayout();
        }

        if (mImageRegion == null) {
            createDefaultImageRegion();
        }

        if (mTextRegion == null) {
            createDefaultTextRegion();
        }