diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-08-15 15:50:07 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-08-15 15:56:33 +0800 |
commit | 827192aefc4c75151dd389e1a1a5ebc8313d0164 (patch) | |
tree | ebeeca1afbbaff18479e1783f84be25e951a824a /src/com | |
parent | ef91f8514bf3c21091dde6b292f9616464dc32e8 (diff) | |
download | LegacyCamera-827192aefc4c75151dd389e1a1a5ebc8313d0164.zip LegacyCamera-827192aefc4c75151dd389e1a1a5ebc8313d0164.tar.gz LegacyCamera-827192aefc4c75151dd389e1a1a5ebc8313d0164.tar.bz2 |
Remove unused files.
Change-Id: I8f7c34ddb1ffa1455131c51ff7d6522f3d94e402
Diffstat (limited to 'src/com')
27 files changed, 1 insertions, 3457 deletions
diff --git a/src/com/android/camera/PreviewFrameLayout.java b/src/com/android/camera/PreviewFrameLayout.java index 8fee82d..75e7c35 100644 --- a/src/com/android/camera/PreviewFrameLayout.java +++ b/src/com/android/camera/PreviewFrameLayout.java @@ -21,8 +21,6 @@ import android.content.Context; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.View; -import android.view.ViewGroup; -import android.widget.RadioGroup; import android.widget.RelativeLayout; /** @@ -37,7 +35,6 @@ public class PreviewFrameLayout extends RelativeLayout { private double mAspectRatio = 4.0 / 3.0; private View mFrame; private View mBorderView; - private OnSizeChangedListener mSizeListener; private final DisplayMetrics mMetrics = new DisplayMetrics(); public PreviewFrameLayout(Context context, AttributeSet attrs) { @@ -46,10 +43,6 @@ public class PreviewFrameLayout extends RelativeLayout { .getDefaultDisplay().getMetrics(mMetrics); } - public void setOnSizeChangedListener(OnSizeChangedListener listener) { - mSizeListener = listener; - } - @Override protected void onFinishInflate() { super.onFinishInflate(); @@ -99,9 +92,5 @@ public class PreviewFrameLayout extends RelativeLayout { MeasureSpec.makeMeasureSpec(frameWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(frameHeight, MeasureSpec.EXACTLY)); mBorderView.layout(hSpace, vSpace, frameWidth + hSpace, frameHeight + vSpace); - - if (mSizeListener != null) { - mSizeListener.onSizeChanged(); - } } } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 7271335..d7e6da0 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -17,7 +17,6 @@ package com.android.camera; import com.android.camera.ui.CameraPicker; -import com.android.camera.ui.GLRootView; import com.android.camera.ui.IndicatorControl; import com.android.camera.ui.IndicatorWheel; import com.android.camera.ui.RotateImageView; @@ -85,7 +84,7 @@ public class VideoCamera extends ActivityBase implements View.OnClickListener, ShutterButton.OnShutterButtonListener, SurfaceHolder.Callback, MediaRecorder.OnErrorListener, MediaRecorder.OnInfoListener, - ModePicker.OnModeChangeListener, PreviewFrameLayout.OnSizeChangedListener { + ModePicker.OnModeChangeListener { private static final String TAG = "videocamera"; @@ -139,7 +138,6 @@ public class VideoCamera extends ActivityBase private PreviewFrameLayout mPreviewFrameLayout; private SurfaceHolder mSurfaceHolder = null; - private GLRootView mGLRootView; private IndicatorControl mIndicatorControl; private View mReviewControl; @@ -405,7 +403,6 @@ public class VideoCamera extends ActivityBase mPreviewFrameLayout = (PreviewFrameLayout) findViewById(R.id.frame_layout); - mPreviewFrameLayout.setOnSizeChangedListener(this); mReviewImage = (ImageView) findViewById(R.id.review_image); mModePicker = (ModePicker) findViewById(R.id.mode_picker); @@ -1752,10 +1749,6 @@ public class VideoCamera extends ActivityBase super.onConfigurationChanged(config); } - public void onSizeChanged() { - // TODO: update the content on GLRootView - } - private void onRestorePreferencesClicked() { Runnable runnable = new Runnable() { public void run() { diff --git a/src/com/android/camera/ui/BasicTexture.java b/src/com/android/camera/ui/BasicTexture.java deleted file mode 100644 index 291b84a..0000000 --- a/src/com/android/camera/ui/BasicTexture.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.android.camera.ui; - -import javax.microedition.khronos.opengles.GL11; - -abstract class BasicTexture implements Texture { - - protected static final int UNSPECIFIED = -1; - - public static final int STATE_UNLOADED = 0; - public static final int STATE_LOADED = 1; - public static final int STATE_ERROR = -1; - - protected GL11 mGL; - - protected int mId; - protected int mState; - - protected int mWidth = UNSPECIFIED; - protected int mHeight = UNSPECIFIED; - - protected int mTextureWidth; - protected int mTextureHeight; - - protected BasicTexture(GL11 gl, int id, int state) { - mGL = gl; - mId = id; - mState = state; - } - - protected BasicTexture() { - this(null, 0, STATE_UNLOADED); - } - - protected void setSize(int width, int height) { - mWidth = width; - mHeight = height; - } - - /** - * Sets the size of the texture. Due to the limit of OpenGL, the texture - * size must be of power of 2, the size of the content may not be the size - * of the texture. - */ - protected void setTextureSize(int width, int height) { - mTextureWidth = width; - mTextureHeight = height; - } - - public int getId() { - return mId; - } - - public int getWidth() { - return mWidth; - } - - public int getHeight() { - return mHeight; - } - - public void deleteFromGL() { - if (mState == STATE_LOADED) { - mGL.glDeleteTextures(1, new int[]{mId}, 0); - } - mState = STATE_UNLOADED; - } - - public void draw(GLRootView root, int x, int y) { - root.drawTexture(this, x, y, mWidth, mHeight); - } - - public void draw(GLRootView root, int x, int y, int w, int h) { - root.drawTexture(this, x, y, w, h); - } - - abstract protected boolean bind(GLRootView root, GL11 gl); -} diff --git a/src/com/android/camera/ui/BitmapTexture.java b/src/com/android/camera/ui/BitmapTexture.java deleted file mode 100644 index c3a4139..0000000 --- a/src/com/android/camera/ui/BitmapTexture.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.android.camera.ui; - -import com.android.camera.Util; - -import android.graphics.Bitmap; -import android.opengl.GLUtils; - -import javax.microedition.khronos.opengles.GL11; -import javax.microedition.khronos.opengles.GL11Ext; - -abstract class BitmapTexture extends BasicTexture { - - @SuppressWarnings("unused") - private static final String TAG = "Texture"; - - protected BitmapTexture() { - super(null, 0, STATE_UNLOADED); - } - - @Override - public int getWidth() { - if (mWidth == UNSPECIFIED) getBitmap(); - return mWidth; - } - - @Override - public int getHeight() { - if (mWidth == UNSPECIFIED) getBitmap(); - return mHeight; - } - - protected abstract Bitmap getBitmap(); - - protected abstract void freeBitmap(Bitmap bitmap); - - private void uploadToGL(GL11 gl) throws GLOutOfMemoryException { - Bitmap bitmap = getBitmap(); - int glError = GL11.GL_NO_ERROR; - if (bitmap != null) { - int[] textureId = new int[1]; - try { - // Define a vertically flipped crop rectangle for - // OES_draw_texture. - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int[] cropRect = {0, height, width, -height}; - - // Upload the bitmap to a new texture. - gl.glGenTextures(1, textureId, 0); - gl.glBindTexture(GL11.GL_TEXTURE_2D, textureId[0]); - gl.glTexParameteriv(GL11.GL_TEXTURE_2D, - GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect, 0); - gl.glTexParameteri(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE); - gl.glTexParameteri(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE); - gl.glTexParameterf(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - gl.glTexParameterf(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - - int widthExt = Util.nextPowerOf2(width); - int heightExt = Util.nextPowerOf2(height); - int format = GLUtils.getInternalFormat(bitmap); - int type = GLUtils.getType(bitmap); - - mTextureWidth = widthExt; - mTextureHeight = heightExt; - gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, - widthExt, heightExt, 0, format, type, null); - GLUtils.texSubImage2D( - GL11.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type); - } finally { - freeBitmap(bitmap); - } - if (glError == GL11.GL_OUT_OF_MEMORY) { - throw new GLOutOfMemoryException(); - } - if (glError != GL11.GL_NO_ERROR) { - mId = 0; - mState = STATE_UNLOADED; - throw new RuntimeException( - "Texture upload fail, glError " + glError); - } else { - // Update texture state. - mGL = gl; - mId = textureId[0]; - mState = BitmapTexture.STATE_LOADED; - } - } else { - mState = STATE_ERROR; - throw new RuntimeException("Texture load fail, no bitmap"); - } - } - - @Override - protected boolean bind(GLRootView root, GL11 gl) { - if (mState == BitmapTexture.STATE_UNLOADED || mGL != gl) { - mState = BitmapTexture.STATE_UNLOADED; - try { - uploadToGL(gl); - } catch (GLOutOfMemoryException e) { - root.handleLowMemory(); - return false; - } - } else { - gl.glBindTexture(GL11.GL_TEXTURE_2D, getId()); - } - return true; - } -} diff --git a/src/com/android/camera/ui/CameraEGLConfigChooser.java b/src/com/android/camera/ui/CameraEGLConfigChooser.java deleted file mode 100644 index 6a3bb2a..0000000 --- a/src/com/android/camera/ui/CameraEGLConfigChooser.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.camera.ui; - -import android.opengl.GLSurfaceView.EGLConfigChooser; -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLDisplay; - -/* - * The code is copied/adapted from - * <code>android.opengl.GLSurfaceView.BaseConfigChooser</code>. Here we try to - * choose a configuration that support RGBA_8888 format and if possible, - * with stencil buffer, but is not required. - */ -class CameraEGLConfigChooser implements EGLConfigChooser { - - private static final int COLOR_BITS = 8; - - private int mStencilBits; - - private final int mConfigSpec[] = new int[] { - EGL10.EGL_RED_SIZE, COLOR_BITS, - EGL10.EGL_GREEN_SIZE, COLOR_BITS, - EGL10.EGL_BLUE_SIZE, COLOR_BITS, - EGL10.EGL_ALPHA_SIZE, COLOR_BITS, - EGL10.EGL_NONE - }; - - public int getStencilBits() { - return mStencilBits; - } - - public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { - int[] numConfig = new int[1]; - if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, numConfig)) { - throw new RuntimeException("eglChooseConfig failed"); - } - - if (numConfig[0] <= 0) { - throw new RuntimeException("No configs match configSpec"); - } - - EGLConfig[] configs = new EGLConfig[numConfig[0]]; - if (!egl.eglChooseConfig(display, - mConfigSpec, configs, configs.length, numConfig)) { - throw new RuntimeException(); - } - - return chooseConfig(egl, display, configs); - } - - private EGLConfig chooseConfig( - EGL10 egl, EGLDisplay display, EGLConfig configs[]) { - - EGLConfig result = null; - int minStencil = Integer.MAX_VALUE; - int value[] = new int[1]; - - // Because we need only one bit of stencil, try to choose a config that - // has stencil support but with smallest number of stencil bits. If - // none is found, choose any one. - for (int i = 0, n = configs.length; i < n; ++i) { - if (egl.eglGetConfigAttrib( - display, configs[i], EGL10.EGL_STENCIL_SIZE, value)) { - if (value[0] == 0) continue; - if (value[0] < minStencil) { - minStencil = value[0]; - result = configs[i]; - } - } else { - throw new RuntimeException( - "eglGetConfigAttrib error: " + egl.eglGetError()); - } - } - if (result == null) result = configs[0]; - egl.eglGetConfigAttrib( - display, result, EGL10.EGL_STENCIL_SIZE, value); - mStencilBits = value[0]; - return result; - } -} diff --git a/src/com/android/camera/ui/CanvasTexture.java b/src/com/android/camera/ui/CanvasTexture.java deleted file mode 100644 index e7c805f..0000000 --- a/src/com/android/camera/ui/CanvasTexture.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Bitmap.Config; - -/** Using a canvas to draw the texture */ -abstract class CanvasTexture extends BitmapTexture { - protected Canvas mCanvas; - - public CanvasTexture(int width, int height) { - setSize(width, height); - } - - @Override - protected Bitmap getBitmap() { - Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); - mCanvas = new Canvas(bitmap); - onDraw(mCanvas, bitmap); - return bitmap; - } - - @Override - protected void freeBitmap(Bitmap bitmap) { - bitmap.recycle(); - } - - abstract protected void onDraw(Canvas canvas, Bitmap backing); -} diff --git a/src/com/android/camera/ui/ColorTexture.java b/src/com/android/camera/ui/ColorTexture.java deleted file mode 100644 index 252df87..0000000 --- a/src/com/android/camera/ui/ColorTexture.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -class ColorTexture implements Texture { - - private int mColor; - - public ColorTexture(int color) { - mColor = color; - } - - public void draw(GLRootView root, int x, int y) { - } - - public void draw(GLRootView root, int x, int y, int w, int h) { - root.drawColor(x, y, w, h, mColor); - } -} diff --git a/src/com/android/camera/ui/GLLinearLayout.java b/src/com/android/camera/ui/GLLinearLayout.java deleted file mode 100644 index cb0f064..0000000 --- a/src/com/android/camera/ui/GLLinearLayout.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Rect; -import android.view.View.MeasureSpec; - -class GLLinearLayout extends GLView { - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - int width = 0; - int height = 0; - for (int i = 0, n = getComponentCount(); i < n; ++i) { - GLView view = getComponent(i); - view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); - width = Math.max(width, view.getMeasuredWidth()); - height += view.getMeasuredHeight(); - } - new MeasureHelper(this) - .setPreferredContentSize(width, height) - .measure(widthSpec, heightSpec); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - Rect p = mPaddings; - int offsetX = p.left; - int width = (r - l) - p.left - p.right; - int offsetY = p.top; - for (int i = 0, n = getComponentCount(); i < n; ++i) { - GLView view = getComponent(i); - view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); - int nextOffsetY = offsetY + view.getMeasuredHeight(); - view.layout(offsetX, offsetY, offsetX + width, nextOffsetY); - offsetY = nextOffsetY; - } - } - -} diff --git a/src/com/android/camera/ui/GLListView.java b/src/com/android/camera/ui/GLListView.java deleted file mode 100644 index ed22ea3..0000000 --- a/src/com/android/camera/ui/GLListView.java +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import static android.view.View.MeasureSpec.makeMeasureSpec; -import com.android.camera.Util; - -import android.content.Context; -import android.graphics.Rect; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.View.MeasureSpec; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import android.view.animation.Transformation; -import android.widget.Scroller; - -import javax.microedition.khronos.opengles.GL11; - -class GLListView extends GLView { - @SuppressWarnings("unused") - private static final String TAG = "GLListView"; - private static final int INDEX_NONE = -1; - private static final int SCROLL_BAR_TIMEOUT = 1000; - - private static final int HIDE_SCROLL_BAR = 1; - - private Model mModel; - private Handler mHandler; - - private int mHighlightIndex = INDEX_NONE; - private GLView mHighlightView; - - private Texture mHighLight; - private NinePatchTexture mScrollbar; - - private int mVisibleStart = 0; // inclusive - private int mVisibleEnd = 0; // exclusive - - private boolean mHasMeasured = false; - - private boolean mScrollBarVisible = false; - private Animation mScrollBarAnimation; - private OnItemSelectedListener mOnItemSelectedListener; - - private GestureDetector mGestureDetector; - private final Scroller mScroller; - private boolean mScrollable; - private boolean mIsPressed = false; - - static public interface Model { - public int size(); - public GLView getView(int index); - public boolean isSelectable(int index); - } - - static public interface OnItemSelectedListener { - public void onItemSelected(GLView view, int position); - } - - public GLListView(Context context) { - mScroller = new Scroller(context); - mHandler = new Handler(Looper.getMainLooper()) { - @Override - public void handleMessage(Message msg) { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - handleMessageLocked(msg); - } - } else { - handleMessageLocked(msg); - } - } - - private void handleMessageLocked(Message msg) { - switch(msg.what) { - case HIDE_SCROLL_BAR: - setScrollBarVisible(false); - break; - } - } - }; - mGestureDetector = new GestureDetector( - context, new MyGestureListener(), mHandler); - } - - private final Runnable mHideScrollBar = new Runnable() { - public void run() { - setScrollBarVisible(false); - } - }; - - @Override - protected void onVisibilityChanged(int visibility) { - super.onVisibilityChanged(visibility); - if (mScrollHeight > getHeight()) updateScrollBar(visibility); - } - - private void updateScrollBar(int visibility) { - if (isVisible()) { - setScrollBarVisible(true); - mHandler.sendEmptyMessageDelayed( - HIDE_SCROLL_BAR, SCROLL_BAR_TIMEOUT); - } else { - mHandler.removeMessages(HIDE_SCROLL_BAR); - } - } - - private void setScrollBarVisible(boolean visible) { - if (mScrollBarVisible == visible || mScrollbar == null) return; - mScrollBarVisible = visible; - if (!visible) { - mScrollBarAnimation = new AlphaAnimation(1, 0); - mScrollBarAnimation.setDuration(300); - mScrollBarAnimation.start(); - } else { - mScrollBarAnimation = null; - } - invalidate(); - } - - public void setHighLight(Texture highLight) { - mHighLight = highLight; - } - - public void setDataModel(Model model) { - mModel = model; - mScrollY = 0; - requestLayout(); - } - - public void setOnItemSelectedListener(OnItemSelectedListener l) { - mOnItemSelectedListener = l; - } - - private boolean drawWithAnimation(GLRootView root, - Texture texture, int x, int y, int w, int h, Animation anim) { - long now = root.currentAnimationTimeMillis(); - Transformation temp = root.obtainTransformation(); - boolean more = anim.getTransformation(now, temp); - Transformation transformation = root.pushTransform(); - transformation.compose(temp); - texture.draw(root, x, y, w, h); - invalidate(); - root.popTransform(); - return more; - } - - @Override - protected void render(GLRootView root, GL11 gl) { - root.clipRect(0, 0, getWidth(), getHeight()); - if (mHighlightIndex != INDEX_NONE) { - GLView view = mModel.getView(mHighlightIndex); - Rect bounds = view.bounds(); - if (mHighLight != null) { - int width = bounds.width(); - int height = bounds.height(); - mHighLight.draw(root, - bounds.left - mScrollX, bounds.top - mScrollY, - width, height); - } - } - super.render(root, gl); - root.clearClip(); - - if (mScrollBarAnimation != null || mScrollBarVisible) { - int width = mScrollbar.getWidth(); - int height = getHeight() * getHeight() / mScrollHeight; - int yoffset = mScrollY * getHeight() / mScrollHeight; - if (mScrollBarAnimation != null) { - if (!drawWithAnimation( - root, mScrollbar, getWidth() - width, yoffset, - width, height, mScrollBarAnimation)) { - mScrollBarAnimation = null; - } - } else { - mScrollbar.draw( - root, getWidth() - width, yoffset, width, height); - } - } - if (mScroller.computeScrollOffset()) { - setScrollPosition(mScroller.getCurrY(), false); - } - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - // first get the total height - int height = 0; - int maxWidth = 0; - for (int i = 0, n = mModel.size(); i < n; ++i) { - GLView view = mModel.getView(i); - view.measure(widthSpec, MeasureSpec.UNSPECIFIED); - height += view.getMeasuredHeight(); - maxWidth = Math.max(maxWidth, view.getMeasuredWidth()); - } - mScrollHeight = height; - mHasMeasured = true; - new MeasureHelper(this) - .setPreferredContentSize(maxWidth, height) - .measure(widthSpec, heightSpec); - } - - @Override - public int getComponentCount() { - return mVisibleEnd - mVisibleStart; - } - - @Override - public GLView getComponent(int index) { - if (index < 0 || index >= mVisibleEnd - mVisibleStart) { - throw new ArrayIndexOutOfBoundsException(index); - } - return mModel.getView(mVisibleStart + index); - } - - @Override - public void requestLayout() { - mHasMeasured = false; - super.requestLayout(); - } - - @Override - protected void onLayout( - boolean change, int left, int top, int right, int bottom) { - - if (!mHasMeasured || mMeasuredWidth != (right - left)) { - measure(makeMeasureSpec(right - left, MeasureSpec.EXACTLY), - makeMeasureSpec(bottom - top, MeasureSpec.EXACTLY)); - } - - mScrollable = mScrollHeight > (bottom - top); - int width = right - left; - int yoffset = 0; - - for (int i = 0, n = mModel.size(); i < n; ++i) { - GLView item = mModel.getView(i); - item.onAddToParent(this); - int nextOffset = yoffset + item.getMeasuredHeight(); - item.layout(0, yoffset, width, nextOffset); - yoffset = nextOffset; - } - setScrollPosition(mScrollY, true); - } - - private void setScrollPosition(int position, boolean force) { - int height = getHeight(); - - position = Util.clamp(position, 0, mScrollHeight - height); - - if (!force && position == mScrollY) return; - mScrollY = position; - - int n = mModel.size(); - - int start = 0; - int end = 0; - for (start = 0; start < n; ++start) { - if (position < mModel.getView(start).mBounds.bottom) break; - } - - int bottom = position + height; - for (end = start; end < n; ++ end) { - if (bottom <= mModel.getView(end).mBounds.top) break; - } - setVisibleRange(start , end); - invalidate(); - } - - private void setVisibleRange(int start, int end) { - if (start == mVisibleStart && end == mVisibleEnd) return; - mVisibleStart = start; - mVisibleEnd = end; - } - - @Override - protected boolean dispatchTouchEvent(MotionEvent event) { - return onTouch(event); - } - - @Override @SuppressWarnings("fallthrough") - protected boolean onTouch(MotionEvent event) { - - mGestureDetector.onTouchEvent(event); - - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - mIsPressed = true; - mHandler.removeMessages(HIDE_SCROLL_BAR); - setScrollBarVisible(mScrollHeight > getHeight()); - if (!mScroller.isFinished()) { - mScroller.forceFinished(true); - break; - } - // fallthrough: we need to highlight the item which is pressed - case MotionEvent.ACTION_MOVE: - if (!mScrollable) { - findAndSetHighlightItem((int) event.getY()); - } - break; - case MotionEvent.ACTION_UP: - mIsPressed = false; - if (mScrollBarVisible) { - mHandler.removeMessages(HIDE_SCROLL_BAR); - mHandler.sendEmptyMessageDelayed( - HIDE_SCROLL_BAR, SCROLL_BAR_TIMEOUT); - } - if (!mScrollable && mOnItemSelectedListener != null - && mHighlightView != null) { - mOnItemSelectedListener - .onItemSelected(mHighlightView, mHighlightIndex); - } - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_OUTSIDE: - setHighlightItem(null, INDEX_NONE); - } - return true; - } - - private void findAndSetHighlightItem(int y) { - int position = y + mScrollY; - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - GLView child = mModel.getView(i); - if (child.mBounds.bottom > position) { - if (mModel.isSelectable(i)) { - setHighlightItem(child, i); - return; - } - break; - } - } - setHighlightItem(null, INDEX_NONE); - } - - private void setHighlightItem(GLView view, int index) { - if (index == mHighlightIndex) return; - mHighlightIndex = index; - mHighlightView = view; - if (mHighLight != null) invalidate(); - } - - public void setScroller(NinePatchTexture scrollbar) { - this.mScrollbar = scrollbar; - requestLayout(); - } - - private class MyGestureListener - extends GestureDetector.SimpleOnGestureListener { - - @Override - public boolean onFling(MotionEvent e1, - MotionEvent e2, float velocityX, float velocityY) { - if (!mScrollable) return false; - mScroller.fling(0, mScrollY, - 0, -(int) velocityY, 0, 0, 0, mScrollHeight - getHeight()); - invalidate(); - return true; - } - - @Override - public boolean onScroll(MotionEvent e1, - MotionEvent e2, float distanceX, float distanceY) { - if (!mScrollable) return false; - setHighlightItem(null, INDEX_NONE); - setScrollPosition(mScrollY + (int) distanceY, false); - return true; - } - - @Override - public void onShowPress(MotionEvent e) { - if (!mScrollable || !mIsPressed) return; - findAndSetHighlightItem((int) e.getY()); - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - if (!mScrollable) return false; - findAndSetHighlightItem((int) e.getY()); - if (mOnItemSelectedListener != null && mHighlightView != null) { - mOnItemSelectedListener - .onItemSelected(mHighlightView, mHighlightIndex); - } - setHighlightItem(null, INDEX_NONE); - return true; - } - } -} diff --git a/src/com/android/camera/ui/GLOptionHeader.java b/src/com/android/camera/ui/GLOptionHeader.java deleted file mode 100644 index c702943..0000000 --- a/src/com/android/camera/ui/GLOptionHeader.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import static com.android.camera.ui.GLRootView.dpToPixel; -import android.content.Context; -import android.graphics.Rect; - -import javax.microedition.khronos.opengles.GL11; - -class GLOptionHeader extends GLView { - private static final int FONT_COLOR = 0xFF979797; - private static final float FONT_SIZE = 12; - private static final int HORIZONTAL_PADDINGS = 4; - private static final int VERTICAL_PADDINGS = 2; - private static final int COLOR_OPTION_HEADER = 0xFF2B2B2B; - - private static int sHorizontalPaddings = -1; - private static int sVerticalPaddings; - - private final StringTexture mTitle; - private Texture mBackground; - - private static void initializeStaticVariables(Context context) { - if (sHorizontalPaddings >= 0) return; - sHorizontalPaddings = dpToPixel(context, HORIZONTAL_PADDINGS); - sVerticalPaddings = dpToPixel(context, VERTICAL_PADDINGS); - } - - public GLOptionHeader(Context context, String title) { - initializeStaticVariables(context); - - float fontSize = GLRootView.dpToPixel(context, FONT_SIZE); - mTitle = StringTexture.newInstance(title, fontSize, FONT_COLOR); - setBackground(new ColorTexture(COLOR_OPTION_HEADER)); - setPaddings(sHorizontalPaddings, - sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); - } - - public void setBackground(Texture background) { - if (mBackground == background) return; - mBackground = background; - invalidate(); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - new MeasureHelper(this) - .setPreferredContentSize(mTitle.getWidth(), mTitle.getHeight()) - .measure(widthSpec, heightSpec); - } - - @Override - protected void render(GLRootView root, GL11 gl) { - if (mBackground != null) { - mBackground.draw(root, 0, 0, getWidth(), getHeight()); - } - Rect p = mPaddings; - mTitle.draw(root, p.left, p.top); - } -} diff --git a/src/com/android/camera/ui/GLOptionItem.java b/src/com/android/camera/ui/GLOptionItem.java deleted file mode 100644 index 55be3eb..0000000 --- a/src/com/android/camera/ui/GLOptionItem.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import static com.android.camera.ui.GLRootView.dpToPixel; -import android.content.Context; -import android.graphics.Color; -import android.graphics.Rect; -import android.view.animation.Transformation; - -import com.android.camera.R; - -import javax.microedition.khronos.opengles.GL11; - -class GLOptionItem extends GLView { - private static final int FONT_COLOR = Color.WHITE; - private static final float FONT_SIZE = 18; - - private static final int MINIMAL_WIDTH = 120; - private static final int MINIMAL_HEIGHT = 32; - - private static final int NO_ICON_LEADING_SPACE = 10; - private static final int TEXT_LEFT_PADDING = 6; - private static final int TEXT_RIGHT_PADDING = 10; - - private static final float ENABLED_ALPHA = 1f; - private static final float DISABLED_ALPHA = 0.3f; - - private static final int HORIZONTAL_PADDINGS = 4; - private static final int VERTICAL_PADDINGS = 2; - - private static ResourceTexture sCheckOn; - private static ResourceTexture sCheckOff; - - private static int sNoIconLeadingSpace; - private static int sTextLeftPadding; - private static int sTextRightPadding; - private static int sMinimalWidth; - private static int sMinimalHeight; - private static float sFontSize; - private static int sHorizontalPaddings = -1; - private static int sVerticalPaddings; - - private final ResourceTexture mIcon; - private final StringTexture mText; - private boolean mEnabled = true; - - private ResourceTexture mCheckBox; - - - private static void initializeStaticVariables(Context context) { - if (sCheckOn != null) return; - - sCheckOn = new ResourceTexture(context, R.drawable.ic_menuselect_on); - sCheckOff = new ResourceTexture(context, R.drawable.ic_menuselect_off); - - sNoIconLeadingSpace = dpToPixel(context, NO_ICON_LEADING_SPACE); - sTextLeftPadding = dpToPixel(context, TEXT_LEFT_PADDING); - sTextRightPadding = dpToPixel(context, TEXT_RIGHT_PADDING); - sMinimalWidth = dpToPixel(context, MINIMAL_WIDTH); - sMinimalHeight = dpToPixel(context, MINIMAL_HEIGHT); - sHorizontalPaddings = dpToPixel(context, HORIZONTAL_PADDINGS); - sVerticalPaddings = dpToPixel(context, VERTICAL_PADDINGS); - - sFontSize = dpToPixel(context, FONT_SIZE); - } - - public GLOptionItem(Context context, int iconId, String title) { - initializeStaticVariables(context); - mIcon = iconId == 0 ? null : new ResourceTexture(context, iconId); - mText = StringTexture.newInstance(title, sFontSize, FONT_COLOR); - mCheckBox = sCheckOff; - setPaddings(sHorizontalPaddings, - sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - int width = mIcon == null ? sNoIconLeadingSpace : mIcon.getWidth(); - width += mText.getWidth() + mCheckBox.getWidth(); - width += sTextRightPadding + sTextLeftPadding; - - int height = Math.max(Math.max(mIcon == null ? 0 : mIcon.getHeight(), - mText.getHeight()), mCheckBox.getHeight()); - - width = Math.max(sMinimalWidth, width); - height = Math.max(sMinimalHeight, height); - - new MeasureHelper(this) - .setPreferredContentSize(width, height) - .measure(widthSpec, heightSpec); - } - - @Override - protected void render(GLRootView root, GL11 gl) { - Rect p = mPaddings; - - int width = getWidth() - p.left - p.right; - int height = getHeight() - p.top - p.bottom; - - int xoffset = p.left; - - Transformation trans = root.getTransformation(); - float oldAlpha = trans.getAlpha(); - trans.setAlpha(oldAlpha * (mEnabled ? ENABLED_ALPHA : DISABLED_ALPHA)); - - ResourceTexture icon = mIcon; - if (icon != null) { - icon.draw(root, xoffset, - p.top + (height - icon.getHeight()) / 2); - xoffset += icon.getWidth(); - } else { - xoffset += sNoIconLeadingSpace; - } - - StringTexture title = mText; - xoffset += sTextLeftPadding; - int yoffset = p.top + (height - title.getHeight()) / 2; - //TODO: cut the text if it is too long - title.draw(root, xoffset, yoffset); - - ResourceTexture checkbox = mCheckBox; - yoffset = p.top + (height - checkbox.getHeight()) / 2; - checkbox.draw(root, width - checkbox.getWidth(), yoffset); - trans.setAlpha(oldAlpha); - } - - public void setChecked(boolean checked) { - mCheckBox = checked ? sCheckOn : sCheckOff; - invalidate(); - } - - public void setEnabled(boolean enabled) { - if (mEnabled == enabled) return; - mEnabled = enabled; - invalidate(); - } -} diff --git a/src/com/android/camera/ui/GLOutOfMemoryException.java b/src/com/android/camera/ui/GLOutOfMemoryException.java deleted file mode 100644 index 10ea4e1..0000000 --- a/src/com/android/camera/ui/GLOutOfMemoryException.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -public class GLOutOfMemoryException extends Exception { -} diff --git a/src/com/android/camera/ui/GLPopupWindow.java b/src/com/android/camera/ui/GLPopupWindow.java deleted file mode 100644 index 79482ac..0000000 --- a/src/com/android/camera/ui/GLPopupWindow.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Rect; -import android.view.View.MeasureSpec; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import android.view.animation.AnimationSet; -import android.view.animation.OvershootInterpolator; -import android.view.animation.ScaleAnimation; - -import javax.microedition.khronos.opengles.GL11; - -class GLPopupWindow extends GLView { - - protected BitmapTexture mAnchor; - protected int mAnchorOffset; - - protected int mAnchorPosition; - private final RotatePane mRotatePane = new RotatePane(); - private RawTexture mBackupTexture; - - protected Texture mBackground; - private boolean mUsingStencil; - - public GLPopupWindow() { - super.addComponent(mRotatePane); - } - - @Override - protected void onAttachToRoot(GLRootView root) { - super.onAttachToRoot(root); - mUsingStencil = root.getEGLConfigChooser().getStencilBits() > 0; - } - - public void setBackground(Texture background) { - if (background == mBackground) return; - mBackground = background; - if (background != null && background instanceof NinePatchTexture) { - setPaddings(((NinePatchTexture) mBackground).getPaddings()); - } else { - setPaddings(0, 0, 0, 0); - } - invalidate(); - } - - public void setAnchor(BitmapTexture anchor, int offset) { - mAnchor = anchor; - mAnchorOffset = offset; - } - - @Override - public void addComponent(GLView component) { - throw new UnsupportedOperationException("use setContent(GLView)"); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - int widthMode = MeasureSpec.getMode(widthSpec); - if (widthMode != MeasureSpec.UNSPECIFIED) { - Rect p = mPaddings; - int width = MeasureSpec.getSize(widthSpec); - widthSpec = MeasureSpec.makeMeasureSpec( - Math.max(0, width - p.left - p.right - - mAnchor.getWidth() + mAnchorOffset), widthMode); - } - - int heightMode = MeasureSpec.getMode(heightSpec); - if (heightMode != MeasureSpec.UNSPECIFIED) { - int height = MeasureSpec.getSize(widthSpec); - widthSpec = MeasureSpec.makeMeasureSpec(Math.max( - 0, height - mPaddings.top - mPaddings.bottom), heightMode); - } - - Rect p = mPaddings; - GLView child = mRotatePane; - child.measure(widthSpec, heightSpec); - setMeasuredSize(child.getMeasuredWidth() - + p.left + p.right + mAnchor.getWidth() - mAnchorOffset, - child.getMeasuredHeight() + p.top + p.bottom); - } - - @Override - protected void onLayout( - boolean change, int left, int top, int right, int bottom) { - Rect p = getPaddings(); - GLView view = mRotatePane; - view.layout(p.left, p.top, - getWidth() - p.right - mAnchor.getWidth() + mAnchorOffset, - getHeight() - p.bottom); - } - - public void setAnchorPosition(int yoffset) { - mAnchorPosition = yoffset; - } - - private void renderBackgroundWithStencil(GLRootView root, GL11 gl) { - int width = getWidth(); - int height = getHeight(); - int aWidth = mAnchor.getWidth(); - int aHeight = mAnchor.getHeight(); - - Rect p = mPaddings; - int aXoffset = width - aWidth; - int aYoffset = Math.max(p.top, mAnchorPosition - aHeight / 2); - aYoffset = Math.min(aYoffset, height - p.bottom - aHeight); - - if (mAnchor != null) { - gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE); - gl.glStencilFunc(GL11.GL_ALWAYS, 1, 1); - mAnchor.draw(root, aXoffset, aYoffset); - gl.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1); - gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); - } - - if (mBackground != null) { - mBackground.draw(root, 0, 0, - width - aWidth + mAnchorOffset, height); - } - } - - private void renderBackgroundWithoutStencil(GLRootView root, GL11 gl) { - int width = getWidth(); - int height = getHeight(); - int aWidth = mAnchor.getWidth(); - int aHeight = mAnchor.getHeight(); - - Rect p = mPaddings; - int aXoffset = width - aWidth; - int aYoffset = Math.max(p.top, mAnchorPosition - aHeight / 2); - aYoffset = Math.min(aYoffset, height - p.bottom - aHeight); - - if (mAnchor != null) { - mAnchor.draw(root, aXoffset, aYoffset); - } - - if (mBackupTexture == null || mBackupTexture.getBoundGL() != gl) { - mBackupTexture = RawTexture.newInstance(gl); - } - - RawTexture backup = mBackupTexture; - try { - // Copy the current drawing results of the triangle area into - // "backup", so that we can restore the content after it is - // overlaid by the background. - root.copyTexture2D(backup, aXoffset, aYoffset, aWidth, aHeight); - } catch (GLOutOfMemoryException e) { - e.printStackTrace(); - } - - if (mBackground != null) { - mBackground.draw(root, 0, 0, - width - aWidth + mAnchorOffset, height); - } - - gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ZERO); - backup.drawBack(root, aXoffset, aYoffset, aWidth, aHeight); - gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - } - - @Override - protected void renderBackground(GLRootView root, GL11 gl) { - if (mUsingStencil) { - renderBackgroundWithStencil(root, gl); - } else { - renderBackgroundWithoutStencil(root, gl); - } - } - - public void setContent(GLView content) { - mRotatePane.setContent(content); - } - - public void popup() { - setVisibility(GLView.VISIBLE); - - AnimationSet set = new AnimationSet(false); - Animation scale = new ScaleAnimation( - 0.7f, 1f, 0.7f, 1f, getWidth(), mAnchorPosition); - Animation alpha = new AlphaAnimation(0.5f, 1.0f); - - set.addAnimation(scale); - set.addAnimation(alpha); - scale.setDuration(150); - alpha.setDuration(100); - scale.setInterpolator(new OvershootInterpolator()); - startAnimation(set); - } - - public void popoff() { - setVisibility(GLView.INVISIBLE); - Animation alpha = new AlphaAnimation(0.7f, 0.0f); - alpha.setDuration(100); - startAnimation(alpha); - } - - public void setOrientation(int orientation) { - switch (orientation) { - case 90: - mRotatePane.setOrientation(RotatePane.LEFT); - break; - case 180: - mRotatePane.setOrientation(RotatePane.DOWN); - break; - case 270: - mRotatePane.setOrientation(RotatePane.RIGHT); - break; - default: - mRotatePane.setOrientation(RotatePane.UP); - break; - } - } -} diff --git a/src/com/android/camera/ui/GLRootView.java b/src/com/android/camera/ui/GLRootView.java deleted file mode 100644 index bdb0a8e..0000000 --- a/src/com/android/camera/ui/GLRootView.java +++ /dev/null @@ -1,739 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import com.android.camera.Util; - -import android.app.Activity; -import android.content.Context; -import android.graphics.Color; -import android.graphics.Matrix; -import android.graphics.PixelFormat; -import android.opengl.GLSurfaceView; -import android.opengl.GLU; -import android.os.SystemClock; -import android.util.AttributeSet; -import android.util.DisplayMetrics; -import android.util.Log; -import android.view.MotionEvent; -import android.view.View; -import android.view.animation.Animation; -import android.view.animation.Transformation; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.Stack; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; -import javax.microedition.khronos.opengles.GL11; -import javax.microedition.khronos.opengles.GL11Ext; - -// The root component of all <code>GLView</code>s. The rendering is done in GL -// thread while the event handling is done in the main thread. To synchronize -// the two threads, the entry points of this package need to synchronize on the -// <code>GLRootView</code> instance unless it can be proved that the rendering -// thread won't access the same thing as the method. The entry points include: -// (1) The public methods of HeadUpDisplay -// (2) The public methods of CameraHeadUpDisplay -// (3) The overridden methods in GLRootView. -public class GLRootView extends GLSurfaceView - implements GLSurfaceView.Renderer { - private static final String TAG = "GLRootView"; - - private final boolean ENABLE_FPS_TEST = false; - private int mFrameCount = 0; - private long mFrameCountingStart = 0; - - // We need 16 vertices for a normal nine-patch image (the 4x4 vertices) - private static final int VERTEX_BUFFER_SIZE = 16 * 2; - - // We need 22 indices for a normal nine-patch image - private static final int INDEX_BUFFER_SIZE = 22; - - private static final int FLAG_INITIALIZED = 1; - private static final int FLAG_NEED_LAYOUT = 2; - - private static boolean mTexture2DEnabled; - - private static float sPixelDensity = -1f; - - private GL11 mGL; - private GLView mContentView; - private DisplayMetrics mDisplayMetrics; - - private final ArrayList<Animation> mAnimations = new ArrayList<Animation>(); - - private final Stack<Transformation> mFreeTransform = - new Stack<Transformation>(); - - private final Transformation mTransformation = new Transformation(); - private final Stack<Transformation> mTransformStack = - new Stack<Transformation>(); - - private float mLastAlpha = mTransformation.getAlpha(); - - private final float mMatrixValues[] = new float[16]; - - private final float mUvBuffer[] = new float[VERTEX_BUFFER_SIZE]; - private final float mXyBuffer[] = new float[VERTEX_BUFFER_SIZE]; - private final byte mIndexBuffer[] = new byte[INDEX_BUFFER_SIZE]; - - private int mNinePatchX[] = new int[4]; - private int mNinePatchY[] = new int[4]; - private float mNinePatchU[] = new float[4]; - private float mNinePatchV[] = new float[4]; - - private ByteBuffer mXyPointer; - private ByteBuffer mUvPointer; - private ByteBuffer mIndexPointer; - - private int mFlags = FLAG_NEED_LAYOUT; - private long mAnimationTime; - - private CameraEGLConfigChooser mEglConfigChooser = new CameraEGLConfigChooser(); - - public GLRootView(Context context) { - this(context, null); - } - - public GLRootView(Context context, AttributeSet attrs) { - super(context, attrs); - initialize(); - } - - void registerLaunchedAnimation(Animation animation) { - // Register the newly launched animation so that we can set the start - // time more precisely. (Usually, it takes much longer for the first - // rendering, so we set the animation start time as the time we - // complete rendering) - mAnimations.add(animation); - } - - public long currentAnimationTimeMillis() { - return mAnimationTime; - } - - public synchronized static float dpToPixel(Context context, float dp) { - if (sPixelDensity < 0) { - DisplayMetrics metrics = new DisplayMetrics(); - ((Activity) context).getWindowManager() - .getDefaultDisplay().getMetrics(metrics); - sPixelDensity = metrics.density; - } - return sPixelDensity * dp; - } - - public static int dpToPixel(Context context, int dp) { - return (int)(dpToPixel(context, (float) dp) + .5f); - } - - public Transformation obtainTransformation() { - if (!mFreeTransform.isEmpty()) { - Transformation t = mFreeTransform.pop(); - t.clear(); - return t; - } - return new Transformation(); - } - - public void freeTransformation(Transformation freeTransformation) { - mFreeTransform.push(freeTransformation); - } - - public Transformation getTransformation() { - return mTransformation; - } - - public Transformation pushTransform() { - Transformation trans = obtainTransformation(); - trans.set(mTransformation); - mTransformStack.push(trans); - return mTransformation; - } - - public void popTransform() { - Transformation trans = mTransformStack.pop(); - mTransformation.set(trans); - freeTransformation(trans); - } - - public CameraEGLConfigChooser getEGLConfigChooser() { - return mEglConfigChooser; - } - - private static ByteBuffer allocateDirectNativeOrderBuffer(int size) { - return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()); - } - - private void initialize() { - mFlags |= FLAG_INITIALIZED; - setEGLConfigChooser(mEglConfigChooser); - getHolder().setFormat(PixelFormat.TRANSLUCENT); - setZOrderOnTop(true); - - setRenderer(this); - - int size = VERTEX_BUFFER_SIZE * Float.SIZE / Byte.SIZE; - mXyPointer = allocateDirectNativeOrderBuffer(size); - mUvPointer = allocateDirectNativeOrderBuffer(size); - mIndexPointer = allocateDirectNativeOrderBuffer(INDEX_BUFFER_SIZE); - } - - public void setContentPane(GLView content) { - mContentView = content; - content.onAttachToRoot(this); - - // no parent for the content pane - content.onAddToParent(null); - requestLayoutContentPane(); - } - - public GLView getContentPane() { - return mContentView; - } - - void handleLowMemory() { - //TODO: delete texture from GL - } - - public synchronized void requestLayoutContentPane() { - if (mContentView == null || (mFlags & FLAG_NEED_LAYOUT) != 0) return; - - // "View" system will invoke onLayout() for initialization(bug ?), we - // have to ignore it since the GLThread is not ready yet. - if ((mFlags & FLAG_INITIALIZED) == 0) return; - - mFlags |= FLAG_NEED_LAYOUT; - requestRender(); - } - - private synchronized void layoutContentPane() { - mFlags &= ~FLAG_NEED_LAYOUT; - int width = getWidth(); - int height = getHeight(); - Log.v(TAG, "layout content pane " + width + "x" + height); - if (mContentView != null && width != 0 && height != 0) { - mContentView.layout(0, 0, width, height); - } - } - - @Override - protected void onLayout( - boolean changed, int left, int top, int right, int bottom) { - if (changed) requestLayoutContentPane(); - } - - /** - * Called when the context is created, possibly after automatic destruction. - */ - // This is a GLSurfaceView.Renderer callback - public void onSurfaceCreated(GL10 gl1, EGLConfig config) { - GL11 gl = (GL11) gl1; - if (mGL != null) { - // The GL Object has changed - Log.i(TAG, "GLObject has changed from " + mGL + " to " + gl); - } - mGL = gl; - - if (!ENABLE_FPS_TEST) { - setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); - } else { - setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); - } - - // Disable unused state - gl.glDisable(GL11.GL_LIGHTING); - - // Enable used features - gl.glEnable(GL11.GL_BLEND); - gl.glEnable(GL11.GL_SCISSOR_TEST); - gl.glEnable(GL11.GL_STENCIL_TEST); - gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); - gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - gl.glEnable(GL11.GL_TEXTURE_2D); - mTexture2DEnabled = true; - - gl.glTexEnvf(GL11.GL_TEXTURE_ENV, - GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); - - // Set the background color - gl.glClearColor(0f, 0f, 0f, 0f); - gl.glClearStencil(0); - - gl.glVertexPointer(2, GL11.GL_FLOAT, 0, mXyPointer); - gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, mUvPointer); - - } - - /** - * Called when the OpenGL surface is recreated without destroying the - * context. - */ - // This is a GLSurfaceView.Renderer callback - public void onSurfaceChanged(GL10 gl1, int width, int height) { - Log.v(TAG, "onSurfaceChanged: " + width + "x" + height - + ", gl10: " + gl1.toString()); - GL11 gl = (GL11) gl1; - mGL = gl; - gl.glViewport(0, 0, width, height); - - gl.glMatrixMode(GL11.GL_PROJECTION); - gl.glLoadIdentity(); - - GLU.gluOrtho2D(gl, 0, width, 0, height); - Matrix matrix = mTransformation.getMatrix(); - matrix.reset(); - matrix.preTranslate(0, getHeight()); - matrix.preScale(1, -1); - } - - private void setAlphaValue(float alpha) { - if (mLastAlpha == alpha) return; - - GL11 gl = mGL; - mLastAlpha = alpha; - if (alpha >= 0.95f) { - gl.glTexEnvf(GL11.GL_TEXTURE_ENV, - GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); - } else { - gl.glTexEnvf(GL11.GL_TEXTURE_ENV, - GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); - gl.glColor4f(alpha, alpha, alpha, alpha); - } - } - - public void drawRect(int x, int y, int width, int height) { - float matrix[] = mMatrixValues; - mTransformation.getMatrix().getValues(matrix); - drawRect(x, y, width, height, matrix); - } - - private static void putRectangle(float x, float y, - float width, float height, float[] buffer, ByteBuffer pointer) { - buffer[0] = x; - buffer[1] = y; - buffer[2] = x + width; - buffer[3] = y; - buffer[4] = x; - buffer[5] = y + height; - buffer[6] = x + width; - buffer[7] = y + height; - pointer.asFloatBuffer().put(buffer, 0, 8).position(0); - } - - private void drawRect( - int x, int y, int width, int height, float matrix[]) { - GL11 gl = mGL; - gl.glPushMatrix(); - gl.glMultMatrixf(toGLMatrix(matrix), 0); - putRectangle(x, y, width, height, mXyBuffer, mXyPointer); - gl.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4); - gl.glPopMatrix(); - } - - public void drawNinePatch( - NinePatchTexture tex, int x, int y, int width, int height) { - - NinePatchChunk chunk = tex.getNinePatchChunk(); - - // The code should be easily extended to handle the general cases by - // allocating more space for buffers. But let's just handle the only - // use case. - if (chunk.mDivX.length != 2 || chunk.mDivY.length != 2) { - throw new RuntimeException("unsupported nine patch"); - } - if (!tex.bind(this, mGL)) { - throw new RuntimeException("cannot bind" + tex.toString()); - } - if (width <= 0 || height <= 0) return ; - - int divX[] = mNinePatchX; - int divY[] = mNinePatchY; - float divU[] = mNinePatchU; - float divV[] = mNinePatchV; - - int nx = stretch(divX, divU, chunk.mDivX, tex.getWidth(), width); - int ny = stretch(divY, divV, chunk.mDivY, tex.getHeight(), height); - - setAlphaValue(mTransformation.getAlpha()); - Matrix matrix = mTransformation.getMatrix(); - matrix.getValues(mMatrixValues); - GL11 gl = mGL; - gl.glPushMatrix(); - gl.glMultMatrixf(toGLMatrix(mMatrixValues), 0); - gl.glTranslatef(x, y, 0); - drawMesh(divX, divY, divU, divV, nx, ny); - gl.glPopMatrix(); - } - - /** - * Stretches the texture according to the nine-patch rules. It will - * linearly distribute the strechy parts defined in the nine-patch chunk to - * the target area. - * - * <pre> - * source - * /--------------^---------------\ - * u0 u1 u2 u3 u4 u5 - * div ---> |fffff|ssssssss|fff|ssssss|ffff| ---> u - * | div0 div1 div2 div3 | - * | | / / / / - * | | / / / / - * | | / / / / - * |fffff|ssss|fff|sss|ffff| ---> x - * x0 x1 x2 x3 x4 x5 - * \----------v------------/ - * target - * - * f: fixed segment - * s: stretchy segment - * </pre> - * - * @param div the stretch parts defined in nine-patch chunk - * @param source the length of the texture - * @param target the length on the drawing plan - * @param u output, the positions of these dividers in the texture - * coordinate - * @param x output, the corresponding position of these dividers on the - * drawing plan - * @return the number of these dividers. - */ - private int stretch( - int x[], float u[], int div[], int source, int target) { - int textureSize = Util.nextPowerOf2(source); - float textureBound = (source - 0.5f) / textureSize; - - int stretch = 0; - for (int i = 0, n = div.length; i < n; i += 2) { - stretch += div[i + 1] - div[i]; - } - - float remaining = target - source + stretch; - - int lastX = 0; - int lastU = 0; - - x[0] = 0; - u[0] = 0; - for (int i = 0, n = div.length; i < n; i += 2) { - // fixed segment - x[i + 1] = lastX + (div[i] - lastU); - u[i + 1] = Math.min((float) div[i] / textureSize, textureBound); - - // stretchy segment - float partU = div[i + 1] - div[i]; - int partX = (int)(remaining * partU / stretch + 0.5f); - remaining -= partX; - stretch -= partU; - - lastX = x[i + 1] + partX; - lastU = div[i + 1]; - x[i + 2] = lastX; - u[i + 2] = Math.min((float) lastU / textureSize, textureBound); - } - // the last fixed segment - x[div.length + 1] = target; - u[div.length + 1] = textureBound; - - // remove segments with length 0. - int last = 0; - for (int i = 1, n = div.length + 2; i < n; ++i) { - if (x[last] == x[i]) continue; - x[++last] = x[i]; - u[last] = u[i]; - } - return last + 1; - } - - private void drawMesh( - int x[], int y[], float u[], float v[], int nx, int ny) { - /* - * Given a 3x3 nine-patch image, the vertex order is defined as the - * following graph: - * - * (0) (1) (2) (3) - * | /| /| /| - * | / | / | / | - * (4) (5) (6) (7) - * | \ | \ | \ | - * | \| \| \| - * (8) (9) (A) (B) - * | /| /| /| - * | / | / | / | - * (C) (D) (E) (F) - * - * And we draw the triangle strip in the following index order: - * - * index: 04152637B6A5948C9DAEBF - */ - int pntCount = 0; - float xy[] = mXyBuffer; - float uv[] = mUvBuffer; - for (int j = 0; j < ny; ++j) { - for (int i = 0; i < nx; ++i) { - int xIndex = (pntCount++) << 1; - int yIndex = xIndex + 1; - xy[xIndex] = x[i]; - xy[yIndex] = y[j]; - uv[xIndex] = u[i]; - uv[yIndex] = v[j]; - } - } - mUvPointer.asFloatBuffer().put(uv, 0, pntCount << 1).position(0); - mXyPointer.asFloatBuffer().put(xy, 0, pntCount << 1).position(0); - - int idxCount = 1; - byte index[] = mIndexBuffer; - for (int i = 0, bound = nx * (ny - 1); true;) { - // normal direction - --idxCount; - for (int j = 0; j < nx; ++j, ++i) { - index[idxCount++] = (byte) i; - index[idxCount++] = (byte) (i + nx); - } - if (i >= bound) break; - - // reverse direction - int sum = i + i + nx - 1; - --idxCount; - for (int j = 0; j < nx; ++j, ++i) { - index[idxCount++] = (byte) (sum - i); - index[idxCount++] = (byte) (sum - i + nx); - } - if (i >= bound) break; - } - mIndexPointer.put(index, 0, idxCount).position(0); - - mGL.glDrawElements(GL11.GL_TRIANGLE_STRIP, - idxCount, GL11.GL_UNSIGNED_BYTE, mIndexPointer); - } - - private float[] mapPoints(Matrix matrix, int x1, int y1, int x2, int y2) { - float[] point = mXyBuffer; - point[0] = x1; point[1] = y1; point[2] = x2; point[3] = y2; - matrix.mapPoints(point, 0, point, 0, 4); - return point; - } - - public void clipRect(int x, int y, int width, int height) { - float point[] = mapPoints( - mTransformation.getMatrix(), x, y + height, x + width, y); - - // mMatrix could be a rotation matrix. In this case, we need to find - // the boundaries after rotation. (only handle 90 * n degrees) - if (point[0] > point[2]) { - x = (int) point[2]; - width = (int) point[0] - x; - } else { - x = (int) point[0]; - width = (int) point[2] - x; - } - if (point[1] > point[3]) { - y = (int) point[3]; - height = (int) point[1] - y; - } else { - y = (int) point[1]; - height = (int) point[3] - y; - } - mGL.glScissor(x, y, width, height); - } - - public void clearClip() { - mGL.glScissor(0, 0, getWidth(), getHeight()); - } - - private static float[] toGLMatrix(float v[]) { - v[15] = v[8]; v[13] = v[5]; v[5] = v[4]; v[4] = v[1]; - v[12] = v[2]; v[1] = v[3]; v[3] = v[6]; - v[2] = v[6] = v[8] = v[9] = 0; - v[10] = 1; - return v; - } - - public void drawColor(int x, int y, int width, int height, int color) { - float alpha = mTransformation.getAlpha(); - GL11 gl = mGL; - if (mTexture2DEnabled) { - // Set mLastAlpha to an invalid value, so that it will reset again - // in setAlphaValue(float) later. - mLastAlpha = -1.0f; - gl.glDisable(GL11.GL_TEXTURE_2D); - mTexture2DEnabled = false; - } - alpha /= 256.0f; - gl.glColor4f(Color.red(color) * alpha, Color.green(color) * alpha, - Color.blue(color) * alpha, Color.alpha(color) * alpha); - drawRect(x, y, width, height); - } - - public void drawTexture( - BasicTexture texture, int x, int y, int width, int height) { - drawTexture(texture, x, y, width, height, mTransformation.getAlpha()); - } - - public void drawTexture(BasicTexture texture, - int x, int y, int width, int height, float alpha) { - - if (!mTexture2DEnabled) { - mGL.glEnable(GL11.GL_TEXTURE_2D); - mTexture2DEnabled = true; - } - - if (!texture.bind(this, mGL)) { - throw new RuntimeException("cannot bind" + texture.toString()); - } - if (width <= 0 || height <= 0) return ; - - Matrix matrix = mTransformation.getMatrix(); - matrix.getValues(mMatrixValues); - - // Test whether it has been rotated or flipped, if so, glDrawTexiOES - // won't work - if (isMatrixRotatedOrFlipped(mMatrixValues)) { - putRectangle(0, 0, - (texture.mWidth - 0.5f) / texture.mTextureWidth, - (texture.mHeight - 0.5f) / texture.mTextureHeight, - mUvBuffer, mUvPointer); - setAlphaValue(alpha); - drawRect(x, y, width, height, mMatrixValues); - } else { - // draw the rect from bottom-left to top-right - float points[] = mapPoints(matrix, x, y + height, x + width, y); - x = (int) points[0]; - y = (int) points[1]; - width = (int) points[2] - x; - height = (int) points[3] - y; - if (width > 0 && height > 0) { - setAlphaValue(alpha); - ((GL11Ext) mGL).glDrawTexiOES(x, y, 0, width, height); - } - } - } - - private static boolean isMatrixRotatedOrFlipped(float matrix[]) { - return matrix[Matrix.MSKEW_X] != 0 || matrix[Matrix.MSKEW_Y] != 0 - || matrix[Matrix.MSCALE_X] < 0 || matrix[Matrix.MSCALE_Y] > 0; - } - - public synchronized void onDrawFrame(GL10 gl) { - if (ENABLE_FPS_TEST) { - long now = System.nanoTime(); - if (mFrameCountingStart == 0) { - mFrameCountingStart = now; - } else if ((now - mFrameCountingStart) > 1000000000) { - Log.v(TAG, "fps: " + (double) mFrameCount - * 1000000000 / (now - mFrameCountingStart)); - mFrameCountingStart = now; - mFrameCount = 0; - } - ++mFrameCount; - } - - if ((mFlags & FLAG_NEED_LAYOUT) != 0) layoutContentPane(); - clearClip(); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_STENCIL_BUFFER_BIT); - gl.glEnable(GL11.GL_BLEND); - gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - mAnimationTime = SystemClock.uptimeMillis(); - if (mContentView != null) { - mContentView.render(GLRootView.this, (GL11) gl); - } - long now = SystemClock.uptimeMillis(); - for (Animation animation : mAnimations) { - animation.setStartTime(now); - } - mAnimations.clear(); - } - - @Override - public synchronized boolean dispatchTouchEvent(MotionEvent event) { - // If this has been detached from root, we don't need to handle event - return mContentView != null - ? mContentView.dispatchTouchEvent(event) - : false; - } - - public DisplayMetrics getDisplayMetrics() { - if (mDisplayMetrics == null) { - mDisplayMetrics = new DisplayMetrics(); - ((Activity) getContext()).getWindowManager() - .getDefaultDisplay().getMetrics(mDisplayMetrics); - } - return mDisplayMetrics; - } - - public void copyTexture2D( - RawTexture texture, int x, int y, int width, int height) - throws GLOutOfMemoryException { - Matrix matrix = mTransformation.getMatrix(); - matrix.getValues(mMatrixValues); - - if (isMatrixRotatedOrFlipped(mMatrixValues)) { - throw new IllegalArgumentException("cannot support rotated matrix"); - } - float points[] = mapPoints(matrix, x, y + height, x + width, y); - x = (int) points[0]; - y = (int) points[1]; - width = (int) points[2] - x; - height = (int) points[3] - y; - - GL11 gl = mGL; - int newWidth = Util.nextPowerOf2(width); - int newHeight = Util.nextPowerOf2(height); - int glError = GL11.GL_NO_ERROR; - - gl.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId()); - - int[] cropRect = {0, 0, width, height}; - gl.glTexParameteriv(GL11.GL_TEXTURE_2D, - GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect, 0); - gl.glTexParameteri(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE); - gl.glTexParameteri(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE); - gl.glTexParameterf(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - gl.glTexParameterf(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - gl.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, - GL11.GL_RGBA, x, y, newWidth, newHeight, 0); - glError = gl.glGetError(); - - if (glError == GL11.GL_OUT_OF_MEMORY) { - throw new GLOutOfMemoryException(); - } - - if (glError != GL11.GL_NO_ERROR) { - throw new RuntimeException( - "Texture copy fail, glError " + glError); - } - - texture.setSize(width, height); - texture.setTextureSize(newWidth, newHeight); - } - - @Override - protected void onVisibilityChanged(View changedView, int v) { - super.onVisibilityChanged(changedView, v); - if (mContentView != null) { - mContentView.onVisibilityChanged( - v == View.VISIBLE ? GLView.VISIBLE : GLView.INVISIBLE); - } - } -} diff --git a/src/com/android/camera/ui/GLView.java b/src/com/android/camera/ui/GLView.java deleted file mode 100644 index 811527a..0000000 --- a/src/com/android/camera/ui/GLView.java +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Matrix; -import android.graphics.Rect; -import android.os.SystemClock; -import android.view.MotionEvent; -import android.view.View; -import android.view.animation.Animation; -import android.view.animation.Transformation; - -import java.util.ArrayList; -import javax.microedition.khronos.opengles.GL11; - -public class GLView { - @SuppressWarnings("unused") - private static final String TAG = "GLView"; - - public static final int VISIBLE = 0; - public static final int INVISIBLE = 1; - - public static final int FLAG_INVISIBLE = 1; - public static final int FLAG_SET_MEASURED_SIZE = 2; - public static final int FLAG_LAYOUT_REQUESTED = 4; - - protected final Rect mBounds = new Rect(); - protected final Rect mPaddings = new Rect(); - - private GLRootView mRootView; - private GLView mParent; - private ArrayList<GLView> mComponents; - private GLView mMotionTarget; - - private OnTouchListener mOnTouchListener; - private Animation mAnimation; - - protected int mViewFlags = 0; - - protected int mMeasuredWidth = 0; - protected int mMeasuredHeight = 0; - - private int mLastWidthSpec = -1; - private int mLastHeightSpec = -1; - - protected int mScrollY = 0; - protected int mScrollX = 0; - protected int mScrollHeight = 0; - protected int mScrollWidth = 0; - - public void startAnimation(Animation animation) { - GLRootView root = getGLRootView(); - if (root == null) throw new IllegalStateException(); - - mAnimation = animation; - animation.initialize(getWidth(), - getHeight(), mParent.getWidth(), mParent.getHeight()); - mAnimation.start(); - root.registerLaunchedAnimation(animation); - invalidate(); - } - - public void setVisibility(int visibility) { - if (visibility == getVisibility()) return; - if (visibility == VISIBLE) { - mViewFlags &= ~FLAG_INVISIBLE; - } else { - mViewFlags |= FLAG_INVISIBLE; - } - invalidate(); - - // Trigger the onVisibilityChanged() if it is visible on the screen. - if (isVisible()) onVisibilityChanged(visibility); - } - - public boolean isVisible() { - if (mRootView == null || mRootView.getVisibility() != View.VISIBLE) { - return false; - } - GLView parent = mParent; - while (parent != null) { - if (parent.getVisibility() == GLView.INVISIBLE) return false; - parent = parent.mParent; - } - return true; - } - - public int getVisibility() { - return (mViewFlags & FLAG_INVISIBLE) == 0 ? VISIBLE : INVISIBLE; - } - - public static interface OnTouchListener { - public boolean onTouch(GLView view, MotionEvent event); - } - - private boolean setBounds(int left, int top, int right, int bottom) { - boolean sizeChanged = (right - left) != (mBounds.right - mBounds.left) - || (bottom - top) != (mBounds.bottom - mBounds.top); - mBounds.set(left, top, right, bottom); - return sizeChanged; - } - - protected void onAddToParent(GLView parent) { - // TODO: enable the check - // if (mParent != null) throw new IllegalStateException(); - mParent = parent; - if (parent != null && parent.mRootView != null) { - onAttachToRoot(parent.mRootView); - } - } - - protected void onRemoveFromParent(GLView parent) { - if (parent != null && parent.mMotionTarget == this) { - long now = SystemClock.uptimeMillis(); - dispatchTouchEvent(MotionEvent.obtain( - now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0)); - parent.mMotionTarget = null; - } - onDetachFromRoot(); - mParent = null; - } - - public void clearComponents() { - mComponents = null; - } - - public int getComponentCount() { - return mComponents == null ? 0 : mComponents.size(); - } - - public GLView getComponent(int index) { - if (mComponents == null) { - throw new ArrayIndexOutOfBoundsException(index); - } - return mComponents.get(index); - } - - public void addComponent(GLView component) { - if (mComponents == null) { - mComponents = new ArrayList<GLView>(); - } - mComponents.add(component); - component.onAddToParent(this); - if (isVisible()) component.onVisibilityChanged(VISIBLE); - } - - public boolean removeComponent(GLView component) { - if (mComponents == null) return false; - if (mComponents.remove(component)) { - component.onRemoveFromParent(this); - return true; - } - return false; - } - - public Rect bounds() { - return mBounds; - } - - public int getWidth() { - return mBounds.right - mBounds.left; - } - - public int getHeight() { - return mBounds.bottom - mBounds.top; - } - - public GLRootView getGLRootView() { - return mRootView; - } - - public void setOnTouchListener(OnTouchListener listener) { - mOnTouchListener = listener; - } - - public void invalidate() { - GLRootView root = getGLRootView(); - if (root != null) root.requestRender(); - } - - public void requestLayout() { - mViewFlags |= FLAG_LAYOUT_REQUESTED; - if (mParent != null) { - mParent.requestLayout(); - } else { - // Is this a content pane ? - GLRootView root = getGLRootView(); - if (root != null) root.requestLayoutContentPane(); - } - } - - protected void render(GLRootView view, GL11 gl) { - renderBackground(view, gl); - for (int i = 0, n = getComponentCount(); i < n; ++i) { - GLView component = getComponent(i); - if (component.getVisibility() != GLView.VISIBLE - && component.mAnimation == null) continue; - renderChild(view, gl, component); - } - } - - protected void renderBackground(GLRootView view, GL11 gl) { - } - - protected void renderChild(GLRootView root, GL11 gl, GLView component) { - int xoffset = component.mBounds.left - mScrollX; - int yoffset = component.mBounds.top - mScrollY; - - Transformation transform = root.getTransformation(); - Matrix matrix = transform.getMatrix(); - matrix.preTranslate(xoffset, yoffset); - - Animation anim = component.mAnimation; - if (anim != null) { - long now = root.currentAnimationTimeMillis(); - Transformation temp = root.obtainTransformation(); - if (!anim.getTransformation(now, temp)) { - component.mAnimation = null; - } - invalidate(); - root.pushTransform(); - transform.compose(temp); - root.freeTransformation(temp); - } - component.render(root, gl); - if (anim != null) root.popTransform(); - matrix.preTranslate(-xoffset, -yoffset); - } - - protected boolean onTouch(MotionEvent event) { - if (mOnTouchListener != null) { - return mOnTouchListener.onTouch(this, event); - } - return false; - } - - private boolean dispatchTouchEvent(MotionEvent event, - int x, int y, GLView component, boolean checkBounds) { - Rect rect = component.mBounds; - int left = rect.left; - int top = rect.top; - if (!checkBounds || rect.contains(x, y)) { - event.offsetLocation(-left, -top); - if (component.dispatchTouchEvent(event)) { - event.offsetLocation(left, top); - return true; - } - event.offsetLocation(left, top); - } - return false; - } - - protected boolean dispatchTouchEvent(MotionEvent event) { - int x = (int) event.getX(); - int y = (int) event.getY(); - int action = event.getAction(); - if (mMotionTarget != null) { - if (action == MotionEvent.ACTION_DOWN) { - MotionEvent cancel = MotionEvent.obtain(event); - cancel.setAction(MotionEvent.ACTION_CANCEL); - mMotionTarget = null; - } else { - dispatchTouchEvent(event, x, y, mMotionTarget, false); - if (action == MotionEvent.ACTION_CANCEL - || action == MotionEvent.ACTION_UP) { - mMotionTarget = null; - } - return true; - } - } - if (action == MotionEvent.ACTION_DOWN) { - for (int i = 0, n = getComponentCount(); i < n; ++i) { - GLView component = getComponent(i); - if (component.getVisibility() != GLView.VISIBLE) continue; - if (dispatchTouchEvent(event, x, y, component, true)) { - mMotionTarget = component; - return true; - } - } - } - return onTouch(event); - } - - public Rect getPaddings() { - return mPaddings; - } - - public void setPaddings(Rect paddings) { - mPaddings.set(paddings); - } - - public void setPaddings(int left, int top, int right, int bottom) { - mPaddings.set(left, top, right, bottom); - } - - public void layout(int left, int top, int right, int bottom) { - boolean sizeChanged = setBounds(left, top, right, bottom); - if (sizeChanged) { - mViewFlags &= ~FLAG_LAYOUT_REQUESTED; - onLayout(true, left, top, right, bottom); - } else if ((mViewFlags & FLAG_LAYOUT_REQUESTED)!= 0) { - mViewFlags &= ~FLAG_LAYOUT_REQUESTED; - onLayout(false, left, top, right, bottom); - } - } - - public void measure(int widthSpec, int heightSpec) { - if (widthSpec == mLastWidthSpec && heightSpec == mLastHeightSpec - && (mViewFlags & FLAG_LAYOUT_REQUESTED) == 0) { - return; - } - - mLastWidthSpec = widthSpec; - mLastHeightSpec = heightSpec; - - mViewFlags &= ~FLAG_SET_MEASURED_SIZE; - onMeasure(widthSpec, heightSpec); - if ((mViewFlags & FLAG_SET_MEASURED_SIZE) == 0) { - throw new IllegalStateException(getClass().getName() - + " should call setMeasuredSize() in onMeasure()"); - } - } - - protected void onMeasure(int widthSpec, int heightSpec) { - } - - protected void setMeasuredSize(int width, int height) { - mViewFlags |= FLAG_SET_MEASURED_SIZE; - mMeasuredWidth = width; - mMeasuredHeight = height; - } - - public int getMeasuredWidth() { - return mMeasuredWidth; - } - - public int getMeasuredHeight() { - return mMeasuredHeight; - } - - protected void onLayout( - boolean changeSize, int left, int top, int right, int bottom) { - } - - /** - * Gets the bounds of the given descendant that relative to this view. - */ - public boolean getBoundsOf(GLView descendant, Rect out) { - int xoffset = 0; - int yoffset = 0; - GLView view = descendant; - while (view != this) { - if (view == null) return false; - Rect bounds = view.mBounds; - xoffset += bounds.left; - yoffset += bounds.top; - view = view.mParent; - } - out.set(xoffset, yoffset, xoffset + descendant.getWidth(), - yoffset + descendant.getHeight()); - return true; - } - - protected void onVisibilityChanged(int visibility) { - for (int i = 0, n = getComponentCount(); i < n; ++i) { - getComponent(i).onVisibilityChanged(visibility); - } - } - - protected void onAttachToRoot(GLRootView root) { - mRootView = root; - for (int i = 0, n = getComponentCount(); i < n; ++i) { - getComponent(i).onAttachToRoot(root); - } - } - - protected void onDetachFromRoot() { - for (int i = 0, n = getComponentCount(); i < n; ++i) { - getComponent(i).onDetachFromRoot(); - } - mRootView = null; - } -} diff --git a/src/com/android/camera/ui/MeasureHelper.java b/src/com/android/camera/ui/MeasureHelper.java deleted file mode 100644 index 370035a..0000000 --- a/src/com/android/camera/ui/MeasureHelper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Rect; -import android.view.View.MeasureSpec; - -class MeasureHelper { - - private final GLView mComponent; - private int mPreferredWidth; - private int mPreferredHeight; - - public MeasureHelper(GLView component) { - mComponent = component; - } - - public MeasureHelper setPreferredContentSize(int width, int height) { - mPreferredWidth = width; - mPreferredHeight = height; - return this; - } - - public void measure(int widthSpec, int heightSpec) { - Rect p = mComponent.getPaddings(); - setMeasuredSize( - getLength(widthSpec, mPreferredWidth + p.left + p.right), - getLength(heightSpec, mPreferredHeight + p.top + p.bottom)); - } - - private static int getLength(int measureSpec, int prefered) { - int specLength = MeasureSpec.getSize(measureSpec); - switch(MeasureSpec.getMode(measureSpec)) { - case MeasureSpec.EXACTLY: return specLength; - case MeasureSpec.AT_MOST: return Math.min(prefered, specLength); - default: return prefered; - } - } - - protected void setMeasuredSize(int width, int height) { - mComponent.setMeasuredSize(width, height); - } - -} diff --git a/src/com/android/camera/ui/NinePatchChunk.java b/src/com/android/camera/ui/NinePatchChunk.java deleted file mode 100644 index d4611ef..0000000 --- a/src/com/android/camera/ui/NinePatchChunk.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.android.camera.ui; - -import android.graphics.Rect; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -// See "frameworks/base/include/utils/ResourceTypes.h" for the format of -// NinePatch chunk. -class NinePatchChunk { - - public static final int NO_COLOR = 0x00000001; - public static final int TRANSPARENT_COLOR = 0x00000000; - - public Rect mPaddings = new Rect(); - - public int mDivX[]; - public int mDivY[]; - public int mColor[]; - - private static void readIntArray(int[] data, ByteBuffer buffer) { - for (int i = 0, n = data.length; i < n; ++i) { - data[i] = buffer.getInt(); - } - } - - private static void checkDivCount(int length) { - if (length == 0 || (length & 0x01) != 0) { - throw new RuntimeException("invalid nine-patch: " + length); - } - } - - public static NinePatchChunk deserialize(byte[] data) { - ByteBuffer byteBuffer = - ByteBuffer.wrap(data).order(ByteOrder.nativeOrder()); - - byte wasSerialized = byteBuffer.get(); - if (wasSerialized == 0) return null; - - NinePatchChunk chunk = new NinePatchChunk(); - chunk.mDivX = new int[byteBuffer.get()]; - chunk.mDivY = new int[byteBuffer.get()]; - chunk.mColor = new int[byteBuffer.get()]; - - checkDivCount(chunk.mDivX.length); - checkDivCount(chunk.mDivY.length); - - // skip 8 bytes - byteBuffer.getInt(); - byteBuffer.getInt(); - - chunk.mPaddings.left = byteBuffer.getInt(); - chunk.mPaddings.right = byteBuffer.getInt(); - chunk.mPaddings.top = byteBuffer.getInt(); - chunk.mPaddings.bottom = byteBuffer.getInt(); - - // skip 4 bytes - byteBuffer.getInt(); - - readIntArray(chunk.mDivX, byteBuffer); - readIntArray(chunk.mDivY, byteBuffer); - readIntArray(chunk.mColor, byteBuffer); - - return chunk; - } -}
\ No newline at end of file diff --git a/src/com/android/camera/ui/NinePatchTexture.java b/src/com/android/camera/ui/NinePatchTexture.java deleted file mode 100644 index 1321ed8..0000000 --- a/src/com/android/camera/ui/NinePatchTexture.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Rect; - -class NinePatchTexture extends ResourceTexture { - private NinePatchChunk mChunk; - - public NinePatchTexture(Context context, int resId) { - super(context, resId); - } - - @Override - protected Bitmap getBitmap() { - if (mBitmap != null) return mBitmap; - - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeResource( - mContext.getResources(), mResId, options); - mBitmap = bitmap; - setSize(bitmap.getWidth(), bitmap.getHeight()); - mChunk = NinePatchChunk.deserialize(bitmap.getNinePatchChunk()); - if (mChunk == null) { - throw new RuntimeException("invalid nine-patch image: " + mResId); - } - return bitmap; - } - - public Rect getPaddings() { - // get the paddings from nine patch - if (mChunk == null) getBitmap(); - return mChunk.mPaddings; - } - - public NinePatchChunk getNinePatchChunk() { - if (mChunk == null) getBitmap(); - return mChunk; - } - - @Override - public void draw(GLRootView root, int x, int y, int w, int h) { - root.drawNinePatch(this, x, y, w, h); - } -} diff --git a/src/com/android/camera/ui/PreferenceAdapter.java b/src/com/android/camera/ui/PreferenceAdapter.java deleted file mode 100644 index d1a094b..0000000 --- a/src/com/android/camera/ui/PreferenceAdapter.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.content.Context; - -import com.android.camera.IconListPreference; -import com.android.camera.ListPreference; -import com.android.camera.Util; - -import java.util.ArrayList; - -class PreferenceAdapter - implements GLListView.Model, GLListView.OnItemSelectedListener { - - private static final int ICON_NONE = 0; - - private final ArrayList<GLView> mContent = new ArrayList<GLView>(); - private final ListPreference mPreference; - private String mOverride; - - public PreferenceAdapter(Context context, ListPreference preference) { - mPreference = preference; - generateContent(context, preference); - } - - public void reload() { - updateContent(null, true); - } - - public void overrideSettings(String settings) { - updateContent(settings, false); - } - - private void updateContent(String settings, boolean reloadValues) { - if (!reloadValues && Util.equals(settings, mOverride)) return; - mOverride = settings; - - CharSequence[] values = mPreference.getEntryValues(); - String value = mPreference.getValue(); - if (settings == null) { - for (int i = 1, n = mContent.size(); i < n; ++i) { - GLOptionItem item = (GLOptionItem) mContent.get(i); - item.setChecked(values[i - 1].equals(value)); - item.setEnabled(true); - } - } else { - for (int i = 1, n = mContent.size(); i < n; ++i) { - GLOptionItem item = (GLOptionItem) mContent.get(i); - boolean checked = values[i - 1].equals(settings); - item.setChecked(checked); - item.setEnabled(checked); - } - } - } - - private void generateContent(Context context, ListPreference preference) { - GLOptionHeader header = - new GLOptionHeader(context, preference.getTitle()); - mContent.add(header); - CharSequence[] entries = preference.getEntries(); - CharSequence[] values = preference.getEntryValues(); - String value = preference.getValue(); - int [] icons = null; - if (preference instanceof IconListPreference) { - IconListPreference iPref = (IconListPreference) preference; - icons = iPref.getIconIds(); - } - for (int i = 0, n = entries.length; i < n; ++i) { - GLOptionItem item = new GLOptionItem( - context, icons == null ? ICON_NONE : icons[i], - entries[i].toString()); - item.setChecked(values[i].equals(value)); - mContent.add(item); - } - } - - public void onItemSelected(GLView view, int position) { - if (mOverride != null) return; - ListPreference pref = mPreference; - CharSequence[] values = pref.getEntryValues(); - if (position < values.length + 1) { - int index = position - 1; - int oldIndex = pref.findIndexOfValue(pref.getValue()); - if (oldIndex != index) { - synchronized (pref.getSharedPreferences()) { - pref.setValueIndex(index); - } - ((GLOptionItem) mContent.get(1 + oldIndex)).setChecked(false); - ((GLOptionItem) view).setChecked(true); - } - return; - } - } - - public GLView getView(int index) { - return mContent.get(index); - } - - public boolean isSelectable(int index) { - return mContent.get(index) instanceof GLOptionItem; - } - - public int size() { - return mContent.size(); - } -} diff --git a/src/com/android/camera/ui/RawTexture.java b/src/com/android/camera/ui/RawTexture.java deleted file mode 100644 index c6073a1..0000000 --- a/src/com/android/camera/ui/RawTexture.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - - -import javax.microedition.khronos.opengles.GL11; - -class RawTexture extends BasicTexture { - - private RawTexture(GL11 gl, int id) { - super(gl, id, STATE_LOADED); - } - - public GL11 getBoundGL() { - return mGL; - } - - public static RawTexture newInstance(GL11 gl) { - int[] textureId = new int[1]; - gl.glGenTextures(1, textureId, 0); - int glError = gl.glGetError(); - if (glError != GL11.GL_NO_ERROR) { - throw new RuntimeException("GL_ERROR: " + glError); - } - return new RawTexture(gl, textureId[0]); - } - - @Override - protected boolean bind(GLRootView glRootView, GL11 gl) { - if (mGL == gl) { - gl.glBindTexture(GL11.GL_TEXTURE_2D, getId()); - return true; - } - return false; - } - - public void drawBack(GLRootView root, int x, int y, int w, int h) { - root.drawTexture(this, x, y, w, h, 1f); - } -} diff --git a/src/com/android/camera/ui/ResourceTexture.java b/src/com/android/camera/ui/ResourceTexture.java deleted file mode 100644 index 4136dfa..0000000 --- a/src/com/android/camera/ui/ResourceTexture.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import com.android.camera.Util; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - -class ResourceTexture extends BitmapTexture { - - protected final Context mContext; - protected final int mResId; - protected Bitmap mBitmap; - - public ResourceTexture(Context context, int resId) { - mContext = Util.checkNotNull(context); - mResId = resId; - } - - @Override - protected Bitmap getBitmap() { - if (mBitmap != null) return mBitmap; - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - mBitmap = BitmapFactory.decodeResource( - mContext.getResources(), mResId, options); - setSize(mBitmap.getWidth(), mBitmap.getHeight()); - return mBitmap; - } - - @Override - protected void freeBitmap(Bitmap bitmap) { - Util.Assert(bitmap == mBitmap); - bitmap.recycle(); - mBitmap = null; - } -} diff --git a/src/com/android/camera/ui/RestoreSettingsItem.java b/src/com/android/camera/ui/RestoreSettingsItem.java deleted file mode 100644 index 1a908a4..0000000 --- a/src/com/android/camera/ui/RestoreSettingsItem.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import static com.android.camera.ui.GLRootView.dpToPixel; -import android.content.Context; -import android.graphics.Color; -import android.graphics.Rect; - -import javax.microedition.khronos.opengles.GL11; - -class RestoreSettingsItem extends GLView { - private static final int FONT_COLOR = Color.WHITE; - private static final float FONT_SIZE = 18; - - private static final int LEFT_PADDING = 20; - private static final int RIGHT_PADDING = 4; - private static final int TOP_PADDING = 2; - private static final int BOTTOM_PADDING = 2; - - private static int sLeftPadding = -1; - private static int sRightPadding; - private static int sTopPadding; - private static int sBottomPadding; - private static float sFontSize; - - private final StringTexture mText; - - private static void initializeStaticVariables(Context context) { - if (sLeftPadding >= 0) return; - - sLeftPadding = dpToPixel(context, LEFT_PADDING); - sRightPadding = dpToPixel(context, RIGHT_PADDING); - sTopPadding = dpToPixel(context, TOP_PADDING); - sBottomPadding = dpToPixel(context, BOTTOM_PADDING); - sFontSize = dpToPixel(context, FONT_SIZE); - } - - public RestoreSettingsItem(Context context, String title) { - initializeStaticVariables(context); - mText = StringTexture.newInstance(title, sFontSize, FONT_COLOR); - setPaddings(sLeftPadding, sTopPadding, sRightPadding, sBottomPadding); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - new MeasureHelper(this) - .setPreferredContentSize(mText.getWidth(), mText.getHeight()) - .measure(widthSpec, heightSpec); - } - - @Override - protected void render(GLRootView root, GL11 gl) { - Rect p = mPaddings; - int height = getHeight() - p.top - p.bottom; - - StringTexture title = mText; - //TODO: cut the text if it is too long - title.draw(root, p.left, p.top + (height - title.getHeight()) / 2); - } -} diff --git a/src/com/android/camera/ui/RotatePane.java b/src/com/android/camera/ui/RotatePane.java deleted file mode 100644 index 45f6a0d..0000000 --- a/src/com/android/camera/ui/RotatePane.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Matrix; -import android.view.MotionEvent; - -import javax.microedition.khronos.opengles.GL11; - - -class RotatePane extends GLView { - - public static final int UP = 0; - public static final int RIGHT = 1; - public static final int DOWN = 2; - public static final int LEFT = 3; - - private int mOrientation = 0; - - private GLView mChild; - - @Override - protected void onLayout( - boolean change, int left, int top, int right, int bottom) { - int width = right - left; - int height = bottom - top; - switch (mOrientation) { - case UP: - case DOWN: - mChild.layout(0, 0, width, height); - break; - case LEFT: - case RIGHT: - mChild.layout(0, 0, height, width); - break; - } - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - GLView c = mChild; - switch(mOrientation) { - case UP: - case DOWN: - c.measure(widthSpec, heightSpec); - setMeasuredSize(c.getMeasuredWidth(), c.getMeasuredHeight()); - break; - case LEFT: - case RIGHT: - mChild.measure(heightSpec, widthSpec); - setMeasuredSize(c.getMeasuredHeight(), c.getMeasuredWidth()); - } - } - - @Override - protected void render(GLRootView view, GL11 gl) { - - if (mOrientation == UP) { - mChild.render(view, gl); - return; - } - - view.pushTransform(); - Matrix matrix = view.getTransformation().getMatrix(); - float width = getWidth(); - float height = getHeight(); - switch (mOrientation) { - case DOWN: - matrix.preRotate(180, width / 2, height / 2); - break; - case LEFT: - matrix.preRotate(270, height / 2, height / 2); - break; - case RIGHT: - matrix.preRotate(90, width / 2, width / 2); - break; - } - mChild.render(view, gl); - view.popTransform(); - } - - @Override - protected boolean dispatchTouchEvent(MotionEvent event) { - float x = event.getX(); - float y = event.getY(); - float width = getWidth(); - float height = getHeight(); - switch (mOrientation) { - case DOWN: event.setLocation(width - x, height - y); break; - case LEFT: event.setLocation(height - y, x); break; - case RIGHT: event.setLocation(y, width - x); break; - } - boolean result = mChild.dispatchTouchEvent(event); - event.setLocation(x, y); - return result; - } - - public void setOrientation(int orientation) { - if (mOrientation == orientation) return; - mOrientation = orientation; - requestLayout(); - } - - public void setContent(GLView view) { - if (mChild == view) return; - if (mChild != null) super.removeComponent(mChild); - mChild = view; - if (view != null) super.addComponent(view); - requestLayout(); - } - - @Override - public void addComponent(GLView view) { - throw new UnsupportedOperationException("use setContent(GLView)"); - } -} diff --git a/src/com/android/camera/ui/StringTexture.java b/src/com/android/camera/ui/StringTexture.java deleted file mode 100644 index 94c3185..0000000 --- a/src/com/android/camera/ui/StringTexture.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Paint.FontMetricsInt; - -class StringTexture extends CanvasTexture { - private static int DEFAULT_PADDING = 1; - - private final String mText; - private final Paint mPaint; - private final FontMetricsInt mMetrics; - - public StringTexture(String text, Paint paint, - FontMetricsInt metrics, int width, int height) { - super(width, height); - mText = text; - mPaint = paint; - mMetrics = metrics; - } - - - public static StringTexture newInstance(String text, Paint paint) { - FontMetricsInt metrics = paint.getFontMetricsInt(); - int width = (int) (.5f + paint.measureText(text)) + DEFAULT_PADDING * 2; - int height = metrics.bottom - metrics.top + DEFAULT_PADDING * 2; - return new StringTexture(text, paint, metrics, width, height); - } - - public static StringTexture newInstance( - String text, float textSize, int color) { - Paint paint = new Paint(); - paint.setTextSize(textSize); - paint.setAntiAlias(true); - paint.setColor(color); - - return newInstance(text, paint); - } - - @Override - protected void onDraw(Canvas canvas, Bitmap backing) { - canvas.translate(DEFAULT_PADDING, DEFAULT_PADDING - mMetrics.ascent); - canvas.drawText(mText, 0, 0, mPaint); - } -} diff --git a/src/com/android/camera/ui/Texture.java b/src/com/android/camera/ui/Texture.java deleted file mode 100644 index c0d841b..0000000 --- a/src/com/android/camera/ui/Texture.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -interface Texture { - public void draw(GLRootView root, int x, int y); - public void draw(GLRootView root, int x, int y, int w, int h); -} diff --git a/src/com/android/camera/ui/ZoomController.java b/src/com/android/camera/ui/ZoomController.java deleted file mode 100644 index 9b9c2f1..0000000 --- a/src/com/android/camera/ui/ZoomController.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import static com.android.camera.ui.GLRootView.dpToPixel; -import android.content.Context; -import android.graphics.Color; -import android.graphics.Rect; -import android.view.MotionEvent; - -import com.android.camera.R; -import com.android.camera.Util; - -import java.text.DecimalFormat; -import java.util.Arrays; - -import javax.microedition.khronos.opengles.GL11; - -class ZoomController extends GLView { - private static final int LABEL_COLOR = Color.WHITE; - - private static final DecimalFormat sZoomFormat = new DecimalFormat("#.#x"); - private static final int INVALID_POSITION = Integer.MAX_VALUE; - - private static final float LABEL_FONT_SIZE = 18; - private static final int HORIZONTAL_PADDING = 3; - private static final int VERTICAL_PADDING = 3; - private static final int MINIMAL_HEIGHT = 150; - private static final float TOLERANCE_RADIUS = 30; - - private static float sLabelSize; - private static int sHorizontalPadding; - private static int sVerticalPadding; - private static int sMinimalHeight; - private static float sToleranceRadius; - - private static NinePatchTexture sBackground; - private static BitmapTexture sSlider; - private static BitmapTexture sTickMark; - private static BitmapTexture sFineTickMark; - - private StringTexture mTickLabels[]; - private float mRatios[]; - private int mIndex; - - private int mFineTickStep; - private int mLabelStep; - - private int mMaxLabelWidth; - private int mMaxLabelHeight; - - private int mSliderTop; - private int mSliderBottom; - private int mSliderLeft; - private int mSliderPosition = INVALID_POSITION; - private float mValueGap; - private ZoomControllerListener mZoomListener; - - public ZoomController(Context context) { - initializeStaticVariable(context); - } - - private void onSliderMoved(int position, boolean isMoving) { - position = Util.clamp(position, - mSliderTop, mSliderBottom - sSlider.getHeight()); - mSliderPosition = position; - invalidate(); - - int index = mRatios.length - 1 - (int) - ((position - mSliderTop) / mValueGap + .5f); - if (index != mIndex || !isMoving) { - mIndex = index; - if (mZoomListener != null) { - mZoomListener.onZoomChanged(mIndex, mRatios[mIndex], isMoving); - } - } - } - - private static void initializeStaticVariable(Context context) { - if (sBackground != null) return; - - sLabelSize = dpToPixel(context, LABEL_FONT_SIZE); - sHorizontalPadding = dpToPixel(context, HORIZONTAL_PADDING); - sVerticalPadding = dpToPixel(context, VERTICAL_PADDING); - sMinimalHeight = dpToPixel(context, MINIMAL_HEIGHT); - sToleranceRadius = dpToPixel(context, TOLERANCE_RADIUS); - - sBackground = new NinePatchTexture(context, R.drawable.zoom_background); - sSlider = new ResourceTexture(context, R.drawable.zoom_slider); - sTickMark = new ResourceTexture(context, R.drawable.zoom_tickmark); - sFineTickMark = new ResourceTexture( - context, R.drawable.zoom_finetickmark); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - if (!changed) return; - Rect p = mPaddings; - int height = b - t - p.top - p.bottom; - int margin = Math.max(sSlider.getHeight(), mMaxLabelHeight); - mValueGap = (float) (height - margin) / (mRatios.length - 1); - - mSliderLeft = p.left + mMaxLabelWidth + sHorizontalPadding - + sTickMark.getWidth() + sHorizontalPadding; - - mSliderTop = p.top + margin / 2 - sSlider.getHeight() / 2; - mSliderBottom = mSliderTop + height - margin + sSlider.getHeight(); - } - - private boolean withInToleranceRange(float x, float y) { - float sx = mSliderLeft + sSlider.getWidth() / 2; - float sy = mSliderTop + (mRatios.length - 1 - mIndex) * mValueGap - + sSlider.getHeight() / 2; - float dist = Util.distance(x, y, sx, sy); - return dist <= sToleranceRadius; - } - - @Override - protected boolean onTouch(MotionEvent e) { - float x = e.getX(); - float y = e.getY(); - switch (e.getAction()) { - case MotionEvent.ACTION_DOWN: - if (withInToleranceRange(x, y)) { - onSliderMoved((int) (y - sSlider.getHeight()), true); - } - return true; - case MotionEvent.ACTION_MOVE: - if (mSliderPosition != INVALID_POSITION) { - onSliderMoved((int) (y - sSlider.getHeight()), true); - } - return true; - case MotionEvent.ACTION_UP: - if (mSliderPosition != INVALID_POSITION) { - onSliderMoved((int) (y - sSlider.getHeight()), false); - mSliderPosition = INVALID_POSITION; - } - return true; - } - return true; - } - - public void setAvailableZoomRatios(float ratios[]) { - if (Arrays.equals(ratios, mRatios)) return; - mRatios = ratios; - mLabelStep = getLabelStep(ratios.length); - mTickLabels = new StringTexture[ - (ratios.length + mLabelStep - 1) / mLabelStep]; - for (int i = 0, n = mTickLabels.length; i < n; ++i) { - mTickLabels[i] = StringTexture.newInstance( - sZoomFormat.format(ratios[i * mLabelStep]), - sLabelSize, LABEL_COLOR); - } - mFineTickStep = mLabelStep % 3 == 0 - ? mLabelStep / 3 - : mLabelStep %2 == 0 ? mLabelStep / 2 : 0; - - int maxHeight = 0; - int maxWidth = 0; - int labelCount = mTickLabels.length; - for (int i = 0; i < labelCount; ++i) { - maxWidth = Math.max(maxWidth, mTickLabels[i].getWidth()); - maxHeight = Math.max(maxHeight, mTickLabels[i].getHeight()); - } - - mMaxLabelHeight = maxHeight; - mMaxLabelWidth = maxWidth; - invalidate(); - } - - private int getLabelStep(final int valueCount) { - if (valueCount < 5) return 1; - for (int step = valueCount / 5;; ++step) { - if (valueCount / step <= 5) return step; - } - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - int labelCount = mTickLabels.length; - int ratioCount = mRatios.length; - - int height = (mMaxLabelHeight + sVerticalPadding) - * (labelCount - 1) * ratioCount / (mLabelStep * labelCount) - + Math.max(sSlider.getHeight(), mMaxLabelHeight); - - int width = mMaxLabelWidth + sHorizontalPadding + sTickMark.getWidth() - + sHorizontalPadding + sBackground.getWidth(); - height = Math.max(sMinimalHeight, height); - - new MeasureHelper(this) - .setPreferredContentSize(width, height) - .measure(widthSpec, heightSpec); - } - - @Override - protected void render(GLRootView root, GL11 gl) { - renderTicks(root, gl); - renderSlider(root, gl); - } - - private void renderTicks(GLRootView root, GL11 gl) { - float gap = mValueGap; - int labelStep = mLabelStep; - - // render the tick labels - int xoffset = mPaddings.left + mMaxLabelWidth; - float yoffset = mSliderBottom - sSlider.getHeight() / 2; - for (int i = 0, n = mTickLabels.length; i < n; ++i) { - BitmapTexture t = mTickLabels[i]; - t.draw(root, xoffset - t.getWidth(), - (int) (yoffset - t.getHeight() / 2)); - yoffset -= labelStep * gap; - } - - // render the main tick marks - BitmapTexture tickMark = sTickMark; - xoffset += sHorizontalPadding; - yoffset = mSliderBottom - sSlider.getHeight() / 2; - int halfHeight = tickMark.getHeight() / 2; - for (int i = 0, n = mTickLabels.length; i < n; ++i) { - tickMark.draw(root, xoffset, (int) (yoffset - halfHeight)); - yoffset -= labelStep * gap; - } - - if (mFineTickStep > 0) { - // render the fine tick marks - tickMark = sFineTickMark; - xoffset += sTickMark.getWidth() - tickMark.getWidth(); - yoffset = mSliderBottom - sSlider.getHeight() / 2; - halfHeight = tickMark.getHeight() / 2; - for (int i = 0, n = mRatios.length; i < n; ++i) { - if (i % mLabelStep != 0) { - tickMark.draw(root, xoffset, (int) (yoffset - halfHeight)); - } - yoffset -= gap; - } - } - } - - private void renderSlider(GLRootView root, GL11 gl) { - int left = mSliderLeft; - int bottom = mSliderBottom; - int top = mSliderTop; - sBackground.draw(root, left, top, sBackground.getWidth(), bottom - top); - - if (mSliderPosition == INVALID_POSITION) { - sSlider.draw(root, left, (int) - (top + mValueGap * (mRatios.length - 1 - mIndex))); - } else { - sSlider.draw(root, left, mSliderPosition); - } - } - - public void setZoomListener(ZoomControllerListener listener) { - mZoomListener = listener; - } - - public void setZoomIndex(int index) { - index = Util.clamp(index, 0, mRatios.length - 1); - if (mIndex == index) return; - mIndex = index; - if (mZoomListener != null) { - mZoomListener.onZoomChanged(mIndex, mRatios[mIndex], false); - } - } -} diff --git a/src/com/android/camera/ui/ZoomControllerListener.java b/src/com/android/camera/ui/ZoomControllerListener.java deleted file mode 100644 index 165714f..0000000 --- a/src/com/android/camera/ui/ZoomControllerListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -public interface ZoomControllerListener { - public void onZoomChanged(int index, float ratio, boolean isMoving); -} - |