-
-
Save jsfan3/e0d356d9f43529c4f9d48df66c898939 to your computer and use it in GitHub Desktop.
Test PhotoCropper
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
import app.aren.client.ui.PhotoCropper; | |
import com.codename1.ui.Form; | |
import com.codename1.ui.Label; | |
import com.codename1.ui.layouts.BoxLayout; | |
import com.codename1.ui.layouts.FlowLayout; | |
import com.codename1.util.OnComplete; | |
import com.codename1.capture.Capture; | |
import com.codename1.io.FileSystemStorage; | |
import com.codename1.io.Log; | |
import com.codename1.ui.Button; | |
import com.codename1.ui.ButtonGroup; | |
import com.codename1.ui.CN; | |
import com.codename1.ui.Image; | |
import com.codename1.ui.RadioButton; | |
import com.codename1.ui.layouts.GridLayout; | |
import com.codename1.util.EasyThread; | |
import com.codename1.util.Wrapper; | |
import java.io.IOException; | |
/** | |
* Photo Cropper basic testing. | |
*/ | |
public class TestPhotoCropper implements OnComplete<String> { | |
private static final EasyThread exifThread = EasyThread.start("exifRotation"); | |
@Override | |
public void completed(String arg) { | |
Form testForm = new Form("Test Photo cropping", BoxLayout.y()); | |
Button button = new Button("Take & Crop photo"); | |
testForm.add(FlowLayout.encloseCenter(button)); | |
ButtonGroup group = new ButtonGroup(); | |
RadioButton squareBtn = RadioButton.createToggle("Square", group); | |
RadioButton circleBtn = RadioButton.createToggle("Circle", group); | |
group.setSelected(0); | |
testForm.add(FlowLayout.encloseCenter(GridLayout.encloseIn(2, squareBtn, circleBtn))); | |
testForm.show(); | |
squareBtn.addActionListener(l -> { | |
PhotoCropper.setType(PhotoCropper.TYPE_SQUARE); | |
}); | |
circleBtn.addActionListener(l -> { | |
PhotoCropper.setType(PhotoCropper.TYPE_CIRCLE); | |
}); | |
button.addActionListener(l -> { | |
String photoTempPath = Capture.capturePhoto(); | |
if (photoTempPath != null) { | |
testForm.add("Pre-elaborating your photo..."); | |
testForm.revalidate(); | |
String photoSafePath = FileSystemStorage.getInstance().getAppHomePath() + "/myPhoto.jpg"; | |
Wrapper<Image> img = new Wrapper<>(null); | |
exifThread.run(() -> { | |
try { | |
img.set(Image.exifRotation(photoTempPath, photoSafePath)); | |
CN.callSerially(() -> { | |
PhotoCropper.cropImage(img.get(), 200, 512, 512, croppedImg -> { | |
Form form = new Form("Cropped photo", BoxLayout.yLast()); | |
form.getContentPane().setSafeArea(true); | |
Label label = new Label(croppedImg); | |
form.add(FlowLayout.encloseCenter(label)); | |
form.add("Original image width: " + img.get().getWidth()); | |
form.add("Original image height: " + img.get().getHeight()); | |
form.add("Cropped image width: " + croppedImg.getWidth()); | |
form.add("Cropped image height: " + croppedImg.getHeight()); | |
Button goBackBtn = new Button("Go Back"); | |
form.add(goBackBtn); | |
goBackBtn.addActionListener(ll -> { | |
testForm.showBack(); | |
}); | |
form.show(); | |
}, | |
"Crop your image", | |
"Warning message image is too small"); | |
}); | |
} catch (IOException ex) { | |
Log.e(ex); | |
} | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment