Commit b7050448 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#913 custom net implementation for Android > 8.0

parent 71f4024d
......@@ -26,6 +26,8 @@ import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
......@@ -51,6 +53,7 @@ public class AndroidLauncher extends AndroidApplication {
private static final int MULTI_SAMPLING_2X = 2;
private static final boolean HAS_SOFT_BACK_BUTTON = false;
private static final boolean HAS_ALTERNATIVE_CONTROLS = false;
private static final int ANDROID_OREO_API_LEVEL = 27;
protected Tablexia tablexia;
private AndroidCameraOpener cameraOpener;
......@@ -70,6 +73,7 @@ public class AndroidLauncher extends AndroidApplication {
}
QRCodeScanner qrCodeScanner = android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? new AndroidCamera2QRCodeScanner(this) : new AndroidQRCodeScanner(this);
Net tablexiaNet = android.os.Build.VERSION.SDK_INT >= ANDROID_OREO_API_LEVEL ? new TablexiaAndroidNet(this) : Gdx.net;
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useWakelock = true;
......@@ -86,7 +90,9 @@ public class AndroidLauncher extends AndroidApplication {
HAS_SOFT_BACK_BUTTON,
HAS_ALTERNATIVE_CONTROLS,
savedInstanceState == null,
Build.SERIAL), config);
Build.SERIAL,
false,
tablexiaNet), config);
}
@Override
......
/*
*
* * Copyright (C) 2016 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/>.
*
*/
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package cz.nic.tablexia.android;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import com.badlogic.gdx.Net;
import com.badlogic.gdx.backends.android.AndroidApplicationBase;
import com.badlogic.gdx.net.NetJavaServerSocketImpl;
import com.badlogic.gdx.net.NetJavaSocketImpl;
import com.badlogic.gdx.net.ServerSocket;
import com.badlogic.gdx.net.ServerSocketHints;
import com.badlogic.gdx.net.Socket;
import com.badlogic.gdx.net.SocketHints;
public class TablexiaAndroidNet implements Net {
final AndroidApplicationBase app;
TablexiaNetJavaImpl netJavaImpl;
public TablexiaAndroidNet(AndroidApplicationBase app) {
this.app = app;
netJavaImpl = new TablexiaNetJavaImpl();
}
@Override
public void sendHttpRequest(HttpRequest httpRequest, HttpResponseListener httpResponseListener) {
netJavaImpl.sendHttpRequest(httpRequest, httpResponseListener);
}
@Override
public void cancelHttpRequest(HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}
@Override
public ServerSocket newServerSocket(Protocol protocol, String hostname, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, hostname, port, hints);
}
@Override
public ServerSocket newServerSocket(Protocol protocol, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, port, hints);
}
@Override
public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints) {
return new NetJavaSocketImpl(protocol, host, port, hints);
}
@Override
public boolean openURI(String URI) {
boolean result = false;
final Uri uri = Uri.parse(URI);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
PackageManager pm = app.getContext().getPackageManager();
if (pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
app.runOnUiThread(new Runnable() {
@Override
public void run () {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// LiveWallpaper and Daydream applications need this flag
if (!(app.getContext() instanceof Activity))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
}
});
result = true;
}
return result;
}
}
......@@ -18,6 +18,7 @@
package cz.nic.tablexia;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
......@@ -116,6 +117,8 @@ public class Tablexia extends TablexiaApplication {
private static CameraOpener cameraOpener;
private static IFileSystemManager fileSystemManager;
private static QRCodeScanner qrCodeScanner;
private static Net net;
private final SQLConnectionType sqlConnectionType;
private MenuController menuController;
......@@ -153,11 +156,16 @@ public class Tablexia extends TablexiaApplication {
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, CameraOpener cameraOpener, IFileSystemManager fileSystemManager,
QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean supportAlternativeControls, boolean reset, String hwSerial) {
this(buildType, systemLocale, sqlConnectionType, connManager, cameraOpener, fileSystemManager, qrCodeScanner, sentryDSN, hasSoftBackButton, supportAlternativeControls, reset, hwSerial, DEFAULT_HD_ASSETS);
this(buildType, systemLocale, sqlConnectionType, connManager, cameraOpener, fileSystemManager, qrCodeScanner, sentryDSN, hasSoftBackButton, supportAlternativeControls, reset, hwSerial, DEFAULT_HD_ASSETS, Gdx.net);
}
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, CameraOpener cameraOpener, IFileSystemManager fileSystemManager,
QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean supportAlternativeControls, boolean reset, String hwSerial, boolean hdAssets) {
this(buildType, systemLocale, sqlConnectionType, connManager, cameraOpener, fileSystemManager, qrCodeScanner, sentryDSN, hasSoftBackButton, supportAlternativeControls, reset, hwSerial, hdAssets, Gdx.net);
}
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, CameraOpener cameraOpener, IFileSystemManager fileSystemManager,
QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean supportAlternativeControls, boolean reset, String hwSerial, boolean hdAssets, Net netImplementation) {
this.reset = reset;
this.connectionManager = validateConnectionManager(connManager);
this.fileSystemManager = validateFileSystemManager(fileSystemManager);
......@@ -165,6 +173,7 @@ public class Tablexia extends TablexiaApplication {
this.sqlConnectionType = sqlConnectionType;
this.cameraOpener = cameraOpener;
this.sentryDSN = sentryDSN;
this.net = netImplementation;
TablexiaSettings.init(buildType, systemLocale, hasSoftBackButton, supportAlternativeControls, hwSerial, hdAssets);
}
......@@ -557,6 +566,11 @@ public class Tablexia extends TablexiaApplication {
return qrCodeScanner;
}
//////////////////////////// Custom Net implementation for Android > 8.0
public static Net getNet() {
return net;
}
//////////////////////////// APPLICATION LOADERS
public void showLoaderErrorDialog(int dialogWidth, int dialogHeight, String loaderError) {
......
......@@ -17,7 +17,6 @@
package cz.nic.tablexia.loader.zip;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Timer;
......@@ -27,6 +26,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaBuildConfig;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
......@@ -304,7 +304,7 @@ public class TablexiaAssetsDownloader implements TablexiaAssetsManager.ILoaderDi
}
public void sendHttpRequest(FileHandle fileHandle, Net.HttpResponseListener httpResponseListener){
Gdx.net.sendHttpRequest(prepareRequest(fileHandle.name(), fileHandle.length()), httpResponseListener);
Tablexia.getNet().sendHttpRequest(prepareRequest(fileHandle.name(), fileHandle.length()), httpResponseListener);
}
public Net.HttpRequest prepareRequest(String fileName, long bytesDownloaded) {
......
......@@ -466,7 +466,7 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
request.setTimeOut(TABLEXIA_ASSETS_DOWNLOAD_TIMEOUT);
request.setUrl(TABLEXIA_ASSETS_DOWNLOAD_BASE_PATH + fileName);
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
Tablexia.getNet().sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
......
......@@ -36,6 +36,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
......@@ -462,7 +463,7 @@ public class AboutScreen extends AbstractTablexiaScreen<Void> {
licenceURL.addListener(new ClickListenerWithSound(){
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.net.openURI(library.getLicence().getURL());
Tablexia.getNet().openURI(library.getLicence().getURL());
}
});
licencesTable.add(linkName).center().expandX();
......@@ -476,7 +477,7 @@ public class AboutScreen extends AbstractTablexiaScreen<Void> {
linkURL.addListener(new ClickListenerWithSound(){
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.net.openURI(library.getUrl());
Tablexia.getNet().openURI(library.getUrl());
}
});
licencesTable.add(linkURL).center().expandX().padBottom(DIALOG_CONTENT_PADDING);
......@@ -491,7 +492,7 @@ public class AboutScreen extends AbstractTablexiaScreen<Void> {
@Override
public void onClick(InputEvent event, float x, float y) {
String url = ((Links) event.getListenerActor().getUserObject()).getLinkAddress();
Gdx.net.openURI(url);
Tablexia.getNet().openURI(url);
}
}
}
\ No newline at end of file
......@@ -104,6 +104,7 @@ import cz.nic.tablexia.util.ui.dialog.components.TextContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.TouchCloseDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.TwoButtonContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.ViewportMaximumSizeComponent;
import javafx.scene.control.Tab;
public class FormScreen extends AbstractTablexiaScreen<Void> {
public static final String SCENARIO_STEP_FORM_SCENE_VISIBLE = "form scene visible";
......@@ -266,7 +267,7 @@ public class FormScreen extends AbstractTablexiaScreen<Void> {
@Override
public void onClick(InputEvent event, float x, float y) {
super.onClick(event, x, y);
Gdx.net.openURI(AboutScreen.LocaleLinks.getLocaleLinksByLocale(TablexiaSettings.getInstance().getLocale()).getZOOU().getLinkAddress());
Tablexia.getNet().openURI(AboutScreen.LocaleLinks.getLocaleLinksByLocale(TablexiaSettings.getInstance().getLocale()).getZOOU().getLinkAddress());
}
});
......
......@@ -91,7 +91,7 @@ public class RestSynchronizationService {
}
Net.HttpRequest request = builder.build();
Log.debug(this.getClass(), "Calling remote url: " + request.getUrl());
Gdx.net.sendHttpRequest(request, listener);
Tablexia.getNet().sendHttpRequest(request, listener);
}
public void setHeader(String key, String value) {
......
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