List of usage examples for android.webkit WebView post
public boolean post(Runnable action)
Causes the Runnable to be added to the message queue.
From source file:im.neon.adapters.VectorMediasViewerAdapter.java
/** * Download the high res image/* w ww . j a v a 2s. co m*/ * @param view the slider page view * @param position the item position */ private void downloadHighResPict(final View view, final int position) { final WebView webView = (WebView) view.findViewById(R.id.media_slider_image_webview); final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart); final SlidableMediaInfo imageInfo = mMediasMessagesList.get(position); final String viewportContent = "width=640"; final String loadingUri = imageInfo.mMediaUrl; final String downloadId = mMediasCache.loadBitmap(mContext, mSession.getHomeserverConfig(), loadingUri, imageInfo.mRotationAngle, imageInfo.mOrientation, imageInfo.mMimeType, imageInfo.mEncryptedFileInfo); webView.getSettings().setDisplayZoomControls(false); if (null != downloadId) { pieFractionView.setVisibility(View.VISIBLE); pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId)); mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() { @Override public void onDownloadError(String downloadId, JsonElement jsonElement) { MatrixError error = JsonUtils.toMatrixError(jsonElement); if ((null != error) && error.isSupportedErrorCode()) { Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } } @Override public void onDownloadProgress(String aDownloadId, DownloadStats stats) { if (aDownloadId.equals(downloadId)) { pieFractionView.setFraction(stats.mProgress); } } @Override public void onDownloadComplete(String aDownloadId) { if (aDownloadId.equals(downloadId)) { pieFractionView.setVisibility(View.GONE); final File mediaFile = mMediasCache.mediaCacheFile(loadingUri, imageInfo.mMimeType); if (null != mediaFile) { mHighResMediaIndex.add(position); Uri uri = Uri.fromFile(mediaFile); final String newHighResUri = uri.toString(); webView.post(new Runnable() { @Override public void run() { Uri mediaUri = Uri.parse(newHighResUri); // refresh the UI loadImage(webView, mediaUri, viewportContent, computeCss(newHighResUri, VectorMediasViewerAdapter.this.mMaxImageWidth, VectorMediasViewerAdapter.this.mMaxImageHeight, imageInfo.mRotationAngle)); } }); } } } }); } }