Search in sources :

Example 66 with Nullable

use of android.support.annotation.Nullable in project k-9 by k9mail.

the class TextPartFinder method findFirstTextPart.

@Nullable
public Part findFirstTextPart(@NonNull Part part) {
    String mimeType = part.getMimeType();
    Body body = part.getBody();
    if (body instanceof Multipart) {
        Multipart multipart = (Multipart) body;
        if (isSameMimeType(mimeType, "multipart/alternative")) {
            return findTextPartInMultipartAlternative(multipart);
        } else {
            return findTextPartInMultipart(multipart);
        }
    } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) {
        return part;
    }
    return null;
}
Also used : Multipart(com.fsck.k9.mail.Multipart) Body(com.fsck.k9.mail.Body) Nullable(android.support.annotation.Nullable)

Example 67 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class CameraUtils method getPreferredPreviewSize.

/*
   * modified from: https://github.com/commonsguy/cwac-camera/blob/master/camera/src/com/commonsware/cwac/camera/CameraUtils.java
   */
@Nullable
public static Size getPreferredPreviewSize(int displayOrientation, int width, int height, @NonNull Parameters parameters) {
    final int targetWidth = displayOrientation % 180 == 90 ? height : width;
    final int targetHeight = displayOrientation % 180 == 90 ? width : height;
    final double targetRatio = (double) targetWidth / targetHeight;
    Log.w(TAG, String.format("getPreferredPreviewSize(%d, %d, %d) -> target %dx%d, AR %.02f", displayOrientation, width, height, targetWidth, targetHeight, targetRatio));
    List<Size> sizes = parameters.getSupportedPreviewSizes();
    List<Size> ideals = new LinkedList<>();
    List<Size> bigEnough = new LinkedList<>();
    for (Size size : sizes) {
        Log.w(TAG, String.format("  %dx%d (%.02f)", size.width, size.height, (float) size.width / size.height));
        if (size.height == size.width * targetRatio && size.height >= targetHeight && size.width >= targetWidth) {
            ideals.add(size);
            Log.w(TAG, "    (ideal ratio)");
        } else if (size.width >= targetWidth && size.height >= targetHeight) {
            bigEnough.add(size);
            Log.w(TAG, "    (good size, suboptimal ratio)");
        }
    }
    if (!ideals.isEmpty())
        return Collections.min(ideals, new AreaComparator());
    else if (!bigEnough.isEmpty())
        return Collections.min(bigEnough, new AspectRatioComparator(targetRatio));
    else
        return Collections.max(sizes, new AreaComparator());
}
Also used : Size(android.hardware.Camera.Size) LinkedList(java.util.LinkedList) Nullable(android.support.annotation.Nullable)

Example 68 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class AttachmentDatabase method getAttachment.

@Nullable
public DatabaseAttachment getAttachment(AttachmentId attachmentId) {
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = database.query(TABLE_NAME, PROJECTION, PART_ID_WHERE, attachmentId.toStrings(), null, null, null);
        if (cursor != null && cursor.moveToFirst())
            return getAttachment(cursor);
        else
            return null;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) Nullable(android.support.annotation.Nullable)

Example 69 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class AttachmentDatabase method getAttachmentDataFile.

@Nullable
private File getAttachmentDataFile(@NonNull AttachmentId attachmentId, @NonNull String dataType) {
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = database.query(TABLE_NAME, new String[] { dataType }, PART_ID_WHERE, attachmentId.toStrings(), null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            if (cursor.isNull(0)) {
                return null;
            }
            return new File(cursor.getString(0));
        } else {
            return null;
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) File(java.io.File) Nullable(android.support.annotation.Nullable)

Example 70 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class ThreadDatabase method getRecipientsForThreadId.

@Nullable
public Recipients getRecipientsForThreadId(long threadId) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = db.query(TABLE_NAME, null, ID + " = ?", new String[] { threadId + "" }, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            String recipientIds = cursor.getString(cursor.getColumnIndexOrThrow(RECIPIENT_IDS));
            return RecipientFactory.getRecipientsForIds(context, recipientIds, false);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)582 View (android.view.View)315 TextView (android.widget.TextView)163 RecyclerView (android.support.v7.widget.RecyclerView)85 BindView (butterknife.BindView)57 ImageView (android.widget.ImageView)52 ArrayList (java.util.ArrayList)43 IOException (java.io.IOException)36 Bundle (android.os.Bundle)35 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)35 Intent (android.content.Intent)32 ViewGroup (android.view.ViewGroup)32 Cursor (android.database.Cursor)29 Uri (android.net.Uri)27 File (java.io.File)24 AdapterView (android.widget.AdapterView)22 List (java.util.List)20 NonNull (android.support.annotation.NonNull)19 Context (android.content.Context)15 Bitmap (android.graphics.Bitmap)15