private void reuseLastShownMedia() { if (!Preferences.Media.isRandomSequence(mContext) && Preferences.Media.isRememberLastMediaShown(mContext)) { String lastMedia = Preferences.Media.getLastMediaShown(mContext); if (!TextUtils.isEmpty(lastMedia)) { File lastMediaFile = new File(lastMedia); int pos = mNewImages.indexOf(lastMediaFile); // Only if not exists or is not the next in the list if (pos > 0) { // Remove all items to used for (int i = pos - 1; i >= 0; i--) { mUsedImages.add(mNewImages.remove(i)); } } } } }
/** {@inheritDoc} */ @Override public void onPartialMediaDiscovered(File[] images, boolean userRequest) { if (mBackgroundTask != null) { // In order to continue with the last media shown, we need all the // images to process them if (!Preferences.Media.isRememberLastMediaShown(mContext)) { mBackgroundTask.setPartialAvailableImages(images); } } }
/** {@inheritDoc} */ @Override public void run() { mRun = true; while (mRun) { // Check if we need to load more images while (!mTaskPaused && PhotoPhaseTextureManager.this.mQueue.items() < PhotoPhaseTextureManager.this.mQueue.size()) { File image; synchronized (mLoadSync) { // Swap arrays if needed if (mNewImages.size() == 0) { mNewImages.addAll(mUsedImages); mUsedImages.clear(); } if (mNewImages.size() == 0) { if (!mEmpty) { reloadMedia(false); } break; } // Extract a random or sequential image int low = 0; int high = mNewImages.size() - 1; if (Preferences.Media.isRandomSequence(mContext)) { image = mNewImages.remove(Utils.getNextRandom(low, high)); } else { image = mNewImages.remove(0); } Preferences.Media.setLastMediaShown(mContext, image.getPath()); // Add to used images mUsedImages.add(image); } // Run commands in the GLThread if (!mRun) break; PictureDispatcher pd = new PictureDispatcher(); pd.mImage = image; mDispatcher.dispatch(pd); // Wait until the texture is loaded try { synchronized (pd.mWait) { pd.mWait.wait(); } } catch (Exception e) { // Ignore } } // Wait for new request synchronized (mLoadSync) { try { mLoadSync.wait(); } catch (Exception e) { // Ignore } } } }