// Path: InthegraApp/src/main/java/com/hcordeiro/android/InthegraApp/Util/Util.java
// public class Util {
//     private static final String TAG = "Util";
// 
//     /*
//     Permissions
//      */
//     public static final int REQUEST_ACCESS_LOCATION = 1;
//     public static boolean IS_LOCATION_AUTHORIZED;
// 
//     public static final int ZOOM = 15;
//     public static final int VEICULOS_REFRESH_TIME = 30000;
//     public static final double DISTANCIA_MAXIMA_A_PE = 250;
//     public static final LatLng TERESINA = new LatLng(-5.070353, -42.803180);
// 
//     private static final int LOCATION_REFRESH_TIME = 10000;
//     private static final int LOCATION_REFRESH_DISTANCE = 10;
// 
// 
// //    public static final String ERRO_API_404 = "Not Found (404)";
// //    public static final String ERRO_HOSTNAME = "Unable to resolve host \"api.inthegra.strans.teresina.pi.gov.br\": No address associated with hostname";
// 
//     @SuppressWarnings("MissingPermission")
//     public static void requestLocation(Context context, LocationListener locationListener) {
//         Log.d(TAG, "requestLocation Called");
//         if (IS_LOCATION_AUTHORIZED) {
//             LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
//             if (locationManager != null && locationListener != null) {
//                 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, Util.LOCATION_REFRESH_TIME, Util.LOCATION_REFRESH_DISTANCE, locationListener);
//             }
//         }
//     }
// 
//     public static void checarPermissoes(Activity activity) {
//         Log.d(TAG, "checarPermissoes Called");
//         if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
//                 && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 
//             String[] PERMISSIONS_LOCATION = {
//                     Manifest.permission.ACCESS_FINE_LOCATION,
//                     Manifest.permission.ACCESS_COARSE_LOCATION,
//             };
//             ActivityCompat.requestPermissions(activity, PERMISSIONS_LOCATION, REQUEST_ACCESS_LOCATION);
//         } else {
//             IS_LOCATION_AUTHORIZED = true;
//         }
//     }
// 
//     public static boolean isOnline(Context context) {
//         ConnectivityManager cm;
//         cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//         NetworkInfo netInfo = cm.getActiveNetworkInfo();
//         return netInfo != null && netInfo.isConnectedOrConnecting();
//     }
// 
//     private static String convertToHex(byte[] data) {
//         StringBuilder buf = new StringBuilder();
//         for (byte b : data) {
//             int halfbyte = (b >>> 4) & 0x0F;
//             int two_halfs = 0;
//             do {
//                 buf.append((0 <= halfbyte) && (halfbyte <= 9) ? (char) ('0' + halfbyte) : (char) ('a' + (halfbyte - 10)));
//                 halfbyte = b & 0x0F;
//             } while (two_halfs++ < 1);
//         }
//         return buf.toString();
//     }
// 
//     public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
//         MessageDigest md = MessageDigest.getInstance("SHA-1");
//         md.update(text.getBytes("iso-8859-1"), 0, text.length());
//         byte[] sha1hash = md.digest();
//         return convertToHex(sha1hash);
//     }
// }


import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import com.google.android.gms.maps.model.LatLng;
import com.hcordeiro.android.InthegraApp.R;
import com.hcordeiro.android.InthegraApp.Util.Util;
             * O botão de selecionar origem é recuperado e desabilitado, a origem
             * é setada com o local do usuário e o CheckedTextView de origem é
             * marcado como verdadeiro (essa última parte não funciona, e eu
             * desconheço a razão) */
            if (meuLocalSwtich.isChecked()) {
                Button selectionarOrigemBtn = (Button) findViewById(R.id.selectionarOrigemBtn);
                assert selectionarOrigemBtn != null;
                selectionarOrigemBtn.setEnabled(false);

                origem = new LatLng(location.getLatitude(), location.getLongitude());

                CheckedTextView origemCheckedTextView = (CheckedTextView) findViewById(R.id.origemCheckedTextView);
                assert origemCheckedTextView != null;
                origemCheckedTextView.setChecked(true);
            }

            /* Sempre que a localização é atualizada,
             * a activity verifica se já possui
             * uma origem e um destino para habilitar
             * o botão de avançar */
            verificaDados();
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.d(TAG, "onStatusChanged");
        }

        @Override
        public void onProviderEnabled(String provider) {
// Path: InthegraApp/src/main/java/com/hcordeiro/android/InthegraApp/Util/Util.java
// public class Util {
//     private static final String TAG = "Util";
// 
//     /*
//     Permissions
//      */
//     public static final int REQUEST_ACCESS_LOCATION = 1;
//     public static boolean IS_LOCATION_AUTHORIZED;
// 
//     public static final int ZOOM = 15;
//     public static final int VEICULOS_REFRESH_TIME = 30000;
//     public static final double DISTANCIA_MAXIMA_A_PE = 250;
//     public static final LatLng TERESINA = new LatLng(-5.070353, -42.803180);
// 
//     private static final int LOCATION_REFRESH_TIME = 10000;
//     private static final int LOCATION_REFRESH_DISTANCE = 10;
// 
// 
// //    public static final String ERRO_API_404 = "Not Found (404)";
// //    public static final String ERRO_HOSTNAME = "Unable to resolve host \"api.inthegra.strans.teresina.pi.gov.br\": No address associated with hostname";
// 
//     @SuppressWarnings("MissingPermission")
//     public static void requestLocation(Context context, LocationListener locationListener) {
//         Log.d(TAG, "requestLocation Called");
//         if (IS_LOCATION_AUTHORIZED) {
//             LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
//             if (locationManager != null && locationListener != null) {
//                 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, Util.LOCATION_REFRESH_TIME, Util.LOCATION_REFRESH_DISTANCE, locationListener);
//             }
//         }
//     }
// 
//     public static void checarPermissoes(Activity activity) {
//         Log.d(TAG, "checarPermissoes Called");
//         if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
//                 && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 
//             String[] PERMISSIONS_LOCATION = {
//                     Manifest.permission.ACCESS_FINE_LOCATION,
//                     Manifest.permission.ACCESS_COARSE_LOCATION,
//             };
//             ActivityCompat.requestPermissions(activity, PERMISSIONS_LOCATION, REQUEST_ACCESS_LOCATION);
//         } else {
//             IS_LOCATION_AUTHORIZED = true;
//         }
//     }
// 
//     public static boolean isOnline(Context context) {
//         ConnectivityManager cm;
//         cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//         NetworkInfo netInfo = cm.getActiveNetworkInfo();
//         return netInfo != null && netInfo.isConnectedOrConnecting();
//     }
// 
//     private static String convertToHex(byte[] data) {
//         StringBuilder buf = new StringBuilder();
//         for (byte b : data) {
//             int halfbyte = (b >>> 4) & 0x0F;
//             int two_halfs = 0;
//             do {
//                 buf.append((0 <= halfbyte) && (halfbyte <= 9) ? (char) ('0' + halfbyte) : (char) ('a' + (halfbyte - 10)));
//                 halfbyte = b & 0x0F;
//             } while (two_halfs++ < 1);
//         }
//         return buf.toString();
//     }
// 
//     public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
//         MessageDigest md = MessageDigest.getInstance("SHA-1");
//         md.update(text.getBytes("iso-8859-1"), 0, text.length());
//         byte[] sha1hash = md.digest();
//         return convertToHex(sha1hash);
//     }
// }


// Path: InthegraApp/src/main/java/com/hcordeiro/android/InthegraApp/Activities/Rotas/RotasMenuActivity.java
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import com.google.android.gms.maps.model.LatLng;
import com.hcordeiro.android.InthegraApp.R;
import com.hcordeiro.android.InthegraApp.Util.Util;

             * O botão de selecionar origem é recuperado e desabilitado, a origem
             * é setada com o local do usuário e o CheckedTextView de origem é
             * marcado como verdadeiro (essa última parte não funciona, e eu
             * desconheço a razão) */
            if (meuLocalSwtich.isChecked()) {
                Button selectionarOrigemBtn = (Button) findViewById(R.id.selectionarOrigemBtn);
                assert selectionarOrigemBtn != null;
                selectionarOrigemBtn.setEnabled(false);

                origem = new LatLng(location.getLatitude(), location.getLongitude());

                CheckedTextView origemCheckedTextView = (CheckedTextView) findViewById(R.id.origemCheckedTextView);
                assert origemCheckedTextView != null;
                origemCheckedTextView.setChecked(true);
            }

            /* Sempre que a localização é atualizada,
             * a activity verifica se já possui
             * uma origem e um destino para habilitar
             * o botão de avançar */
            verificaDados();
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.d(TAG, "onStatusChanged");
        }

        @Override
        public void onProviderEnabled(String provider) {
            Log.d(TAG, "onProviderEnabled");