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;
}
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());
}
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();
}
}
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();
}
}
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;
}
Aggregations