From 79b10eaf83513cd0fcd2d69ff46dda80dc80c13a Mon Sep 17 00:00:00 2001 From: ddiyooong Date: Mon, 3 Apr 2023 21:11:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=80=EB=8F=84=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B6=8C=ED=95=9C=20=EC=84=A4=EC=A0=95=20-=20HomeF?= =?UTF-8?q?ragment.kt=EC=97=90=20filtering,=20fav=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20=EC=B9=B4=ED=8E=98=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EB=B7=B0=20=EC=B6=94=EA=B0=80=20-=20=ED=98=84?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B2=84=ED=8A=BC=20=ED=99=9C=EC=84=B1?= =?UTF-8?q?=ED=99=94=20-=20=EC=9C=84=EC=B9=98=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 14 +-- .../mocacong/activities/MainActivity.kt | 16 ++- .../mocacong/fragments/HomeFragment.kt | 108 ++++++++++++++++++ app/src/main/res/drawable/fav_btn_img.xml | 17 +++ app/src/main/res/drawable/search_icon.xml | 5 + app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/fragment_home.xml | 89 +++++++++++++++ app/src/main/res/layout/fragment_map.xml | 10 +- 9 files changed, 243 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/example/mocacong/fragments/HomeFragment.kt create mode 100644 app/src/main/res/drawable/fav_btn_img.xml create mode 100644 app/src/main/res/drawable/search_icon.xml create mode 100644 app/src/main/res/layout/fragment_home.xml diff --git a/app/build.gradle b/app/build.gradle index 0d3806e..c4f9070 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,5 +53,6 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation 'com.google.android.gms:play-services-location:16.0.0' implementation 'com.naver.maps:map-sdk:3.16.2' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d672d2b..eef2b3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,9 +3,10 @@ xmlns:tools="http://schemas.android.com/tools"> + + - - + android:exported="true" /> - - - + android:exported="true" /> @@ -39,7 +36,6 @@ - \ No newline at end of file diff --git a/app/src/main/java/com/example/mocacong/activities/MainActivity.kt b/app/src/main/java/com/example/mocacong/activities/MainActivity.kt index 001cc1c..b529bf8 100644 --- a/app/src/main/java/com/example/mocacong/activities/MainActivity.kt +++ b/app/src/main/java/com/example/mocacong/activities/MainActivity.kt @@ -2,8 +2,10 @@ package com.example.mocacong.activities import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.fragment.app.FragmentManager import com.example.mocacong.R import com.example.mocacong.databinding.ActivityMainBinding +import com.example.mocacong.fragments.HomeFragment import com.naver.maps.map.MapFragment class MainActivity : AppCompatActivity() { @@ -15,11 +17,15 @@ class MainActivity : AppCompatActivity() { setContentView(binding.root) - val fm = supportFragmentManager - val mapFragment = fm.findFragmentById(R.id.map) as MapFragment? - ?: MapFragment.newInstance().also { - fm.beginTransaction().add(R.id.map, it).commit() - } + createFragment() + + + } + + fun createFragment(){ + val transaction = supportFragmentManager.beginTransaction() + val homeFragment = HomeFragment() + transaction.replace(R.id.home, homeFragment).commit() } } \ No newline at end of file diff --git a/app/src/main/java/com/example/mocacong/fragments/HomeFragment.kt b/app/src/main/java/com/example/mocacong/fragments/HomeFragment.kt new file mode 100644 index 0000000..d3efe9c --- /dev/null +++ b/app/src/main/java/com/example/mocacong/fragments/HomeFragment.kt @@ -0,0 +1,108 @@ +package com.example.mocacong.fragments + +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.example.mocacong.R +import com.example.mocacong.databinding.FragmentHomeBinding +import com.naver.maps.map.* +import com.naver.maps.map.util.FusedLocationSource + + +class HomeFragment : Fragment(), OnMapReadyCallback { + + private var _binding: FragmentHomeBinding? = null + private val binding get() = _binding!! + + private lateinit var naverMap: NaverMap + private lateinit var locationSource: FusedLocationSource + + companion object { + private const val LOCATION_PERMISSION_REQUEST_CODE = 1000 + } + + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentHomeBinding.inflate(inflater, container, false) + locationSource = FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE) + + getMapFragment() + //setLocation() + return binding.root + } + + + private fun setLocation() { + naverMap.locationOverlay.performClick() + } + + + //위치 권한 요청 + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { + Log.d("map", "들어왔다") + if (locationSource.onRequestPermissionsResult(requestCode, permissions, grantResults)) { + if (!locationSource.isActivated) { // 권한 거부됨 + naverMap.locationTrackingMode = LocationTrackingMode.None + } else { + naverMap.locationTrackingMode = LocationTrackingMode.Follow // 현위치 버튼 컨트롤 활성 + } + return + } + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + } + + + + private fun getMapFragment() { + + //네이버 지도 Fragment 불러오기 + val fm = childFragmentManager + val mapFragment = fm.findFragmentById(R.id.map) as MapFragment? + ?: MapFragment.newInstance().also { + fm.beginTransaction().add(R.id.map, it).commit() + } + mapFragment.getMapAsync(this) + } + + override fun onMapReady(naverMap: NaverMap) { + //지도 객체 세팅 + Log.d("DDD","객체 초기화") + this.naverMap = naverMap + + //현위치 버튼 활성 및 줌 버튼 제거 + naverMap.uiSettings.apply { + isZoomControlEnabled = false + isLocationButtonEnabled = true + } + + naverMap.locationSource = locationSource + + + val locationOverlay = naverMap.locationOverlay + locationOverlay.isVisible = true + + } + + + + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + + + + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/fav_btn_img.xml b/app/src/main/res/drawable/fav_btn_img.xml new file mode 100644 index 0000000..e460834 --- /dev/null +++ b/app/src/main/res/drawable/fav_btn_img.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable/search_icon.xml b/app/src/main/res/drawable/search_icon.xml new file mode 100644 index 0000000..1716f83 --- /dev/null +++ b/app/src/main/res/drawable/search_icon.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ff0b9fa..f610996 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -14,7 +14,7 @@ app:layout_constraintBottom_toTopOf="@id/bottomMenu" app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toLeftOf="parent" - android:id="@+id/map" + android:id="@+id/home" /> + + + + + + + + +