Search in sources :

Example 91 with WorkerThread

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);
}
Also used : BufferedSink(okio.BufferedSink) File(java.io.File) WorkerThread(android.support.annotation.WorkerThread)

Example 92 with WorkerThread

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);
}
Also used : ContentValues(android.content.ContentValues) WorkerThread(android.support.annotation.WorkerThread)

Example 93 with WorkerThread

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);
}
Also used : Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 94 with WorkerThread

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;
}
Also used : Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) File(java.io.File) WorkerThread(android.support.annotation.WorkerThread)

Example 95 with WorkerThread

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();
    }
}
Also used : SettableFuture(org.whispersystems.signalservice.internal.util.concurrent.SettableFuture) HandlerThread(android.os.HandlerThread) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) ExecutionException(java.util.concurrent.ExecutionException) ResultReceiver(android.os.ResultReceiver) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)152 Cursor (android.database.Cursor)37 ArrayList (java.util.ArrayList)36 NonNull (android.support.annotation.NonNull)34 File (java.io.File)20 HashMap (java.util.HashMap)17 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)15 StorIOException (com.pushtorefresh.storio.StorIOException)15 IOException (java.io.IOException)13 ContentValues (android.content.ContentValues)11 Resources (android.content.res.Resources)10 Bitmap (android.graphics.Bitmap)10 Context (android.content.Context)8 Intent (android.content.Intent)7 SharedPreferences (android.content.SharedPreferences)7 Uri (android.net.Uri)7 Nullable (android.support.annotation.Nullable)7 VisibleForTesting (android.support.annotation.VisibleForTesting)7 Media (com.doctoror.fuckoffmusicplayer.domain.queue.Media)7 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)6