• PUDN用户
  • Java
  • 805KB
  • rar
  • 0
  • 1 积分
  • 1985
  • 2010-12-30 16:32
/* * 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.cooliris.media; import java.util.ArrayList; import javax.microedition.khronos.opengles.GL11; import android.hardware.SensorEvent; import android.opengl.GLU; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.content.Context; import com.cooliris.app.App; import com.cooliris.app.Res; public final class GridLayer extends RootLayer implements MediaFeed.Listener, TimeBar.Listener { private static final String TAG = "GridLayer"; public static final int STATE_MEDIA_SETS = 0; public static final int STATE_GRID_VIEW = 1; public static final int STATE_FULL_SCREEN = 2; public static final int STATE_TIMELINE = 3; public static final int ANCHOR_LEFT = 0; public static final int ANCHOR_RIGHT = 1; public static final int ANCHOR_CENTER = 2; public static final int MAX_ITEMS_PER_SLOT = 32; public static final int MAX_DISPLAYED_ITEMS_PER_SLOT = 4; public static final int MAX_DISPLAYED_ITEMS_PER_FOCUSED_SLOT = 32; public static final int MAX_DISPLAY_SLOTS = 96; public static final int MAX_ITEMS_DRAWABLE = MAX_ITEMS_PER_SLOT * MAX_DISPLAY_SLOTS; private static final float SLIDESHOW_TRANSITION_TIME = 3.5f; private HudLayer mHud; private int mState; private final IndexRange mBufferedVisibleRange = new IndexRange(); private final IndexRange mVisibleRange = new IndexRange(); private final IndexRange mPreviousDataRange = new IndexRange(); private final IndexRange mCompleteRange = new IndexRange(); private final Pool<Vector3f> mTempVec; private final Pool<Vector3f> mTempVecAlt; private final ArrayList<MediaItem> mTempList = new ArrayList<MediaItem>(); private final MediaItem[] mTempHash = new MediaItem[64]; private final Vector3f mDeltaAnchorPositionUncommited = new Vector3f(); private Vector3f mDeltaAnchorPosition = new Vector3f(); // The display primitives. final private GridDrawables mDrawables; private float mSelectedAlpha = 0.0f; private float mTargetAlpha = 0.0f; final private GridCamera mCamera; final private GridCameraManager mCameraManager; final private GridDrawManager mDrawManager; final private GridInputProcessor mInputProcessor; private boolean mFeedAboutToChange; private boolean mPerformingLayoutChange; private boolean mFeedChanged; private final LayoutInterface mLayoutInterface; private static final LayoutInterface sfullScreenLayoutInterface = new GridLayoutInterface(1); private static final float DEPTH_POSITION = 0.55f; private MediaFeed mMediaFeed; private boolean mInAlbum = false; private int mCurrentExpandedSlot; private final DisplayList mDisplayList = new DisplayList(); private final DisplayItem[] mDisplayItems = new DisplayItem[MAX_ITEMS_DRAWABLE]; private final DisplaySlot[] mDisplaySlots = new DisplaySlot[MAX_DISPLAY_SLOTS]; private ArrayList<MediaItem> mVisibleItems; private final BackgroundLayer mBackground; private boolean mLocationFilter; private float mZoomValue = 1.0f; private float mCurrentFocusItemWidth = 1.0f; private float mCurrentFocusItemHeight = 1.0f; private float mTimeElapsedSinceGridViewReady = 0.0f; private boolean mSlideshowMode; private boolean mNoDeleteMode = false; private float mTimeElapsedSinceView; private final MediaBucketList mSelectedBucketList = new MediaBucketList(); private final MediaBucketList mMarkedBucketList = new MediaBucketList(); private float mTimeElapsedSinceStackViewReady; private Context mContext; private RenderView mView; private boolean mPickIntent; private boolean mViewIntent; private WakeLock mWakeLock; private int mStartMemoryRange; private int mFramesDirty; private String mRequestFocusContentUri; private int mFrameCount; private boolean mRequestToEnterSelection; private boolean mLayoutChanged = false; // private ArrayList<Integer> mBreakSlots = new ArrayList<Integer>(); // private ArrayList<Integer> mOldBreakSlots; // private LongSparseArray<Integer> mBreakSlots = new // LongSparseArray<Integer>(); // private LongSparseArray<Integer> mOldBreakSlots; public GridLayer(Context context, int itemWidth, int itemHeight, LayoutInterface layoutInterface, RenderView view) { mBackground = new BackgroundLayer(this); mContext = context; mView = view; Vector3f[] vectorPool = new Vector3f[128]; int length = vectorPool.length; for (int i = 0; i < length; ++i) { vectorPool[i] = new Vector3f(); } Vector3f[] vectorPoolRenderThread = new Vector3f[128]; length = vectorPoolRenderThread.length; for (int i = 0; i < length; ++i) { vectorPoolRenderThread[i] = new Vector3f(); } mTempVec = new Pool<Vector3f>(vectorPool); mTempVecAlt = new Pool<Vector3f>(vectorPoolRenderThread); DisplaySlot[] displaySlots = mDisplaySlots; for (int i = 0; i < MAX_DISPLAY_SLOTS; ++i) { DisplaySlot slot = new DisplaySlot(); displaySlots[i] = slot; } mLayoutInterface = layoutInterface; mCamera = new GridCamera(0, 0, itemWidth, itemHeight); mDrawables = new GridDrawables(itemWidth, itemHeight); mBufferedVisibleRange.set(Shared.INVALID, Shared.INVALID); mVisibleRange.set(Shared.INVALID, Shared.INVALID); mCompleteRange.set(Shared.INVALID, Shared.INVALID); mPreviousDataRange.set(Shared.INVALID, Shared.INVALID); mDeltaAnchorPosition.set(0, 0, 0); mDeltaAnchorPositionUncommited.set(0, 0, 0); mSelectedBucketList.clear(); mVisibleItems = new ArrayList<MediaItem>(); mHud = new HudLayer(context); mHud.setContext(context); mHud.setGridLayer(this); mHud.getPathBar().clear(); mHud.setGridLayer(this); mHud.getTimeBar().setListener(this); mHud.getPathBar().pushLabel(Res.drawable.icon_home_small, context.getResources().getString(Res.string.app_name), new Runnable() { public void run() { if (mHud.getAlpha() == 1.0f) { if (!mFeedAboutToChange) { setState(STATE_MEDIA_SETS); } } else { mHud.setAlpha(1.0f); } } }); mCameraManager = new GridCameraManager(mCamera); mDrawManager = new GridDrawManager(context, mCamera, mDrawables, mDisplayList, mDisplayItems, mDisplaySlots); mInputProcessor = new GridInputProcessor(context, mCamera, this, mView, mTempVec, mDisplayItems); setState(STATE_MEDIA_SETS); } public HudLayer getHud() { return mHud; } public void shutdown() { if (mMediaFeed != null) { mMediaFeed.shutdown(); } mContext = null; mSelectedBucketList.clear(); mView = null; } public void stop() { endSlideshow(); mBackground.clear(); handleLowMemory(); } @Override public void generate(Rende