Created
December 19, 2015 09:58
-
-
Save amaembo/34b32637ca05ff65eeb9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package issue63; | |
import java.io.File; | |
import java.io.IOException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
public class ProfilePictureServiceImpl { | |
static class Environment { | |
static final String DIRECTORY_PICTURES = "/pictures/directory"; | |
public static File getExternalStoragePublicDirectory( | |
String path) { | |
return new File(path); | |
} | |
} | |
static class Uri { | |
public Uri(File f) { | |
// stub | |
} | |
static Uri fromFile(File f) { | |
return new Uri(f); | |
} | |
} | |
static class Log { | |
public static void e(String tag, String errorKind, Exception e) { | |
// stub | |
} | |
} | |
private static final String TAG = "ProfilePicServiceImpl"; | |
private static final String UMEWIN_PROFILE = "UMW_PROFILE_%1$s.jpeg"; | |
private static final String IO_ERROR = "IO Error"; | |
public Uri getCameraProfilePicPath() { | |
final File photoFile; | |
try { | |
photoFile = createCameraImageFile(); | |
} catch (final IOException e) { | |
Log.e(TAG, IO_ERROR, e); | |
return null; | |
} | |
return Uri.fromFile(photoFile); | |
} | |
private static File createCameraImageFile() throws IOException { | |
final String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); | |
final String cameraPhotoFileName = String.format(UMEWIN_PROFILE, timeStamp); | |
final File storageDir = Environment.getExternalStoragePublicDirectory( | |
Environment.DIRECTORY_PICTURES); | |
return new File(storageDir, cameraPhotoFileName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment