Commit 22e97d6e authored by Bastien Zigmann's avatar Bastien Zigmann

MOBILE APP : Optimisation de la détection de changement d'état du wifi

parent 17aa27d6
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
......@@ -5,11 +5,12 @@
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
......
......@@ -25,7 +25,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
def appCenterSdkVersion = '1.2.0'
compile "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
compile "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
def appCenterSdkVersion = '1.4.0'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
}
......@@ -2,6 +2,7 @@ package geocropping.com.geocroppingapp;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
public class DebugPerso {
......@@ -9,8 +10,8 @@ public class DebugPerso {
AlertDialog.Builder build;
AlertDialog alert;
public DebugPerso(){
this.build = new AlertDialog.Builder(MainActivity.getAppContext(),R.style.MyDialogTheme);
public DebugPerso(Context context){
this.build = new AlertDialog.Builder(context,R.style.MyDialogTheme);
}
public void afficherMessage(String str) {
......
......@@ -24,18 +24,20 @@ import android.webkit.WebViewClient;
import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.analytics.Analytics;
import com.microsoft.appcenter.crashes.Crashes;
// TODO : TOAST
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_GPS = 0;
private static final int REQUEST_WIFI = 1;
private static WebView wv;
private static Context context;
private WebView wv;
private Context context;
// Gestion du GPS
private LocationManager locationManager;
private LocationListener locationListener;
private NetworkChangeReceiver receiver;
// Quand on fait retour, si on l'a autorisé fait un retour sur la webview
@Override
......@@ -61,7 +63,6 @@ public class MainActivity extends AppCompatActivity {
});
final AlertDialog alert = builder.create();
alert.show();
//super.onBackPressed();
}
}
......@@ -69,6 +70,22 @@ public class MainActivity extends AppCompatActivity {
return (((LocationManager) getSystemService( Context.LOCATION_SERVICE ))).isProviderEnabled(LocationManager.GPS_PROVIDER);
}
public void buildAlertMessageNoConnection(final Context context, final WebView wv){
final AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialogTheme);
builder.setMessage("Connexion perdue, l'application ne peut pas fonctionner correctement.").setCancelable(false).setPositiveButton("Recharger", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
boolean IsConnected = NetworkUtil.getConnectivityStatusString(context);
if(IsConnected)
wv.reload();
else
buildAlertMessageNoConnection(context, wv);
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyDialogTheme);
builder.setMessage("Le GPS semble être désactivé, l'activer?")
......@@ -93,14 +110,6 @@ public class MainActivity extends AppCompatActivity {
alert.show();
}
public static Context getAppContext() {
return context;
}
public static WebView getAppWebview() {
return MainActivity.wv;
}
public void callJS(String js) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
wv.evaluateJavascript(js, new ValueCallback<String>() {
......@@ -205,6 +214,7 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
this.context = this;
setContentView(R.layout.activity_main);
wv = findViewById(R.id.wv);
// vérification que les droits sont bien donné pour l'accès au gps
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
......@@ -219,9 +229,9 @@ public class MainActivity extends AppCompatActivity {
}
// Vérification de la connexion internet au lancement
boolean IsConnected = NetworkUtil.getConnectivityStatusString(MainActivity.getAppContext());
boolean IsConnected = NetworkUtil.getConnectivityStatusString(this.context);
if(!IsConnected) {
NetworkChangeReceiver.buildAlertMessageNoConnection();
buildAlertMessageNoConnection(this.context, this.wv);
}
// Vérification du GPS au lancement
......@@ -231,7 +241,6 @@ public class MainActivity extends AppCompatActivity {
}
// Parametrage de la WebView
wv = findViewById(R.id.wv);
WebSettings wvSettings = wv.getSettings();
wv.setWebViewClient(new WebViewClient(){
......@@ -275,6 +284,14 @@ public class MainActivity extends AppCompatActivity {
}
});
this.receiver = new NetworkChangeReceiver();
this.receiver.setOnChangeReceivedListener(new NetworkChangeReceiver.OnChangeReceivedListener(){
@Override
public void onChangeReceived(){
buildAlertMessageNoConnection(context, wv);
}
});
// Permet de récupérer les rapports d'erreur : https://appcenter.ms/orgs/Xsalto/apps/GeoCropping-1/crashes/groups
AppCenter.start(getApplication(), "136e9a5d-b497-4a82-9169-008ef2a8830f", Analytics.class, Crashes.class);
......
package geocropping.com.geocroppingapp;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
public class NetworkChangeReceiver extends BroadcastReceiver {
public static void buildAlertMessageNoConnection(){
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.getAppContext(), R.style.MyDialogTheme);
builder.setMessage("Connexion perdue").setCancelable(false).setPositiveButton("Recharger", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
boolean IsConnected = NetworkUtil.getConnectivityStatusString(MainActivity.getAppContext());
if(IsConnected)
MainActivity.getAppWebview().reload();
else
buildAlertMessageNoConnection();
}
});
AlertDialog alert = builder.create();
alert.show();
private static OnChangeReceivedListener listener;
public interface OnChangeReceivedListener{
void onChangeReceived();
}
public void setOnChangeReceivedListener(OnChangeReceivedListener listener){
NetworkChangeReceiver.listener = listener;
}
@Override
public void onReceive(final Context context, final Intent intent) {
boolean IsConnected = NetworkUtil.getConnectivityStatusString(context);
if(!IsConnected){
buildAlertMessageNoConnection();
}
//if(listener != null){
boolean isConnected = NetworkUtil.getConnectivityStatusString(context);
if(!isConnected)
NetworkChangeReceiver.listener.onChangeReceived();
//}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
......
#Thu Jan 18 11:14:23 CET 2018
#Tue Mar 27 13:38:58 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
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