Skip to content

Commit f670458

Browse files
committed
1. Added a generic method for getting data from database's table. And this method can be assigned to ArrayList of any type.
2. Added new class for getting current locations latitude, longitude and address. 3. Deprecated MyLocation and LocationAddress class.
1 parent 2d55c19 commit f670458

File tree

6 files changed

+648
-116
lines changed

6 files changed

+648
-116
lines changed

README.md

Lines changed: 61 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,37 @@ dbHelper.executeDatabaseOperation(tableName, operation, values, hasConditions, c
244244
dbHelper.executeSelectQuery(tableName, values, hasConditions, conditionalValues);
245245

246246

247+
/**
248+
* execute Select Query method
249+
* this method is used for selecting data from database
250+
*
251+
* parameters for this method are
252+
*
253+
* @param tableName - name of the table to perform select operation
254+
*
255+
* @param values - values to perform select query on
256+
* Ex: "*" or "id, firstName"
257+
*
258+
* @param hasConditions - if you want to use the where clause in select query
259+
* then this parameter should be set to true
260+
* else this parameter can be false
261+
*
262+
* @param conditionalValues - if the hasConditions is set to true
263+
* then the user has to pass conditionalValues
264+
* else it can be null
265+
* Ex: ID = 1 OR firstName LIKE '%Your String%'
266+
*
267+
* @param tClass - Pass your Model class like this
268+
* Ex: ModelClass.class
269+
* this is required for setting the values
270+
*
271+
* @return ArrayList of Type pass as class
272+
*
273+
**/
274+
//#endregion COMMENTS FOR executeSelectQuery method
275+
dbHelper.executeSelectQuery(tableName, values, hasConditions, conditionalValues, class);
276+
277+
247278
// for select query use this method
248279
//
249280
// parameters to be passed are as follows:
@@ -464,93 +495,50 @@ switchButton.setOnSwitchListener(new SwitchButton.OnSwitchListener()
464495
});
465496
```
466497

467-
### MyLocation class
498+
### GeoLocation class
468499

469-
>**This class will get the current location of the user.**
500+
>**This class will get the current location and address of the user. This class will check and ask for locations permission if not granted**
470501
471502
```java
472503

473504
// this will check whether gps is enabled or not
474-
MyLocation.isGPSEnabled(Context context); // returns true or false
505+
GeoLocation.isGPSEnabled(Context context); // returns true or false
475506

476507
// following code is for getting latitude and longitude
477-
// Declare this class globally inside your activity or class.
478-
private double latitude = 0.0, longitude = 0.0;
479-
private MyLocation myLocation = new MyLocation();
508+
double latitude = geoLocation.getLatitude();
509+
double longitude = geoLocation.getLongitude();
480510

481-
// Use myLocation's class's Location listener which will return latitude and longitude of current location.
482-
private MyLocation.LocationResult locationResult = new Mylocation.LocationResult()
483-
{
484-
@Override
485-
public void gotLocation(Location location)
486-
{
487-
try
488-
{
489-
latitude = location.getLatitude();
490-
longitude = location.getLongitude();
491-
492-
Log.e(TAG, "gotLocation: Latitude of the location is: " + latitude);
493-
Log.e(TAG, "gotLocation: Longitude of the location is: " + longitude);
494-
}
495-
catch(Exception e)
496-
{
497-
Log.e(TAG, "gotLocation: exception while getting location lat, long:\n");
498-
e.printStackTrace();
499-
}
500-
}
501-
};
511+
// this method will get address of current location
512+
// you can also get city, state, country, etc.
513+
String address = geoLocation.getAddress;
502514

503-
// all the above code should be used globally.
504-
// now use the myLocation's class's object as below inside onCreate method.
505-
myLocation.getLocation(this, locationResult);
506-
```
515+
String city = geoLocation.getCity();
507516

508-
### LocationAddress class
517+
String state = geoLocation.getState();
509518

510-
>**This class helps your to get the address of the current location or by using latitude and longitude.**
519+
String country = geoLocation.getCountry();
511520

512-
```java
513-
// use the following code to get the address of the latitude and longitude.
514-
// declare this inside onCreate() method or anywhere you would like to use it.
515-
// on button click or anywhere.
521+
String premises = geoLocation.getPremises();
516522

517-
LocationAddress.getAddressFromLocation(mLatitude, mLongitude, this, new GeocoderHandler());
523+
String knownName = geoLocation.getKnownName();
524+
525+
String postalCode = geoLocation.getPostalCode();
526+
527+
String subLocality = geoLocation.getSubLocality();
528+
529+
String subAdminArea = geoLocation.getSubAdminArea();
530+
531+
String thoroughFare = geoLocation.getThoroughFare();
532+
533+
String subThoroughFare = geoLocation.getSubThoroughFare();
534+
535+
// if you want to capture the address and latitude and longitude
536+
// after getting access to locations permission
537+
// then use *onRequestPermissionsResult* of the activity
538+
// and re-call this class as follows.
539+
// considering *geoLocation* is declared globally
540+
geoLocation = new GeoLocation(YourActivity.this);
518541

519-
// this is the GeocoderHandler class where you'll get the address
520-
private class GeocoderHandler extends Handler
521-
{
522-
@Override
523-
public void handleMessage(Message msg)
524-
{
525-
switch (msg.what)
526-
{
527-
case 1:
528-
529-
Bundle bundle = msg.getData();
530-
531-
// note that subThoroughFare may return null sometimes.
532-
// so you should manage it accordling.
533-
String address = bundle.getString("subThoroughFare") + ", " +
534-
bundle.getString("thoroughFare");
535-
536-
String subLocality = bundle.getString("subLocality");
537-
String subAdminArea = bundle.getString("subAdminArea");
538-
String postalCode = bundle.getString("postalCode");
539-
540-
String city = bundle.getString("city");
541-
String state = bundle.getString("state");
542-
String country = bundle.getString("country");
543-
544-
break;
545-
546-
default:
547-
548-
// address not found.
549-
550-
break;
551-
}
552-
}
553-
}
554542
```
555543

556544
### FontHelper Class

0 commit comments

Comments
 (0)