예제 #1
0
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Test {@link ImageView#setImageURI(Uri)}",
        method = "setImageURI",
        args = {android.net.Uri.class}
    )
    @UiThreadTest
    public void testSetImageURI() {
        mImageView = findImageViewById(R.id.imageview);
        mImageView.setImageURI(null);
        assertNull(mImageView.getDrawable());

        File dbDir = getInstrumentation().getTargetContext().getDir("tests",
                Context.MODE_PRIVATE);
        File imagefile = new File(dbDir, "tempimage.jpg");
        if (imagefile.exists()) {
            imagefile.delete();
        }
        createSampleImage(imagefile, R.raw.testimage);
        final String path = imagefile.getPath();
        mImageView.setImageURI(Uri.parse(path));
        assertTrue(mImageView.isLayoutRequested());
        assertNotNull(mImageView.getDrawable());

        Drawable imageViewDrawable = mImageView.getDrawable();
        BitmapDrawable imageViewBitmap = (BitmapDrawable) imageViewDrawable;
        Bitmap.Config viewConfig = imageViewBitmap.getBitmap().getConfig();
        Bitmap testimageBitmap = WidgetTestUtils.getUnscaledAndDitheredBitmap(
                mActivity.getResources(), R.raw.testimage, viewConfig);

        WidgetTestUtils.assertEquals(testimageBitmap, imageViewBitmap.getBitmap());
    }
예제 #2
0
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Test {@link ImageView#setImageResource(int)}",
        method = "setImageResource",
        args = {int.class}
    )
    @UiThreadTest
    public void testSetImageResource() {
        mImageView = findImageViewById(R.id.imageview);
        mImageView.setImageResource(-1);
        assertNull(mImageView.getDrawable());

        mImageView.setImageResource(R.drawable.testimage);
        assertTrue(mImageView.isLayoutRequested());
        assertNotNull(mImageView.getDrawable());
        Drawable drawable = mActivity.getResources().getDrawable(R.drawable.testimage);
        BitmapDrawable testimageBitmap = (BitmapDrawable) drawable;
        Drawable imageViewDrawable = mImageView.getDrawable();
        BitmapDrawable imageViewBitmap = (BitmapDrawable) imageViewDrawable;
        WidgetTestUtils.assertEquals(testimageBitmap.getBitmap(), imageViewBitmap.getBitmap());
    }
예제 #3
0
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Test {@link ImageView#setImageBitmap(Bitmap)}",
        method = "setImageBitmap",
        args = {android.graphics.Bitmap.class}
    )
    @UiThreadTest
    public void testSetImageBitmap() {
        mImageView = findImageViewById(R.id.imageview);

        mImageView.setImageBitmap(null);
        // A BitmapDrawable is always created for the ImageView.
        assertNotNull(mImageView.getDrawable());

        final Bitmap bitmap =
            BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.testimage);
        mImageView.setImageBitmap(bitmap);
        assertTrue(mImageView.isLayoutRequested());
        assertNotNull(mImageView.getDrawable());
        Drawable imageViewDrawable = mImageView.getDrawable();
        BitmapDrawable imageViewBitmap = (BitmapDrawable) imageViewDrawable;
        WidgetTestUtils.assertEquals(bitmap, imageViewBitmap.getBitmap());
    }