diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java index 00b8ed2..100f0cd 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java @@ -25,7 +25,6 @@ import android.support.design.widget.FloatingActionButton; import android.support.v4.view.GravityCompat; import android.support.v7.app.ActionBar; -import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; @@ -84,9 +83,6 @@ * Fragment managing the behaviors, interactions and presentation of the navigation drawer. */ - /** - * Used to store the last screen title. For use in {@link #restoreActionBar()}. - */ private CharSequence mTitle; private CharSequence mDrawerTitle; private static final int GPS_MIN_TIME = 5000; @@ -347,7 +343,10 @@ //Log.e(TAG, "Could not cast " + v.getClass().toString() + " to ImageView!"); } } - if(tv == null || iv == null) Log.e(TAG, "Neither TextView nor ImageView can be null!"); + if(tv == null || iv == null){ + Log.e(TAG, "Neither TextView nor ImageView can be null!"); + return; + } int type = getType(position); if(iv.getTag() == null || iv.getTag() == "disabled"){ iv.setColorFilter(null); @@ -411,6 +410,7 @@ Drawable[] iconLayer = new Drawable[2]; iconLayer[0] = res.getDrawable(R.mipmap.ic_poi); BitmapDrawable bd = (BitmapDrawable) res.getDrawable(entryImgs[type]); + if(bd == null) continue; Bitmap b = bd.getBitmap(); Bitmap bResized = Bitmap.createScaledBitmap(b, b.getWidth()/2, b.getHeight()/2, false); bd = new BitmapDrawable(res, bResized); @@ -875,7 +875,6 @@ public class AddPathDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final List mSelectedItems = new ArrayList<>(); final CheckboxImageAdapter adapter = new CheckboxImageAdapter(MainActivity.this, pathOptions, pathDescs, pathOptionImgs); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.path_dialog_title) @@ -927,7 +926,6 @@ public class AddBreakpointDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final List mSelectedItems = new ArrayList<>(); final CheckboxImageAdapter adapter = new CheckboxImageAdapter(MainActivity.this, breakPointOptions, null, breakPointOptionsImgs); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.break_point_dialog_title) @@ -992,19 +990,40 @@ private void addWifiPoi(){ //TODO - setActiveNetwork(); - if(activeNetwork != null && activeNetwork.isConnected()){ - if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI){ - String ssid = wm.getConnectionInfo().getSSID(); - int rssi = wm.getConnectionInfo().getRssi(); - int levels = WifiManager.calculateSignalLevel(rssi, MAX_WIFI_LEVELS); - Log.d(TAG, "You are currently connected to '" + ssid + "' with " + levels + " (" + rssi + ")"); - addPoi(Types.WIFI); - } else { - Log.d(TAG, "Wifi network not available/connected"); - } + if(!wm.isWifiEnabled()){ + AlertDialog.Builder wifiIntentDialogBuilder = new AlertDialog.Builder(MainActivity.this); + wifiIntentDialogBuilder + .setTitle(R.string.wifi_disabled_title) + .setMessage(R.string.wifi_disabled_text) + .setPositiveButton(R.string.enable_wifi_button, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); + startActivity(intent); + } + }) + .setNegativeButton(R.string.dont_enable_wifi_button, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + AlertDialog wifiIntentDialog = wifiIntentDialogBuilder.create(); + wifiIntentDialog.show(); } else { - Log.d(TAG, "You are not connected to any network"); + setActiveNetwork(); + if (activeNetwork != null && activeNetwork.isConnected()) { + if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { + String ssid = wm.getConnectionInfo().getSSID(); + int rssi = wm.getConnectionInfo().getRssi(); + int levels = WifiManager.calculateSignalLevel(rssi, MAX_WIFI_LEVELS); + Log.d(TAG, "You are currently connected to '" + ssid + "' with " + levels + " (" + rssi + ")"); + addPoi(Types.WIFI); + } else { + Log.d(TAG, "Wifi network not available/connected"); + } + } else { + Log.d(TAG, "You are not connected to any network"); + } } } @@ -1100,44 +1119,4 @@ protected void onDestroy() { super.onDestroy(); } - - public void restoreActionBar() { - ActionBar actionBar = getSupportActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setTitle(mTitle); - } - - /** - * A placeholder fragment containing a simple view. - */ - public static class PlaceholderFragment extends Fragment { - /** - * The fragment argument representing the section number for this - * fragment. - */ - private static final String ARG_SECTION_NUMBER = "section_number"; - - /** - * Returns a new instance of this fragment for the given section - * number. - */ - public static PlaceholderFragment newInstance(int sectionNumber) { - PlaceholderFragment fragment = new PlaceholderFragment(); - Bundle args = new Bundle(); - args.putInt(ARG_SECTION_NUMBER, sectionNumber); - fragment.setArguments(args); - return fragment; - } - - public PlaceholderFragment() { - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_main, container, false); - } - } - }