Пример #1
0
  private void checkGPS(Context context, final boolean forceClose) {
    GPSTracker gpsTracker = new GPSTracker(context);
    if (gpsTracker.canGetLocation()) {
      boolean enable = SharedValues.getEnableLocation(context);
      double offRange = SharedValues.getOffRange(context);
      double lat = SharedValues.getLat(context);
      double lng = SharedValues.getLng(context);

      Log.d(
          "locationn",
          "setting is: " + enable + " offRange: " + offRange + " lat: " + lat + " lng: " + lng);
      if (enable && offRange != 0 && lat != 0 && lng != 0) {
        double distance =
            calculateDistance(lat, lng, gpsTracker.getLatitude(), gpsTracker.getLongitude());
        Log.d(
            "locationn",
            "getting lat: " + gpsTracker.getLatitude() + " lng: " + gpsTracker.getLongitude());
        Log.d("locationn", "getting distance: " + distance);

        if (distance >= offRange) {
          Log.d("locationn", "distance >= offRange");
          SwitchCloseTask task = new SwitchCloseTask(context);
          task.execute();
        }
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    String gps_status = getBaseContext().getString(R.string.gps_status);
    String gps_inform = getBaseContext().getString(R.string.gps_inform);

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_place);

    Intent i = getIntent();

    // Place referece id
    String reference = i.getStringExtra(KEY_REFERENCE);

    // Calling a Async Background thread
    new LoadSinglePlaceDetails().execute(reference);

    gps = new GPSTracker(this);
    if (gps.canGetLocation()) {
      Log.d(
          "Your Location", "latitude:" + gps.getLatitude() + ", longitude: " + gps.getLongitude());
    } else {
      // Can't get user's current location
      alert.showAlertDialog(SinglePlaceActivity.this, gps_status, gps_inform, false);
      // stop executing code by returno
      return;
    }
  }
  protected void syncToWebservice() {

    try {

      GPSTracker gps = new GPSTracker(getBaseContext());

      if (gps.canGetLocation()) {

        latitude = gps.getLatitude();
        longitude = gps.getLongitude();
        //
        //				 lat = String.valueOf(latitude);
        //				 lng = String.valueOf(longitude);
        //
        //				 share.saveLatfollow(lat);
        //				 share.saveLongfollow(lng);
        Location location = new Location("dummy provider");
        location.setLatitude(latitude);
        location.setLongitude(longitude);
        new GetAddressTask().execute(location);
      }
    } catch (Exception e) {
      // TODO: handle exception
      CommonFunctionMapid.displayToastshort(
          getApplicationContext(), e.getMessage(), Gravity.CENTER);
    }
  }
Пример #4
0
  /*
   * Get Users GPS coordinates
   */
  public void getGpsCords() {
    gps = new GPSTracker(LoginActivity.this);

    // check if GPS enabled
    if (gps.canGetLocation()) {
      latitude = gps.getLatitude();
      longitude = gps.getLongitude();
      // Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong:
      // " + longitude, Toast.LENGTH_LONG).show();
    } else {
      // can't get location
      // GPS or Network is not enabled
      // Ask user to enable GPS/network in settings
      gps.showSettingsAlert();
    }
  }
Пример #5
0
  public void findMyCurrentLocation() {
    gps = new GPSTracker(CompassActivity.this);

    // check if GPS enabled
    if (gps.canGetLocation()) {

      latitude = gps.getLatitude();
      longitude = gps.getLongitude();

      Toast.makeText(
              getApplicationContext(),
              "Your Location is - \nLat: " + latitude + "\nLong: " + longitude,
              Toast.LENGTH_LONG)
          .show();
    } else {
      // gps.showSettingsAlert();
    }
  }
Пример #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /*

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);*/

    locales = new HashMap<>();

    try {
      // Loading map
      initilizeMap();

      double latitude = 0;
      double longitude = 0;
      GPSTracker gps;
      gps = new GPSTracker(this);
      if (gps.canGetLocation()) {
        latitude = gps.getLatitude();
        longitude = gps.getLongitude();
        LatLng UPV = new LatLng(latitude, longitude);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(UPV, 15));

      } else {
        gps.showSettingsAlert();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #7
0
  @Override
  protected void onResume() {
    // check if GPS enabled
    if (gps.canGetLocation()) {

      double latitude = gps.getLatitude();
      double longitude = gps.getLongitude();

      // \n is for new line
      //            Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude
      // + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
      Log.i("rishab", "Latitude : " + latitude + " longitude " + longitude);

      getResponse(latitude, longitude);
    } else {
      // can't get location
      // GPS or Network is not enabled
      // Ask user to enable GPS/network in settings
      gps.showSettingsAlert();
    }
    super.onResume();
  }
Пример #8
0
  private ArrayList<String> refreshFrequentChoice() {

    /* See Where is selected (GPS) */
    /* Create GPS class object */
    gps = new GPSTracker(getActivity());
    /* Check if GPS enabled */
    if (gps.canGetLocation()) {
      lat = gps.getLatitude();
      lon = gps.getLongitude();
      // \n is for new line
      /*Toast.makeText(getActivity(),
      "Your Location is - \nLat: " + lat + "\nLong: " + lon,
      Toast.LENGTH_LONG).show();*/
    } else {
      // can't get location
      // GPS or Network is not enabled
      // Ask user to enable GPS/network in settings
      gps.showSettingsAlert();
    }
    float tmplong = 0;
    float tmplat = 0;
    float tmpdis = 0;
    ContentValues value = new ContentValues();
    String sql =
        "SELECT food_name,latitude, longitude, distance "
            + " FROM FoodGPS WHERE food_name NOT NULL";
    mCursor = mDb.rawQuery(sql, null);
    if (mCursor.getCount() > 0) { // now it is taking the first match WIP
      // fix later
      mCursor.moveToFirst();
      tmplat = mCursor.getFloat(mCursor.getColumnIndex("latitude"));
      tmplong = mCursor.getFloat(mCursor.getColumnIndex("longitude"));
      tmpdis = distFrom(tmplat, tmplong, lat.floatValue(), lon.floatValue());
      Log.d(TAG, "Adding distance " + tmpdis + " to FoodGPS");
      value.put("distance", tmpdis);
      mDb.update("FoodGPS", value, null, null);
      while (!mCursor.isLast()) {
        mCursor.moveToNext();
        tmplat = mCursor.getFloat(mCursor.getColumnIndex("latitude"));
        tmplong = mCursor.getFloat(mCursor.getColumnIndex("longitude"));
        tmpdis = distFrom(tmplat, tmplong, lat.floatValue(), lon.floatValue());
        Log.d(TAG, "Adding distance " + tmpdis + " to FoodGPS");
        value.put("distance", tmpdis);
        mDb.update("FoodGPS", value, null, null);
      }
      // showToastMessage("Got " + tmplat + "\n& " + tmplong +"\ndistance is" + tmpdis);
    }

    // Display on the list
    ArrayList<String> sData = new ArrayList<String>();
    sql =
        "SELECT food_name, COUNT(food_name), distance, GL"
            + " FROM FoodGPS WHERE food_name NOT NULL"
            + " GROUP BY food_name"
            + " ORDER BY COUNT(food_name) DESC"
            + " LIMIT 5";

    sql = "SELECT food_name, distance, GL FROM (" + sql + ") ORDER BY distance DESC";
    mCursor = mDb.rawQuery(sql, null);

    if (mCursor.getCount() > 0) { // now it is taking the first match WIP
      // fix later
      // testing
      inputMethod = GPS_INPUT;

      mCursor.moveToFirst();
      sData.add(mCursor.getString(mCursor.getColumnIndex("food_name")));
      while (!mCursor.isLast()) {
        mCursor.moveToNext();
        String Name = mCursor.getString(mCursor.getColumnIndex("food_name"));
        sData.add(Name);
      }
    }
    isValid = true;
    return sData;
  }
Пример #9
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_one, container, false);

    // Get user's login data from session
    session = new SessionManager(getActivity().getApplicationContext());
    session.checkLogin();
    HashMap<String, String> user = session.getUserDetails();
    name = user.get(SessionManager.KEY_NAME);
    number = user.get(SessionManager.KEY_EMAIL);

    // Loading Font Face
    Typeface mont_reg =
        Typeface.createFromAsset(getActivity().getAssets(), "fonts/Montserrat-Regular.otf");

    // bt_ride = (Button)view.findViewById(R.id.bt_ride);
    bt_sms = (Button) view.findViewById(R.id.bt_smsHelp);
    bt_call = (Button) view.findViewById(R.id.bt_callHelp);
    bt_emerg = (Button) view.findViewById(R.id.bt_emergencyButton_one);

    bt_sms.setText("Send Help SMS to : " + number);
    bt_call.setText("Make a Call to : " + number);
    bt_emerg.setText("Emergency Numbers");

    // bt_ride.setTypeface(mont_reg);
    bt_sms.setTypeface(mont_reg);
    bt_call.setTypeface(mont_reg);
    bt_emerg.setTypeface(mont_reg);

    // Location Tracker
    gps = new GPSTracker(getActivity());

    // check if GPS enabled
    if (gps.canGetLocation()) {
      lat = gps.getLatitude();
      lon = gps.getLongitude();
    } else {
      // can't get location or GPS or Network is not enabled then Ask user to enable GPS/network in
      // settings
      // gps.showSettingsAlert();
    }

    bt_sms.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              // check if GPS enabled
              if (gps.canGetLocation()) {
              } else {
                //                        gps.showSettingsAlert();
              }

              AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());

              // Setting Dialog Title
              alertDialog.setTitle("Send Help SMS?");

              // Setting Dialog Message
              alertDialog.setMessage(
                  "\nSend SMS to "
                      + number
                      + " ?\n\n\nContent of SMS : \n\n"
                      + "Contact "
                      + name
                      + ", he/she is not in a condition to drive & needs your help to get back home from location : \'Google Maps URL of your location\' \n\n");

              alertDialog.setNegativeButton(
                  "No",
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      // Write your code here to invoke NO event
                    }
                  });

              alertDialog.setPositiveButton(
                  "Yes",
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      // Write your code here to invoke NO event

                      SmsManager smsManager_2 = SmsManager.getDefault();
                      String smsBody;
                      smsBody = "http://maps.google.com/?q=" + lat + "," + lon;
                      smsManager_2.sendTextMessage(
                          number,
                          null,
                          "Contact "
                              + name
                              + ", he/she is not in a condition to drive & needs your help to get back home from location : "
                              + smsBody,
                          null,
                          null);
                      Toast.makeText(
                              getActivity().getApplicationContext(),
                              "SMS successfully sent!",
                              Toast.LENGTH_LONG)
                          .show();
                    }
                  });

              // Showing Alert Message
              alertDialog.show();
            } catch (Exception e) {
              Toast.makeText(
                      getActivity().getApplicationContext(),
                      "SMS failed, please try again.",
                      Toast.LENGTH_LONG)
                  .show();
              e.printStackTrace();
            }
          }
        });

    bt_call.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());

            // Setting Dialog Title
            alertDialog.setTitle("Are you sure ?");

            // Setting Dialog Message
            alertDialog.setMessage("Make a call to " + number + " ?");

            alertDialog.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to invoke NO event
                  }
                });

            alertDialog.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to invoke NO event
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + number));
                    startActivity(callIntent);
                  }
                });

            alertDialog.show();
          }
        });

    bt_emerg.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(getActivity(), EmergencyNumbers.class);
            startActivity(i);
          }
        });

    // Inflate the layout for this fragment
    return view;
  }
  public void UpdateCarCurrentLocation(final String clientid) {

    if ((gps.getLatitude() + "").equalsIgnoreCase("0.0")
        && (gps.getLongitude() + "").equalsIgnoreCase("0.0")) {
      gps.showSettingsAlert(UpdateLocation.this);
    } else {
      if (PAST_LOCATION == null
          || PAST_LOCATION != null && (PAST_LOCATION.distanceTo(gps.getLocation()) > 10)) {
        gps = new GPSTracker(this);
        new AsyncTask<Void, Void, String>() {
          // ProgressDialog mProgressDialog;

          @Override
          protected String doInBackground(Void... params) {
            // TODO Auto-generated method stub

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(ApplicationData.serviceURL_UpdateCarCurrentLocation);

            SharedPreferences mprefes = getSharedPreferences("DEVICE_ID", 0);
            String deviceid = mprefes.getString("ID", "");

            //					Trip_SharedPref = getSharedPreferences("START_TRIP_STATUS",
            //							0);
            //					boolean getTripStatus = Trip_SharedPref.getBoolean(
            //							"STATUS", false);
            //					Log.e("get trip status", getTripStatus + "");

            try {
              // Add your data
              List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
              nameValuePairs.add(new BasicNameValuePair("iDriverId", clientid));
              nameValuePairs.add(
                  new BasicNameValuePair("latitude", String.valueOf(gps.getLatitude())));
              nameValuePairs.add(
                  new BasicNameValuePair("longitude", String.valueOf(gps.getLongitude())));
              nameValuePairs.add(new BasicNameValuePair("device_id", deviceid));
              Log.e("Driver lat lon", gps.getLatitude() + gps.getLongitude() + "" + clientid);

              //						if (getTripStatus == true) {
              //							Route_Lat_Lng = String.valueOf(gps.getLatitude())
              //									+ "," + String.valueOf(gps.getLongitude());
              //
              //							Update_Trip_Lat_Lng = getSharedPreferences(
              //									"UPDATE_LAT_LNG", 0);
              //							String previous_val = Update_Trip_Lat_Lng
              //									.getString("LAT_LNG", "0.0");
              //							if (Route_Lat_Lng.equalsIgnoreCase("0.0,0.0")) {
              //								if (previous_val.equalsIgnoreCase("0.0")) {
              //									Editor edit1 = Update_Trip_Lat_Lng.edit();
              //									edit1.putString("LAT_LNG", Route_Lat_Lng
              //											+ "|");
              //									edit1.commit();
              //								} else {
              //									Editor edit1 = Update_Trip_Lat_Lng.edit();
              //									edit1.putString("LAT_LNG", previous_val
              //											 + Route_Lat_Lng+"|");
              //									edit1.commit();
              //
              //									Log.e("bunch of lat lng From start to finish", previous_val
              //											 + Route_Lat_Lng+"|");
              //									Log.e("Route lat lng", Route_Lat_Lng);
              //								}
              //							}
              //						}

              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

              // Execute HTTP Post Request
              HttpResponse response = httpclient.execute(httppost);
              BufferedReader in =
                  new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
              StringBuffer sb = new StringBuffer("");
              String line = "";
              while ((line = in.readLine()) != null) {
                sb.append(line);
              }
              in.close();
              Log.e("Driver UpdateCurrentLocation Data", "" + sb.toString());
              return sb.toString();
            } catch (Exception e) {
              Log.e("UpdateCurrentLocation problem data setting", "" + e);
              return "";
            }
          }

          @Override
          protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            try {

              // mProgressDialog.dismiss();
              JSONObject object = new JSONObject(result.toString());
              String msg = object.getString("msg");
              if (msg.equalsIgnoreCase("Success")) {

              } else if (msg.equalsIgnoreCase("You can log out")) {

                DriverLogout();
              }
              PAST_LOCATION = gps.getLocation();
            } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }

          @Override
          protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            // mProgressDialog = new ProgressDialog(this);
            // mProgressDialog.setTitle("");
            // mProgressDialog.setCanceledOnTouchOutside(false);
            // mProgressDialog.setMessage("Please Wait...");
            // mProgressDialog.show();

          }
        }.execute();
      }
    }
  }
