Finally added coordinator layout with proper action bar
This commit is contained in:
parent
9de09e0855
commit
621d4fef2c
@ -28,6 +28,8 @@ dependencies {
|
|||||||
})
|
})
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
||||||
implementation 'com.android.support:appcompat-v7:25.4.0'
|
implementation 'com.android.support:appcompat-v7:25.4.0'
|
||||||
|
compile 'com.android.support:design:25.4.0'
|
||||||
|
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
implementation 'com.google.android.gms:play-services-maps:10.2.1'
|
implementation 'com.google.android.gms:play-services-maps:10.2.1'
|
||||||
implementation 'com.google.android.gms:play-services-location:10.2.1'
|
implementation 'com.google.android.gms:play-services-location:10.2.1'
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".YelpMapActivity"
|
android:name=".YelpMapActivity"
|
||||||
android:label="@string/title_activity_maps">
|
android:label="@string/title_activity_maps"
|
||||||
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
package fishrungames.yelpmapapp
|
package fishrungames.yelpmapapp
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import com.koushikdutta.ion.Ion
|
|
||||||
import java.io.BufferedInputStream
|
|
||||||
import java.net.HttpURLConnection
|
|
||||||
import java.net.URL
|
|
||||||
import java.security.AccessController.getContext
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import com.koushikdutta.async.future.FutureCallback
|
|
||||||
import android.os.AsyncTask
|
|
||||||
import org.json.JSONObject
|
|
||||||
|
|
||||||
|
import com.koushikdutta.ion.Ion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mephi on 09.06.2017.
|
* Created by mephi on 09.06.2017.
|
||||||
|
26
app/src/main/java/fishrungames/yelpmapapp/DetailFragment.kt
Executable file
26
app/src/main/java/fishrungames/yelpmapapp/DetailFragment.kt
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
package fishrungames.yelpmapapp
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment
|
||||||
|
import android.os.Bundle
|
||||||
|
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mephi on 10.06.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class DetailFragment : Fragment()
|
||||||
|
{
|
||||||
|
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
val rootView = inflater!!.inflate(R.layout.detail_fragment, container, false)
|
||||||
|
|
||||||
|
return rootView
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ import com.google.android.gms.location.LocationListener;
|
|||||||
import com.google.android.gms.location.LocationRequest;
|
import com.google.android.gms.location.LocationRequest;
|
||||||
import com.google.android.gms.location.LocationServices;
|
import com.google.android.gms.location.LocationServices;
|
||||||
|
|
||||||
import android.support.v4.app.FragmentActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
|
|
||||||
@ -20,14 +20,15 @@ import com.google.android.gms.maps.GoogleMap
|
|||||||
import com.google.android.gms.maps.OnMapReadyCallback
|
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.LatLng
|
||||||
import com.google.android.gms.maps.model.MarkerOptions
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import android.support.v4.app.ActivityCompat
|
import android.support.v4.app.ActivityCompat
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
|
||||||
|
|
||||||
open class MapsActivity : FragmentActivity(), OnMapReadyCallback, LocationListener,
|
|
||||||
|
open class MapsActivity : AppCompatActivity(), OnMapReadyCallback, LocationListener,
|
||||||
GoogleApiClient.ConnectionCallbacks,
|
GoogleApiClient.ConnectionCallbacks,
|
||||||
GoogleApiClient.OnConnectionFailedListener {
|
GoogleApiClient.OnConnectionFailedListener {
|
||||||
|
|
||||||
@ -42,37 +43,26 @@ open class MapsActivity : FragmentActivity(), OnMapReadyCallback, LocationListen
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_maps)
|
setContentView(R.layout.activity_maps)
|
||||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
|
||||||
val mapFragment = supportFragmentManager
|
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||||
.findFragmentById(R.id.map) as SupportMapFragment
|
|
||||||
|
//val mapFragment = SupportMapFragment()
|
||||||
|
|
||||||
|
//supportFragmentManager.beginTransaction().add(R.id.container, mapFragment).commit()
|
||||||
|
|
||||||
mapFragment.getMapAsync(this)
|
mapFragment.getMapAsync(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manipulates the map once available.
|
|
||||||
* This callback is triggered when the map is ready to be used.
|
|
||||||
* This is where we can add markers or lines, add listeners or move the camera. In this case,
|
|
||||||
* we just add a marker near Sydney, Australia.
|
|
||||||
* If Google Play services is not installed on the device, the user will be prompted to install
|
|
||||||
* it inside the SupportMapFragment. This method will only be triggered once the user has
|
|
||||||
* installed Google Play services and returned to the app.
|
|
||||||
*/
|
|
||||||
override fun onMapReady(googleMap: GoogleMap) {
|
override fun onMapReady(googleMap: GoogleMap) {
|
||||||
|
|
||||||
// Add a marker in Sydney and move the camera
|
|
||||||
//val sydney = LatLng(-34.0, 151.0)
|
|
||||||
//googleMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
|
|
||||||
//googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||||
//Location Permission already granted
|
|
||||||
buildGoogleApiClient()
|
buildGoogleApiClient()
|
||||||
googleMap.isMyLocationEnabled = true
|
googleMap.isMyLocationEnabled = true
|
||||||
} else {
|
} else {
|
||||||
//Request Location Permission
|
|
||||||
checkLocationPermission()
|
checkLocationPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,18 +118,16 @@ open class MapsActivity : FragmentActivity(), OnMapReadyCallback, LocationListen
|
|||||||
private fun checkLocationPermission() {
|
private fun checkLocationPermission() {
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
|
||||||
// Should we show an explanation?
|
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
|
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION)) {
|
Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||||
|
|
||||||
// Show an explanation to the user *asynchronously* -- don't block
|
|
||||||
// this thread waiting for the user's response! After the user
|
|
||||||
// sees the explanation, try again to request the permission.
|
|
||||||
AlertDialog.Builder(this)
|
AlertDialog.Builder(this)
|
||||||
.setTitle("Location Permission Needed")
|
.setTitle("Location Permission Needed")
|
||||||
.setMessage("This app needs the Location permission, please accept to use location functionality")
|
.setMessage("This app needs the Location permission, please accept to use location functionality")
|
||||||
.setPositiveButton("OK", DialogInterface.OnClickListener { dialogInterface, i ->
|
.setPositiveButton("OK", DialogInterface.OnClickListener { dialogInterface, i ->
|
||||||
//Prompt the user once explanation has been shown
|
|
||||||
ActivityCompat.requestPermissions(this,
|
ActivityCompat.requestPermissions(this,
|
||||||
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
|
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
|
||||||
PERMISSIONS_REQUEST_LOCATION_CODE)
|
PERMISSIONS_REQUEST_LOCATION_CODE)
|
||||||
|
@ -4,16 +4,8 @@ import android.location.Location
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import com.google.android.gms.maps.GoogleMap
|
import com.google.android.gms.maps.GoogleMap
|
||||||
import com.google.android.gms.maps.model.Marker
|
import com.google.android.gms.maps.model.Marker
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory
|
|
||||||
import com.google.android.gms.maps.model.MarkerOptions
|
|
||||||
import com.google.android.gms.maps.model.LatLng
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import com.google.maps.android.clustering.ClusterManager
|
import com.google.maps.android.clustering.ClusterManager
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory
|
|
||||||
import android.widget.Toast
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -137,21 +129,20 @@ class YelpMapActivity : MapsActivity(), GoogleMap.OnInfoWindowClickListener
|
|||||||
|
|
||||||
private fun setUpClusterer(googleMap: GoogleMap) {
|
private fun setUpClusterer(googleMap: GoogleMap) {
|
||||||
|
|
||||||
// Initialize the manager with the context and the map.
|
|
||||||
// (Activity extends context, so we can pass 'this' in the constructor.)
|
|
||||||
mClusterManager = ClusterManager<MapMarkerClusterItem>(this, googleMap)
|
mClusterManager = ClusterManager<MapMarkerClusterItem>(this, googleMap)
|
||||||
|
|
||||||
// Point the map's listeners at the listeners implemented by the cluster
|
|
||||||
// manager.
|
|
||||||
googleMap.setOnCameraIdleListener(mClusterManager)
|
googleMap.setOnCameraIdleListener(mClusterManager)
|
||||||
googleMap.setOnMarkerClickListener(mClusterManager)
|
googleMap.setOnMarkerClickListener(mClusterManager)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onInfoWindowClick(marker: Marker) {
|
override fun onInfoWindowClick(marker: Marker) {
|
||||||
Toast.makeText(this, "Info window clicked",
|
|
||||||
Toast.LENGTH_SHORT).show()
|
val detailFragment = DetailFragment()
|
||||||
|
|
||||||
|
supportFragmentManager.beginTransaction().add(R.id.container, detailFragment).addToBackStack("detailFragment").commit()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
BIN
app/src/main/res/drawable/bkgtest.jpg
Executable file
BIN
app/src/main/res/drawable/bkgtest.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
@ -1,8 +1,47 @@
|
|||||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
xmlns:map="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/background_light">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView5"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="18dp"
|
||||||
|
android:layout_marginStart="18dp"
|
||||||
|
android:text="Yelp Map App"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large.Inverse" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<fragment
|
||||||
android:id="@+id/map"
|
android:id="@+id/map"
|
||||||
android:name="com.google.android.gms.maps.SupportMapFragment"
|
android:name="com.google.android.gms.maps.SupportMapFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
tools:context="fishrungames.yelpmapapp.YelpMapActivity" />
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
67
app/src/main/res/layout/detail_fragment.xml
Executable file
67
app/src/main/res/layout/detail_fragment.xml
Executable file
@ -0,0 +1,67 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<android.support.design.widget.CoordinatorLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/background_light"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
>
|
||||||
|
|
||||||
|
<android.support.design.widget.AppBarLayout
|
||||||
|
android:id="@+id/main.appbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="300dp"
|
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
>
|
||||||
|
|
||||||
|
<android.support.design.widget.CollapsingToolbarLayout
|
||||||
|
android:id="@+id/main.collapsing"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_scrollFlags="scroll|exitUntilCollapsed"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
app:contentScrim="?attr/colorPrimary"
|
||||||
|
app:expandedTitleMarginStart="48dp"
|
||||||
|
app:expandedTitleMarginEnd="64dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/main.backdrop"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
android:src="@drawable/bkgtest"
|
||||||
|
app:layout_collapseMode="parallax"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/main.toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||||
|
app:layout_collapseMode="pin"
|
||||||
|
/>
|
||||||
|
</android.support.design.widget.CollapsingToolbarLayout>
|
||||||
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
|
<android.support.v4.widget.NestedScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
|
>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:lineSpacingExtra="8dp"
|
||||||
|
android:text="La la la la la la"
|
||||||
|
android:padding="12dp"
|
||||||
|
/>
|
||||||
|
</android.support.v4.widget.NestedScrollView>
|
||||||
|
|
||||||
|
</android.support.design.widget.CoordinatorLayout>
|
@ -8,4 +8,13 @@
|
|||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.NoActionBar">
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||||
|
|
||||||
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user