: (initialSize + 7) / 8 * 8;
}
- public static Bitmap resizeDownToPixels(
- Bitmap bitmap, int targetPixels, boolean recycle) {
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- float scale = FloatMath.sqrt((float) targetPixels / (width * height));
- if (scale >= 1.0f) return bitmap;
- return resizeBitmapByScale(bitmap, scale, recycle);
- }
-
public static Bitmap resizeBitmapByScale(
Bitmap bitmap, float scale, boolean recycle) {
int width = Math.round(bitmap.getWidth() * scale);
return resizeBitmapByScale(bitmap, scale, recycle);
}
- // Crops a square from the center of the original image.
- public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) {
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- if (width == height) return bitmap;
- int size = Math.min(width, height);
-
- Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
- Canvas canvas = new Canvas(target);
- canvas.translate((size - width) / 2, (size - height) / 2);
- Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
- canvas.drawBitmap(bitmap, 0, 0, paint);
- if (recycle) bitmap.recycle();
- return target;
- }
-
public static Bitmap resizeDownAndCropCenter(Bitmap bitmap, int size,
boolean recycle) {
int w = bitmap.getWidth();
return (a == b) || (a == null ? false : a.equals(b));
}
- // Returns true if the input is power of 2.
- // Throws IllegalArgumentException if the input is <= 0.
- public static boolean isPowerOf2(int n) {
- if (n <= 0) throw new IllegalArgumentException();
- return (n & -n) == n;
- }
-
// Returns the next power of two.
// Returns the input if it is already power of 2.
// Throws IllegalArgumentException if the input is <= 0 or
return Integer.highestOneBit(n);
}
- // Returns the euclidean distance between (x, y) and (sx, sy).
- public static float distance(float x, float y, float sx, float sy) {
- float dx = x - sx;
- float dy = y - sy;
- return (float) Math.hypot(dx, dy);
- }
-
// Returns the input value x clamped to the range [min, max].
public static int clamp(int x, int min, int max) {
if (x > max) return max;
return color >>> 24 == 0xFF;
}
- public static <T> void swap(T[] array, int i, int j) {
- T temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
-
public static void swap(int[] array, int i, int j) {
int temp = array[i];
array[i] = array[j];
return value == null ? "" : value;
}
- // Used for debugging. Should be removed before submitting.
- public static void debug(String format, Object ... args) {
- if (args.length == 0) {
- Log.d(DEBUG_TAG, format);
- } else {
- Log.d(DEBUG_TAG, String.format(format, args));
- }
- }
-
public static float parseFloatSafely(String content, float defaultValue) {
if (content == null) return defaultValue;
try {
return TextUtils.isEmpty(exifMake);
}
- public static boolean hasSpaceForSize(long size) {
- String state = Environment.getExternalStorageState();
- if (!Environment.MEDIA_MOUNTED.equals(state)) {
- return false;
- }
-
- String path = Environment.getExternalStorageDirectory().getPath();
- try {
- StatFs stat = new StatFs(path);
- return stat.getAvailableBlocks() * (long) stat.getBlockSize() > size;
- } catch (Exception e) {
- Log.i(TAG, "Fail to access external storage", e);
- }
- return false;
- }
-
public static void waitWithoutInterrupt(Object object) {
try {
object.wait();
}
}
- public static void shuffle(int array[], Random random) {
- for (int i = array.length; i > 0; --i) {
- int t = random.nextInt(i);
- if (t == i - 1) continue;
- int tmp = array[i - 1];
- array[i - 1] = array[t];
- array[t] = tmp;
- }
- }
-
public static boolean handleInterrruptedException(Throwable e) {
// A helper to deal with the interrupt exception
// If an interrupt detected, we will setup the bit again.
return result;
}
- public static PendingIntent deserializePendingIntent(byte[] rawPendingIntent) {
- Parcel parcel = null;
- try {
- if (rawPendingIntent != null) {
- parcel = Parcel.obtain();
- parcel.unmarshall(rawPendingIntent, 0, rawPendingIntent.length);
- return PendingIntent.readPendingIntentOrNullFromParcel(parcel);
- } else {
- return null;
- }
- } catch (Exception e) {
- throw new IllegalArgumentException("error parsing PendingIntent");
- } finally {
- if (parcel != null) parcel.recycle();
- }
- }
-
- public static byte[] serializePendingIntent(PendingIntent pendingIntent) {
- Parcel parcel = null;
- try {
- parcel = Parcel.obtain();
- PendingIntent.writePendingIntentOrNullToParcel(pendingIntent, parcel);
- return parcel.marshall();
- } finally {
- if (parcel != null) parcel.recycle();
- }
- }
-
// Mask information for debugging only. It returns <code>info.toString()</code> directly
// for debugging build (i.e., 'eng' and 'userdebug') and returns a mask ("****")
// in release build to protect the information (e.g. for privacy issue).
+++ /dev/null
-/*
- * 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.anim;
-
-import com.android.gallery3d.ui.GLCanvas;
-
-import java.util.ArrayList;
-
-public class AnimationSet extends CanvasAnimation {
-
- private final ArrayList<CanvasAnimation> mAnimations =
- new ArrayList<CanvasAnimation>();
- private int mSaveFlags = 0;
-
-
- public void addAnimation(CanvasAnimation anim) {
- mAnimations.add(anim);
- mSaveFlags |= anim.getCanvasSaveFlags();
- }
-
- @Override
- public void apply(GLCanvas canvas) {
- for (int i = 0, n = mAnimations.size(); i < n; i++) {
- mAnimations.get(i).apply(canvas);
- }
- }
-
- @Override
- public int getCanvasSaveFlags() {
- return mSaveFlags;
- }
-
- @Override
- protected void onCalculate(float progress) {
- // DO NOTHING
- }
-
- @Override
- public boolean calculate(long currentTimeMillis) {
- boolean more = false;
- for (CanvasAnimation anim : mAnimations) {
- more |= anim.calculate(currentTimeMillis);
- }
- return more;
- }
-
- @Override
- public void start() {
- for (CanvasAnimation anim : mAnimations) {
- anim.start();
- }
- }
-
- @Override
- public boolean isActive() {
- for (CanvasAnimation anim : mAnimations) {
- if (anim.isActive()) return true;
- }
- return false;
- }
-
-}
private static final String TAG = "AbstractGalleryActivity";
private GLRootView mGLRootView;
private StateManager mStateManager;
- private PositionRepository mPositionRepository = new PositionRepository();
private AlertDialog mAlertDialog = null;
private BroadcastReceiver mMountReceiver = new BroadcastReceiver() {
return this;
}
- public ImageCacheService getImageCacheService() {
- return ((GalleryApp) getApplication()).getImageCacheService();
- }
-
public DataManager getDataManager() {
return ((GalleryApp) getApplication()).getDataManager();
}
return ((GalleryApp) getApplication()).getThreadPool();
}
- public GalleryApp getGalleryApplication() {
- return (GalleryApp) getApplication();
- }
-
public synchronized StateManager getStateManager() {
if (mStateManager == null) {
mStateManager = new StateManager(this);
return mGLRootView;
}
- public PositionRepository getPositionRepository() {
- return mPositionRepository;
- }
-
@Override
public void setContentView(int resId) {
super.setContentView(resId);
mGLRootView = (GLRootView) findViewById(R.id.gl_root_view);
}
- public int getActionBarHeight() {
- ActionBar actionBar = getActionBar();
- return actionBar != null ? actionBar.getHeight() : 0;
- }
-
protected void onStorageReady() {
if (mAlertDialog != null) {
mAlertDialog.dismiss();
public int requestCode;
public int resultCode = Activity.RESULT_CANCELED;
public Intent resultData;
- ResultEntry next;
}
private boolean mDestroyed = false;
return mActiveStart;
}
- public int getActiveEnd() {
- return mActiveEnd;
- }
-
public boolean isActive(int index) {
return index >= mActiveStart && index < mActiveEnd;
}
AlbumSetPage.class, REQUEST_DO_ANIMATION, data);
}
- public void doFilter(int filterType) {
- String basePath = mMediaSet.getPath().toString();
- String newPath = FilterUtils.switchFilterPath(basePath, filterType);
- Bundle data = new Bundle(getData());
- data.putString(AlbumPage.KEY_MEDIA_PATH, newPath);
- mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
- mActivity.getStateManager().switchState(this, AlbumPage.class, data);
- }
-
- public void onOperationComplete() {
- mAlbumView.invalidate();
- // TODO: enable animation
- }
-
@Override
protected void onCreate(Bundle data, Bundle restoreState) {
mUserDistance = GalleryUtils.meterToPixel(USER_DISTANCE_METER);
return mActiveStart;
}
- public int getActiveEnd() {
- return mActiveEnd;
- }
-
public boolean isActive(int index) {
return index >= mActiveStart && index < mActiveEnd;
}
mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);
}
- public void doFilter(int filterType) {
- String basePath = mMediaSet.getPath().toString();
- String newPath = FilterUtils.switchFilterPath(basePath, filterType);
- Bundle data = new Bundle(getData());
- data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath);
- mAlbumSetView.savePositions(PositionRepository.getInstance(mActivity));
- mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);
- }
-
- public void onOperationComplete() {
- mAlbumSetView.invalidate();
- // TODO: enable animation
- }
-
@Override
public void onCreate(Bundle data, Bundle restoreState) {
initializeViews();
void showErrorMessage(String message);
- void hide();
-
void setTimes(int currentTime, int totalTime);
-
- void resetTime();
-
}
return "/cluster/{" + base + "}/" + kind;
}
- // Change the topmost filter to the specified type.
- public static String switchFilterPath(String base, int filterType) {
- return newFilterPath(removeOneFilterFromPath(base), filterType);
- }
-
// Change the topmost clustering to the specified type.
public static String switchClusterPath(String base, int clusterType) {
return newClusterPath(removeOneClusterFromPath(base), clusterType);
}
return sb.toString();
}
-
- // Remove the topmost filter (if any) from the path.
- private static String removeOneFilterFromPath(String base) {
- boolean[] done = new boolean[1];
- return removeOneFilterFromPath(base, done);
- }
-
- private static String removeOneFilterFromPath(String base, boolean[] done) {
- if (done[0]) return base;
-
- String[] segments = Path.split(base);
- if (segments[0].equals("filter") && segments[1].equals("mediatype")) {
- done[0] = true;
- return Path.splitSequence(segments[3])[0];
- }
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < segments.length; i++) {
- sb.append("/");
- if (segments[i].startsWith("{")) {
- sb.append("{");
- String[] sets = Path.splitSequence(segments[i]);
- for (int j = 0; j < sets.length; j++) {
- if (j > 0) {
- sb.append(",");
- }
- sb.append(removeOneFilterFromPath(sets[j], done));
- }
- sb.append("}");
- } else {
- sb.append(segments[i]);
- }
- }
- return sb.toString();
- }
}
if (mActionBar != null) mActionBar.setSubtitle(title);
}
- public void setNavigationMode(int mode) {
- if (mActionBar != null) mActionBar.setNavigationMode(mode);
- }
-
- public int getHeight() {
- return mActionBar == null ? 0 : mActionBar.getHeight();
- }
-
public boolean setSelectedAction(int type) {
for (int i = 0, n = sClusterItems.length; i < n; i++) {
ActionItem item = sClusterItems[i];
public interface GalleryActivity extends GalleryContext {
public StateManager getStateManager();
public GLRoot getGLRoot();
- public PositionRepository getPositionRepository();
- public GalleryApp getGalleryApplication();
public GalleryActionBar getGalleryActionBar();
}
import android.os.Looper;
public interface GalleryContext {
- public ImageCacheService getImageCacheService();
public DataManager getDataManager();
public Context getAndroidContext();
public Looper getMainLooper();
public Resources getResources();
- public ContentResolver getContentResolver();
public ThreadPool getThreadPool();
}
showMainView(errorView);
}
- public void resetTime() {
- timeBar.resetTime();
- }
-
public void setTimes(int currentTime, int totalTime) {
timeBar.setTime(currentTime, totalTime);
}
return mContentDirty.compareAndSet(true, false);
}
+ // For debugging only.
public void fakeChange() {
onChange(false);
}
- public void clearDirty() {
- mContentDirty.set(false);
- }
-
protected void onChange(boolean selfChange) {
if (mContentDirty.compareAndSet(false, true)) {
mMediaSet.notifyContentChanged();
return path.getObject();
}
- public MediaSet peekMediaSet(Path path) {
- return (MediaSet) path.getObject();
- }
-
public MediaObject getMediaObject(Path path) {
MediaObject obj = path.getObject();
if (obj != null) return obj;
return getMediaObject(path).getMediaType();
}
- public MediaDetails getDetails(Path path) {
- return getMediaObject(path).getDetails();
- }
-
- public void cache(Path path, int flag) {
- getMediaObject(path).cache(flag);
- }
-
public Path findPathByUri(Uri uri) {
if (uri == null) return null;
for (MediaSource source : mSourceMap.values()) {
}
}
- public static Bitmap requestDecode(JobContext jc, final String filePath,
- Options options) {
- if (options == null) options = new Options();
- jc.setCancelListener(new DecodeCanceller(options));
- return ensureGLCompatibleBitmap(
- BitmapFactory.decodeFile(filePath, options));
- }
-
public static Bitmap requestDecode(JobContext jc, FileDescriptor fd, Options options) {
if (options == null) options = new Options();
jc.setCancelListener(new DecodeCanceller(options));
BitmapFactory.decodeByteArray(data, 0, data.length, options));
}
- public static Bitmap requestDecode(JobContext jc,
- FileDescriptor fileDescriptor, Rect paddings, Options options) {
- if (options == null) options = new Options();
- jc.setCancelListener(new DecodeCanceller(options));
- return ensureGLCompatibleBitmap(BitmapFactory.decodeFileDescriptor
- (fileDescriptor, paddings, options));
- }
-
// TODO: This function should not be called directly from
// DecodeUtils.requestDecode(...), since we don't have the knowledge
// if the bitmap will be uploaded to GL.
return null;
}
}
-
- public static BitmapRegionDecoder requestCreateBitmapRegionDecoder(
- JobContext jc, Uri uri, ContentResolver resolver,
- boolean shareable) {
- ParcelFileDescriptor pfd = null;
- try {
- pfd = resolver.openFileDescriptor(uri, "r");
- return BitmapRegionDecoder.newInstance(
- pfd.getFileDescriptor(), shareable);
- } catch (Throwable t) {
- Log.w(TAG, t);
- return null;
- } finally {
- Utils.closeSilently(pfd);
- }
- }
}
private long mTotalBytes = 0;
private boolean mInitialized = false;
- private WeakHashMap<Object, Entry> mAssociateMap = new WeakHashMap<Object, Entry>();
public DownloadCache(GalleryApp application, File root, long capacity) {
mRoot = Utils.checkNotNull(root);
return null;
}
- public Entry lookup(URL url) {
- if (!mInitialized) initialize();
- String stringUrl = url.toString();
-
- // First find in the entry-pool
- synchronized (mEntryMap) {
- Entry entry = mEntryMap.get(stringUrl);
- if (entry != null) {
- updateLastAccess(entry.mId);
- return entry;
- }
- }
-
- // Then, find it in database
- TaskProxy proxy = new TaskProxy();
- synchronized (mTaskMap) {
- Entry entry = findEntryInDatabase(stringUrl);
- if (entry != null) {
- updateLastAccess(entry.mId);
- return entry;
- }
- }
- return null;
- }
-
public Entry download(JobContext jc, URL url) {
if (!mInitialized) initialize();
mId = id;
this.cacheFile = Utils.checkNotNull(cacheFile);
}
-
- public void associateWith(Object object) {
- mAssociateMap.put(Utils.checkNotNull(object), this);
- }
}
private class DownloadTask implements Job<File>, FutureListener<File> {
}
}
- public static byte[] requestDownload(JobContext jc, URL url) {
- ByteArrayOutputStream baos = null;
- try {
- baos = new ByteArrayOutputStream();
- if (!download(jc, url, baos)) {
- return null;
- }
- return baos.toByteArray();
- } catch (Throwable t) {
- Log.w(TAG, t);
- return null;
- } finally {
- Utils.closeSilently(baos);
- }
- }
-
public static void dump(JobContext jc, InputStream is, OutputStream os)
throws IOException {
byte buffer[] = new byte[4096];
return mPosition;
}
- public int getWidth() {
- return mPosition.right - mPosition.left;
- }
-
- public int getHeight() {
- return mPosition.bottom - mPosition.top;
- }
-
public String getName() {
return mName;
}
- public String getPersonId() {
- return mPersonId;
- }
-
@Override
public boolean equals(Object obj) {
if (obj instanceof Face) {
};
private final GalleryApp mApplication;
- private static Bitmap sOverlay;
public int durationInSec;
public boolean isFlashFired() {
return (mState & FLASH_FIRED_MASK) != 0;
}
-
- public int getFlashReturn() {
- return (mState & FLASH_RETURN_MASK) >> 1;
- }
-
- public int getFlashMode() {
- return (mState & FLASH_MODE_MASK) >> 3;
- }
-
- public boolean isFlashPresent() {
- return (mState & FLASH_FUNCTION_MASK) != 0;
- }
-
- public boolean isRedEyeModePresent() {
- return (mState & FLASH_RED_EYE_MASK) != 0;
- }
}
public void addDetail(int index, Object value) {
return mSegment;
}
- public String getSuffix(int level) {
- // We don't need lock because mSegment and mParent are final.
- Path p = this;
- while (level-- != 0) {
- p = p.mParent;
- }
- return p.mSegment;
- }
-
// Below are for testing/debugging only
static void clearAll() {
synchronized (Path.class) {
ImageColumns.ORIENTATION};
private DataManager mDataManager;
- private DownloadCache mDownloadCache;
private static Uri sBaseUri;
public static String getAuthority(Context context) {
return true;
}
- private DownloadCache getDownloadCache() {
- if (mDownloadCache == null) {
- GalleryApp app = (GalleryApp) getContext().getApplicationContext();
- mDownloadCache = app.getDownloadCache();
- }
- return mDownloadCache;
- }
-
// TODO: consider concurrent access
@Override
public Cursor query(Uri uri, String[] projection,
+++ /dev/null
-/*
- * 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.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.LightingColorFilter;
-import android.graphics.Paint;
-
-import com.android.gallery3d.anim.FloatAnimation;
-
-public class AdaptiveBackground extends GLView {
-
- private static final int BACKGROUND_WIDTH = 128;
- private static final int BACKGROUND_HEIGHT = 64;
- private static final int FILTERED_COLOR = 0xffaaaaaa;
- private static final int ANIMATION_DURATION = 500;
-
- private BasicTexture mOldBackground;
- private BasicTexture mBackground;
-
- private final Paint mPaint;
- private Bitmap mPendingBitmap;
- private final FloatAnimation mAnimation =
- new FloatAnimation(0, 1, ANIMATION_DURATION);
-
- public AdaptiveBackground() {
- Paint paint = new Paint();
- paint.setFilterBitmap(true);
- paint.setColorFilter(new LightingColorFilter(FILTERED_COLOR, 0));
- mPaint = paint;
- }
-
- public Bitmap getAdaptiveBitmap(Bitmap bitmap) {
- Bitmap target = Bitmap.createBitmap(
- BACKGROUND_WIDTH, BACKGROUND_HEIGHT, Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(target);
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- int left = 0;
- int top = 0;
- if (width * BACKGROUND_HEIGHT > height * BACKGROUND_WIDTH) {
- float scale = (float) BACKGROUND_HEIGHT / height;
- canvas.scale(scale, scale);
- left = (BACKGROUND_WIDTH - (int) (width * scale + 0.5)) / 2;
- } else {
- float scale = (float) BACKGROUND_WIDTH / width;
- canvas.scale(scale, scale);
- top = (BACKGROUND_HEIGHT - (int) (height * scale + 0.5)) / 2;
- }
- canvas.drawBitmap(bitmap, left, top, mPaint);
- BoxBlurFilter.apply(target,
- BoxBlurFilter.MODE_REPEAT, BoxBlurFilter.MODE_CLAMP);
- return target;
- }
-
- private void startTransition(Bitmap bitmap) {
- BitmapTexture texture = new BitmapTexture(bitmap);
- if (mBackground == null) {
- mBackground = texture;
- } else {
- if (mOldBackground != null) mOldBackground.recycle();
- mOldBackground = mBackground;
- mBackground = texture;
- mAnimation.start();
- }
- invalidate();
- }
-
- public void setImage(Bitmap bitmap) {
- if (mAnimation.isActive()) {
- mPendingBitmap = bitmap;
- } else {
- startTransition(bitmap);
- }
- }
-
- public void setScrollPosition(int position) {
- if (mScrollX == position) return;
- mScrollX = position;
- invalidate();
- }
-
- @Override
- protected void render(GLCanvas canvas) {
- if (mBackground == null) return;
-
- int height = getHeight();
- float scale = (float) height / BACKGROUND_HEIGHT;
- int width = (int) (BACKGROUND_WIDTH * scale + 0.5f);
- int scroll = mScrollX;
- int start = (scroll / width) * width;
-
- if (mOldBackground == null) {
- for (int i = start, n = scroll + getWidth(); i < n; i += width) {
- mBackground.draw(canvas, i - scroll, 0, width, height);
- }
- } else {
- boolean moreAnimation = mAnimation.calculate(AnimationTime.get());
- float ratio = mAnimation.get();
- for (int i = start, n = scroll + getWidth(); i < n; i += width) {
- canvas.drawMixed(mOldBackground,
- mBackground, ratio, i - scroll, 0, width, height);
- }
- if (moreAnimation) {
- invalidate();
- } else if (mPendingBitmap != null) {
- startTransition(mPendingBitmap);
- mPendingBitmap = null;
- }
- }
- }
-}
removeDisplayItem(entry.labelItem);
}
- public int size() {
- return mDataWindow.size();
- }
-
@Override
public void onLayoutChanged(int width, int height) {
updateVisibleRange(0, 0);
return mData[slotIndex % mData.length];
}
- public int size() {
- return mSize;
- }
-
public boolean isActiveSlot(int slotIndex) {
return slotIndex >= mActiveStart && slotIndex < mActiveEnd;
}
BitmapUtils.recycleSilently(mBackup);
}
- public int getRotation() {
- return 0;
- }
-
public boolean isFailedToLoad() {
return false;
}
+++ /dev/null
-/*
- * 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.graphics.Bitmap;
-
-
-public class BoxBlurFilter {
- private static final int RED_MASK = 0xff0000;
- private static final int RED_MASK_SHIFT = 16;
- private static final int GREEN_MASK = 0x00ff00;
- private static final int GREEN_MASK_SHIFT = 8;
- private static final int BLUE_MASK = 0x0000ff;
- private static final int RADIUS = 4;
- private static final int KERNEL_SIZE = RADIUS * 2 + 1;
- private static final int NUM_COLORS = 256;
- private static final int[] KERNEL_NORM = new int[KERNEL_SIZE * NUM_COLORS];
-
- public static final int MODE_REPEAT = 1;
- public static final int MODE_CLAMP = 2;
-
- static {
- int index = 0;
- // Build a lookup table from summed to normalized kernel values.
- // The formula: KERNAL_NORM[value] = value / KERNEL_SIZE
- for (int i = 0; i < NUM_COLORS; ++i) {
- for (int j = 0; j < KERNEL_SIZE; ++j) {
- KERNEL_NORM[index++] = i;
- }
- }
- }
-
- private BoxBlurFilter() {
- }
-
- private static int sample(int x, int width, int mode) {
- if (x >= 0 && x < width) return x;
- return mode == MODE_REPEAT
- ? x < 0 ? x + width : x - width
- : x < 0 ? 0 : width - 1;
- }
-
- public static void apply(
- Bitmap bitmap, int horizontalMode, int verticalMode) {
-
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- int data[] = new int[width * height];
- bitmap.getPixels(data, 0, width, 0, 0, width, height);
- int temp[] = new int[width * height];
- applyOneDimension(data, temp, width, height, horizontalMode);
- applyOneDimension(temp, data, height, width, verticalMode);
- bitmap.setPixels(data, 0, width, 0, 0, width, height);
- }
-
- private static void applyOneDimension(
- int[] in, int[] out, int width, int height, int mode) {
- for (int y = 0, read = 0; y < height; ++y, read += width) {
- // Evaluate the kernel for the first pixel in the row.
- int red = 0;
- int green = 0;
- int blue = 0;
- for (int i = -RADIUS; i <= RADIUS; ++i) {
- int argb = in[read + sample(i, width, mode)];
- red += (argb & RED_MASK) >> RED_MASK_SHIFT;
- green += (argb & GREEN_MASK) >> GREEN_MASK_SHIFT;
- blue += argb & BLUE_MASK;
- }
- for (int x = 0, write = y; x < width; ++x, write += height) {
- // Output the current pixel.
- out[write] = 0xFF000000
- | (KERNEL_NORM[red] << RED_MASK_SHIFT)
- | (KERNEL_NORM[green] << GREEN_MASK_SHIFT)
- | KERNEL_NORM[blue];
-
- // Slide to the next pixel, adding the new rightmost pixel and
- // subtracting the former leftmost.
- int prev = in[read + sample(x - RADIUS, width, mode)];
- int next = in[read + sample(x + RADIUS + 1, width, mode)];
- red += ((next & RED_MASK) - (prev & RED_MASK)) >> RED_MASK_SHIFT;
- green += ((next & GREEN_MASK) - (prev & GREEN_MASK)) >> GREEN_MASK_SHIFT;
- blue += (next & BLUE_MASK) - (prev & BLUE_MASK);
- }
- }
- }
-}
+++ /dev/null
-/*
- * 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;
-
-interface DetailsWindowConfig {
- public static final int FONT_SIZE = 18;
- public static final int PREFERRED_WIDTH = 400;
- public static final int LEFT_RIGHT_EXTRA_PADDING = 9;
- public static final int TOP_BOTTOM_EXTRA_PADDING = 9;
- public static final int LINE_SPACING = 5;
- public static final int FIRST_LINE_SPACING = 18;
-}
-
-interface TextButtonConfig {
- public static final int HORIZONTAL_PADDINGS = 16;
- public static final int VERTICAL_PADDINGS = 5;
-}
mListener = listener;
}
- public MenuItem findMenuItem(int id) {
- MenuItem item = null;
- for (DropDownMenu menu : mMenus) {
- item = menu.findItem(id);
- if (item != null) return item;
- }
- return item;
- }
-
- public void setMenuItemAppliedEnabled(int id, boolean applied, boolean enabled,
- boolean updateTitle) {
- MenuItem item = null;
- for (DropDownMenu menu : mMenus) {
- item = menu.findItem(id);
- if (item != null) {
- item.setCheckable(true);
- item.setChecked(applied);
- item.setEnabled(enabled);
- if (updateTitle) {
- menu.setTitle(item.getTitle());
- }
- }
- }
- }
-
- public void setMenuItemVisibility(int id, boolean visibility) {
- MenuItem item = findMenuItem(id);
- if (item != null) {
- item.setVisible(visibility);
- }
- }
-
public boolean onMenuItemClick(MenuItem item) {
if (mListener != null) {
return mListener.onMenuItemClick(item);
}
}
- public boolean isVisible() {
- return mDialog.isShowing();
- }
-
private void setDetails(MediaDetails details) {
mAdapter = new DetailsAdapter(details);
String title = String.format(
+++ /dev/null
-/*
- * 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.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-
-// DrawableTexture is a texture whose content is from a Drawable.
-public class DrawableTexture extends CanvasTexture {
-
- private final Drawable mDrawable;
-
- public DrawableTexture(Drawable drawable, int width, int height) {
- super(width, height);
- mDrawable = drawable;
- }
-
- @Override
- protected void onDraw(Canvas canvas, Bitmap backing) {
- mDrawable.setBounds(0, 0, mWidth, mHeight);
- mDrawable.draw(canvas);
- }
-}
import android.view.MotionEvent;
import android.view.View.MeasureSpec;
-public class FilmStripView extends GLView implements ScrollBarView.Listener,
- UserInteractionListener {
+public class FilmStripView extends GLView implements UserInteractionListener {
@SuppressWarnings("unused")
private static final String TAG = "FilmStripView";
addComponent(mAlbumView);
mScrollBarView = new ScrollBarView(activity.getAndroidContext(),
mGripSize, gripWidth);
- mScrollBarView.setListener(this);
addComponent(mScrollBarView);
mAlbumView.setModel(mAlbumDataAdapter);
mUIListener.onUserInteraction();
}
- // Called by ScrollBarView
- @Override
- public void onScrollBarPositionChanged(int position) {
- mAlbumView.setScrollPosition(position);
- }
-
public void setFocusIndex(int slotIndex) {
mAlbumView.setFocusIndex(slotIndex);
mAlbumView.makeSlotVisible(slotIndex);
// Clear the drawing buffers. This should only be used by GLRoot.
public void clearBuffer();
- public void setBlendEnabled(boolean enabled);
-
// Sets and gets the current alpha, alpha must be in [0, 1].
public void setAlpha(float alpha);
public float getAlpha();
public void rotate(float angle, float x, float y, float z);
public void multiplyMatrix(float[] mMatrix, int offset);
- // Modifies the current clip with the specified rectangle.
- // (current clip) = (current clip) intersect (specified rectangle).
- // Returns true if the result clip is non-empty.
- public boolean clipRect(int left, int top, int right, int bottom);
-
- // Pushes the configuration state (matrix, alpha, and clip) onto
+ // Pushes the configuration state (matrix, and alpha) onto
// a private stack.
public void save();
public void save(int saveFlags);
public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;
- public static final int SAVE_FLAG_CLIP = 0x01;
- public static final int SAVE_FLAG_ALPHA = 0x02;
- public static final int SAVE_FLAG_MATRIX = 0x04;
+ public static final int SAVE_FLAG_ALPHA = 0x01;
+ public static final int SAVE_FLAG_MATRIX = 0x02;
// Pops from the top of the stack as current configuration state (matrix,
// alpha, and clip). This call balances a previous call to save(), and is
public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,
int uvBuffer, int indexBuffer, int indexCount);
- // Draws a texture to the specified rectangle. The "alpha" parameter
- // overrides the current drawing alpha value.
- public void drawTexture(BasicTexture texture,
- int x, int y, int width, int height, float alpha);
-
// Draws a the source rectangle part of the texture to the target rectangle.
public void drawTexture(BasicTexture texture, RectF source, RectF target);
// Draw two textures to the specified rectangle. The actual texture used is
// from * (1 - ratio) + to * ratio
// The two textures must have the same size.
- public void drawMixed(BasicTexture from, BasicTexture to,
- float ratio, int x, int y, int w, int h);
-
public void drawMixed(BasicTexture from, int toColor,
float ratio, int x, int y, int w, int h);
- // Return a texture copied from the specified rectangle.
- public BasicTexture copyTexture(int x, int y, int width, int height);
-
// Gets the underlying GL instance. This is used only when direct access to
// GL is needed.
public GL11 getGLInstance();
// called in the GL thread.
public void deleteRecycledResources();
+ // Dump statistics information and clear the counters. For debug only.
+ public void dumpStatisticsAndClear();
}
private final GLState mGLState;
private float mAlpha;
- private final Rect mClipRect = new Rect();
private final ArrayList<ConfigState> mRestoreStack =
new ArrayList<ConfigState>();
private ConfigState mRecycledRestoreAction;
Matrix.translateM(matrix, 0, 0, mHeight, 0);
Matrix.scaleM(matrix, 0, 1, -1, 1);
- mClipRect.set(0, 0, width, height);
gl.glScissor(0, 0, width, height);
}
mAlpha = alpha;
}
+ public float getAlpha() {
+ return mAlpha;
+ }
+
public void multiplyAlpha(float alpha) {
Utils.assertTrue(alpha >= 0 && alpha <= 1);
mAlpha *= alpha;
}
- public float getAlpha() {
- return mAlpha;
- }
-
private static ByteBuffer allocateDirectNativeOrderBuffer(int size) {
return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
}
mGLState.setColorMode(paint.getColor(), mAlpha);
mGLState.setLineWidth(paint.getLineWidth());
- mGLState.setLineSmooth(paint.getAntiAlias());
saveTransform();
translate(x, y);
mGLState.setColorMode(paint.getColor(), mAlpha);
mGLState.setLineWidth(paint.getLineWidth());
- mGLState.setLineSmooth(paint.getAntiAlias());
saveTransform();
translate(x1, y1);
return r;
}
- public boolean clipRect(int left, int top, int right, int bottom) {
- float point[] = mapPoints(mMatrixValues, left, top, right, bottom);
-
- // 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]) {
- left = (int) point[2];
- right = (int) point[0];
- } else {
- left = (int) point[0];
- right = (int) point[2];
- }
- if (point[1] > point[3]) {
- top = (int) point[3];
- bottom = (int) point[1];
- } else {
- top = (int) point[1];
- bottom = (int) point[3];
- }
- Rect clip = mClipRect;
-
- boolean intersect = clip.intersect(left, top, right, bottom);
- if (!intersect) clip.set(0, 0, 0, 0);
- mGL.glScissor(clip.left, clip.top, clip.width(), clip.height());
- return intersect;
- }
-
private void drawBoundTexture(
BasicTexture texture, int x, int y, int width, int height) {
// Test whether it has been rotated or flipped, if so, glDrawTexiOES
drawTexture(texture, x, y, width, height, mAlpha);
}
- public void setBlendEnabled(boolean enabled) {
- mBlendEnabled = enabled;
- }
-
- public void drawTexture(BasicTexture texture,
+ private void drawTexture(BasicTexture texture,
int x, int y, int width, int height, float alpha) {
if (width <= 0 || height <= 0) return;
drawMixed(from, toColor, ratio, x, y, w, h, mAlpha);
}
- public void drawMixed(BasicTexture from, BasicTexture to,
- float ratio, int x, int y, int w, int h) {
- drawMixed(from, to, ratio, x, y, w, h, mAlpha);
- }
-
private boolean bindTexture(BasicTexture texture) {
if (!texture.onBind(this)) return false;
mGLState.setTexture2DEnabled(true);
mGLState.setTexEnvMode(GL11.GL_REPLACE);
}
- private void drawMixed(BasicTexture from, BasicTexture to,
- float ratio, int x, int y, int width, int height, float alpha) {
-
- if (ratio <= 0) {
- drawTexture(from, x, y, width, height, alpha);
- return;
- } else if (ratio >= 1) {
- drawTexture(to, x, y, width, height, alpha);
- return;
- }
-
- // In the current implementation the two textures must have the
- // same size.
- Utils.assertTrue(from.getWidth() == to.getWidth()
- && from.getHeight() == to.getHeight());
-
- mGLState.setBlendEnabled(mBlendEnabled && (!from.isOpaque()
- || !to.isOpaque() || alpha < OPAQUE_ALPHA));
-
- final GL11 gl = mGL;
- if (!bindTexture(from)) return;
-
- //
- // The formula we want:
- // alpha * ((1 - ratio) * from + ratio * to)
- // The formula that GL supports is in the form of:
- // combo * (modulate * from) + (1 - combo) * to
- //
- // So, we have combo = 1 - alpha * ratio
- // and modulate = alpha * (1f - ratio) / combo
- //
- float comboRatio = 1 - alpha * ratio;
-
- // handle the case that (1 - comboRatio) == 0
- if (alpha < OPAQUE_ALPHA) {
- mGLState.setTextureAlpha(alpha * (1f - ratio) / comboRatio);
- } else {
- mGLState.setTextureAlpha(1f);
- }
-
- gl.glActiveTexture(GL11.GL_TEXTURE1);
- if (!bindTexture(to)) {
- // Disable TEXTURE1.
- gl.glDisable(GL11.GL_TEXTURE_2D);
- // Switch back to the default texture unit.
- gl.glActiveTexture(GL11.GL_TEXTURE0);
- return;
- }
- gl.glEnable(GL11.GL_TEXTURE_2D);
-
- // Interpolate the RGB and alpha values between both textures.
- mGLState.setTexEnvMode(GL11.GL_COMBINE);
- gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_RGB, GL11.GL_INTERPOLATE);
- gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_ALPHA, GL11.GL_INTERPOLATE);
-
- // Specify the interpolation factor via the alpha component of
- // GL_TEXTURE_ENV_COLORs.
- // We don't use the RGB color, so just give them 0s.
- setTextureColor(0, 0, 0, comboRatio);
- gl.glTexEnvfv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, mTextureColor, 0);
-
- // Wire up the interpolation factor for RGB.
- gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC2_RGB, GL11.GL_CONSTANT);
- gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND2_RGB, GL11.GL_SRC_ALPHA);
-
- // Wire up the interpolation factor for alpha.
- gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC2_ALPHA, GL11.GL_CONSTANT);
- gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND2_ALPHA, GL11.GL_SRC_ALPHA);
-
- // Draw the combined texture.
- drawBoundTexture(to, x, y, width, height);
-
- // Disable TEXTURE1.
- gl.glDisable(GL11.GL_TEXTURE_2D);
- // Switch back to the default texture unit.
- gl.glActiveTexture(GL11.GL_TEXTURE0);
- }
-
// TODO: the code only work for 2D should get fixed for 3D or removed
private static final int MSKEW_X = 4;
private static final int MSKEW_Y = 1;
|| matrix[MSCALE_Y] > eps;
}
- public BasicTexture copyTexture(int x, int y, int width, int height) {
-
- if (isMatrixRotatedOrFlipped(mMatrixValues)) {
- throw new IllegalArgumentException("cannot support rotated matrix");
- }
- float points[] = mapPoints(mMatrixValues, 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;
-
- RawTexture texture = RawTexture.newInstance(this);
- gl.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());
- texture.setSize(width, height);
-
- 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_RGB, x, y, texture.getTextureWidth(),
- texture.getTextureHeight(), 0);
-
- return texture;
- }
-
private static class GLState {
private final GL11 mGL;
mGL.glLineWidth(width);
}
- public void setLineSmooth(boolean enabled) {
- if (mLineSmooth == enabled) return;
- mLineSmooth = enabled;
- if (enabled) {
- mGL.glEnable(GL11.GL_LINE_SMOOTH);
- } else {
- mGL.glDisable(GL11.GL_LINE_SMOOTH);
- }
- }
-
public void setTextureAlpha(float alpha) {
if (mTextureAlpha == alpha) return;
mTextureAlpha = alpha;
config.mAlpha = -1;
}
- if ((saveFlags & SAVE_FLAG_CLIP) != 0) {
- config.mRect.set(mClipRect);
- } else {
- config.mRect.left = Integer.MAX_VALUE;
- }
if ((saveFlags & SAVE_FLAG_MATRIX) != 0) {
System.arraycopy(mMatrixValues, 0, config.mMatrix, 0, 16);
public void restore(GLCanvasImpl canvas) {
if (mAlpha >= 0) canvas.setAlpha(mAlpha);
- if (mRect.left != Integer.MAX_VALUE) {
- Rect rect = mRect;
- canvas.mClipRect.set(rect);
- canvas.mGL.glScissor(
- rect.left, rect.top, rect.width(), rect.height());
- }
if (mMatrix[0] != Float.NEGATIVE_INFINITY) {
System.arraycopy(mMatrix, 0, canvas.mMatrixValues, 0, 16);
}
public class GLPaint {
- public static final int FLAG_ANTI_ALIAS = 0x01;
-
- private int mFlags = 0;
private float mLineWidth = 1f;
private int mColor = 0;
- public int getFlags() {
- return mFlags;
- }
-
- public void setFlags(int flags) {
- mFlags = flags;
- }
-
public void setColor(int color) {
mColor = color;
}
public float getLineWidth() {
return mLineWidth;
}
-
- public void setAntiAlias(boolean enabled) {
- if (enabled) {
- mFlags |= FLAG_ANTI_ALIAS;
- } else {
- mFlags &= ~FLAG_ANTI_ALIAS;
- }
- }
-
- public boolean getAntiAlias(){
- return (mFlags & FLAG_ANTI_ALIAS) != 0;
- }
}
public void registerLaunchedAnimation(CanvasAnimation animation);
public void requestRender();
public void requestLayoutContentPane();
- public boolean hasStencil();
public void lockRenderThread();
public void unlockRenderThread();
private static final int FLAG_NEED_LAYOUT = 2;
private GL11 mGL;
- private GLCanvasImpl mCanvas;
+ private GLCanvas mCanvas;
private GLView mContentView;
- private DisplayMetrics mDisplayMetrics;
private int mFlags = FLAG_NEED_LAYOUT;
private volatile boolean mRenderRequested = false;
//setDebugFlags(DEBUG_CHECK_GL_ERROR);
}
- public GalleryEGLConfigChooser getEGLConfigChooser() {
- return mEglConfigChooser;
- }
-
- @Override
- public boolean hasStencil() {
- return getEGLConfigChooser().getStencilBits() > 0;
- }
-
@Override
public void registerLaunchedAnimation(CanvasAnimation animation) {
// Register the newly launched animation so that we can set the start
}
}
- public GLView getContentPane() {
- return mContentView;
- }
-
@Override
public void requestRender() {
if (DEBUG_INVALIDATE) {
}
}
- public DisplayMetrics getDisplayMetrics() {
- if (mDisplayMetrics == null) {
- mDisplayMetrics = new DisplayMetrics();
- ((Activity) getContext()).getWindowManager()
- .getDefaultDisplay().getMetrics(mDisplayMetrics);
- }
- return mDisplayMetrics;
- }
-
- public GLCanvas getCanvas() {
- return mCanvas;
- }
-
private class IdleRunner implements Runnable {
// true if the idle runner is in the queue
private boolean mActive = false;
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) {
class GalleryEGLConfigChooser implements EGLConfigChooser {
private static final String TAG = "GalleryEGLConfigChooser";
- private int mStencilBits;
private final int mConfigSpec[] = new int[] {
EGL10.EGL_RED_SIZE, 5,
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)) {
if (result == null) result = configs[0];
egl.eglGetConfigAttrib(
display, result, EGL10.EGL_STENCIL_SIZE, value);
- mStencilBits = value[0];
logConfig(egl, display, result);
return result;
}
+++ /dev/null
-/*
- * 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 Icon extends GLView {
- private final BasicTexture mIcon;
-
- // The width and height requested by the user.
- private int mReqWidth;
- private int mReqHeight;
-
- public Icon(Context context, int iconId, int width, int height) {
- this(context, new ResourceTexture(context, iconId), width, height);
- }
-
- public Icon(Context context, BasicTexture icon, int width, int height) {
- mIcon = icon;
- mReqWidth = width;
- mReqHeight = height;
- }
-
- @Override
- protected void onMeasure(int widthSpec, int heightSpec) {
- MeasureHelper.getInstance(this)
- .setPreferredContentSize(mReqWidth, mReqHeight)
- .measure(widthSpec, heightSpec);
- }
-
- @Override
- protected void render(GLCanvas canvas) {
- Rect p = mPaddings;
-
- int width = getWidth() - p.left - p.right;
- int height = getHeight() - p.top - p.bottom;
-
- // Draw the icon in the center of the space
- int xoffset = p.left + (width - mReqWidth) / 2;
- int yoffset = p.top + (height - mReqHeight) / 2;
-
- mIcon.draw(canvas, xoffset, yoffset, mReqWidth, mReqHeight);
- }
-}
+++ /dev/null
-/*
- * 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;
-
-public interface OnSelectedListener {
- public void onSelected(GLView source);
-}
private final Interpolator mInterpolator;
private int mState;
- private long mAnimationStartTime;
private float mValue;
private float mValueStart;
+++ /dev/null
-/*
- * 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 javax.microedition.khronos.opengles.GL11;
-
-// RawTexture is used for texture created by glCopyTexImage2D.
-//
-// It will throw RuntimeException in onBind() if used with a different GL
-// context. It is only used internally by copyTexture() in GLCanvas.
-class RawTexture extends BasicTexture {
-
- private RawTexture(GLCanvas canvas, int id) {
- super(canvas, id, STATE_LOADED);
- }
-
- public static RawTexture newInstance(GLCanvas canvas) {
- int[] textureId = new int[1];
- GL11 gl = canvas.getGLInstance();
- gl.glGenTextures(1, textureId, 0);
- return new RawTexture(canvas, textureId[0]);
- }
-
- @Override
- protected boolean onBind(GLCanvas canvas) {
- if (mCanvasRef != canvas) {
- throw new RuntimeException("cannot bind to different canvas");
- }
- return true;
- }
-
- public boolean isOpaque() {
- return true;
- }
-
- @Override
- public void yield() {
- // we cannot free the texture because we have no backup.
- }
-}
@SuppressWarnings("unused")
private static final String TAG = "ScrollBarView";
- public interface Listener {
- void onScrollBarPositionChanged(int position);
- }
-
private int mBarHeight;
private int mGripHeight;
private int mContentPosition;
private int mContentTotal;
- private Listener mListener;
private NinePatchTexture mScrollBarTexture;
public ScrollBarView(Context context, int gripHeight, int gripWidth) {
mGripHeight = gripHeight;
}
- public void setListener(Listener listener) {
- mListener = listener;
- }
-
@Override
protected void onLayout(
boolean changed, int left, int top, int right, int bottom) {
mGripPosition = Math.round(r * mContentPosition);
}
- private void notifyContentPositionFromGrip() {
- if (mContentTotal <= 0) return;
- float r = (getWidth() - mGripWidth) / (float) mContentTotal;
- int newContentPosition = Math.round(mGripPosition / r);
- mListener.onScrollBarPositionChanged(newContentPosition);
- }
-
@Override
protected void render(GLCanvas canvas) {
super.render(canvas);
int y = (mBarHeight - mGripHeight) / 2;
mScrollBarTexture.draw(canvas, mGripPosition, y, mGripWidth, mGripHeight);
}
-
- // The onTouch() handler is disabled because now we don't want the user
- // to drag the bar (it's an indicator only).
- /*
- @Override
- protected boolean onTouch(MotionEvent event) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN: {
- int x = (int) event.getX();
- return (x >= mGripPosition && x < mGripPosition + mGripWidth);
- }
- case MotionEvent.ACTION_MOVE: {
- // Adjust x by mGripWidth / 2 so the center of the grip
- // matches the touch position.
- int x = (int) event.getX() - mGripWidth / 2;
- x = Utils.clamp(x, 0, getWidth() - mGripWidth);
- if (mGripPosition != x) {
- mGripPosition = x;
- notifyContentPositionFromGrip();
- invalidate();
- }
- break;
- }
- }
- return true;
- }
- */
}
mSourceMediaSet = set;
mTotal = -1;
}
-
- public MediaSet getSourceMediaSet() {
- return mSourceMediaSet;
- }
}
}
@Override
- public boolean removeComponent(GLView view) {
- throw new UnsupportedOperationException();
- }
-
- @Override
protected void onLayout(boolean changeSize, int l, int t, int r, int b) {
if (!changeSize) return;
public int rowsLand = -1;
public int rowsPort = -1;
public int slotGap = -1;
-
- static Spec newWithSize(int width, int height) {
- Spec s = new Spec();
- s.slotWidth = width;
- s.slotHeight = height;
- return s;
- }
-
- static Spec newWithRows(int rowsLand, int rowsPort, int slotGap) {
- Spec s = new Spec();
- s.rowsLand = rowsLand;
- s.rowsPort = rowsPort;
- s.slotGap = slotGap;
- return s;
- }
}
public static class Layout {
return mSlotHeight;
}
- public int getContentLength() {
- return mContentLength;
- }
-
// Calculate
// (1) mUnitCount: the number of slots we can fit into one column (or row).
// (2) mContentLength: the width (or height) we need to display all the
+++ /dev/null
-/*
- * 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;
-
-public class StaticBackground extends GLView {
-
- private Context mContext;
- private int mLandscapeResource;
- private int mPortraitResource;
-
- private BasicTexture mBackground;
- private boolean mIsLandscape = false;
-
- public StaticBackground(Context context) {
- mContext = context;
- }
-
- @Override
- protected void onLayout(boolean changeSize, int l, int t, int r, int b) {
- setOrientation(getWidth() >= getHeight());
- }
-
- private void setOrientation(boolean isLandscape) {
- if (mIsLandscape == isLandscape) return;
- mIsLandscape = isLandscape;
- if (mBackground != null) mBackground.recycle();
- mBackground = new ResourceTexture(
- mContext, mIsLandscape ? mLandscapeResource : mPortraitResource);
- invalidate();
- }
-
- public void setImage(int landscapeId, int portraitId) {
- mLandscapeResource = landscapeId;
- mPortraitResource = portraitId;
- if (mBackground != null) mBackground.recycle();
- mBackground = new ResourceTexture(
- mContext, mIsLandscape ? landscapeId : portraitId);
- invalidate();
- }
-
- @Override
- protected void render(GLCanvas canvas) {
- mBackground.draw(canvas, 0, 0, getWidth(), getHeight());
- }
-}
// -- ColorTexture
// -- FadeInTexture
// -- BasicTexture
-// -- RawTexture
// -- UploadedTexture
// -- BitmapTexture
// -- Tile
// -- ResourceTexture
// -- NinePatchTexture
// -- CanvasTexture
-// -- DrawableTexture
// -- StringTexture
//
public interface Texture {
+++ /dev/null
-/*
- * 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.util;
-
-import java.util.concurrent.Callable;
-
-// NOTE: If the Callable throws any Throwable, the result value will be null.
-public class FutureTask<T> implements Runnable, Future<T> {
- private static final String TAG = "FutureTask";
- private Callable<T> mCallable;
- private FutureListener<T> mListener;
- private volatile boolean mIsCancelled;
- private boolean mIsDone;
- private T mResult;
-
- public FutureTask(Callable<T> callable, FutureListener<T> listener) {
- mCallable = callable;
- mListener = listener;
- }
-
- public FutureTask(Callable<T> callable) {
- this(callable, null);
- }
-
- public void cancel() {
- mIsCancelled = true;
- }
-
- public synchronized T get() {
- while (!mIsDone) {
- try {
- wait();
- } catch (InterruptedException t) {
- // ignore.
- }
- }
- return mResult;
- }
-
- public void waitDone() {
- get();
- }
-
- public synchronized boolean isDone() {
- return mIsDone;
- }
-
- public boolean isCancelled() {
- return mIsCancelled;
- }
-
- public void run() {
- T result = null;
-
- if (!mIsCancelled) {
- try {
- result = mCallable.call();
- } catch (Throwable ex) {
- Log.w(TAG, "Exception in running a task", ex);
- }
- }
-
- synchronized(this) {
- mResult = result;
- mIsDone = true;
- if (mListener != null) {
- mListener.onFutureDone(this);
- }
- notifyAll();
- }
- }
-}
return false;
}
- public static void assertInMainThread() {
- if (Thread.currentThread() == sContext.getMainLooper().getThread()) {
- throw new AssertionError();
- }
- }
-
- public static void doubleToRational(double value, long[] output) {
- // error is a magic number to control the tollerance of error
- doubleToRational(value, output, 0.00001);
- }
-
- private static void doubleToRational(double value, long[] output, double error) {
- long number = (long) value;
- value -= number;
- if (value < 0.000001 || error > 1) {
- output[0] = (int) (number + value + 0.5);
- output[1] = 1;
- } else {
- doubleToRational(1.0 / value, output, error / value);
- number = number * output[0] + output[1];
- output[1] = output[0];
- output[0] = number;
- }
- }
-
public static boolean isPanorama(MediaItem item) {
if (item == null) return false;
int w = item.getWidth();
return entry == null ? null : entry.get();
}
+ // This is currently unused.
+ /*
public synchronized void clear() {
mWeakMap.clear();
mQueue = new ReferenceQueue<V>();
}
+ */
+ // This is for debugging only
public synchronized ArrayList<K> keys() {
Set<K> set = mWeakMap.keySet();
ArrayList<K> result = new ArrayList<K>(set);
return mSize;
}
+ // For testing only
public int[] toArray(int[] result) {
if (result == null || result.length < mSize) {
result = new int[mSize];
return future;
}
- public <T> Future<T> submit(Job<T> job) {
- return submit(job, null);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
private void submitTasksIfAllowed() {
while (mLimit > 0 && !mJobs.isEmpty()) {
public static class List<T extends LinkedNode> {
private LinkedNode mHead = new LinkedNode();
- public void insertFirst(T node) {
- mHead.insert(node);
- }
-
public void insertLast(T node) {
mHead.mPrev.insert(node);
}
return original;
}
- public double update(float original, float update) {
- if (original != update) {
- mUpdated = true;
- original = update;
- }
- return original;
- }
-
public <T> T update(T original, T update) {
if (!Utils.equals(original, update)) {
mUpdated = true;
assertFalse(Utils.equals(a, b));
}
- public void testIsPowerOf2() {
- for (int i = 0; i < 31; i++) {
- int v = (1 << i);
- assertTrue(Utils.isPowerOf2(v));
- }
-
- int[] f = new int[] {3, 5, 6, 7, 9, 10, 65535, Integer.MAX_VALUE - 1,
- Integer.MAX_VALUE };
- for (int v : f) {
- assertFalse(Utils.isPowerOf2(v));
- }
-
- int[] e = new int[] {0, -1, -2, -4, -65536, Integer.MIN_VALUE + 1,
- Integer.MIN_VALUE };
- for (int v : e) {
- try {
- Utils.isPowerOf2(v);
- fail();
- } catch (IllegalArgumentException ex) {
- // expected.
- }
- }
- }
-
public void testNextPowerOf2() {
int[] q = new int[] {1, 2, 3, 4, 5, 6, 10, 65535, (1 << 30) - 1, (1 << 30)};
int[] a = new int[] {1, 2, 4, 4, 8, 8, 16, 65536, (1 << 30) , (1 << 30)};
}
}
- public void testDistance() {
- assertFloatEq(0f, Utils.distance(0, 0, 0, 0));
- assertFloatEq(1f, Utils.distance(0, 1, 0, 0));
- assertFloatEq(1f, Utils.distance(0, 0, 0, 1));
- assertFloatEq(2f, Utils.distance(1, 2, 3, 2));
- assertFloatEq(5f, Utils.distance(1, 2, 1 + 3, 2 + 4));
- assertFloatEq(5f, Utils.distance(1, 2, 1 + 3, 2 + 4));
- assertFloatEq(Float.MAX_VALUE, Utils.distance(Float.MAX_VALUE, 0, 0, 0));
- }
-
public void testClamp() {
assertEquals(1000, Utils.clamp(300, 1000, 2000));
assertEquals(1300, Utils.clamp(1300, 1000, 2000));
assertFalse(Utils.isOpaque(0xAA0000FF));
}
- public static void testSwap() {
- Integer[] a = {1, 2, 3};
- Utils.swap(a, 0, 2);
- assertEquals(a[0].intValue(), 3);
- assertEquals(a[1].intValue(), 2);
- assertEquals(a[2].intValue(), 1);
- }
-
public static void assertFloatEq(float expected, float actual) {
if (Math.abs(actual - expected) > 1e-6) {
Log.v(TAG, "expected: " + expected + ", actual: " + actual);
}
public void deleteRecycledResources() {}
public void multiplyMatrix(float[] mMatrix, int offset) {}
+ public void dumpStatisticsAndClear() {}
}
}
@SmallTest
- public void testClipRect() {
- // The test is currently broken, waiting for the fix
- // new ClipRectTest().run();
- }
-
- private static class ClipRectTest extends GLStub {
- int mX, mY, mWidth, mHeight;
-
- @Override
- public void glScissor(int x, int y, int width, int height) {
- mX = x;
- mY = 100 - y - height; // flip in Y direction
- mWidth = width;
- mHeight = height;
- }
-
- private void assertClipRect(int x, int y, int width, int height) {
- assertEquals(x, mX);
- assertEquals(y, mY);
- assertEquals(width, mWidth);
- assertEquals(height, mHeight);
- }
-
- private void assertEmptyClipRect() {
- assertEquals(0, mWidth);
- assertEquals(0, mHeight);
- }
-
- void run() {
- GLCanvas canvas = new GLCanvasImpl(this);
- canvas.setSize(100, 100);
- canvas.save();
- assertClipRect(0, 0, 100, 100);
-
- assertTrue(canvas.clipRect(10, 10, 70, 70));
- canvas.save();
- assertClipRect(10, 10, 60, 60);
-
- assertTrue(canvas.clipRect(30, 30, 90, 90));
- canvas.save();
- assertClipRect(30, 30, 40, 40);
-
- assertTrue(canvas.clipRect(40, 40, 60, 90));
- assertClipRect(40, 40, 20, 30);
-
- assertFalse(canvas.clipRect(30, 30, 70, 40));
- assertEmptyClipRect();
- assertFalse(canvas.clipRect(0, 0, 100, 100));
- assertEmptyClipRect();
-
- canvas.restore();
- assertClipRect(30, 30, 40, 40);
-
- canvas.restore();
- assertClipRect(10, 10, 60, 60);
-
- canvas.restore();
- assertClipRect(0, 0, 100, 100);
-
- canvas.translate(10, 20, 30);
- assertTrue(canvas.clipRect(10, 10, 70, 70));
- canvas.save();
- assertClipRect(20, 30, 60, 60);
- }
- }
-
- @SmallTest
- public void testSaveRestore() {
- new SaveRestoreTest().run();
- }
-
- private static class SaveRestoreTest extends GLStub {
- int mX, mY, mWidth, mHeight;
-
- @Override
- public void glScissor(int x, int y, int width, int height) {
- mX = x;
- mY = 100 - y - height; // flip in Y direction
- mWidth = width;
- mHeight = height;
- }
-
- private void assertClipRect(int x, int y, int width, int height) {
- assertEquals(x, mX);
- assertEquals(y, mY);
- assertEquals(width, mWidth);
- assertEquals(height, mHeight);
- }
-
- void run() {
- GLCanvas canvas = new GLCanvasImpl(this);
- canvas.setSize(100, 100);
-
- canvas.setAlpha(0.7f);
- assertTrue(canvas.clipRect(10, 10, 70, 70));
-
- canvas.save(canvas.SAVE_FLAG_CLIP);
- canvas.setAlpha(0.6f);
- assertTrue(canvas.clipRect(30, 30, 90, 90));
-
- canvas.save(canvas.SAVE_FLAG_CLIP | canvas.SAVE_FLAG_ALPHA);
- canvas.setAlpha(0.5f);
- assertTrue(canvas.clipRect(40, 40, 60, 90));
-
- assertEquals(0.5f, canvas.getAlpha());
- assertClipRect(40, 40, 20, 30);
-
- canvas.restore(); // now both clipping rect and alpha are restored.
- assertEquals(0.6f, canvas.getAlpha());
- assertClipRect(30, 30, 40, 40);
-
- canvas.restore(); // now only clipping rect is restored.
-
- canvas.save(0);
- canvas.save(0);
- canvas.restore();
- canvas.restore();
-
- assertEquals(0.6f, canvas.getAlpha());
- assertTrue(canvas.clipRect(10, 10, 60, 60));
- }
- }
-
- @SmallTest
- public void testDrawTexture() {
- new DrawTextureTest().run();
- new DrawTextureMixedTest().run();
- }
-
- private static class MyTexture extends BasicTexture {
- boolean mIsOpaque;
- int mBindCalled;
-
- MyTexture(GLCanvas canvas, int id, boolean isOpaque) {
- super(canvas, id, STATE_LOADED);
- setSize(1, 1);
- mIsOpaque = isOpaque;
- }
-
- @Override
- protected boolean onBind(GLCanvas canvas) {
- mBindCalled++;
- return true;
- }
-
- public boolean isOpaque() {
- return mIsOpaque;
- }
- }
-
- private static class DrawTextureTest extends GLMock {
- int mDrawTexiOESCalled;
- int mDrawArrayCalled;
- int[] mResult = new int[4];
-
- @Override
- public void glDrawTexiOES(int x, int y, int z,
- int width, int height) {
- mDrawTexiOESCalled++;
- }
-
- @Override
- public void glDrawArrays(int mode, int first, int count) {
- assertNotNull(mGLVertexPointer);
- assertEquals(GL10.GL_TRIANGLE_STRIP, mode);
- assertEquals(4, count);
- mGLVertexPointer.bindByteBuffer();
-
- double[] coord = new double[4];
- mGLVertexPointer.getArrayElement(first, coord);
- mResult[0] = (int) coord[0];
- mResult[1] = (int) coord[1];
- mGLVertexPointer.getArrayElement(first + 1, coord);
- mResult[2] = (int) coord[0];
- mResult[3] = (int) coord[1];
- mDrawArrayCalled++;
- }
-
- void run() {
- GLCanvas canvas = new GLCanvasImpl(this);
- canvas.setSize(400, 300);
- MyTexture texture = new MyTexture(canvas, 42, false); // non-opaque
- MyTexture texture_o = new MyTexture(canvas, 47, true); // opaque
-
- // Draw a non-opaque texture
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(42, mGLBindTextureId);
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertPremultipliedBlending(this);
- assertFalse(mGLStencilEnabled);
-
- // Draw an opaque texture
- canvas.drawTexture(texture_o, 100, 200, 300, 400);
- assertEquals(47, mGLBindTextureId);
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertFalse(mGLBlendEnabled);
-
- // Draw a non-opaque texture with alpha = 0.5
- canvas.setAlpha(0.5f);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(42, mGLBindTextureId);
- assertEquals(0x80808080, mGLColor);
- assertEquals(GL_MODULATE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertPremultipliedBlending(this);
- assertFalse(mGLStencilEnabled);
-
- // Draw an non-opaque texture with overriden alpha = 1
- canvas.drawTexture(texture, 100, 200, 300, 400, 1f);
- assertEquals(42, mGLBindTextureId);
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertPremultipliedBlending(this);
-
- // Draw an opaque texture with overriden alpha = 1
- canvas.drawTexture(texture_o, 100, 200, 300, 400, 1f);
- assertEquals(47, mGLBindTextureId);
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertFalse(mGLBlendEnabled);
-
- // Draw an opaque texture with overridden alpha = 0.25
- canvas.drawTexture(texture_o, 100, 200, 300, 400, 0.25f);
- assertEquals(47, mGLBindTextureId);
- assertEquals(0x40404040, mGLColor);
- assertEquals(GL_MODULATE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertPremultipliedBlending(this);
-
- // Draw an opaque texture with overridden alpha = 0.125
- // but with some rotation so it will use DrawArray.
- canvas.save();
- canvas.rotate(30, 0, 0, 1);
- canvas.drawTexture(texture_o, 100, 200, 300, 400, 0.125f);
- canvas.restore();
- assertEquals(47, mGLBindTextureId);
- assertEquals(0x20202020, mGLColor);
- assertEquals(GL_MODULATE, getTexEnvi(GL_TEXTURE_ENV_MODE));
- assertPremultipliedBlending(this);
-
- // We have drawn seven textures above.
- assertEquals(1, mDrawArrayCalled);
- assertEquals(6, mDrawTexiOESCalled);
-
- // translate and scale does not affect whether we
- // can use glDrawTexiOES, but rotate may.
- canvas.translate(10, 20, 30);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(7, mDrawTexiOESCalled);
-
- canvas.scale(10, 20, 30);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(8, mDrawTexiOESCalled);
-
- canvas.rotate(90, 1, 2, 3);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(8, mDrawTexiOESCalled);
-
- canvas.rotate(-90, 1, 2, 3);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(9, mDrawTexiOESCalled);
-
- canvas.rotate(180, 0, 0, 1);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(9, mDrawTexiOESCalled);
-
- canvas.rotate(180, 0, 0, 1);
- canvas.drawTexture(texture, 100, 200, 300, 400);
- assertEquals(10, mDrawTexiOESCalled);
-
- assertEquals(3, mDrawArrayCalled);
-
- assertTrue(texture.isLoaded(canvas));
- texture.recycle();
- assertFalse(texture.isLoaded(canvas));
- canvas.deleteRecycledResources();
-
- assertTrue(texture_o.isLoaded(canvas));
- texture_o.recycle();
- assertFalse(texture_o.isLoaded(canvas));
- }
- }
-
- private static class DrawTextureMixedTest extends GLMock {
-
- boolean mTexture2DEnabled0, mTexture2DEnabled1;
- int mBindTexture0;
- int mBindTexture1;
-
- @Override
- public void glEnable(int cap) {
- if (cap == GL_TEXTURE_2D) {
- texture2DEnable(true);
- }
- }
-
- @Override
- public void glDisable(int cap) {
- if (cap == GL_TEXTURE_2D) {
- texture2DEnable(false);
- }
- }
-
- private void texture2DEnable(boolean enable) {
- if (mGLActiveTexture == GL_TEXTURE0) {
- mTexture2DEnabled0 = enable;
- } else if (mGLActiveTexture == GL_TEXTURE1) {
- mTexture2DEnabled1 = enable;
- } else {
- fail();
- }
- }
-
- @Override
- public void glTexEnvfv(int target, int pname, float[] params, int offset) {
- if (target == GL_TEXTURE_ENV && pname == GL_TEXTURE_ENV_COLOR) {
- assertEquals(0.5f, params[offset + 3]);
- }
- }
-
- @Override
- public void glBindTexture(int target, int texture) {
- if (target == GL_TEXTURE_2D) {
- if (mGLActiveTexture == GL_TEXTURE0) {
- mBindTexture0 = texture;
- } else if (mGLActiveTexture == GL_TEXTURE1) {
- mBindTexture1 = texture;
- } else {
- fail();
- }
- }
- }
-
- void run() {
- GLCanvas canvas = new GLCanvasImpl(this);
- canvas.setSize(400, 300);
- MyTexture from = new MyTexture(canvas, 42, false); // non-opaque
- MyTexture to = new MyTexture(canvas, 47, true); // opaque
-
- canvas.drawMixed(from, to, 0.5f, 100, 200, 300, 400);
- assertEquals(42, mBindTexture0);
- assertEquals(47, mBindTexture1);
- assertTrue(mTexture2DEnabled0);
- assertFalse(mTexture2DEnabled1);
-
- assertEquals(GL_COMBINE, getTexEnvi(GL_TEXTURE1, GL_TEXTURE_ENV_MODE));
- assertEquals(GL_INTERPOLATE, getTexEnvi(GL_TEXTURE1, GL_COMBINE_RGB));
- assertEquals(GL_INTERPOLATE, getTexEnvi(GL_TEXTURE1, GL_COMBINE_ALPHA));
- assertEquals(GL_CONSTANT, getTexEnvi(GL_TEXTURE1, GL_SRC2_RGB));
- assertEquals(GL_CONSTANT, getTexEnvi(GL_TEXTURE1, GL_SRC2_ALPHA));
- assertEquals(GL_SRC_ALPHA, getTexEnvi(GL_TEXTURE1, GL_OPERAND2_RGB));
- assertEquals(GL_SRC_ALPHA, getTexEnvi(GL_TEXTURE1, GL_OPERAND2_ALPHA));
-
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE0, GL_TEXTURE_ENV_MODE));
-
- assertFalse(mGLBlendEnabled);
-
- canvas.drawMixed(from, to, 0, 100, 200, 300, 400);
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE0, GL_TEXTURE_ENV_MODE));
- assertEquals(42, mBindTexture0);
-
- canvas.drawMixed(from, to, 1, 100, 200, 300, 400);
- assertEquals(GL_REPLACE, getTexEnvi(GL_TEXTURE0, GL_TEXTURE_ENV_MODE));
- assertEquals(47, mBindTexture0);
- }
- }
-
- @SmallTest
public void testGetGLInstance() {
GL11 glStub = new GLStub();
GLCanvas canvas = new GLCanvasImpl(glStub);
}
@SmallTest
- public void testPaddings() {
- GLView view = new GLView();
-
- Rect p = view.getPaddings();
- assertEquals(0, p.left);
- assertEquals(0, p.top);
- assertEquals(0, p.right);
- assertEquals(0, p.bottom);
-
- view.setPaddings(10, 20, 30, 100);
- p = view.getPaddings();
- assertEquals(10, p.left);
- assertEquals(20, p.top);
- assertEquals(30, p.right);
- assertEquals(100, p.bottom);
-
- p = new Rect(11, 22, 33, 104);
- view.setPaddings(p);
- p = view.getPaddings();
- assertEquals(11, p.left);
- assertEquals(22, p.top);
- assertEquals(33, p.right);
- assertEquals(104, p.bottom);
- }
-
- @SmallTest
public void testParent() {
GLView a = new GLView();
GLView b = new GLView();
}
@SmallTest
- public void testRawTexture() {
- GL11 glStub = new GLStub();
- GLCanvas canvas = new GLCanvasImpl(glStub);
- RawTexture texture = RawTexture.newInstance(canvas);
- texture.onBind(canvas);
-
- GLCanvas canvas2 = new GLCanvasImpl(new GLStub());
- try {
- texture.onBind(canvas2);
- fail();
- } catch (RuntimeException ex) {
- // expected.
- }
-
- assertTrue(texture.isOpaque());
- }
-
- @SmallTest
public void testColorTexture() {
GLCanvasMock canvas = new GLCanvasMock();
ColorTexture texture = new ColorTexture(0x12345678);