public void load(final String fileUrl, final String cachePath, final TextureOptions options) { mIsAsync = false; mFileUrl = fileUrl; mCachePath = cachePath; // mFilePath = filePath; mOptions = options; int[] dimensions = new int[2]; Bitmap bitmap = null; final File file = new File(mCachePath); if (file.exists()) { bitmap = Pure2DUtils.getFileBitmap(mCachePath, options, dimensions); } else if (fileUrl != null && fileUrl.length() > 0) { // try to download and cache if (new DownloadTask(mFileUrl, mCachePath).run()) { bitmap = Pure2DUtils.getFileBitmap(mCachePath, options, dimensions); } } if (bitmap != null) { load(bitmap, dimensions[0], dimensions[1], options != null ? options.inMipmaps : 0); bitmap.recycle(); } else { Log.e(TAG, "Unable to load bitmap: " + mCachePath, new Exception()); // callback, regardless whether it's successful or not if (mListener != null) { mListener.onTextureLoad(this); } } }
@Override protected Void doInBackground(final Void... params) { final int[] dimensions = new int[2]; Bitmap bitmap = null; final File file = new File(mCachePath); if (file.exists()) { bitmap = Pure2DUtils.getFileBitmap(mCachePath, mOptions, dimensions); } else if (mFileUrl != null && mFileUrl.length() > 0) { // try to download and cache if (new DownloadTask(mFileUrl, mCachePath).run()) { bitmap = Pure2DUtils.getFileBitmap(mCachePath, mOptions, dimensions); } } final Bitmap finalBitmap = bitmap; mGLState.queueEvent( new Runnable() { @Override public void run() { if (finalBitmap != null) { load( finalBitmap, dimensions[0], dimensions[1], mOptions != null ? mOptions.inMipmaps : 0); finalBitmap.recycle(); } else { Log.e(TAG, "Unable to load bitmap: " + mCachePath, new Exception()); // callback, regardless whether it's successful or not if (mListener != null) { mListener.onTextureLoad(URLCacheTexture.this); } } } }); return null; }