use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class FavoriteManager method toFile.
@WorkerThread
private Uri toFile(Context context, Cursor cursor) throws IOException {
if (cursor.getCount() == 0) {
return null;
}
File dir = new File(context.getFilesDir(), PATH_SAVED);
if (!dir.exists() && !dir.mkdir()) {
return null;
}
File file = new File(dir, FILENAME_EXPORT);
if (!file.exists() && !file.createNewFile()) {
return null;
}
BufferedSink bufferedSink = Okio.buffer(Okio.sink(file));
do {
Favorite item = cursor.getFavorite();
bufferedSink.writeUtf8(item.getDisplayedTitle()).writeByte('\n').writeUtf8(item.getUrl()).writeByte('\n').writeUtf8(String.format(HackerNewsClient.WEB_ITEM_PATH, item.getId()));
if (!cursor.isLast()) {
bufferedSink.writeByte('\n').writeByte('\n');
}
} while (cursor.moveToNext());
Util.closeQuietly(bufferedSink);
return getUriForFile(context, file);
}
use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class SessionManager method insert.
@WorkerThread
private void insert(ContentResolver cr, String itemId) {
ContentValues contentValues = new ContentValues();
contentValues.put(MaterialisticProvider.ViewedEntry.COLUMN_NAME_ITEM_ID, itemId);
cr.insert(MaterialisticProvider.URI_VIEWED, contentValues);
}
use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class SessionManager method isViewed.
@WorkerThread
@NonNull
Observable<Boolean> isViewed(ContentResolver contentResolver, String itemId) {
if (TextUtils.isEmpty(itemId)) {
return Observable.just(false);
}
Cursor cursor = contentResolver.query(MaterialisticProvider.URI_VIEWED, null, MaterialisticProvider.ViewedEntry.COLUMN_NAME_ITEM_ID + " = ?", new String[] { itemId }, null);
boolean result = false;
if (cursor != null) {
result = cursor.getCount() > 0;
cursor.close();
}
return Observable.just(result);
}
use of android.support.annotation.WorkerThread in project k-9 by k9mail.
the class AttachmentController method getBestViewIntentAndSaveFile.
@WorkerThread
private Intent getBestViewIntentAndSaveFile() {
Uri intentDataUri;
try {
intentDataUri = AttachmentTempFileProvider.createTempUriForContentUri(context, attachment.internalUri);
} catch (IOException e) {
Timber.e(e, "Error creating temp file for attachment!");
return null;
}
String displayName = attachment.displayName;
String inferredMimeType = MimeUtility.getMimeTypeByExtension(displayName);
IntentAndResolvedActivitiesCount resolvedIntentInfo;
String mimeType = attachment.mimeType;
if (MimeUtility.isDefaultMimeType(mimeType)) {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, inferredMimeType);
} else {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, mimeType);
if (!resolvedIntentInfo.hasResolvedActivities() && !inferredMimeType.equals(mimeType)) {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, inferredMimeType);
}
}
if (!resolvedIntentInfo.hasResolvedActivities()) {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE);
}
Intent viewIntent;
if (resolvedIntentInfo.hasResolvedActivities() && resolvedIntentInfo.containsFileUri()) {
try {
File tempFile = TemporaryAttachmentStore.getFileForWriting(context, displayName);
writeAttachmentToStorage(tempFile);
viewIntent = createViewIntentForFileUri(resolvedIntentInfo.getMimeType(), Uri.fromFile(tempFile));
} catch (IOException e) {
Timber.e(e, "Error while saving attachment to use file:// URI with ACTION_VIEW Intent");
viewIntent = createViewIntentForAttachmentProviderUri(intentDataUri, MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE);
}
} else {
viewIntent = resolvedIntentInfo.getIntent();
}
return viewIntent;
}
use of android.support.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class WebRtcCallService method isCallActive.
@WorkerThread
public static boolean isCallActive(Context context) {
Log.w(TAG, "isCallActive()");
HandlerThread handlerThread = null;
try {
handlerThread = new HandlerThread("webrtc-callback");
handlerThread.start();
final SettableFuture<Boolean> future = new SettableFuture<>();
ResultReceiver resultReceiver = new ResultReceiver(new Handler(handlerThread.getLooper())) {
protected void onReceiveResult(int resultCode, Bundle resultData) {
Log.w(TAG, "Got result...");
future.set(resultCode == 1);
}
};
Intent intent = new Intent(context, WebRtcCallService.class);
intent.setAction(ACTION_IS_IN_CALL_QUERY);
intent.putExtra(EXTRA_RESULT_RECEIVER, resultReceiver);
context.startService(intent);
Log.w(TAG, "Blocking on result...");
return future.get();
} catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e);
return false;
} finally {
if (handlerThread != null)
handlerThread.quit();
}
}
Aggregations