1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/FileBitmapHunter.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* 1.5 + * Copyright (C) 2013 Square, Inc. 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 +package com.squareup.picasso; 1.20 + 1.21 +import android.content.Context; 1.22 +import android.graphics.Bitmap; 1.23 +import android.media.ExifInterface; 1.24 +import android.net.Uri; 1.25 +import java.io.IOException; 1.26 + 1.27 +import static android.media.ExifInterface.ORIENTATION_NORMAL; 1.28 +import static android.media.ExifInterface.ORIENTATION_ROTATE_180; 1.29 +import static android.media.ExifInterface.ORIENTATION_ROTATE_270; 1.30 +import static android.media.ExifInterface.ORIENTATION_ROTATE_90; 1.31 +import static android.media.ExifInterface.TAG_ORIENTATION; 1.32 + 1.33 +class FileBitmapHunter extends ContentStreamBitmapHunter { 1.34 + 1.35 + FileBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache, 1.36 + Stats stats, Action action) { 1.37 + super(context, picasso, dispatcher, cache, stats, action); 1.38 + } 1.39 + 1.40 + @Override Bitmap decode(Request data) 1.41 + throws IOException { 1.42 + setExifRotation(getFileExifRotation(data.uri)); 1.43 + return super.decode(data); 1.44 + } 1.45 + 1.46 + static int getFileExifRotation(Uri uri) throws IOException { 1.47 + ExifInterface exifInterface = new ExifInterface(uri.getPath()); 1.48 + int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL); 1.49 + switch (orientation) { 1.50 + case ORIENTATION_ROTATE_90: 1.51 + return 90; 1.52 + case ORIENTATION_ROTATE_180: 1.53 + return 180; 1.54 + case ORIENTATION_ROTATE_270: 1.55 + return 270; 1.56 + default: 1.57 + return 0; 1.58 + } 1.59 + } 1.60 +}