Skip to content

Commit

Permalink
feat: 지도 화면 컴포넌트 추가 및 권한 설정
Browse files Browse the repository at this point in the history
- HomeFragment.kt에 filtering, fav 버튼 추가
- 카페 검색 뷰 추가
- 현위치 버튼 활성화
- 위치 권한 설정
  • Loading branch information
ddiyooong committed Apr 3, 2023
1 parent 78ae551 commit 79b10ea
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
14 changes: 5 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Mocacong"
android:usesCleartextTraffic="true"
tools:targetApi="31">

<meta-data
Expand All @@ -21,15 +23,10 @@

<activity
android:name=".activities.SignInActivity"
android:exported="true" >
</activity>

android:exported="true" />
<activity
android:name=".activities.SignUpActivity"
android:exported="true">

</activity>

android:exported="true" />
<activity
android:name=".activities.MainActivity"
android:exported="true">
Expand All @@ -39,7 +36,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
16 changes: 11 additions & 5 deletions app/src/main/java/com/example/mocacong/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()

}
}
108 changes: 108 additions & 0 deletions app/src/main/java/com/example/mocacong/fragments/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -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<out String>,
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
}





}
17 changes: 17 additions & 0 deletions app/src/main/res/drawable/fav_btn_img.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="18"
android:viewportHeight="18">
<path
android:strokeWidth="1"
android:pathData="M9,9m-8.5,0a8.5,8.5 0,1 1,17 0a8.5,8.5 0,1 1,-17 0"
android:fillColor="#483F30"
android:strokeColor="#ffffff"/>
<path
android:pathData="M9.125,8.242C9.125,7.202 8.283,6.36 7.242,6.36C6.203,6.36 5.36,7.202 5.36,8.242C5.36,8.786 5.595,9.273 5.965,9.618L5.96,9.618L9.125,12.783L12.29,9.618C12.29,9.618 12.288,9.618 12.287,9.616C12.656,9.272 12.89,8.786 12.89,8.242C12.89,7.202 12.047,6.36 11.007,6.36C9.968,6.36 9.125,7.202 9.125,8.242Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M9.125,13.144C9.033,13.144 8.941,13.109 8.871,13.038L5.705,9.873C5.695,9.862 5.685,9.851 5.676,9.839C5.24,9.411 5,8.846 5,8.242C5,7.006 6.006,6 7.242,6C8.031,6 8.725,6.408 9.125,7.024C9.525,6.408 10.22,6 11.007,6C12.244,6 13.25,7.006 13.25,8.242C13.25,8.846 13.011,9.412 12.575,9.839C12.566,9.851 12.556,9.862 12.545,9.873L9.38,13.038C9.31,13.109 9.217,13.144 9.125,13.144ZM6.255,9.404L9.125,12.274L11.998,9.402C12.01,9.385 12.025,9.368 12.041,9.353C12.356,9.059 12.529,8.664 12.529,8.242C12.529,7.403 11.847,6.72 11.007,6.72C10.168,6.72 9.486,7.403 9.486,8.242C9.486,8.441 9.324,8.602 9.125,8.602C8.926,8.602 8.765,8.441 8.765,8.242C8.765,7.403 8.082,6.72 7.242,6.72C6.403,6.72 5.72,7.403 5.72,8.242C5.72,8.664 5.894,9.059 6.211,9.354C6.227,9.37 6.242,9.386 6.255,9.404Z"
android:fillColor="#ffffff"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/search_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#6C6C6C"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>

<com.google.android.material.bottomnavigation.BottomNavigationView
Expand Down
89 changes: 89 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragments.HomeFragment">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/search_icon"
app:layout_constraintTop_toTopOf="@id/searchBar"
app:layout_constraintLeft_toLeftOf="@id/searchBar"
app:layout_constraintBottom_toBottomOf="@id/searchBar"
app:layout_constraintRight_toRightOf="@id/searchBar"
app:layout_constraintHorizontal_bias="0.02"
android:elevation="10dp"
/>



<Button
android:id="@+id/searchBar"
android:layout_width="0dp"
android:layout_height="40dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@drawable/round_white_rectangle"
app:layout_constraintWidth_percent="0.9"
app:layout_constraintVertical_bias="0.05"
android:text="카페를 검색해 보세요!"
android:paddingLeft="40dp"
android:gravity="left|center"
android:textColor="@color/jingray"
android:elevation="1dp"
/>

<ImageButton
android:id="@+id/filteringBtn"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/filtering_btn_img"
app:layout_constraintTop_toBottomOf="@id/searchBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:elevation="2dp"
android:scaleType="fitCenter"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintVertical_bias="0.1"
/>

<ImageButton
android:id="@+id/favBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/filteringBtn"
app:layout_constraintLeft_toLeftOf="@id/filteringBtn"
app:layout_constraintRight_toRightOf="@id/filteringBtn"
android:background="@drawable/fav_btn_img"
android:elevation="2dp"
android:layout_marginTop="20dp"
/>



<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>


</androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>
10 changes: 6 additions & 4 deletions app/src/main/res/layout/fragment_map.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.naver.maps.map.MapFragment" />
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.naver.maps.map.MapFragment"
/>

0 comments on commit 79b10ea

Please sign in to comment.