Search in sources :

Example 21 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 22 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 23 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 24 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)

Example 25 with Nullable

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

the class ThreadDatabase method getAttachmentUriFor.

@Nullable
private Uri getAttachmentUriFor(MessageRecord record) {
    if (!record.isMms() || record.isMmsNotification() || record.isGroupAction())
        return null;
    SlideDeck slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
    Slide thumbnail = slideDeck.getThumbnailSlide();
    return thumbnail != null ? thumbnail.getThumbnailUri() : null;
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Slide(org.thoughtcrime.securesms.mms.Slide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)477 View (android.view.View)266 TextView (android.widget.TextView)131 RecyclerView (android.support.v7.widget.RecyclerView)70 ImageView (android.widget.ImageView)41 IOException (java.io.IOException)32 Intent (android.content.Intent)30 Bundle (android.os.Bundle)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)28 ViewGroup (android.view.ViewGroup)27 Uri (android.net.Uri)25 BindView (butterknife.BindView)25 ArrayList (java.util.ArrayList)25 Cursor (android.database.Cursor)23 File (java.io.File)22 AdapterView (android.widget.AdapterView)16 Bitmap (android.graphics.Bitmap)15 Context (android.content.Context)14 Drawable (android.graphics.drawable.Drawable)13 EditText (android.widget.EditText)13