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

#612 Removed gallery opener for all platforms.

parent 09faf22b
......@@ -17,7 +17,6 @@
package cz.nic.tablexia.android;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
......@@ -40,7 +39,6 @@ import cz.nic.tablexia.debug.BuildConfig;
import cz.nic.tablexia.debug.R;
import cz.nic.tablexia.loader.application.ApplicationAvatarManager;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.GalleryOpener;
import cz.nic.tablexia.android.camera.AndroidQRCodeScanner;
import cz.nic.tablexia.util.IFileSystemManager;
import cz.nic.tablexia.util.Log;
......@@ -54,13 +52,11 @@ public class AndroidLauncher extends AndroidApplication {
private static final boolean HAS_SOFT_BACK_BUTTON = false;
private Tablexia tablexia;
private AndroidGalleryOpener galleryOpener;
private AndroidCameraOpener cameraOpener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.galleryOpener = new AndroidGalleryOpener(this);
this.cameraOpener = new AndroidCameraOpener(this);
// workaround for launching app from market or installation dialog
......@@ -82,7 +78,6 @@ public class AndroidLauncher extends AndroidApplication {
getResources().getConfiguration().locale,
SQL_CONNECTION_TYPE,
new AndroidConnectionManager(getContext()),
galleryOpener,
cameraOpener,
new AndroidFileSystemManager(),
qrCodeScanner,
......@@ -94,20 +89,7 @@ public class AndroidLauncher extends AndroidApplication {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == AndroidGalleryOpener.SELECT_IMAGE_CODE) {
if(resultCode == RESULT_OK) {
Uri imageUri = data.getData();
String imagePath = getPath(imageUri);
//Creates pixmap in correct resolution. Check ApplicationAvatarManager.AVATAR_WIDTH and AVATAR_HEIGHT for more info.
Pixmap resultPixmap = ApplicationAvatarManager.getInstance().createAvatarPixmap(new FileHandle(imagePath));
galleryOpener.setPixmap(resultPixmap, true);
}
else {
galleryOpener.setPixmap(null, false);
}
} else if (requestCode == AndroidCameraOpener.TAKE_PHOTO_CODE){
if (requestCode == AndroidCameraOpener.TAKE_PHOTO_CODE){
Log.info(getClass(), resultCode + " == " + RESULT_OK);
if(resultCode == RESULT_OK) {
String imagePath = getPath(cameraOpener.getPhotoPath());
......@@ -147,26 +129,6 @@ public class AndroidLauncher extends AndroidApplication {
handler.post(r);
}
private static class AndroidGalleryOpener extends GalleryOpener {
private static final String INTENT_TYPE = "image/*";
public static final int SELECT_IMAGE_CODE = 1337;
private final Activity activity;
public AndroidGalleryOpener(Activity activity) {
super();
this.activity = activity;
}
@Override
public void openGallery() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(INTENT_TYPE);
activity.startActivityForResult(Intent.createChooser(intent, "Select Users Image"), SELECT_IMAGE_CODE);
}
}
private static class AndroidConnectionManager implements IConnectionManager {
private Context androidContext;
......
......@@ -49,7 +49,6 @@ import cz.nic.tablexia.model.DatabaseManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.CameraOpener;
import cz.nic.tablexia.util.GalleryOpener;
import cz.nic.tablexia.util.IFileSystemManager;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Utility;
......@@ -94,7 +93,6 @@ public class Tablexia extends TablexiaApplication {
private static final boolean LOADER_ERROR_DIALOG_HIDE_ANIMATION = false;
private static IConnectionManager connectionManager;
private static GalleryOpener galleryOpener;
private static CameraOpener cameraOpener;
private static IFileSystemManager fileSystemManager;
private static QRCodeScanner qrCodeScanner;
......@@ -131,13 +129,12 @@ public class Tablexia extends TablexiaApplication {
}
}
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, GalleryOpener galleryOpener, CameraOpener cameraOpener, IFileSystemManager fileSystemManager, QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean reset, String hwSerial) {
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, CameraOpener cameraOpener, IFileSystemManager fileSystemManager, QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean reset, String hwSerial) {
this.reset = reset;
this.connectionManager = validateConnectionManager(connManager);
this.fileSystemManager = validateFileSystemManager(fileSystemManager);
this.qrCodeScanner = qrCodeScanner;
this.sqlConnectionType = sqlConnectionType;
this.galleryOpener = galleryOpener;
this.cameraOpener = cameraOpener;
TablexiaSettings.init(buildType, systemLocale, hasSoftBackButton, hwSerial);
......@@ -473,10 +470,6 @@ public class Tablexia extends TablexiaApplication {
return connectionManager;
}
public static GalleryOpener getGalleryOpener() {
return galleryOpener;
}
//////////////////////////// File System Manager
private static IFileSystemManager validateFileSystemManager(IFileSystemManager fileSystemManager) {
if(fileSystemManager == null)
......
......@@ -75,7 +75,6 @@ import cz.nic.tablexia.screen.createuser.form.SignaturePane;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.shared.model.definitions.GenderDefinition;
import cz.nic.tablexia.util.CameraOpener;
import cz.nic.tablexia.util.GalleryOpener;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.util.ScaleUtil;
......
......@@ -30,15 +30,11 @@ public abstract class CameraOpener {
}
public void openCamera(){
onCameraOpen();
}
public void closeCamera(){
onCameraClose();
}
......
/*
* Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.nic.tablexia.util;
import com.badlogic.gdx.graphics.Pixmap;
/**
* Created by drahomir on 3/11/16.
*/
public abstract class GalleryOpener {
public interface ImageChosenListener {
void onImageChosen(Pixmap pixmap, boolean success);
}
private ImageChosenListener imageChosenListener;
protected GalleryOpener() {}
public void setImageChosenListener(ImageChosenListener listener) {
if(listener != null) {
this.imageChosenListener = listener;
}
}
public void setPixmap(Pixmap pixmap, boolean success) {
if(imageChosenListener != null)
imageChosenListener.onImageChosen(pixmap, success);
}
public abstract void openGallery();
}
......@@ -20,25 +20,15 @@ package cz.nic.tablexia.desktop;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
import com.jcabi.manifests.Manifests;
import java.awt.Component;
import java.awt.HeadlessException;
import java.io.File;
import java.util.Locale;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaBuildConfig;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.application.ApplicationAvatarManager;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.GalleryOpener;
import cz.nic.tablexia.util.IFileSystemManager;
public class DesktopLauncher {
......@@ -92,7 +82,6 @@ public class DesktopLauncher {
Locale.getDefault(),
SQL_CONNECTION_TYPE,
new DesktopConnectionManager(),
new DesktopGalleryOpener(),
null, //CameraOpener
new DesktopFileSystemManager(),
null,
......@@ -110,57 +99,6 @@ public class DesktopLauncher {
return defaultValue;
}
private static class DesktopGalleryOpener extends GalleryOpener {
private static final FileFilter FILE_FILTER = new FileFilter() {
@Override
public boolean accept(File file) {
if(file.isDirectory()) return true;
String lowerCaseName = file.getName().toLowerCase();
for(String fileType : ApplicationAvatarManager.CUSTOM_AVATAR_ALLOWED_FILE_TYPES) {
if(lowerCaseName.endsWith(fileType)) return true;
}
return false;
}
@Override
public String getDescription() { return null; }
};
@Override
public void openGallery() {
JFileChooser jFileChooser = new JFileChooser() {
/*
* Let me explain this dirty hack...
* I swear there was no other way how to keep this dialog on top of other windows...
*/
@Override
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog dialog = super.createDialog(parent);
dialog.setModal(true);
dialog.setAlwaysOnTop(true);
return dialog;
}
};
jFileChooser.setMultiSelectionEnabled(false);
jFileChooser.setDragEnabled(false);
jFileChooser.setRequestFocusEnabled(true);
jFileChooser.setFileFilter(FILE_FILTER);
int result = jFileChooser.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION) {
String filePath = jFileChooser.getSelectedFile().getAbsolutePath();
Pixmap resutlPixmap = ApplicationAvatarManager.getInstance().createAvatarPixmap(new FileHandle(filePath));
setPixmap(resutlPixmap, true);
}
else {
setPixmap(null, false);
}
}
}
private static class DesktopConnectionManager implements IConnectionManager {
@Override
public boolean isUsingMobileData() {
......
......@@ -21,21 +21,7 @@ import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import com.badlogic.gdx.graphics.Pixmap;
import org.robovm.apple.foundation.NSData;
import org.robovm.apple.foundation.NSException;
import org.robovm.apple.uikit.UIImage;
import org.robovm.apple.uikit.UIImagePickerController;
import org.robovm.apple.uikit.UIImagePickerControllerDelegate;
import org.robovm.apple.uikit.UIImagePickerControllerEditingInfo;
import org.robovm.apple.uikit.UIImagePickerControllerSourceType;
import org.robovm.apple.uikit.UIInterfaceOrientation;
import org.robovm.apple.uikit.UIInterfaceOrientationMask;
import org.robovm.apple.uikit.UINavigationController;
import org.robovm.apple.uikit.UINavigationControllerDelegateAdapter;
import org.robovm.apple.uikit.UIViewController;
import org.robovm.objc.ObjCObject;
import org.robovm.apple.foundation.NSErrorException;
import org.robovm.apple.foundation.NSFileManager;
import org.robovm.apple.foundation.NSFileSystemAttributes;
......@@ -50,11 +36,9 @@ import org.robovm.apple.systemconfiguration.SCNetworkReachabilityFlags;
import org.robovm.apple.uikit.UIApplication;
import org.robovm.apple.uikit.UIApplicationLaunchOptions;
import java.nio.ByteBuffer;
import java.util.Locale;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.GalleryOpener;
import cz.nic.tablexia.util.IFileSystemManager;
import cz.nic.tablexia.util.Log;
......@@ -92,7 +76,6 @@ public class IOSLauncher extends IOSApplication.Delegate {
Locale.getDefault(),
SQL_CONNECTION_TYPE,
new IOSConnectionManager(),
new IOSGalleryOpener(),
new IOSCameraOpener(),
new IOSFileSystemManager(),
new IOSQRCodeScanner(),
......@@ -160,76 +143,6 @@ public class IOSLauncher extends IOSApplication.Delegate {
}
}
private class IOSGalleryOpener extends GalleryOpener {
private UIViewController appController;
private PickerControllerDelegate delegate;
private UIImagePickerController imagePickerController;
private class PickerControllerDelegate extends UINavigationControllerDelegateAdapter implements UIImagePickerControllerDelegate {
@Override
public void didFinishPickingMedia(UIImagePickerController picker, UIImagePickerControllerEditingInfo info) {
UIImage uiImage = info.getOriginalImage();
NSData nsData = uiImage.toPNGData();
ByteBuffer buffer = nsData.asByteBuffer();
byte[] test = new byte[buffer.capacity()]; //limit ?
buffer.get(test);
Pixmap pixmap = new Pixmap(test, 0, test.length);
setPixmap(pixmap, true);
picker.dismissViewController(true, null);
}
@Override
public void didCancel(UIImagePickerController picker) {
picker.dismissViewController(true, null);
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(UINavigationController navigationController) {
return UIInterfaceOrientationMask.All;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(UINavigationController navigationController) {
return UIInterfaceOrientation.LandscapeRight;
}
}
@Override
public void openGallery() {
appController = iosApplication.getUIViewController();
imagePickerController = new UIImagePickerController() {
@Override
public boolean shouldAutorotate() {
return false;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation() {
return UIInterfaceOrientation.LandscapeRight;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations() {
return UIInterfaceOrientationMask.All;
}
};
imagePickerController.getView().setBounds(appController.getView().getBounds());
imagePickerController.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary);
delegate = new PickerControllerDelegate();
imagePickerController.setDelegate(delegate);
imagePickerController.addStrongRef((ObjCObject) delegate);
appController.presentViewController(imagePickerController, true, null);
}
}
private static class IOSFileSystemManager implements IFileSystemManager {
@Override
public Long getSpaceAvailable(String path) {
......
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