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.Color; 22 import android.graphics.Rect; 23 24 import javax.microedition.khronos.opengles.GL11; 25 26 public class RestoreSettingsItem extends GLView { 27 private static final int FONT_COLOR = Color.WHITE; 28 private static final float FONT_SIZE = 18; 29 30 private static final int LEFT_PADDING = 20; 31 private static final int RIGHT_PADDING = 4; 32 private static final int TOP_PADDING = 2; 33 private static final int BOTTOM_PADDING = 2; 34 35 private static int sLeftPadding = -1; 36 private static int sRightPadding; 37 private static int sTopPadding; 38 private static int sBottomPadding; 39 private static float sFontSize; 40 41 private final StringTexture mText; 42 43 private static void initializeStaticVariables(Context context) { 44 if (sLeftPadding >= 0) return; 45 46 sLeftPadding = dpToPixel(context, LEFT_PADDING); 47 sRightPadding = dpToPixel(context, RIGHT_PADDING); 48 sTopPadding = dpToPixel(context, TOP_PADDING); 49 sBottomPadding = dpToPixel(context, BOTTOM_PADDING); 50 sFontSize = dpToPixel(context, FONT_SIZE); 51 } 52 53 public RestoreSettingsItem(Context context, String title) { 54 initializeStaticVariables(context); 55 mText = StringTexture.newInstance(title, sFontSize, FONT_COLOR); 56 setPaddings(sLeftPadding, sTopPadding, sRightPadding, sBottomPadding); 57 } 58 59 @Override 60 protected void onMeasure(int widthSpec, int heightSpec) { 61 new MeasureHelper(this) 62 .setPreferredContentSize(mText.getWidth(), mText.getHeight()) 63 .measure(widthSpec, heightSpec); 64 } 65 66 @Override 67 protected void render(GLRootView root, GL11 gl) { 68 Rect p = mPaddings; 69 int height = getHeight() - p.top - p.bottom; 70 71 StringTexture title = mText; 72 //TODO: cut the text if it is too long 73 title.draw(root, p.left, p.top + (height - title.getHeight()) / 2); 74 } 75 } 76