Summary 8
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a0f719d..838adf5 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -9,6 +9,7 @@
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
diff --git a/src/org/climbingguide/main/MainActivity.java b/src/org/climbingguide/main/MainActivity.java
index 65416ca..9b300b2 100644
--- a/src/org/climbingguide/main/MainActivity.java
+++ b/src/org/climbingguide/main/MainActivity.java
@@ -25,8 +25,11 @@
import org.climbingguide.update.Update;
import android.app.Activity;
+import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.app.Fragment;
@@ -354,45 +357,69 @@
FragmentRoutes route = (FragmentRoutes)getFragmentManager().findFragmentByTag("Routes");
if(areaAll != null && areaAll.isVisible()){
- fragment = new FragmentCreateArea();
- tagFragment = "CreateArea";
- break;
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo netInfo = cm.getActiveNetworkInfo();
+ if (netInfo != null && netInfo.isConnectedOrConnecting()) {
+ fragment = new FragmentCreateArea();
+ tagFragment = "CreateArea";
+ break;
+ }else{
+ Toast.makeText(getApplicationContext(), "There is no network access", Toast.LENGTH_LONG).show();
+ }
}
else
if(sectorAll != null && sectorAll.isVisible()){
- Toast.makeText(getApplicationContext(), "Najprv vyber oblast", Toast.LENGTH_LONG).show();
+ Toast.makeText(getApplicationContext(), "First select the area", Toast.LENGTH_LONG).show();
break;
}
else
if(routeAll != null && routeAll.isVisible()){
- Toast.makeText(getApplicationContext(), "Najprv vyber sektor", Toast.LENGTH_LONG).show();
+ Toast.makeText(getApplicationContext(), "First select the sector", Toast.LENGTH_LONG).show();
break;
}
else
if(sector != null && sector.isVisible()){
- fragment = new FragmentCreateSector();
- bundle.putInt("idOfArea", sector.getIdOfArea());
- fragment.setArguments(bundle);
- tagFragment = "CreateSector";
- break;
-
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo netInfo = cm.getActiveNetworkInfo();
+ if (netInfo != null && netInfo.isConnectedOrConnecting()) {
+ fragment = new FragmentCreateSector();
+ bundle.putInt("idOfArea", sector.getIdOfArea());
+ fragment.setArguments(bundle);
+ tagFragment = "CreateSector";
+ break;
+ }else{
+ Toast.makeText(getApplicationContext(), "There is no network access", Toast.LENGTH_LONG).show();
+ }
}
else
if(route != null && route.isVisible() ){
- fragment = new FragmentCreateRoute();
- bundle.putInt("idOfSector", route.getIdOfSector());
- fragment.setArguments(bundle);
- tagFragment = "CreateRoute";
- break;
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo netInfo = cm.getActiveNetworkInfo();
+ if (netInfo != null && netInfo.isConnectedOrConnecting()) {
+ fragment = new FragmentCreateRoute();
+ bundle.putInt("idOfSector", route.getIdOfSector());
+ fragment.setArguments(bundle);
+ tagFragment = "CreateRoute";
+ break;
+ }else{
+ Toast.makeText(getApplicationContext(), "There is no network access", Toast.LENGTH_LONG).show();
+ }
}
case 4:
- Update update = new Update();
- update.updateA(getApplicationContext());
- update.updateS(getApplicationContext());
- update.updateR(getApplicationContext());
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo netInfo = cm.getActiveNetworkInfo();
+ if (netInfo != null && netInfo.isConnectedOrConnecting()) {
+ Update update = new Update();
+ update.updateA(getApplicationContext());
+ update.updateS(getApplicationContext());
+ update.updateR(getApplicationContext());
+ }else{
+ Toast.makeText(getApplicationContext(), "There is no network access", Toast.LENGTH_LONG).show();
+ }
+
break;
// case 5:
// fragment = new ();
diff --git a/src/org/climbingguide/update/Update.java b/src/org/climbingguide/update/Update.java
index ce5d2ae..ee39a6f 100644
--- a/src/org/climbingguide/update/Update.java
+++ b/src/org/climbingguide/update/Update.java
@@ -96,21 +96,11 @@
}
else{
Toast.makeText(context, "Your areas are up to date", Toast.LENGTH_LONG).show();
-
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
-
-
-// area.updateArea(1, "Drevenik",context);
-// area.updateArea(2, "Turniska",context);
-// area.updateArea(3, "Zamutov",context);
-// area.updateArea(4, "Zadiel",context);
-
-
}
//---------------------------------------------------------------
public void updateS(Context context)
@@ -150,26 +140,11 @@
}
else{
Toast.makeText(context, "Your sectors are up to date", Toast.LENGTH_LONG).show();
-
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
-// sector.updateSector(1,"Peklo",1,context);
-// sector.updateSector(2,"Raj",1,context);
-// sector.updateSector(3,"Najvyssia turna",2,context);
-// sector.updateSector(4,"Velkonocna turna",2,context);
-// sector.updateSector(5,"Zarastena turna",2,context);
-// sector.updateSector(6,"Mur",2,context);
-// sector.updateSector(7,"Klemba",2,context);
-// sector.updateSector(8,"Najnisia turna",2,context);
-// sector.updateSector(9,"Cervene previsy",1,context);
-// sector.updateSector(10,"Marta",1,context);
-// sector.updateSector(11,"Amerika",1,context);
-// sector.updateSector(12,"Previsy",3,context);
-
}
//---------------------------------------------------------------
public void updateR(Context context)
@@ -209,17 +184,10 @@
}
else{
Toast.makeText(context, "Your routes are up to date", Toast.LENGTH_LONG).show();
-
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
-// route.updateRoute(1, "Moreplavec", 12, "7", 6, 10, 48.9947059,21.2347516, context);
-// route.updateRoute(2, "Vecko", 12, "7-", 8, 15, 48.9947059,21.2347516, context);
-// route.updateRoute(3, "Flora",3,"9/9+",6, 10, 48.9947059,21.2347516, context);
-// route.updateRoute(4, "Vanicky",3, "8+",10, 17, 48.9947059,21.2347516, context);
-
}
}