Пример #11
0
  public void send(View v) {
    Button button = (Button) v;
    button.setText("SENT");
    EditText edittext = (EditText) findViewById(R.id.editText);
    String details = edittext.getText().toString();

    String phoneNo = "9292442978"; // Insert server phone number here. 9292442978

    gps = new GPSTracker(MainActivity.this);
    double latitude = 0.0;
    double longitude = 0.0;
    if (gps.canGetLocation()) {
      latitude = gps.getLatitude();
      longitude = gps.getLongitude();
    } else {
      // can't get location
      // GPS or Network is not enabled
      // Ask user to enable GPS/network in settings
      gps.showSettingsAlert();
    }
    String message = "swagmaster2000\n";
    String cityName;
    String countryName;
    Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
    List<Address> addresses;
    try {
      addresses = gcd.getFromLocation(latitude, longitude, 1);
      cityName = addresses.get(0).getLocality();
      countryName = addresses.get(0).getCountryName();
      Address address = addresses.get(0);
      String readablehurrdurr =
          String.format(
              "%s, %s, %s, %s",
              // If there's a street address, add it
              address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
              // Locality is usually a city
              address.getLocality(),
              // The country of the address
              address.getCountryName(),
              address.getPostalCode()); // getPostalCode()
      message += (readablehurrdurr + "\n");
      message += (countryName + "\n");
      message += (cityName + "\n");
    } catch (IOException e) {
      e.printStackTrace();
    }
    message += details + "\n";
    // Toast.makeText(getApplicationContext(), message + longitude + "\n" + latitude,
    // Toast.LENGTH_LONG).show();

    if (edittext.getText().toString().equals("")) {
      Toast.makeText(
              getApplicationContext(),
              "Please describe the emergency and your location",
              Toast.LENGTH_LONG)
          .show();
      button.setText("SEND");
      return;
    }

    flag = displayGpsStatus();

    if (flag) {

      try {
        SmsManager smsManager = SmsManager.getDefault();
        PendingIntent sentPI;
        String SENT = "SMS_SENT";

        sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);

        smsManager.sendTextMessage(phoneNo, null, message, sentPI, null);
        Toast.makeText(
                getApplicationContext(),
                "Sent. Please wait for aid.", // "SMS sent. " + sentPI.toString()
                Toast.LENGTH_LONG)
            .show();
      } catch (Exception e) {
        // error lol
        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
        e.printStackTrace();
      }
    } else {
      alertbox();
    }
    edittext.setText("");
  }
