1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.layoutlib.bridge.android;
18 
19 import com.android.ide.common.rendering.api.SessionParams;
20 import com.android.layoutlib.bridge.Bridge;
21 import com.android.layoutlib.bridge.impl.RenderAction;
22 import com.android.layoutlib.bridge.impl.RenderActionTestUtil;
23 import com.android.layoutlib.bridge.intensive.RenderTestBase;
24 import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback;
25 import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser;
26 import com.android.ninepatch.NinePatch;
27 
28 import org.junit.Assert;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 
32 import android.R;
33 import android.content.res.Configuration;
34 import android.graphics.Bitmap;
35 import android.graphics.BitmapFactory;
36 import android.graphics.ImageDecoder;
37 import android.graphics.ImageDecoder.Source;
38 import android.util.DisplayMetrics;
39 
40 import java.awt.image.BufferedImage;
41 import java.awt.image.DataBufferInt;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.nio.Buffer;
45 import java.nio.ByteBuffer;
46 
47 import static org.junit.Assert.assertNotNull;
48 
49 public class SampleRenderTest extends PlatformRenderTestCase {
50     @Test
testLoadImage()51     public void testLoadImage() throws Exception {
52         Source source = ImageDecoder.createSource(context.getResources(),
53                 R.drawable.button_onoff_indicator_on);
54         Bitmap bitmap = ImageDecoder.decodeBitmap(source);
55         BufferedImage image = new BufferedImage(bitmap.getWidth(), bitmap.getHeight(),
56                 BufferedImage.TYPE_INT_ARGB);
57         int[] imageData = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
58         bitmap.getPixels(imageData, 0, image.getWidth(), 0, 0, image.getWidth(),
59                 image.getHeight());
60         RenderTestBase.verify("bitmap_decoder.png", image);
61     }
62 }
63