summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/ui/GLOptionHeader.java
blob: bec9b76df6cfa16c271a1af96ed74be102e8ab12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.android.camera.ui;

import android.content.Context;
import android.graphics.Rect;

import com.android.camera.ListPreference;

import javax.microedition.khronos.opengles.GL11;

public class GLOptionHeader extends GLView {
    private static final int FONT_COLOR = 0xFF979797;
    private static final float FONT_SIZE = 12;

    private final ListPreference mPreference;
    private final StringTexture mTitle;
    private NinePatchTexture mBackground;

    public GLOptionHeader(Context context, ListPreference preference) {
        float fontSize = GLRootView.dpToPixel(context, FONT_SIZE);
        mPreference = preference;
        mTitle = StringTexture.newInstance(
                preference.getTitle(), fontSize, FONT_COLOR);
    }

    public ListPreference getPreference() {
        return mPreference;
    }

    public void setBackground(NinePatchTexture background) {
        if (mBackground == background) return;
        mBackground = background;
        invalidate();
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        new MeasureHelper(this)
                .setPreferedContentSize(mTitle.getWidth(), mTitle.getHeight())
                .measure(widthSpec, heightSpec);
    }

    @Override
    protected void render(GLRootView root, GL11 gl) {
        if (mBackground != null) {
            mBackground.setSize(getWidth(), getHeight());
            if (mBackground.bind(root, gl)) mBackground.draw(root, 0, 0);
        }
        if (mTitle.bind(root, gl)) {
            Rect p = mPaddings;
            mTitle.draw(root, p.left, p.top);
        }
    }
}