Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
c1756dfd
Commit
c1756dfd
authored
Feb 04, 2019
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Locate on start if already has permission
parent
743b082c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
11 deletions
+19
-11
app/src/main/java/app/insti/activity/MainActivity.java
app/src/main/java/app/insti/activity/MainActivity.java
+1
-1
app/src/main/java/app/insti/fragment/MapFragment.java
app/src/main/java/app/insti/fragment/MapFragment.java
+18
-10
No files found.
app/src/main/java/app/insti/activity/MainActivity.java
View file @
c1756dfd
...
@@ -658,7 +658,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -658,7 +658,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
// Map
// Map
MapFragment
mapFragment
=
(
MapFragment
)
getSupportFragmentManager
().
findFragmentByTag
(
MapFragment
.
TAG
);
MapFragment
mapFragment
=
(
MapFragment
)
getSupportFragmentManager
().
findFragmentByTag
(
MapFragment
.
TAG
);
if
(
mapFragment
!=
null
&&
mapFragment
.
isVisible
())
{
if
(
mapFragment
!=
null
&&
mapFragment
.
isVisible
())
{
MapFragment
.
getMainActivity
().
setupGPS
();
MapFragment
.
getMainActivity
().
setupGPS
(
true
);
}
}
// File complaint
// File complaint
...
...
app/src/main/java/app/insti/fragment/MapFragment.java
View file @
c1756dfd
...
@@ -318,15 +318,22 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -318,15 +318,22 @@ public class MapFragment extends Fragment implements TextWatcher,
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
v
)
{
public
void
onClick
(
View
v
)
{
locate
();
locate
(
true
);
}
}
});
});
// Setup GPS if already has permission
String
permission
=
Manifest
.
permission
.
ACCESS_FINE_LOCATION
;
int
res
=
getContext
().
checkCallingOrSelfPermission
(
permission
);
if
(
res
==
PackageManager
.
PERMISSION_GRANTED
)
{
locate
(
false
);
}
}
}
private
void
locate
()
{
private
void
locate
(
boolean
showWarning
)
{
followingUser
=
true
;
followingUser
=
true
;
if
(!
GPSIsSetup
)
{
if
(!
GPSIsSetup
)
{
displayLocationSettingsRequest
();
displayLocationSettingsRequest
(
showWarning
);
}
else
if
(
user
!=
null
)
{
}
else
if
(
user
!=
null
)
{
if
(!
campusMapView
.
isAddedMarker
(
user
))
{
if
(!
campusMapView
.
isAddedMarker
(
user
))
{
campusMapView
.
addMarker
(
user
);
campusMapView
.
addMarker
(
user
);
...
@@ -985,7 +992,7 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -985,7 +992,7 @@ public class MapFragment extends Fragment implements TextWatcher,
return
slidingLayout
;
return
slidingLayout
;
}
}
public
void
setupGPS
()
{
public
void
setupGPS
(
boolean
showWarning
)
{
if
(
getView
()
==
null
||
getActivity
()
==
null
)
return
;
if
(
getView
()
==
null
||
getActivity
()
==
null
)
return
;
// Permissions stuff
// Permissions stuff
if
(
ContextCompat
.
checkSelfPermission
(
getActivity
(),
if
(
ContextCompat
.
checkSelfPermission
(
getActivity
(),
...
@@ -996,8 +1003,6 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -996,8 +1003,6 @@ public class MapFragment extends Fragment implements TextWatcher,
MY_PERMISSIONS_REQUEST_LOCATION
);
MY_PERMISSIONS_REQUEST_LOCATION
);
}
else
{
}
else
{
try
{
try
{
// Create the location request to start receiving updates
// Create the location request to start receiving updates
mLocationRequest
=
new
LocationRequest
();
mLocationRequest
=
new
LocationRequest
();
mLocationRequest
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
);
mLocationRequest
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
);
...
@@ -1019,7 +1024,10 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -1019,7 +1024,10 @@ public class MapFragment extends Fragment implements TextWatcher,
fusedLocationProviderClient
.
requestLocationUpdates
(
mLocationRequest
,
myLocationCallback
,
Looper
.
myLooper
());
fusedLocationProviderClient
.
requestLocationUpdates
(
mLocationRequest
,
myLocationCallback
,
Looper
.
myLooper
());
GPSIsSetup
=
true
;
GPSIsSetup
=
true
;
if
(
showWarning
)
{
Toast
.
makeText
(
getContext
(),
"WARNING: Location is in Beta. Use with Caution."
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getContext
(),
"WARNING: Location is in Beta. Use with Caution."
,
Toast
.
LENGTH_LONG
).
show
();
}
}
catch
(
SecurityException
ignored
)
{
}
catch
(
SecurityException
ignored
)
{
Toast
.
makeText
(
getContext
(),
"No permission!"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getContext
(),
"No permission!"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
...
@@ -1030,7 +1038,7 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -1030,7 +1038,7 @@ public class MapFragment extends Fragment implements TextWatcher,
this
.
followingUser
=
followingUser
;
this
.
followingUser
=
followingUser
;
}
}
private
void
displayLocationSettingsRequest
()
{
private
void
displayLocationSettingsRequest
(
final
boolean
showWarning
)
{
if
(
getView
()
==
null
||
getActivity
()
==
null
)
return
;
if
(
getView
()
==
null
||
getActivity
()
==
null
)
return
;
LocationRequest
mLocationRequest
=
LocationRequest
.
create
()
LocationRequest
mLocationRequest
=
LocationRequest
.
create
()
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
)
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
)
...
@@ -1050,7 +1058,7 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -1050,7 +1058,7 @@ public class MapFragment extends Fragment implements TextWatcher,
result
.
getLocationSettingsStates
().
isGpsUsable
()
&&
result
.
getLocationSettingsStates
().
isGpsUsable
()
&&
result
.
getLocationSettingsStates
().
isLocationPresent
()
&&
result
.
getLocationSettingsStates
().
isLocationPresent
()
&&
result
.
getLocationSettingsStates
().
isLocationUsable
())
{
result
.
getLocationSettingsStates
().
isLocationUsable
())
{
setupGPS
();
setupGPS
(
showWarning
);
}
}
}
catch
(
ApiException
ex
)
{
}
catch
(
ApiException
ex
)
{
switch
(
ex
.
getStatusCode
())
{
switch
(
ex
.
getStatusCode
())
{
...
@@ -1060,7 +1068,7 @@ public class MapFragment extends Fragment implements TextWatcher,
...
@@ -1060,7 +1068,7 @@ public class MapFragment extends Fragment implements TextWatcher,
(
ResolvableApiException
)
ex
;
(
ResolvableApiException
)
ex
;
resolvableApiException
resolvableApiException
.
startResolutionForResult
(
getActivity
(),
87
);
.
startResolutionForResult
(
getActivity
(),
87
);
setupGPS
();
setupGPS
(
showWarning
);
}
catch
(
IntentSender
.
SendIntentException
e
)
{
}
catch
(
IntentSender
.
SendIntentException
e
)
{
}
}
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment