This commit is contained in:
ashishandroid
2016-12-30 16:47:05 +05:30
parent 7f24e8550f
commit 95310c3375
9 changed files with 331 additions and 50 deletions
+12
View File
@@ -54,6 +54,18 @@
android:label="@string/title_activity_store_list_geotag" android:label="@string/title_activity_store_list_geotag"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".geotag.GeoTagActivity"
android:label="@string/title_activity_store_geotag"
android:theme="@style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD02po19go2JMhXJeAnKDiZSiNloPsWqzI" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application> </application>
@@ -1,35 +1,69 @@
package cpm.com.gskmtorange.geotag; package cpm.com.gskmtorange.geotag;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Geocoder;
import android.location.Location; import android.location.Location;
import android.location.LocationManager; import android.location.LocationManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import cpm.com.gskmtorange.R; import cpm.com.gskmtorange.R;
import cpm.com.gskmtorange.constant.CommonString;
import cpm.com.gskmtorange.database.GSKOrangeDB;
/** /**
* Created by ashishc on 27-12-2016. * Created by ashishc on 27-12-2016.
*/ */
public class GeoTagActivity extends AppCompatActivity //implements OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener public class GeoTagActivity extends AppCompatActivity implements OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener
{ {
private GoogleMap mMap; private GoogleMap mMap;
double latitude =0.0; double latitude =0.0;
double longitude =0.0; double longitude =0.0;
LocationManager locationManager;
private Location mLastLocation; private Location mLastLocation;
private LocationManager locmanager = null; private LocationManager locmanager = null;
FloatingActionButton fab,fabcarmabtn; FloatingActionButton fab,fabcarmabtn;
SupportMapFragment mapFragment; SupportMapFragment mapFragment;
SharedPreferences preferences; SharedPreferences preferences;
String username,storeid,str;
GSKOrangeDB db;
LocationManager locationManager;
Geocoder geocoder;
boolean enabled;
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 1000;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private static int UPDATE_INTERVAL = 500; // 5 sec
private static int FATEST_INTERVAL = 100; // 1 sec
private static int DISPLACEMENT = 5; // 10 meters
private static final String TAG = GeoTagActivity.class.getSimpleName();
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -38,21 +72,93 @@ public class GeoTagActivity extends AppCompatActivity //implements OnMapReady
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences = PreferenceManager.getDefaultSharedPreferences(this);
//username = preferences.getString(CommonString.KEY_USERNAME, null); username = preferences.getString(CommonString.KEY_USERNAME, null);
fab = (FloatingActionButton) findViewById(R.id.fab); fab = (FloatingActionButton) findViewById(R.id.fab);
fabcarmabtn = (FloatingActionButton) findViewById(R.id.camrabtn); fabcarmabtn = (FloatingActionButton) findViewById(R.id.camrabtn);
db = new GSKOrangeDB(GeoTagActivity.this);
db.open();
storeid = getIntent().getStringExtra("Storeid");
str = CommonString.FILE_PATH;
mapFragment = (SupportMapFragment) getSupportFragmentManager() mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map); .findFragmentById(R.id.map);
// mapFragment.getMapAsync(this); mapFragment.getMapAsync(this);
locationManager = (LocationManager) this
.getSystemService(LOCATION_SERVICE);
geocoder = new Geocoder(this);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (checkPlayServices()) {
// Building the GoogleApi client
buildGoogleApiClient();
}
if (checkPlayServices()) {
// Building the GoogleApi client
buildGoogleApiClient();
createLocationRequest();
}
locmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
enabled = locmanager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
GeoTagActivity.this);
// Setting Dialog Title
alertDialog.setTitle("GPS IS DISABLED...");
// Setting Dialog Message
alertDialog.setMessage("Click ok to enable GPS.");
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
@@ -60,6 +166,142 @@ public class GeoTagActivity extends AppCompatActivity //implements OnMapReady
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Toast.makeText(getApplicationContext(),
"This device is not supported.", Toast.LENGTH_LONG)
.show();
finish();
}
return false;
}
return true;
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(FATEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
}
protected void startLocationUpdates() {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
/**
* Stopping location updates
*/
protected void stopLocationUpdates() {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
@Override
public void onConnected(Bundle bundle) {
mLastLocation = LocationServices.FusedLocationApi
.getLastLocation(mGoogleApiClient);
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
if (mLastLocation != null) {
latitude = mLastLocation.getLatitude();
longitude = mLastLocation.getLongitude();
mMap.setMyLocationEnabled(true);
// Add a marker of latest location and move the camera
LatLng latLng = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(latLng));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
}
// if (mRequestingLocationUpdates) {
startLocationUpdates();
// }
// startLocationUpdates();
}
@Override
public void onConnectionSuspended(int i) {
mGoogleApiClient.connect();
}
@Override
public void onLocationChanged (Location location){
}
@Override
public void onConnectionFailed (ConnectionResult connectionResult) {
Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + connectionResult.getErrorCode());
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
protected void onStart() {
super.onStart();
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
}
@Override
protected void onResume() {
super.onResume();
/* checkPlayServices();
// Resuming the periodic location updates
if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) {
startLocationUpdates();
}*/
}
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
protected void onPause() {
super.onPause();
stopLocationUpdates();
}
@@ -1,6 +1,7 @@
package cpm.com.gskmtorange.geotag; package cpm.com.gskmtorange.geotag;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@@ -81,6 +82,12 @@ public class GeoTagStoreList extends AppCompatActivity {
int position, long id) { int position, long id) {
Intent in =new Intent(GeoTagStoreList.this,GeoTagActivity.class);
startActivity(in);
finish();
Toast.makeText(getApplicationContext(),"Click",Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(),"Click",Toast.LENGTH_LONG).show();
@@ -11,6 +11,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.location.Location; import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
@@ -44,6 +45,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@@ -154,6 +156,20 @@ public class LoginActivity extends AppCompatActivity {
mLoginFormView = findViewById(R.id.login_form); mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress); mProgressView = findViewById(R.id.login_progress);
// Create a Folder for Images
File file = new File(Environment.getExternalStorageDirectory(),
"GSK_MT_Images");
if (!file.isDirectory()) {
file.mkdir();
}
} }
/* private void populateAutoComplete() { /* private void populateAutoComplete() {
@@ -1,5 +1,7 @@
package cpm.com.gskmtorange.constant; package cpm.com.gskmtorange.constant;
import android.os.Environment;
/** /**
* Created by yadavendras on 19-12-2016. * Created by yadavendras on 19-12-2016.
*/ */
@@ -14,7 +16,7 @@ public class CommonString {
public static final String KEY_PASSWORD = "password"; public static final String KEY_PASSWORD = "password";
public static final String KEY_DATE = "date"; public static final String KEY_DATE = "date";
public static final String KEY_STOREVISITED_STATUS = "STOREVISITED_STATUS"; public static final String KEY_STOREVISITED_STATUS = "STOREVISITED_STATUS";
public static final String FILE_PATH = Environment.getExternalStorageDirectory() + "/GSK_MT_Images/";
public static final String KEY_PATH = "path"; public static final String KEY_PATH = "path";
@@ -9,64 +9,64 @@
android:id="@+id/card_view" android:id="@+id/card_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="35" android:layout_weight="35"
card_view:cardBackgroundColor="@color/colorOrange" card_view:cardBackgroundColor="@color/colorOrange"
card_view:cardCornerRadius="15dp"> card_view:cardCornerRadius="15dp">
<RelativeLayout <RelativeLayout
android:id="@+id/storenamelistview_layout" android:id="@+id/storenamelistview_layout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="10sp">
<ImageView
android:id="@+id/storelistviewxml_storeico"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginRight="6sp"
android:background="@mipmap/store"
android:paddingTop="5sp" />
<TextView android:padding="10sp">
android:id="@+id/storelistviewxml_storename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/storelistviewxml_storeico"
android:layout_toRightOf="@+id/storelistviewxml_storeico"
android:text="GSK MT ORANGE STORE"
android:textColor="#1F3A6C"
android:textSize="16sp"
android:textStyle="bold" />
<TextView <ImageView
android:id="@+id/storelistviewxml_storeaddress" android:id="@+id/storelistviewxml_storeico"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="@+id/storelistviewxml_storename" android:layout_alignParentLeft="true"
android:layout_below="@+id/storelistviewxml_storename" android:layout_alignParentTop="true"
android:text="C 126, Okhla II, " android:layout_marginRight="6sp"
android:textColor="#666666" android:background="@mipmap/store"
android:textSize="10sp" android:paddingTop="5sp" />
android:textStyle="normal" />
<Button <TextView
android:id="@+id/chkout" android:id="@+id/storelistviewxml_storename"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignTop="@+id/storelistviewxml_storeico"
android:layout_alignParentTop="true" android:layout_toRightOf="@+id/storelistviewxml_storeico"
android:focusable="false" android:text="GSK MT ORANGE STORE"
android:visibility="invisible" /> android:textColor="#1F3A6C"
</RelativeLayout> android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/storelistviewxml_storeaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/storelistviewxml_storename"
android:layout_below="@+id/storelistviewxml_storename"
android:text="C 126, Okhla II, "
android:textColor="#666666"
android:textSize="10sp"
android:textStyle="normal" />
<Button
android:id="@+id/chkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false"
android:visibility="invisible" />
</RelativeLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
</RelativeLayout> </RelativeLayout>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

@@ -26,6 +26,8 @@
<string name="title_activity_store_list_geotag">Store List</string> <string name="title_activity_store_list_geotag">Store List</string>
<string name="title_activity_store_geotag">Geo Tag</string>
<string name="menu_daily_route_plan">Daily Route Plan</string> <string name="menu_daily_route_plan">Daily Route Plan</string>
<string name="menu_daily_download">Daily Data Download</string> <string name="menu_daily_download">Daily Data Download</string>