android.os.OperationCanceledException Java Examples
The following examples show how to use
android.os.OperationCanceledException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseUtils.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) { switch (code) { case 2: throw new IllegalArgumentException(msg); case 3: throw new UnsupportedOperationException(msg); case 4: throw new SQLiteAbortException(msg); case 5: throw new SQLiteConstraintException(msg); case 6: throw new SQLiteDatabaseCorruptException(msg); case 7: throw new SQLiteFullException(msg); case 8: throw new SQLiteDiskIOException(msg); case 9: throw new SQLiteException(msg); case 11: throw new OperationCanceledException(msg); default: reply.readException(code, msg); } }
Example #2
Source File: AsyncTaskLoader.java From FireFiles with Apache License 2.0 | 6 votes |
@Override protected D doInBackground(Void... params) { if (DEBUG) Log.v(TAG, this + " >>> doInBackground"); try { D data = AsyncTaskLoader.this.onLoadInBackground(); if (DEBUG) Log.v(TAG, this + " <<< doInBackground"); return data; } catch (OperationCanceledException ex) { if (!isCancelled()) { // onLoadInBackground threw a canceled exception spuriously. // This is problematic because it means that the LoaderManager did not // cancel the Loader itself and still expects to receive a result. // Additionally, the Loader's own state will not have been updated to // reflect the fact that the task was being canceled. // So we treat this case as an unhandled exception. throw ex; } if (DEBUG) Log.v(TAG, this + " <<< doInBackground (was canceled)", ex); return null; } }
Example #3
Source File: DocumentsContract.java From FireFiles with Apache License 2.0 | 6 votes |
/** * Return thumbnail representing the document at the given URI. Callers are * responsible for their own in-memory caching. * * @param documentUri document to return thumbnail for, which must have * {@link Document#FLAG_SUPPORTS_THUMBNAIL} set. * @param size optimal thumbnail size desired. A provider may return a * thumbnail of a different size, but never more than double the * requested size. * @param signal signal used to indicate if caller is no longer interested * in the thumbnail. * @return decoded thumbnail, or {@code null} if problem was encountered. * @see DocumentsProvider#openDocumentThumbnail(String, Point, * CancellationSignal) */ public static Bitmap getDocumentThumbnail( ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) { final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, documentUri.getAuthority()); try { if(UsbStorageProvider.AUTHORITY.equals(documentUri.getAuthority())) { return ImageUtils.getThumbnail(resolver, documentUri, size.x, size.y); } return getDocumentThumbnails(client, documentUri, size, signal); } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e); } return null; } finally { ContentProviderClientCompat.releaseQuietly(client); } }
Example #4
Source File: UriDerivativeLoader.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public final R loadInBackground() { synchronized (this) { if (isLoadInBackgroundCanceled2()) { throw new OperationCanceledException(); } mCancellationSignal = new CancellationSignal(); } try { return loadInBackground(mParam, mCancellationSignal); } finally { synchronized (this) { mCancellationSignal = null; } } }
Example #5
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 6 votes |
@Override protected Long doInBackground(Uri... params) { if (isCancelled()) return null; Long result = null; try { if (!TextUtils.isEmpty(mPath)) { File dir = new File(mPath); result = Utils.getDirectorySize(dir); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to calculate size for " + mPath + ": " + e); } Crashlytics.logException(e); } return result; }
Example #6
Source File: AsyncTaskLoader.java From FireFiles with Apache License 2.0 | 6 votes |
@Override protected D doInBackground(Void... params) { if (DEBUG) Log.v(TAG, this + " >>> doInBackground"); try { D data = AsyncTaskLoader.this.onLoadInBackground(); if (DEBUG) Log.v(TAG, this + " <<< doInBackground"); return data; } catch (OperationCanceledException ex) { if (!isCancelled()) { // onLoadInBackground threw a canceled exception spuriously. // This is problematic because it means that the LoaderManager did not // cancel the Loader itself and still expects to receive a result. // Additionally, the Loader's own state will not have been updated to // reflect the fact that the task was being canceled. // So we treat this case as an unhandled exception. throw ex; } if (DEBUG) Log.v(TAG, this + " <<< doInBackground (was canceled)", ex); return null; } }
Example #7
Source File: DocumentsContract.java From FireFiles with Apache License 2.0 | 6 votes |
/** * Return thumbnail representing the document at the given URI. Callers are * responsible for their own in-memory caching. * * @param documentUri document to return thumbnail for, which must have * {@link Document#FLAG_SUPPORTS_THUMBNAIL} set. * @param size optimal thumbnail size desired. A provider may return a * thumbnail of a different size, but never more than double the * requested size. * @param signal signal used to indicate if caller is no longer interested * in the thumbnail. * @return decoded thumbnail, or {@code null} if problem was encountered. * @see DocumentsProvider#openDocumentThumbnail(String, Point, * CancellationSignal) */ public static Bitmap getDocumentThumbnail( ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) { final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, documentUri.getAuthority()); try { if(UsbStorageProvider.AUTHORITY.equals(documentUri.getAuthority())) { return ImageUtils.getThumbnail(resolver, documentUri, size.x, size.y); } return getDocumentThumbnails(client, documentUri, size, signal); } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e); } return null; } finally { ContentProviderClientCompat.releaseQuietly(client); } }
Example #8
Source File: UriDerivativeLoader.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public final R loadInBackground() { synchronized (this) { if (isLoadInBackgroundCanceled2()) { throw new OperationCanceledException(); } mCancellationSignal = new CancellationSignal(); } try { return loadInBackground(mParam, mCancellationSignal); } finally { synchronized (this) { mCancellationSignal = null; } } }
Example #9
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 6 votes |
@Override protected Long doInBackground(Uri... params) { if (isCancelled()) return null; Long result = null; try { if (!TextUtils.isEmpty(mPath)) { File dir = new File(mPath); result = Utils.getDirectorySize(dir); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to calculate size for " + mPath + ": " + e); } Crashlytics.logException(e); } return result; }
Example #10
Source File: AsyncTaskLoader.java From FireFiles with Apache License 2.0 | 6 votes |
@Override protected D doInBackground(Void... params) { if (DEBUG) Log.v(TAG, this + " >>> doInBackground"); try { D data = AsyncTaskLoader.this.onLoadInBackground(); if (DEBUG) Log.v(TAG, this + " <<< doInBackground"); return data; } catch (OperationCanceledException ex) { if (!isCancelled()) { // onLoadInBackground threw a canceled exception spuriously. // This is problematic because it means that the LoaderManager did not // cancel the Loader itself and still expects to receive a result. // Additionally, the Loader's own state will not have been updated to // reflect the fact that the task was being canceled. // So we treat this case as an unhandled exception. throw ex; } if (DEBUG) Log.v(TAG, this + " <<< doInBackground (was canceled)", ex); return null; } }
Example #11
Source File: UriDerivativeLoader.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public final R loadInBackground() { synchronized (this) { if (isLoadInBackgroundCanceled2()) { throw new OperationCanceledException(); } mCancellationSignal = new CancellationSignal(); } try { return loadInBackground(mParam, mCancellationSignal); } finally { synchronized (this) { mCancellationSignal = null; } } }
Example #12
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 6 votes |
@Override protected Long doInBackground(Uri... params) { if (isCancelled()) return null; Long result = null; try { if (!TextUtils.isEmpty(mPath)) { File dir = new File(mPath); result = Utils.getDirectorySize(dir); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to calculate size for " + mPath + ": " + e); } CrashReportingManager.logException(e); } return result; }
Example #13
Source File: AsyncTaskLoader.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override protected D doInBackground(Void... params) { if (DEBUG) Log.v(TAG, this + " >>> doInBackground"); try { D data = AsyncTaskLoader.this.onLoadInBackground(); if (DEBUG) Log.v(TAG, this + " <<< doInBackground"); return data; } catch (OperationCanceledException ex) { if (!isCancelled()) { // onLoadInBackground threw a canceled exception spuriously. // This is problematic because it means that the LoaderManager did not // cancel the Loader itself and still expects to receive a result. // Additionally, the Loader's own state will not have been updated to // reflect the fact that the task was being canceled. // So we treat this case as an unhandled exception. throw ex; } if (DEBUG) Log.v(TAG, this + " <<< doInBackground (was canceled)", ex); return null; } }
Example #14
Source File: DocumentsContract.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Return thumbnail representing the document at the given URI. Callers are * responsible for their own in-memory caching. * * @param documentUri document to return thumbnail for, which must have * {@link Document#FLAG_SUPPORTS_THUMBNAIL} set. * @param size optimal thumbnail size desired. A provider may return a * thumbnail of a different size, but never more than double the * requested size. * @param signal signal used to indicate if caller is no longer interested * in the thumbnail. * @return decoded thumbnail, or {@code null} if problem was encountered. * @see DocumentsProvider#openDocumentThumbnail(String, Point, * android.os.CancellationSignal) */ public static Bitmap getDocumentThumbnail( ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) throws FileNotFoundException { final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( documentUri.getAuthority()); try { return getDocumentThumbnail(client, documentUri, size, signal); } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e); } rethrowIfNecessary(resolver, e); return null; } finally { ContentProviderClient.releaseQuietly(client); } }
Example #15
Source File: DocumentsContract.java From FireFiles with Apache License 2.0 | 6 votes |
/** * Return thumbnail representing the document at the given URI. Callers are * responsible for their own in-memory caching. * * @param documentUri document to return thumbnail for, which must have * {@link Document#FLAG_SUPPORTS_THUMBNAIL} set. * @param size optimal thumbnail size desired. A provider may return a * thumbnail of a different size, but never more than double the * requested size. * @param signal signal used to indicate if caller is no longer interested * in the thumbnail. * @return decoded thumbnail, or {@code null} if problem was encountered. * @see DocumentsProvider#openDocumentThumbnail(String, Point, * CancellationSignal) */ public static Bitmap getDocumentThumbnail( ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) { final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, documentUri.getAuthority()); try { if(UsbStorageProvider.AUTHORITY.equals(documentUri.getAuthority())) { return ImageUtils.getThumbnail(resolver, documentUri, size.x, size.y); } return getDocumentThumbnails(client, documentUri, size, signal); } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e); } return null; } finally { ContentProviderClientCompat.releaseQuietly(client); } }
Example #16
Source File: DetailFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { filePath = doc.path; if (!Utils.isDir(doc.mimeType)) { final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, doc.mimeType); int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width); Point mThumbSize = new Point(thumbSize, thumbSize); final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId); final Context context = getActivity(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; try { if (doc.mimeType.equals(Document.MIME_TYPE_APK) && !TextUtils.isEmpty(filePath)) { result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, filePath, Document.MIME_TYPE_APK)).getBitmap(); } else { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, uri, mThumbSize, null); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG_DETAIL, "Failed to load thumbnail for " + uri + ": " + e); } Crashlytics.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } sizeString = Formatter.formatFileSize(context, doc.size); } else{ if(!TextUtils.isEmpty(filePath)){ File dir = new File(filePath); sizeString = Formatter.formatFileSize(getActivity(), Utils.getDirectorySize(dir)); } } return null; }
Example #17
Source File: OAuthManagerTest.java From android-oauth-client with Apache License 2.0 | 5 votes |
@Test public void testCallback() throws InterruptedException, OperationCanceledException, IOException { MockOAuthCallback mockCallback = new MockOAuthCallback(); mock.runTest(null, mockCallback, null); latch.await(10, TimeUnit.SECONDS); assertEquals("ok", mockCallback.getResult()); }
Example #18
Source File: OAuthManagerTest.java From android-oauth-client with Apache License 2.0 | 5 votes |
@Test(expected = RuntimeException.class) public void testTaskExecutionThatThrowsException() throws OperationCanceledException, IOException { OAuthFuture<String> future = mock.runTest(new Runnable() { @Override public void run() { throw new RuntimeException(); } }, null, null); future.getResult(); }
Example #19
Source File: IconHelper.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Bitmap doInBackground(Uri... params) { if (isCancelled()) return null; final Context context = mIconThumb.getContext(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; Bitmap result = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal); if (null == result){ result = ImageUtils.getThumbnail(mPath, mimeType, mThumbSize.x, mThumbSize.y); } if (result != null) { final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize); thumbs.put(mUri, result); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e); } Crashlytics.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } return result; }
Example #20
Source File: DatabaseUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Special function for writing an exception result at the header of * a parcel, to be used when returning an exception from a transaction. * exception will be re-thrown by the function in another process * @param reply Parcel to write to * @param e The Exception to be written. * @see Parcel#writeNoException * @see Parcel#writeException */ public static final void writeExceptionToParcel(Parcel reply, Exception e) { int code = 0; boolean logException = true; if (e instanceof FileNotFoundException) { code = 1; logException = false; } else if (e instanceof IllegalArgumentException) { code = 2; } else if (e instanceof UnsupportedOperationException) { code = 3; } else if (e instanceof SQLiteAbortException) { code = 4; } else if (e instanceof SQLiteConstraintException) { code = 5; } else if (e instanceof SQLiteDatabaseCorruptException) { code = 6; } else if (e instanceof SQLiteFullException) { code = 7; } else if (e instanceof SQLiteDiskIOException) { code = 8; } else if (e instanceof SQLiteException) { code = 9; } else if (e instanceof OperationApplicationException) { code = 10; } else if (e instanceof OperationCanceledException) { code = 11; logException = false; } else { reply.writeException(e); Log.e(TAG, "Writing exception to parcel", e); return; } reply.writeInt(code); reply.writeString(e.getMessage()); if (logException) { Log.e(TAG, "Writing exception to parcel", e); } }
Example #21
Source File: CursorLoader.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public Cursor loadInBackground() { synchronized (this) { if (isLoadInBackgroundCanceled()) { throw new OperationCanceledException(); } mCancellationSignal = new CancellationSignal(); } try { Cursor cursor = getContext().getContentResolver().query(mUri, mProjection, mSelection, mSelectionArgs, mSortOrder, mCancellationSignal); if (cursor != null) { try { // Ensure the cursor window is filled. cursor.getCount(); cursor.registerContentObserver(mObserver); } catch (RuntimeException ex) { cursor.close(); throw ex; } } return cursor; } finally { synchronized (this) { mCancellationSignal = null; } } }
Example #22
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Bitmap doInBackground(Uri... params) { if (isCancelled()) return null; final Context context = mIconThumb.getContext(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; Bitmap result = null; try { if (Utils.isAPK(mMimeType)) { result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, mPath, Document.MIME_TYPE_APK)).getBitmap(); } else { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal); } if (null == result){ result = ImageUtils.getThumbnail(mPath, mMimeType, mThumbSize.x, mThumbSize.y); } if (result != null) { final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize); thumbs.put(mUri, result); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e); } Crashlytics.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } return result; }
Example #23
Source File: IconHelper.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Bitmap doInBackground(Uri... params) { if (isCancelled()) return null; final Context context = mIconThumb.getContext(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; Bitmap result = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal); if (null == result){ result = ImageUtils.getThumbnail(mPath, mimeType, mThumbSize.x, mThumbSize.y); } if (result != null) { final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize); thumbs.put(mUri, result); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e); } Crashlytics.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } return result; }
Example #24
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 5 votes |
void error(Throwable ex) { if (ex instanceof MessagingException && ("connection failure".equals(ex.getMessage()) || "Not connected".equals(ex.getMessage()) || // POP3 ex.getCause() instanceof SocketException || ex.getCause() instanceof ConnectionException)) recoverable = false; if (ex instanceof ConnectionException) // failed to create new store connection // BYE, Socket is closed recoverable = false; if (ex instanceof StoreClosedException || ex instanceof FolderClosedException || ex instanceof FolderNotFoundException) // Lost folder connection to server recoverable = false; if (ex instanceof IllegalStateException && ( "Not connected".equals(ex.getMessage()) || "This operation is not allowed on a closed folder".equals(ex.getMessage()))) recoverable = false; if (ex instanceof OperationCanceledException) recoverable = false; thread.interrupt(); yield(); }
Example #25
Source File: DetailFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { filePath = doc.path; if (!Utils.isDir(doc.mimeType)) { final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, doc.mimeType); int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width); Point mThumbSize = new Point(thumbSize, thumbSize); final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId); final Context context = getActivity(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; try { if (doc.mimeType.equals(Document.MIME_TYPE_APK) && !TextUtils.isEmpty(filePath)) { result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, filePath, Document.MIME_TYPE_APK)).getBitmap(); } else { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, uri, mThumbSize, null); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG_DETAIL, "Failed to load thumbnail for " + uri + ": " + e); } CrashReportingManager.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } sizeString = Formatter.formatFileSize(context, doc.size); } else{ if(!TextUtils.isEmpty(filePath)){ File dir = new File(filePath); sizeString = Formatter.formatFileSize(getActivity(), Utils.getDirectorySize(dir)); } } return null; }
Example #26
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Bitmap doInBackground(Uri... params) { if (isCancelled()) return null; final Context context = mIconThumb.getContext(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; Bitmap result = null; try { if (Utils.isAPK(mMimeType)) { result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, mPath, Document.MIME_TYPE_APK)).getBitmap(); } else { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal); } if (null == result){ result = ImageUtils.getThumbnail(mPath, mMimeType, mThumbSize.x, mThumbSize.y); } if (result != null) { final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize); thumbs.put(mUri, result); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e); } CrashReportingManager.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } return result; }
Example #27
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Bitmap doInBackground(Uri... params) { if (isCancelled()) return null; final Context context = mIconThumb.getContext(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; Bitmap result = null; try { if (Utils.isAPK(mMimeType)) { result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, mPath, Document.MIME_TYPE_APK)).getBitmap(); } else { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal); } if (null == result){ result = ImageUtils.getThumbnail(mPath, mMimeType, mThumbSize.x, mThumbSize.y); } if (result != null) { final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize); thumbs.put(mUri, result); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e); } Crashlytics.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } return result; }
Example #28
Source File: DetailFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { filePath = doc.path; if (!Utils.isDir(doc.mimeType)) { final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, doc.mimeType); int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width); Point mThumbSize = new Point(thumbSize, thumbSize); final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId); final Context context = getActivity(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; try { if (doc.mimeType.equals(Document.MIME_TYPE_APK) && !TextUtils.isEmpty(filePath)) { result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, filePath, Document.MIME_TYPE_APK)).getBitmap(); } else { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, uri, mThumbSize, null); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG_DETAIL, "Failed to load thumbnail for " + uri + ": " + e); } Crashlytics.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } sizeString = Formatter.formatFileSize(context, doc.size); } else{ if(!TextUtils.isEmpty(filePath)){ File dir = new File(filePath); sizeString = Formatter.formatFileSize(getActivity(), Utils.getDirectorySize(dir)); } } return null; }
Example #29
Source File: IconHelper.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected Bitmap doInBackground(Uri... params) { if (isCancelled()) return null; final Context context = mIconThumb.getContext(); final ContentResolver resolver = context.getContentResolver(); ContentProviderClient client = null; Bitmap result = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority()); result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal); if (null == result){ result = ImageUtils.getThumbnail(mPath, mimeType, mThumbSize.x, mThumbSize.y); } if (result != null) { final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize); thumbs.put(mUri, result); } } catch (Exception e) { if (!(e instanceof OperationCanceledException)) { Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e); } CrashReportingManager.logException(e); } finally { ContentProviderClientCompat.releaseQuietly(client); } return result; }
Example #30
Source File: OAuthManagerTest.java From android-oauth-client with Apache License 2.0 | 4 votes |
@Test public void testNormalTaskExecution() throws OperationCanceledException, IOException { OAuthFuture<String> future = mock.runTest(null, null, null); String result = future.getResult(); assertEquals("ok", result); }