From a85c80227a56f3b7f917464096cd33877093616f Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 17 Aug 2011 22:07:43 +0800 Subject: Initial code for Gallery2. fix: 5176434 Change-Id: I041e282b9c7b34ceb1db8b033be2b853bb3a992c --- src/com/android/gallery3d/ui/ProgressBar.java | 65 +++++++++++++++++++ src/com/android/gallery3d/ui/ProgressSpinner.java | 78 +++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 src/com/android/gallery3d/ui/ProgressBar.java create mode 100644 src/com/android/gallery3d/ui/ProgressSpinner.java (limited to 'src') diff --git a/src/com/android/gallery3d/ui/ProgressBar.java b/src/com/android/gallery3d/ui/ProgressBar.java new file mode 100644 index 000000000..c62fa9a62 --- /dev/null +++ b/src/com/android/gallery3d/ui/ProgressBar.java @@ -0,0 +1,65 @@ +/* + * 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.gallery3d.ui; + +import android.content.Context; +import android.graphics.Rect; + +public class ProgressBar extends GLView { + private final int MAX_PROGRESS = 10000; + private int mProgress; + private int mSecondaryProgress; + private BasicTexture mProgressTexture; + private BasicTexture mSecondaryProgressTexture; + private BasicTexture mBackgrondTexture; + + + public ProgressBar(Context context, int resProgress, + int resSecondaryProgress, int resBackground) { + mProgressTexture = new NinePatchTexture(context, resProgress); + mSecondaryProgressTexture = new NinePatchTexture( + context, resSecondaryProgress); + mBackgrondTexture = new NinePatchTexture(context, resBackground); + + } + + // The progress value is between 0 (empty) and MAX_PROGRESS (full). + public void setProgress(int progress) { + mProgress = progress; + } + + public void setSecondaryProgress(int progress) { + mSecondaryProgress = progress; + } + + @Override + protected void render(GLCanvas canvas) { + Rect p = mPaddings; + + int width = getWidth() - p.left - p.right; + int height = getHeight() - p.top - p.bottom; + + int primary = width * mProgress / MAX_PROGRESS; + int secondary = width * mSecondaryProgress / MAX_PROGRESS; + int x = p.left; + int y = p.top; + + canvas.drawTexture(mBackgrondTexture, x, y, width, height); + canvas.drawTexture(mProgressTexture, x, y, primary, height); + canvas.drawTexture(mSecondaryProgressTexture, x, y, secondary, height); + } +} diff --git a/src/com/android/gallery3d/ui/ProgressSpinner.java b/src/com/android/gallery3d/ui/ProgressSpinner.java new file mode 100644 index 000000000..e4d60242b --- /dev/null +++ b/src/com/android/gallery3d/ui/ProgressSpinner.java @@ -0,0 +1,78 @@ +/* + * 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.gallery3d.ui; + +import com.android.gallery3d.R; + +import android.content.Context; + +public class ProgressSpinner { + private static float ROTATE_SPEED_OUTER = 1080f / 3500f; + private static float ROTATE_SPEED_INNER = -720f / 3500f; + private final ResourceTexture mOuter; + private final ResourceTexture mInner; + private final int mWidth; + private final int mHeight; + + private float mInnerDegree = 0f; + private float mOuterDegree = 0f; + private long mAnimationTimestamp = -1; + + public ProgressSpinner(Context context) { + mOuter = new ResourceTexture(context, R.drawable.spinner_76_outer_holo); + mInner = new ResourceTexture(context, R.drawable.spinner_76_inner_holo); + + mWidth = Math.max(mOuter.getWidth(), mInner.getWidth()); + mHeight = Math.max(mOuter.getHeight(), mInner.getHeight()); + } + + public int getWidth() { + return mWidth; + } + + public int getHeight() { + return mHeight; + } + + public void startAnimation() { + mAnimationTimestamp = -1; + mOuterDegree = 0; + mInnerDegree = 0; + } + + public void draw(GLCanvas canvas, int x, int y) { + long now = canvas.currentAnimationTimeMillis(); + if (mAnimationTimestamp == -1) mAnimationTimestamp = now; + mOuterDegree += (now - mAnimationTimestamp) * ROTATE_SPEED_OUTER; + mInnerDegree += (now - mAnimationTimestamp) * ROTATE_SPEED_INNER; + + mAnimationTimestamp = now; + + // just preventing overflow + if (mOuterDegree > 360) mOuterDegree -= 360f; + if (mInnerDegree < 0) mInnerDegree += 360f; + + canvas.save(GLCanvas.SAVE_FLAG_MATRIX); + + canvas.translate(x + mWidth / 2, y + mHeight / 2, 0); + canvas.rotate(mInnerDegree, 0, 0, 1); + mOuter.draw(canvas, -mOuter.getWidth() / 2, -mOuter.getHeight() / 2); + canvas.rotate(mOuterDegree - mInnerDegree, 0, 0, 1); + mInner.draw(canvas, -mInner.getWidth() / 2, -mInner.getHeight() / 2); + canvas.restore(); + } +} -- cgit v1.2.3