Пример #12
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_community, container, false);

    gps = new GPSTracker(getActivity());

    // check if GPS enabled
    if (gps.canGetLocation()) {

      double latitude = gps.getLatitude();
      double longitude = gps.getLongitude();
      // String a1=Double.toString(latitude);
      // String a2=Double.toString(longitude);

      a1 = Double.toString(latitude);
      a2 = Double.toString(longitude);

      longtitude =
          a1
              + ","
              + a2
              + "&radius=5000"
              + "&categoryId=4bf58dd8d48988d16d941735,4bf58dd8d48988d1e5931735,4bf58dd8d48988d137941735,4d4b7105d754a06374d81259";

    } else {
      // can't get location
      // GPS or Network is not enabled
      // Ask user to enable GPS/network in settings
      gps.showSettingsAlert();
    }

    listView = (ListView) rootView.findViewById(R.id.card_listView);
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
    mSwipeRefreshLayout.setColorSchemeResources(
        R.color.orange, R.color.green, R.color.blue, R.color.orange);
    mSwipeRefreshLayout.setOnRefreshListener(
        new OnRefreshListener() {

          @Override
          public void onRefresh() {
            Ace();
          }
        });

    //        listView.addHeaderView(new View(this));
    //        listView.addFooterView(new View(this));

    //        cardArrayAdapter = new CardArrayAdapter(getActivity(), R.layout.list_item_card);
    //
    //        for (int i = 0; i < 10; i++) {
    //            Card card = new Card("Manev " + (i+1) + " Line 1", "Manev " + (i+1) + " Line 2");
    //            cardArrayAdapter.add(card);
    //        }
    //        listView.setAdapter(cardArrayAdapter);

    new fourquare().execute();

    return rootView;
  }