Commit 4a6d1414 authored by Drahomír Karchňák's avatar Drahomír Karchňák

#612 Custom avatar image is cropped correctly now.

parent d353e132
......@@ -124,16 +124,17 @@ public class ApplicationAvatarManager {
return result;
}
public Pixmap createAvatarPixmap(FileHandle textureFile) {
return createAvatarPixmap(new Pixmap(textureFile));
}
/**
* Creates preview avatar pixmap from FileHandle
* Creating huge texture in case of high resolution textureFile doesn't really work on older devices
* So this method loads texture into Pixmap and creates pixmap with resolution AVATAR_WIDTH x AVATAR_HEIGHT, which is cropped correctly
* @param textureFile input texture file (*.png or *.jpg file)
* @return avatar pixmap (Don't forget to dispose pixmap)
*/
public Pixmap createAvatarPixmap(FileHandle textureFile) {
Pixmap srcPixmap = new Pixmap(textureFile);
public Pixmap createAvatarPixmap(Pixmap srcPixmap) {
//Probably not gonna happen, but input image file may already be correct resolution
if(srcPixmap.getWidth() == AVATAR_WIDTH && srcPixmap.getHeight() == AVATAR_HEIGHT) {
return srcPixmap;
......
......@@ -19,6 +19,8 @@ package cz.nic.tablexia.util;
import com.badlogic.gdx.graphics.Pixmap;
import cz.nic.tablexia.loader.application.ApplicationAvatarManager;
public abstract class CameraOpener {
OnPhotoTakenListener onPhotoTakenListener;
......@@ -53,8 +55,10 @@ public abstract class CameraOpener {
abstract public void deleteTemporaryFile();
public void onPhotoTaken(Pixmap pixmap, boolean success){
Pixmap resultPixmap = ApplicationAvatarManager.getInstance().createAvatarPixmap(pixmap);
if (onPhotoTakenListener != null){
onPhotoTakenListener.onPhotoTaken(pixmap, success);
onPhotoTakenListener.onPhotoTaken(resultPixmap, success);
}
}
}
......@@ -60,7 +60,6 @@ public class IOSCameraOpener extends CameraOpener {
onPhotoTaken(pixmap, true);
}
@Override
public void didCancel(UIImagePickerController picker) {
picker.dismissViewController(true, null);
......@@ -87,7 +86,7 @@ public class IOSCameraOpener extends CameraOpener {
imagePickerController = new UIImagePickerController() {
@Override
public boolean shouldAutorotate() {
return false;
return true;
}
@Override
......@@ -118,7 +117,6 @@ public class IOSCameraOpener extends CameraOpener {
delegate = null;
imagePickerController.dismissViewController(true, null);
imagePickerController.removeFromParentViewController();
imagePickerController = null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment