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
ce530c97
Commit
ce530c97
authored
Jul 03, 2017
by
Sajal Narang
Committed by
GitHub
Jul 03, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #22 from unstablebrainiac/locationButton, fix #14
Add location FAB
parents
df3ddfef
e5d39397
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
95 additions
and
38 deletions
+95
-38
app/build.gradle
app/build.gradle
+15
-9
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragments/MapFragment.java
...va/in/ac/iitb/gymkhana/iitbapp/fragments/MapFragment.java
+65
-26
app/src/main/res/drawable-hdpi/ic_my_location_black_24dp.png
app/src/main/res/drawable-hdpi/ic_my_location_black_24dp.png
+0
-0
app/src/main/res/drawable-mdpi/ic_my_location_black_24dp.png
app/src/main/res/drawable-mdpi/ic_my_location_black_24dp.png
+0
-0
app/src/main/res/drawable-xhdpi/ic_my_location_black_24dp.png
...src/main/res/drawable-xhdpi/ic_my_location_black_24dp.png
+0
-0
app/src/main/res/drawable-xxhdpi/ic_my_location_black_24dp.png
...rc/main/res/drawable-xxhdpi/ic_my_location_black_24dp.png
+0
-0
app/src/main/res/drawable-xxxhdpi/ic_my_location_black_24dp.png
...c/main/res/drawable-xxxhdpi/ic_my_location_black_24dp.png
+0
-0
app/src/main/res/layout/fragment_map.xml
app/src/main/res/layout/fragment_map.xml
+11
-0
app/src/main/res/values/colors.xml
app/src/main/res/values/colors.xml
+1
-0
build.gradle
build.gradle
+1
-1
gradle/wrapper/gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+2
-2
No files found.
app/build.gradle
View file @
ce530c97
...
@@ -21,18 +21,24 @@ android {
...
@@ -21,18 +21,24 @@ android {
}
}
}
}
ext
{
supportLibVersion
=
'25.3.1'
playServicesVersion
=
'11.0.2'
butterKnifeVersion
=
'8.6.0'
appAuthVersion
=
'0.2.0'
}
dependencies
{
dependencies
{
compile
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
compile
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
androidTestCompile
(
'com.android.support.test.espresso:espresso-core:2.2.2'
,
{
androidTestCompile
(
'com.android.support.test.espresso:espresso-core:2.2.2'
,
{
exclude
group:
'com.android.support'
,
module:
'support-annotations'
exclude
group:
'com.android.support'
,
module:
'support-annotations'
})
})
compile
'com.android.support:appcompat-v7:25.3.1'
compile
"com.android.support:appcompat-v7:${supportLibVersion}"
compile
'net.openid:appauth:0.2.0'
compile
"net.openid:appauth:${appAuthVersion}"
testCompile
'junit:junit:4.12'
testCompile
"junit:junit:4.12"
compile
'com.android.support:design:25.3.1'
compile
"com.android.support:design:${supportLibVersion}"
compile
'com.google.android.gms:play-services-maps:10.2.6'
compile
"com.google.android.gms:play-services-maps:${playServicesVersion}"
compile
'com.android.support.constraint:constraint-layout:1.0.2'
compile
"com.android.support:support-v4:${supportLibVersion}"
compile
'com.android.support:support-v4:25.3.1'
compile
"com.jakewharton:butterknife:${butterKnifeVersion}"
compile
'com.jakewharton:butterknife:8.6.0'
annotationProcessor
"com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
annotationProcessor
'com.jakewharton:butterknife-compiler:8.6.0'
}
}
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragments/MapFragment.java
View file @
ce530c97
...
@@ -2,7 +2,11 @@ package in.ac.iitb.gymkhana.iitbapp.fragments;
...
@@ -2,7 +2,11 @@ package in.ac.iitb.gymkhana.iitbapp.fragments;
import
android.Manifest
;
import
android.Manifest
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.graphics.PorterDuff
;
import
android.location.Location
;
import
android.location.LocationManager
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -10,6 +14,7 @@ import android.view.View;
...
@@ -10,6 +14,7 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.google.android.gms.maps.CameraUpdate
;
import
com.google.android.gms.maps.CameraUpdateFactory
;
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.OnMapReadyCallback
;
...
@@ -18,12 +23,18 @@ import com.google.android.gms.maps.model.LatLng;
...
@@ -18,12 +23,18 @@ import com.google.android.gms.maps.model.LatLng;
import
com.google.android.gms.maps.model.LatLngBounds
;
import
com.google.android.gms.maps.model.LatLngBounds
;
import
com.google.android.gms.maps.model.MarkerOptions
;
import
com.google.android.gms.maps.model.MarkerOptions
;
import
java.util.List
;
import
in.ac.iitb.gymkhana.iitbapp.R
;
import
in.ac.iitb.gymkhana.iitbapp.R
;
import
static
android
.
content
.
Context
.
LOCATION_SERVICE
;
public
class
MapFragment
extends
Fragment
implements
OnMapReadyCallback
{
public
class
MapFragment
extends
Fragment
implements
OnMapReadyCallback
{
SupportMapFragment
gMapFragment
;
SupportMapFragment
gMapFragment
;
GoogleMap
googleMap
;
GoogleMap
googleMap
;
FloatingActionButton
locationButton
;
Location
currentLocation
;
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
Bundle
savedInstanceState
)
{
...
@@ -36,44 +47,72 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
...
@@ -36,44 +47,72 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
return
view
;
return
view
;
}
}
private
Location
getLastKnownLocation
()
{
LocationManager
mLocationManager
=
(
LocationManager
)
getContext
().
getSystemService
(
LOCATION_SERVICE
);
List
<
String
>
providers
=
mLocationManager
.
getProviders
(
true
);
Location
bestLocation
=
null
;
for
(
String
provider
:
providers
)
{
Location
l
=
mLocationManager
.
getLastKnownLocation
(
provider
);
if
(
l
==
null
)
{
continue
;
}
if
(
bestLocation
==
null
||
l
.
getAccuracy
()
<
bestLocation
.
getAccuracy
())
{
bestLocation
=
l
;
}
}
return
bestLocation
;
}
@Override
@Override
public
void
onMapReady
(
GoogleMap
gMap
)
{
public
void
onMapReady
(
GoogleMap
gMap
)
{
googleMap
=
gMap
;
//TODO: Handle Location permissions in MainActivity, permission required to view fragment
if
(
ContextCompat
.
checkSelfPermission
(
getActivity
(),
googleMap
=
gMap
;
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
if
(
ContextCompat
.
checkSelfPermission
(
getActivity
(),
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
==
PackageManager
.
PERMISSION_GRANTED
)
{
googleMap
.
setMyLocationEnabled
(
true
);
googleMap
.
setMyLocationEnabled
(
true
);
googleMap
.
getUiSettings
().
setMyLocationButtonEnabled
(
tru
e
);
googleMap
.
getUiSettings
().
setMyLocationButtonEnabled
(
fals
e
);
googleMap
.
getUiSettings
().
setZoomGesturesEnabled
(
true
);
googleMap
.
getUiSettings
().
setZoomGesturesEnabled
(
true
);
}
else
{
}
else
{
requestPermissions
(
new
String
[]{
Manifest
.
permission
.
ACCESS_FINE_LOCATION
},
0
);
requestPermissions
(
new
String
[]{
Manifest
.
permission
.
ACCESS_FINE_LOCATION
},
0
);
}
}
LatLngBounds
iitbBounds
=
new
LatLngBounds
(
new
LatLng
(
19.1249000
,
72.9046000
),
new
LatLng
(
19.143522
,
72.920000
));
LatLngBounds
iitbBounds
=
new
LatLngBounds
(
new
LatLng
(
19.1249000
,
72.9046000
),
new
LatLng
(
19.143522
,
72.920000
));
googleMap
.
setLatLngBoundsForCameraTarget
(
iitbBounds
);
googleMap
.
setLatLngBoundsForCameraTarget
(
iitbBounds
);
googleMap
.
setMaxZoomPreference
(
30
);
googleMap
.
setMaxZoomPreference
(
30
);
googleMap
.
setMinZoomPreference
(
(
float
)
14.5
);
googleMap
.
setMinZoomPreference
(
14.5f
);
// Position the map's camera near Mumbai
// Position the map's camera near Mumbai
LatLng
iitb
=
new
LatLng
(
19.1334
,
72.9133
);
LatLng
iitb
=
new
LatLng
(
19.1334
,
72.9133
);
googleMap
.
addMarker
(
new
MarkerOptions
().
position
(
iitb
)
googleMap
.
addMarker
(
new
MarkerOptions
().
position
(
iitb
).
title
(
"Marker in IITB"
));
.
title
(
"Marker in IITB"
));
googleMap
.
moveCamera
(
CameraUpdateFactory
.
newLatLng
(
iitb
));
googleMap
.
moveCamera
(
CameraUpdateFactory
.
newLatLng
(
iitb
));
googleMap
.
setOnCameraMoveListener
(
new
GoogleMap
.
OnCameraMoveListener
()
{
@Override
public
void
onCameraMove
()
{
locationButton
.
getDrawable
().
setColorFilter
(
ContextCompat
.
getColor
(
getContext
(),
R
.
color
.
colorGray
),
PorterDuff
.
Mode
.
SRC_IN
);
}
}
public
void
onRequestPermissionsResult
(
int
requestCode
,
});
String
[]
permissions
,
int
[]
grantResults
)
locationButton
=
(
FloatingActionButton
)
getActivity
().
findViewById
(
R
.
id
.
location
);
{
locationButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
if
(
grantResults
[
0
]==
PackageManager
.
PERMISSION_GRANTED
)
@Override
{
public
void
onClick
(
View
v
)
{
currentLocation
=
getLastKnownLocation
();
CameraUpdate
cameraUpdate
=
CameraUpdateFactory
.
newLatLngZoom
(
new
LatLng
(
currentLocation
.
getLatitude
(),
currentLocation
.
getLongitude
()),
17
);
googleMap
.
animateCamera
(
cameraUpdate
);
locationButton
.
getDrawable
().
setColorFilter
(
ContextCompat
.
getColor
(
getContext
(),
R
.
color
.
colorPrimary
),
PorterDuff
.
Mode
.
SRC_IN
);
}
});
}
public
void
onRequestPermissionsResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
)
{
if
(
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
googleMap
.
setMyLocationEnabled
(
true
);
googleMap
.
setMyLocationEnabled
(
true
);
googleMap
.
getUiSettings
().
setMyLocationButtonEnabled
(
tru
e
);
googleMap
.
getUiSettings
().
setMyLocationButtonEnabled
(
fals
e
);
googleMap
.
getUiSettings
().
setZoomGesturesEnabled
(
true
);
googleMap
.
getUiSettings
().
setZoomGesturesEnabled
(
true
);
}
}
else
{
else
{
Toast
toast
=
Toast
.
makeText
(
getActivity
(),
"Need Permission"
,
Toast
.
LENGTH_SHORT
);
Toast
toast
=
Toast
.
makeText
(
getActivity
(),
"Need Permission"
,
Toast
.
LENGTH_SHORT
);
toast
.
show
();
toast
.
show
();
}
}
}}
}
}
app/src/main/res/drawable-hdpi/ic_my_location_black_24dp.png
0 → 100644
View file @
ce530c97
549 Bytes
app/src/main/res/drawable-mdpi/ic_my_location_black_24dp.png
0 → 100644
View file @
ce530c97
341 Bytes
app/src/main/res/drawable-xhdpi/ic_my_location_black_24dp.png
0 → 100644
View file @
ce530c97
660 Bytes
app/src/main/res/drawable-xxhdpi/ic_my_location_black_24dp.png
0 → 100644
View file @
ce530c97
976 Bytes
app/src/main/res/drawable-xxxhdpi/ic_my_location_black_24dp.png
0 → 100644
View file @
ce530c97
1.3 KB
app/src/main/res/layout/fragment_map.xml
View file @
ce530c97
...
@@ -12,4 +12,15 @@
...
@@ -12,4 +12,15 @@
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
map:cameraZoom=
"18"
/>
map:cameraZoom=
"18"
/>
<!--TODO: Change colours-->
<android.support.design.widget.FloatingActionButton
android:id=
"@+id/location"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"bottom|end"
android:layout_marginBottom=
"48dp"
android:layout_marginEnd=
"@dimen/fab_margin"
android:src=
"@drawable/ic_my_location_black_24dp"
/>
</FrameLayout>
</FrameLayout>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
ce530c97
...
@@ -4,4 +4,5 @@
...
@@ -4,4 +4,5 @@
<color
name=
"colorPrimaryDark"
>
#44C0CA
</color>
<color
name=
"colorPrimaryDark"
>
#44C0CA
</color>
<color
name=
"colorAccent"
>
#ECF833
</color>
<color
name=
"colorAccent"
>
#ECF833
</color>
<color
name=
"colorCalendarWeek"
>
#000000
</color>
<color
name=
"colorCalendarWeek"
>
#000000
</color>
<color
name=
"colorGray"
>
#757575
</color>
</resources>
</resources>
build.gradle
View file @
ce530c97
...
@@ -7,7 +7,7 @@ buildscript {
...
@@ -7,7 +7,7 @@ buildscript {
jcenter
()
jcenter
()
}
}
dependencies
{
dependencies
{
classpath
'com.android.tools.build:gradle:3.0.0-alpha
3
'
classpath
'com.android.tools.build:gradle:3.0.0-alpha
4
'
// NOTE: Do not place your application dependencies here; they belong
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// in the individual module build.gradle files
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
ce530c97
#Fri
May 19 05:35:14
IST 2017
#Fri
Jun 30 22:37:20
IST 2017
distributionBase
=
GRADLE_USER_HOME
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-4.0-
milestone
-1-all.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-4.0-
rc
-1-all.zip
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