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 17package com.android.camera.ui; 18 19import android.content.Context; 20import android.graphics.Matrix; 21import android.graphics.Rect; 22import android.view.animation.AlphaAnimation; 23import android.view.animation.Transformation; 24 25import javax.microedition.khronos.opengles.GL11; 26 27abstract class AbstractIndicator extends GLView { 28 private static final int DEFAULT_PADDING = 3; 29 private int mOrientation = 0; 30 31 abstract protected BitmapTexture getIcon(); 32 33 public AbstractIndicator(Context context) { 34 int padding = GLRootView.dpToPixel(context, DEFAULT_PADDING); 35 setPaddings(padding, 0, padding, 0); 36 } 37 38 @Override 39 protected void onMeasure(int widthSpec, int heightSpec) { 40 BitmapTexture icon = getIcon(); 41 new MeasureHelper(this) 42 .setPreferredContentSize(icon.getWidth(), icon.getHeight()) 43 .measure(widthSpec, heightSpec); 44 } 45 46 @Override 47 protected void render(GLRootView root, GL11 gl) { 48 BitmapTexture icon = getIcon(); 49 if (icon != null) { 50 Rect p = mPaddings; 51 int width = getWidth() - p.left - p.right; 52 int height = getHeight() - p.top - p.bottom; 53 if (mOrientation != 0) { 54 Transformation trans = root.pushTransform(); 55 Matrix matrix = trans.getMatrix(); 56 matrix.preTranslate(p.left + width / 2, p.top + height / 2); 57 matrix.preRotate(-mOrientation); 58 icon.draw(root, -icon.getWidth() / 2, -icon.getHeight() / 2); 59 root.popTransform(); 60 } else { 61 icon.draw(root, 62 p.left + (width - icon.getWidth()) / 2, 63 p.top + (height - icon.getHeight()) / 2); 64 } 65 } 66 } 67 68 public void setOrientation(int orientation) { 69 if (orientation % 90 != 0) throw new IllegalArgumentException(); 70 orientation = orientation % 360; 71 if (orientation < 0) orientation += 360; 72 73 if (mOrientation == orientation) return; 74 mOrientation = orientation; 75 76 if (getGLRootView() != null) { 77 AlphaAnimation anim = new AlphaAnimation(0.2f, 1); 78 anim.setDuration(200); 79 startAnimation(anim); 80 } 81 } 82 83 abstract public GLView getPopupContent(); 84 85 abstract public void overrideSettings(String key, String settings); 86 87 abstract public void reloadPreferences(); 88} 89