Last active
December 27, 2015 08:39
-
-
Save twocity/7297924 to your computer and use it in GitHub Desktop.
android gallery3d source snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getLocalizedName(Resources res, int bucketId, | |
String name) { | |
if (bucketId == MediaSetUtils.CAMERA_BUCKET_ID) { | |
return res.getString(R.string.folder_camera); | |
} else if (bucketId == MediaSetUtils.DOWNLOAD_BUCKET_ID) { | |
return res.getString(R.string.folder_download); | |
} else if (bucketId == MediaSetUtils.IMPORTED_BUCKET_ID) { | |
return res.getString(R.string.folder_imported); | |
} else if (bucketId == MediaSetUtils.SNAPSHOT_BUCKET_ID) { | |
return res.getString(R.string.folder_screenshot); | |
} else if (bucketId == MediaSetUtils.EDITED_ONLINE_PHOTOS_BUCKET_ID) { | |
return res.getString(R.string.folder_edited_online_photos); | |
} else { | |
return name; | |
} | |
} | |
// Relative path is the absolute path minus external storage path | |
public static String getRelativePath(int bucketId) { | |
String relativePath = "/"; | |
if (bucketId == MediaSetUtils.CAMERA_BUCKET_ID) { | |
relativePath += BucketNames.CAMERA; | |
} else if (bucketId == MediaSetUtils.DOWNLOAD_BUCKET_ID) { | |
relativePath += BucketNames.DOWNLOAD; | |
} else if (bucketId == MediaSetUtils.IMPORTED_BUCKET_ID) { | |
relativePath += BucketNames.IMPORTED; | |
} else if (bucketId == MediaSetUtils.SNAPSHOT_BUCKET_ID) { | |
relativePath += BucketNames.SCREENSHOTS; | |
} else if (bucketId == MediaSetUtils.EDITED_ONLINE_PHOTOS_BUCKET_ID) { | |
relativePath += BucketNames.EDITED_ONLINE_PHOTOS; | |
} else { | |
// If the first few cases didn't hit the matching path, do a | |
// thorough search in the local directories. | |
File extStorage = Environment.getExternalStorageDirectory(); | |
String path = GalleryUtils.searchDirForPath(extStorage, bucketId); | |
if (path == null) { | |
Log.w(TAG, "Relative path for bucket id: " + bucketId + " is not found."); | |
relativePath = null; | |
} else { | |
relativePath = path.substring(extStorage.getAbsolutePath().length()); | |
} | |
} | |
return relativePath; | |
} | |
@Override | |
public void rotate(int degrees) { | |
GalleryUtils.assertNotInRenderThread(); | |
Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI; | |
ContentValues values = new ContentValues(); | |
int rotation = (this.rotation + degrees) % 360; | |
if (rotation < 0) rotation += 360; | |
if (mimeType.equalsIgnoreCase("image/jpeg")) { | |
ExifInterface exifInterface = new ExifInterface(); | |
ExifTag tag = exifInterface.buildTag(ExifInterface.TAG_ORIENTATION, | |
ExifInterface.getOrientationValueForRotation(rotation)); | |
if(tag != null) { | |
exifInterface.setTag(tag); | |
try { | |
exifInterface.forceRewriteExif(filePath); | |
fileSize = new File(filePath).length(); | |
values.put(Images.Media.SIZE, fileSize); | |
} catch (FileNotFoundException e) { | |
Log.w(TAG, "cannot find file to set exif: " + filePath); | |
} catch (IOException e) { | |
Log.w(TAG, "cannot set exif data: " + filePath); | |
} | |
} else { | |
Log.w(TAG, "Could not build tag: " + ExifInterface.TAG_ORIENTATION); | |
} | |
} | |
values.put(Images.Media.ORIENTATION, rotation); | |
mApplication.getContentResolver().update(baseUri, values, "_id=?", | |
new String[]{String.valueOf(id)}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment