alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Android example source code file (DrawableBgMinSizeTest.java)

This example Android source code file (DrawableBgMinSizeTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Android by Example" TM.

Java - Android tags/keywords

absolutelayout, activityinstrumentationtestcase, android, button, drawable's, drawablebgminsizetest, drawing, exception, framelayout, linearlayout, mediumtest, override, relativelayout, test, textview, ui, view, widget

The DrawableBgMinSizeTest.java Android example source code

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import com.android.frameworks.coretests.R;
import android.view.DrawableBgMinSize;
import android.test.TouchUtils;
import android.test.suitebuilder.annotation.MediumTest;

import android.graphics.drawable.Drawable;
import android.test.ActivityInstrumentationTestCase;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * {@link DrawableBgMinSize} exercises Views to obey their background drawable's
 * minimum sizes.
 */
public class DrawableBgMinSizeTest extends
        ActivityInstrumentationTestCase<DrawableBgMinSize> {
    private Button mChangeBackgroundsButton;
    
    private Drawable mBackgroundDrawable;
    private Drawable mBigBackgroundDrawable;
    
    private TextView mTextView;
    private LinearLayout mLinearLayout;
    private RelativeLayout mRelativeLayout;
    private FrameLayout mFrameLayout;
    private AbsoluteLayout mAbsoluteLayout;
    
    public DrawableBgMinSizeTest() {
        super("com.android.frameworks.coretests", DrawableBgMinSize.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        final DrawableBgMinSize a = getActivity();

        mChangeBackgroundsButton = (Button) a.findViewById(R.id.change_backgrounds);
        mBackgroundDrawable = a.getResources().getDrawable(R.drawable.drawable_background);
        mBigBackgroundDrawable = a.getResources().getDrawable(R.drawable.big_drawable_background);
        mTextView = (TextView) a.findViewById(R.id.text_view);
        mLinearLayout = (LinearLayout) a.findViewById(R.id.linear_layout);
        mRelativeLayout = (RelativeLayout) a.findViewById(R.id.relative_layout);
        mFrameLayout = (FrameLayout) a.findViewById(R.id.frame_layout);
        mAbsoluteLayout = (AbsoluteLayout) a.findViewById(R.id.absolute_layout);
    }

    @MediumTest
    public void testSetUpConditions() throws Exception {
        assertNotNull(mChangeBackgroundsButton);
        assertNotNull(mBackgroundDrawable);
        assertNotNull(mBigBackgroundDrawable);
        assertNotNull(mTextView);
        assertNotNull(mLinearLayout);
        assertNotNull(mRelativeLayout);
        assertNotNull(mFrameLayout);
        assertNotNull(mAbsoluteLayout);
    }
    
    public void doMinimumSizeTest(View view) throws Exception {
        assertTrue(view.getClass().getSimpleName() + " should respect the background Drawable's minimum width",
                view.getWidth() >= mBackgroundDrawable.getMinimumWidth());
        assertTrue(view.getClass().getSimpleName() + " should respect the background Drawable's minimum height",
                view.getHeight() >= mBackgroundDrawable.getMinimumHeight());
    }

    @MediumTest
    public void testTextViewMinimumSize() throws Exception {
        doMinimumSizeTest(mTextView);
    }
    
    @MediumTest
    public void testLinearLayoutMinimumSize() throws Exception {
        doMinimumSizeTest(mLinearLayout);
    }
    
    @MediumTest
    public void testRelativeLayoutMinimumSize() throws Exception {
        doMinimumSizeTest(mRelativeLayout);
    }
    
    @MediumTest
    public void testAbsoluteLayoutMinimumSize() throws Exception {
        doMinimumSizeTest(mAbsoluteLayout);
    }
    
    @MediumTest
    public void testFrameLayoutMinimumSize() throws Exception {
        doMinimumSizeTest(mFrameLayout);
    }
    
    public void doDiffBgMinimumSizeTest(final View view) throws Exception {
        // Change to the bigger backgrounds
        TouchUtils.tapView(this, mChangeBackgroundsButton);

        assertTrue(view.getClass().getSimpleName()
                + " should respect the different bigger background Drawable's minimum width", view
                .getWidth() >= mBigBackgroundDrawable.getMinimumWidth());
        assertTrue(view.getClass().getSimpleName()
                + " should respect the different bigger background Drawable's minimum height", view
                .getHeight() >= mBigBackgroundDrawable.getMinimumHeight());
    }

    @MediumTest
    public void testTextViewDiffBgMinimumSize() throws Exception {
        doDiffBgMinimumSizeTest(mTextView);
    }
    
    @MediumTest
    public void testLinearLayoutDiffBgMinimumSize() throws Exception {
        doDiffBgMinimumSizeTest(mLinearLayout);
    }
    
    @MediumTest
    public void testRelativeLayoutDiffBgMinimumSize() throws Exception {
        doDiffBgMinimumSizeTest(mRelativeLayout);
    }
    
    @MediumTest
    public void testAbsoluteLayoutDiffBgMinimumSize() throws Exception {
        doDiffBgMinimumSizeTest(mAbsoluteLayout);
    }
    
    @MediumTest
    public void testFrameLayoutDiffBgMinimumSize() throws Exception {
        doDiffBgMinimumSizeTest(mFrameLayout);
    }
    
}

Other Android examples (source code examples)

Here is a short list of links related to this Android DrawableBgMinSizeTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.