1 /* 2 * Copyright (C) 2010 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.camera.ui; 18 19 import static com.android.camera.ui.GLRootView.dpToPixel; 20 import android.content.Context; 21 import android.graphics.Rect; 22 23 import javax.microedition.khronos.opengles.GL11; 24 25 class GLOptionHeader extends GLView { 26 private static final int FONT_COLOR = 0xFF979797; 27 private static final float FONT_SIZE = 12; 28 private static final int HORIZONTAL_PADDINGS = 4; 29 private static final int VERTICAL_PADDINGS = 2; 30 private static final int COLOR_OPTION_HEADER = 0xFF2B2B2B; 31 32 private static int sHorizontalPaddings = -1; 33 private static int sVerticalPaddings; 34 35 private final StringTexture mTitle; 36 private Texture mBackground; 37 38 private static void initializeStaticVariables(Context context) { 39 if (sHorizontalPaddings >= 0) return; 40 sHorizontalPaddings = dpToPixel(context, HORIZONTAL_PADDINGS); 41 sVerticalPaddings = dpToPixel(context, VERTICAL_PADDINGS); 42 } 43 44 public GLOptionHeader(Context context, String title) { 45 initializeStaticVariables(context); 46 47 float fontSize = GLRootView.dpToPixel(context, FONT_SIZE); 48 mTitle = StringTexture.newInstance(title, fontSize, FONT_COLOR); 49 setBackground(new ColorTexture(COLOR_OPTION_HEADER)); 50 setPaddings(sHorizontalPaddings, 51 sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); 52 } 53 54 public void setBackground(Texture background) { 55 if (mBackground == background) return; 56 mBackground = background; 57 invalidate(); 58 } 59 60 @Override 61 protected void onMeasure(int widthSpec, int heightSpec) { 62 new MeasureHelper(this) 63 .setPreferredContentSize(mTitle.getWidth(), mTitle.getHeight()) 64 .measure(widthSpec, heightSpec); 65 } 66 67 @Override 68 protected void render(GLRootView root, GL11 gl) { 69 if (mBackground != null) { 70 mBackground.draw(root, 0, 0, getWidth(), getHeight()); 71 } 72 Rect p = mPaddings; 73 mTitle.draw(root, p.left, p.top); 74 } 75 } 76