public class BookObject implements IDBSerializable{
long id;
long series_id;
long publisher_id;
int published_at_year;
int page_count;
int byte_count;
String title_ru;
String title_ln;
String title_il;
String description;
String author_first_name_ru;
String author_last_name_ru;
String author_first_name_ln;
String author_last_name_ln;
String content_preview;
String content;
String isbn;
String apple_product_id;
Date created;
Date updated;
CoverObject cover;
ArrayList<BookObject> recomendations;
@Override
public void putToContentValues(ContentValues values) {
values.put(FIELD_ID, id);
// values.put(FIELD_FOREIGN_ID, id);
values.put(FIELD_SERIES_ID, series_id);
values.put(FIELD_PUBLISHER_ID, publisher_id);
values.put(FIELD_YEAR, published_at_year);
values.put(FIELD_PAGE_COUNT, page_count);
values.put(FIELD_BYTE_COUNT, byte_count);
values.put(FIELD_TITLE_RU, title_ru);
values.put(FIELD_TITLE_LN, title_ln);
values.put(FIELD_TITLE_IL, title_il);
values.put(FIELD_DESCRIPTION, description);
values.put(FIELD_AUTHOR_FIRST_NAME_RU, author_first_name_ru);
values.put(FIELD_AUTHOR_LAST_NAME_RU, author_last_name_ru);
values.put(FIELD_AUTHOR_FIRST_NAME_LN, author_first_name_ln);
values.put(FIELD_AUTHOR_LAST_NAME_LN, author_last_name_ln);
values.put(FIELD_ISBN, isbn);
values.put(FIELD_PRODUCT_ID, apple_product_id);
values.put(FIELD_CREATED, created.getTime());
values.put(FIELD_UPDATED, updated.getTime());
values.put(FIELD_BOOK, content); // book url
values.put(FIELD_BOOK_PREVIEW, content_preview); // book preview url
values.put(FIELD_COVER_IMAGE, cover.original); // book cover url
values.put(FIELD_COVER_PREVIEW_IMAGE, cover.preview); // book cover preview url
}
public BookObject() {
}
public BookObject(Cursor cursor){
this.id = cursor.getLong(cursor.getColumnIndex(FIELD_ID));
this.series_id = cursor.getLong(cursor.getColumnIndex(FIELD_SERIES_ID));
this.publisher_id = cursor.getLong(cursor.getColumnIndex(FIELD_PUBLISHER_ID));
this.published_at_year = cursor.getInt(cursor.getColumnIndex(FIELD_YEAR));
this.page_count = cursor.getInt(cursor.getColumnIndex(FIELD_PAGE_COUNT));
this.byte_count = cursor.getInt(cursor.getColumnIndex(FIELD_BYTE_COUNT));
this.title_ru = cursor.getString(cursor.getColumnIndex(FIELD_TITLE_RU));
this.title_ln = cursor.getString(cursor.getColumnIndex(FIELD_TITLE_LN));
this.title_il = cursor.getString(cursor.getColumnIndex(FIELD_TITLE_IL));
this.description = cursor.getString(cursor.getColumnIndex(FIELD_DESCRIPTION));
this.author_first_name_ru = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_FIRST_NAME_RU));
this.author_last_name_ru = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_LAST_NAME_RU));
this.author_first_name_ln = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_FIRST_NAME_LN));
this.author_last_name_ln = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_LAST_NAME_LN));
this.isbn = cursor.getString(cursor.getColumnIndex(FIELD_ISBN));
this.apple_product_id = cursor.getString(cursor.getColumnIndex(FIELD_PRODUCT_ID));
this.created = new Date(cursor.getInt(cursor.getColumnIndex(FIELD_CREATED)));
this.updated = new Date(cursor.getInt(cursor.getColumnIndex(FIELD_UPDATED)));
this.content = cursor.getString(cursor.getColumnIndex(FIELD_BOOK));
this.content_preview = cursor.getString(cursor.getColumnIndex(FIELD_BOOK_PREVIEW));
this.cover = new CoverObject(
cursor.getString(cursor.getColumnIndex(FIELD_COVER_IMAGE)),
cursor.getString(cursor.getColumnIndex(FIELD_COVER_PREVIEW_IMAGE))
);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getSeries_id() {
return series_id;
}
public void setSeries_id(long series_id) {
this.series_id = series_id;
}
public long getPublisher_id() {
return publisher_id;
}
public void setPublisher_id(long publisher_id) {
this.publisher_id = publisher_id;
}
public int getPublished_at_year() {
return published_at_year;
}
public void setPublished_at_year(int published_at_year) {
this.published_at_year = published_at_year;
}
public int getPage_count() {
return page_count;
}
public void setPage_count(int page_count) {
this.page_count = page_count;
}
public int getByte_count() {
return byte_count;
}
public void setByte_count(int byte_count) {
this.byte_count = byte_count;
}
public String getTitle_ru() {
return title_ru;
}
public void setTitle_ru(String title_ru) {
this.title_ru = title_ru;
}
public String getTitle_ln() {
return title_ln;
}
public void setTitle_ln(String title_ln) {
this.title_ln = title_ln;
}
public String getTitle_il() {
return title_il;
}
public void setTitle_il(String title_il) {
this.title_il = title_il;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAuthor_first_name_ru() {
return author_first_name_ru;
}
public void setAuthor_first_name_ru(String author_first_name_ru) {
this.author_first_name_ru = author_first_name_ru;
}
public String getAuthor_last_name_ru() {
return author_last_name_ru;
}
public void setAuthor_last_name_ru(String author_last_name_ru) {
this.author_last_name_ru = author_last_name_ru;
}
public String getAuthor_first_name_ln() {
return author_first_name_ln;
}
public void setAuthor_first_name_ln(String author_first_name_ln) {
this.author_first_name_ln = author_first_name_ln;
}
public String getAuthor_last_name_ln() {
return author_last_name_ln;
}
public void setAuthor_last_name_ln(String author_last_name_ln) {
this.author_last_name_ln = author_last_name_ln;
}
public String getContent_preview() {
return content_preview;
}
public void setContent_preview(String content_preview) {
this.content_preview = content_preview;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getApple_product_id() {
return apple_product_id;
}
public void setApple_product_id(String apple_product_id) {
this.apple_product_id = apple_product_id;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
public CoverObject getCover() {
return cover;
}
public void setCover(CoverObject cover) {
this.cover = cover;
}
public ArrayList<BookObject> getRecomendations() {
return recomendations;
}
public void setRecomendations(ArrayList<BookObject> recomendations) {
this.recomendations = recomendations;
}
public static class CoverObject {
String original;
String preview;
CoverObject() {
}
CoverObject(String original, String preview) {
this.original = original;
this.preview = preview;
}
public String getOriginal() {
return original;
}
public void setOriginal(String original) {
this.original = original;
}
public String getPreview() {
return preview;
}
public void setPreview(String preview) {
this.preview = preview;
}
}
}
private ArrayList<BookObject> jsonToBooks(JSONArray json){
Type mListType = new TypeToken< ArrayList<BookObject>>(){}.getType();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd kk:mm:ss").create();
return gson.fromJson(String.valueOf(json), mListType);
}
public class GPSTracker implements LocationListener {
private final Context mContext;
// flag for GPS status
public boolean isGPSEnabled = false;
// flag for network status
boolean isNetworkEnabled = false;
// flag for GPS status
boolean canGetLocation = false;
Location location; // location
double latitude; // latitude
double longitude; // longitude
// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1; // 10 meters
// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1; // 1 minute
// Declaring a Location Manager
protected LocationManager locationManager;
public GPSTracker(Context context) {
this.mContext = context;
getLocation();
}
/**
* Function to get the user's current location
*
* @return
*/
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
Log.v("isGPSEnabled", "=" + isGPSEnabled);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.v("isNetworkEnabled", "=" + isNetworkEnabled);
if (isGPSEnabled == false && isNetworkEnabled == false) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
location=null;
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
location=null;
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
/**
* Stop using GPS listener Calling this function will stop using GPS in your
* app
* */
public void stopUsingGPS() {
if (locationManager != null) {
locationManager.removeUpdates(GPSTracker.this);
}
}
/**
* Function to get latitude
* */
public double getLatitude() {
if (location != null) {
latitude = location.getLatitude();
}
// return latitude
return latitude;
}
/**
* Function to get longitude
* */
public double getLongitude() {
if (location != null) {
longitude = location.getLongitude();
}
// return longitude
return longitude;
}
/**
* Function to check GPS/wifi enabled
*
* @return boolean
* */
public boolean canGetLocation() {
return this.canGetLocation;
}
/**
* Function to show settings alert dialog On pressing Settings button will
* lauch Settings Options
* */
public void showSettingsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
// Setting Dialog Title
alertDialog.setTitle("GPS is settings");
// Setting Dialog Message
alertDialog
.setMessage("GPS is not enabled. Do you want to go to settings menu?");
// On pressing Settings button
alertDialog.setPositiveButton("Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
...
GPSTracker tracker = new GPSTracker(this);
if (tracker.canGetLocation() == false) {
tracker.showSettingsAlert();
} else {
latitude = tracker.getLatitude();
longitude = tracker.getLongitude();
//put code to push date to server
}
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>