1aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardpackage com.android.layoutlib.test.myapplication.widgets;
2aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard
3aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardimport android.content.Context;
4aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardimport android.graphics.drawable.Drawable;
5aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardimport android.util.AttributeSet;
6aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardimport android.view.View;
7aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard
8aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardimport java.io.IOException;
9aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardimport java.io.InputStream;
10aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard
11aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillardpublic class AssetView extends View {
12aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    public AssetView(Context context) {
13aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        super(context);
14aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        init(context);
15aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    }
16aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard
17aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    public AssetView(Context context, AttributeSet attrs) {
18aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        super(context, attrs);
19aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        init(context);
20aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    }
21aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard
22aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    public AssetView(Context context, AttributeSet attrs, int defStyle) {
23aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        super(context, attrs, defStyle);
24aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        init(context);
25aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    }
26aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard
27aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    private void init(Context context) {
28aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        try {
29aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard            InputStream istr = context.getAssets().open("asset.png");
30aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard            setBackground(Drawable.createFromStream(istr, null));
31aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        } catch (IOException e) {
32aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard            e.printStackTrace();
33aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard        }
34aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard    }
35aec75b2a26641d702f42c74ae2ab69e3242f073dJerome Gaillard}
36