类android.os.OperationCanceledException源码实例Demo

下面列出了怎么用android.os.OperationCanceledException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: DatabaseUtils.java
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);
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: AsyncTaskLoader.java
@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;
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: DocumentsContract.java
/**
 * 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);
    }
}
 
源代码4 项目: FireFiles   文件: DirectoryFragment.java
@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;
}
 
源代码5 项目: FireFiles   文件: UriDerivativeLoader.java
@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;
        }
    }
}
 
源代码6 项目: FireFiles   文件: DocumentsContract.java
/**
 * 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);
    }
}
 
源代码7 项目: FireFiles   文件: AsyncTaskLoader.java
@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;
    }
}
 
源代码8 项目: FireFiles   文件: DirectoryFragment.java
@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;
}
 
源代码9 项目: FireFiles   文件: UriDerivativeLoader.java
@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;
        }
    }
}
 
源代码10 项目: FireFiles   文件: DocumentsContract.java
/**
 * 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);
    }
}
 
源代码11 项目: FireFiles   文件: AsyncTaskLoader.java
@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;
    }
}
 
源代码12 项目: FireFiles   文件: DirectoryFragment.java
@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;
}
 
源代码13 项目: FireFiles   文件: UriDerivativeLoader.java
@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;
        }
    }
}
 
源代码14 项目: FireFiles   文件: DocumentsContract.java
/**
 * 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);
    }
}
 
源代码15 项目: FireFiles   文件: AsyncTaskLoader.java
@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;
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: DatabaseUtils.java
/**
 * 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);
    }
}
 
源代码17 项目: android_9.0.0_r45   文件: CursorLoader.java
@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;
        }
    }
}
 
源代码18 项目: FairEmail   文件: Core.java
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();
}
 
源代码19 项目: FireFiles   文件: DetailFragment.java
@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;
}
 
源代码20 项目: FireFiles   文件: DirectoryFragment.java
@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;
}
 
源代码21 项目: FireFiles   文件: IconHelper.java
@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;
}
 
源代码22 项目: FireFiles   文件: DetailFragment.java
@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;
}
 
源代码23 项目: FireFiles   文件: DirectoryFragment.java
@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;
}
 
源代码24 项目: FireFiles   文件: IconHelper.java
@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;
}
 
源代码25 项目: FireFiles   文件: DetailFragment.java
@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;
}
 
源代码26 项目: FireFiles   文件: DirectoryFragment.java
@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;
}
 
源代码27 项目: FireFiles   文件: IconHelper.java
@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;
}
 
源代码28 项目: android-oauth-client   文件: OAuthManagerTest.java
@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();
}
 
源代码29 项目: android-oauth-client   文件: OAuthManagerTest.java
@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());
}
 
源代码30 项目: android-oauth-client   文件: OAuthManagerTest.java
@Test
public void testNormalTaskExecution() throws OperationCanceledException, IOException {
    OAuthFuture<String> future = mock.runTest(null, null, null);
    String result = future.getResult();
    assertEquals("ok", result);
}
 
 类所在包
 同包方法