本文整理汇总了Java中android.os.OperationCanceledException类的典型用法代码示例。如果您正苦于以下问题:Java OperationCanceledException类的具体用法?Java OperationCanceledException怎么用?Java OperationCanceledException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OperationCanceledException类属于android.os包,在下文中一共展示了OperationCanceledException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDocumentThumbnail
import android.os.OperationCanceledException; //导入依赖的package包/类
/**
* 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);
}
}
示例2: doInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@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;
}
示例3: loadInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@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;
}
}
}
示例4: doInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@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;
}
}
示例5: readExceptionFromParcel
import android.os.OperationCanceledException; //导入依赖的package包/类
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);
}
}
示例6: loadInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@Override
public FSCursor loadInBackground() {
synchronized (this) {
if (isLoadInBackgroundCanceled()) {
throw new OperationCanceledException();
}
mCancellationSignal = new CancellationSignal();
}
FSCursor cursor = (FSCursor) resolver.preserveQueryStateAndGet();
if (cursor != null) {
try {
cursor.getCount(); // TODO: determine whether you need to make this call
} catch (RuntimeException ex) {
cursor.close();
throw ex;
}
}
return cursor;
}
示例7: testRawQueryWithFactoryAndCancellationSignal
import android.os.OperationCanceledException; //导入依赖的package包/类
@Test
public void testRawQueryWithFactoryAndCancellationSignal() throws Exception {
CancellationSignal signal = new CancellationSignal();
Cursor cursor = database.rawQueryWithFactory(null, "select * from table_name", null, null, signal);
assertThat(cursor).isNotNull();
assertThat(cursor.getColumnCount()).isEqualTo(5);
assertThat(cursor.isClosed()).isFalse();
signal.cancel();
try {
cursor.moveToNext();
fail("did not get cancellation signal");
} catch (OperationCanceledException e) {
// expected
}
}
示例8: doInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@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;
}
示例9: doInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@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;
}
示例10: writeExceptionToParcel
import android.os.OperationCanceledException; //导入依赖的package包/类
/**
* 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);
}
}
示例11: loadInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
/**
*/
@Override
public D loadInBackground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
synchronized (this) {
if (isLoadInBackgroundCanceled()) {
throw new OperationCanceledException();
}
this.mCancellationSignal = new CancellationSignal();
}
}
try {
final Cursor cursor = query();
if (cursor != null) {
try {
// Ensure that the cursor window is filled.
cursor.getCount();
cursor.registerContentObserver(mObserver);
} catch (RuntimeException e) {
cursor.close();
throw e;
}
}
return cursor == null ? onLoadFailed() : onLoadFinished(cursor);
} finally {
synchronized (this) {
this.mCancellationSignal = null;
}
}
}
示例12: loadInBackground
import android.os.OperationCanceledException; //导入依赖的package包/类
@Override
public D 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 wrap(cursor);
}
return null;
} finally {
synchronized (this) {
mCancellationSignal = null;
}
}
}
示例13: testTaskExecutionThatThrowsException
import android.os.OperationCanceledException; //导入依赖的package包/类
@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();
}
示例14: testCallback
import android.os.OperationCanceledException; //导入依赖的package包/类
@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());
}
示例15: isFrameworkOperationCanceledException
import android.os.OperationCanceledException; //导入依赖的package包/类
static boolean isFrameworkOperationCanceledException(Exception e) {
return e instanceof OperationCanceledException;
}