diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 8a54553..033776e 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,9 +1,9 @@ - + - + @@ -11,7 +11,7 @@ - - + + \ No newline at end of file diff --git a/app/src/main/java/com/greener/HotelMap.java b/app/src/main/java/com/greener/HotelMap.java index 52f6fda..52d98a5 100644 --- a/app/src/main/java/com/greener/HotelMap.java +++ b/app/src/main/java/com/greener/HotelMap.java @@ -1,7 +1,14 @@ package com.greener; import android.Manifest; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; import android.content.pm.PackageManager; +import android.location.Address; +import android.location.Geocoder; +import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -10,9 +17,12 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import com.google.firebase.database.DataSnapshot; @@ -33,10 +43,20 @@ import com.naver.maps.map.overlay.OverlayImage; import com.naver.maps.map.util.FusedLocationSource; +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import static android.content.Context.LOCATION_SERVICE; + public class HotelMap extends Fragment implements OnMapReadyCallback { private GPSTracker gpsTracker; + private static final int GPS_ENABLE_REQUEST_CODE = 2001; + private static final int PERMISSIONS_REQUEST_CODE = 100; + String[] REQUIRED_PERMISSIONS = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; + private MapView mapView; private DatabaseReference databaseReference; private NaverMap naverMap; @@ -47,11 +67,18 @@ public class HotelMap extends Fragment implements OnMapReadyCallback { private View view; private Button btn; + private Context mContext; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); mLocationSource = new FusedLocationSource(this, 100); + + mContext = getContext(); + + if (!checkLocationServicesStatus()) { + showDialogForLocationServiceSetting(); + }else { checkRunTimePermission(); } } @Nullable @@ -100,6 +127,9 @@ public void onClick(View v) { double latitude = gpsTracker.getLatitude(); double longitude = gpsTracker.getLongitude(); + String addrStr = getCurrentAddress(latitude, longitude); + System.out.println("addrStr : " + addrStr); + CameraPosition cameraPosition = new CameraPosition(new LatLng(latitude, longitude), 13); naverMap.setCameraPosition(cameraPosition); } @@ -154,4 +184,141 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); inflater.inflate(R.menu.actionbar_map_action, menu); } + + public String getCurrentAddress( double latitude, double longitude) { + Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault()); + List
addresses; + try { + addresses = geocoder.getFromLocation(latitude, longitude, 7); + } catch (IOException ioException) { + Toast.makeText(getContext(), "지오코더 서비스 사용불가", Toast.LENGTH_LONG).show(); + return "지오코더 서비스 사용불가"; + } catch (IllegalArgumentException illegalArgumentException) { + Toast.makeText(getContext(), "잘못된 GPS 좌표", Toast.LENGTH_LONG).show(); + return "잘못된 GPS 좌표"; + + } + if (addresses == null || addresses.size() == 0) { + Toast.makeText(getContext(), "주소 미발견", Toast.LENGTH_LONG).show(); + return "주소 미발견"; + + } + + Address address = addresses.get(0); + return address.getAddressLine(0).toString()+"\n"; + + } + + @Override + public void onRequestPermissionsResult(int permsRequestCode, @NonNull String[] permissions, @NonNull int[] grandResults) { + + if ( permsRequestCode == PERMISSIONS_REQUEST_CODE && grandResults.length == REQUIRED_PERMISSIONS.length) { + + boolean check_result = true; + + for (int result : grandResults) { + if (result != PackageManager.PERMISSION_GRANTED) { + check_result = false; + break; + } + } + + if ( check_result ) { } + else { + + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[0]) + || ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[1])) { + + Toast.makeText(getContext(), "퍼미션이 거부되었습니다. 앱을 다시 실행하여 퍼미션을 허용해주세요.", Toast.LENGTH_LONG).show(); + + + + }else { + + Toast.makeText(getContext(), "퍼미션이 거부되었습니다. 설정(앱 정보)에서 퍼미션을 허용해야 합니다. ", Toast.LENGTH_LONG).show(); + + } + } + + } + } + + void checkRunTimePermission(){ + int hasFineLocationPermission = ContextCompat.checkSelfPermission(getContext(), + Manifest.permission.ACCESS_FINE_LOCATION); + int hasCoarseLocationPermission = ContextCompat.checkSelfPermission(getContext(), + Manifest.permission.ACCESS_COARSE_LOCATION); + + + if (hasFineLocationPermission == PackageManager.PERMISSION_GRANTED && + hasCoarseLocationPermission == PackageManager.PERMISSION_GRANTED) { + + } else { + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[0])) { + + Toast.makeText(getContext(), "이 앱을 실행하려면 위치 접근 권한이 필요합니다.", Toast.LENGTH_LONG).show(); + ActivityCompat.requestPermissions(getActivity(), REQUIRED_PERMISSIONS, + PERMISSIONS_REQUEST_CODE); + + } else { + ActivityCompat.requestPermissions(getActivity(), REQUIRED_PERMISSIONS, + PERMISSIONS_REQUEST_CODE); + } + + } + + } + + private void showDialogForLocationServiceSetting() { + + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle("위치 서비스 비활성화"); + builder.setMessage("앱을 사용하기 위해서는 위치 서비스가 필요합니다.\n" + + "위치 설정을 수정하실래요?"); + builder.setCancelable(true); + builder.setPositiveButton("설정", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Intent callGPSSettingIntent + = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); + startActivityForResult(callGPSSettingIntent, GPS_ENABLE_REQUEST_CODE); + } + }); + builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + builder.create().show(); + } + + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + switch (requestCode) { + + case GPS_ENABLE_REQUEST_CODE: + + //사용자가 GPS 활성 시켰는지 검사 + if (checkLocationServicesStatus()) { + if (checkLocationServicesStatus()) { + checkRunTimePermission(); + return; + } + } + + break; + } + } + + public boolean checkLocationServicesStatus() { + LocationManager locationManager; + locationManager = (LocationManager)mContext.getSystemService(LOCATION_SERVICE); + + return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) + || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); + } } \ No newline at end of file diff --git a/app/src/main/java/com/greener/LikedMap.java b/app/src/main/java/com/greener/LikedMap.java index 3bab81c..6cb8e25 100644 --- a/app/src/main/java/com/greener/LikedMap.java +++ b/app/src/main/java/com/greener/LikedMap.java @@ -2,8 +2,19 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import android.Manifest; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Address; +import android.location.Geocoder; +import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -12,6 +23,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; @@ -29,9 +41,20 @@ import com.naver.maps.map.overlay.OverlayImage; import com.naver.maps.map.util.FusedLocationSource; +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import static android.content.Context.LOCATION_SERVICE; + public class LikedMap extends Fragment implements OnMapReadyCallback { private GPSTracker gpsTracker; + + private static final int GPS_ENABLE_REQUEST_CODE = 2001; + private static final int PERMISSIONS_REQUEST_CODE = 100; + String[] REQUIRED_PERMISSIONS = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; + private MapView mapView; private NaverMap naverMap; private FusedLocationSource mLocationSource; @@ -40,6 +63,7 @@ public class LikedMap extends Fragment implements OnMapReadyCallback { private DatabaseReference databaseReference; private FirebaseDatabase database; private View view; + private Context mContext; private Button btn; private OverlayImage image = OverlayImage.fromResource(R.drawable.ic_place_marker); @@ -48,6 +72,12 @@ public class LikedMap extends Fragment implements OnMapReadyCallback { public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); mLocationSource = new FusedLocationSource(this, 100); + + mContext = getContext(); + + if (!checkLocationServicesStatus()) { + showDialogForLocationServiceSetting(); + }else { checkRunTimePermission(); } } @Nullable @@ -100,6 +130,9 @@ public void onClick(View v) { double latitude = gpsTracker.getLatitude(); double longitude = gpsTracker.getLongitude(); + String addrStr = getCurrentAddress(latitude, longitude); + System.out.println("addrStr : " + addrStr); + CameraPosition cameraPosition = new CameraPosition(new LatLng(latitude, longitude), 13); naverMap.setCameraPosition(cameraPosition); } @@ -151,4 +184,141 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); inflater.inflate(R.menu.actionbar_map_action, menu); } + + public String getCurrentAddress( double latitude, double longitude) { + Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault()); + List
addresses; + try { + addresses = geocoder.getFromLocation(latitude, longitude, 7); + } catch (IOException ioException) { + Toast.makeText(getContext(), "지오코더 서비스 사용불가", Toast.LENGTH_LONG).show(); + return "지오코더 서비스 사용불가"; + } catch (IllegalArgumentException illegalArgumentException) { + Toast.makeText(getContext(), "잘못된 GPS 좌표", Toast.LENGTH_LONG).show(); + return "잘못된 GPS 좌표"; + + } + if (addresses == null || addresses.size() == 0) { + Toast.makeText(getContext(), "주소 미발견", Toast.LENGTH_LONG).show(); + return "주소 미발견"; + + } + + Address address = addresses.get(0); + return address.getAddressLine(0).toString()+"\n"; + + } + + @Override + public void onRequestPermissionsResult(int permsRequestCode, @NonNull String[] permissions, @NonNull int[] grandResults) { + + if ( permsRequestCode == PERMISSIONS_REQUEST_CODE && grandResults.length == REQUIRED_PERMISSIONS.length) { + + boolean check_result = true; + + for (int result : grandResults) { + if (result != PackageManager.PERMISSION_GRANTED) { + check_result = false; + break; + } + } + + if ( check_result ) { } + else { + + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[0]) + || ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[1])) { + + Toast.makeText(getContext(), "퍼미션이 거부되었습니다. 앱을 다시 실행하여 퍼미션을 허용해주세요.", Toast.LENGTH_LONG).show(); + + + + }else { + + Toast.makeText(getContext(), "퍼미션이 거부되었습니다. 설정(앱 정보)에서 퍼미션을 허용해야 합니다. ", Toast.LENGTH_LONG).show(); + + } + } + + } + } + + void checkRunTimePermission(){ + int hasFineLocationPermission = ContextCompat.checkSelfPermission(getContext(), + Manifest.permission.ACCESS_FINE_LOCATION); + int hasCoarseLocationPermission = ContextCompat.checkSelfPermission(getContext(), + Manifest.permission.ACCESS_COARSE_LOCATION); + + + if (hasFineLocationPermission == PackageManager.PERMISSION_GRANTED && + hasCoarseLocationPermission == PackageManager.PERMISSION_GRANTED) { + + } else { + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[0])) { + + Toast.makeText(getContext(), "이 앱을 실행하려면 위치 접근 권한이 필요합니다.", Toast.LENGTH_LONG).show(); + ActivityCompat.requestPermissions(getActivity(), REQUIRED_PERMISSIONS, + PERMISSIONS_REQUEST_CODE); + + } else { + ActivityCompat.requestPermissions(getActivity(), REQUIRED_PERMISSIONS, + PERMISSIONS_REQUEST_CODE); + } + + } + + } + + private void showDialogForLocationServiceSetting() { + + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle("위치 서비스 비활성화"); + builder.setMessage("앱을 사용하기 위해서는 위치 서비스가 필요합니다.\n" + + "위치 설정을 수정하실래요?"); + builder.setCancelable(true); + builder.setPositiveButton("설정", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Intent callGPSSettingIntent + = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); + startActivityForResult(callGPSSettingIntent, GPS_ENABLE_REQUEST_CODE); + } + }); + builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + builder.create().show(); + } + + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + switch (requestCode) { + + case GPS_ENABLE_REQUEST_CODE: + + //사용자가 GPS 활성 시켰는지 검사 + if (checkLocationServicesStatus()) { + if (checkLocationServicesStatus()) { + checkRunTimePermission(); + return; + } + } + + break; + } + } + + public boolean checkLocationServicesStatus() { + LocationManager locationManager; + locationManager = (LocationManager)mContext.getSystemService(LOCATION_SERVICE); + + return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) + || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); + } } \ No newline at end of file diff --git a/app/src/main/java/com/greener/MediaDetailView.java b/app/src/main/java/com/greener/MediaDetailView.java index a6e0a1f..fdf9319 100644 --- a/app/src/main/java/com/greener/MediaDetailView.java +++ b/app/src/main/java/com/greener/MediaDetailView.java @@ -31,7 +31,6 @@ public class MediaDetailView extends AppCompatActivity implements View.OnClickLi private DatabaseReference databaseReference; private Button Back; - private String Title; public static String Path; @Override @@ -39,15 +38,11 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.media_detail_view); - TextView MediaDetailTitle = findViewById(R.id.media_detail_title); - Back = findViewById(R.id.btn_go_back); Back.setOnClickListener(this); Intent intent = getIntent(); - MediaDetailTitle.setText(intent.getStringExtra("Title")); - recyclerView = (RecyclerView)findViewById(R.id.media_detail_recyclerView); recyclerView.setHasFixedSize(true); //리사이클러뷰 성능 강화 @@ -56,8 +51,6 @@ protected void onCreate(Bundle savedInstanceState) { arrayList = new ArrayList(); // User 객체를 담을 어레이 리스트 (어댑터쪽으로) - Title = MediaDetailTitle.getText().toString(); - database = FirebaseDatabase.getInstance(); databaseReference = database.getReference("환경정보").child(Path); databaseReference.addListenerForSingleValueEvent(new ValueEventListener() { diff --git a/app/src/main/java/com/greener/MediaViewAdapter.java b/app/src/main/java/com/greener/MediaViewAdapter.java index fcc1521..c74409e 100644 --- a/app/src/main/java/com/greener/MediaViewAdapter.java +++ b/app/src/main/java/com/greener/MediaViewAdapter.java @@ -70,7 +70,6 @@ public void onClick(View view) { int position = getAdapterPosition(); Intent intent = new Intent(context, MediaDetailView.class); - intent.putExtra("Title", arrayList.get(position).getTitleStr()); MediaDetailView.Path = arrayList.get(position).getImageTitle(); diff --git a/app/src/main/java/com/greener/SettingMain.java b/app/src/main/java/com/greener/SettingMain.java index 1185dc1..d4e0675 100644 --- a/app/src/main/java/com/greener/SettingMain.java +++ b/app/src/main/java/com/greener/SettingMain.java @@ -46,7 +46,7 @@ public class SettingMain extends Fragment { FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); FirebaseDatabase database = FirebaseDatabase.getInstance(); - DatabaseReference databaseReference; + DatabaseReference databaseReference, deleteReference; private ArrayList arrayList; private TextView setting_userid; @@ -129,6 +129,9 @@ public void onComplete(@NonNull Task task) { Toast.makeText(view.getContext(), "계정이 삭제 되었습니다.", Toast.LENGTH_LONG).show(); } }); + String path = "users/"+firebaseAuth.getUid(); + deleteReference = database.getInstance().getReference(); + deleteReference.child(path).removeValue(); intent = new Intent(view.getContext(), LoginActivity.class); startActivity(intent); removeFragment(SettingMain.this); diff --git a/app/src/main/java/com/greener/ShopMap.java b/app/src/main/java/com/greener/ShopMap.java index 5b92319..91d29f6 100644 --- a/app/src/main/java/com/greener/ShopMap.java +++ b/app/src/main/java/com/greener/ShopMap.java @@ -2,8 +2,19 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import android.Manifest; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Address; +import android.location.Geocoder; +import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -12,6 +23,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; @@ -29,11 +41,22 @@ import com.naver.maps.map.overlay.OverlayImage; import com.naver.maps.map.util.FusedLocationSource; +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import static android.content.Context.LOCATION_SERVICE; + public class ShopMap extends Fragment implements OnMapReadyCallback { private GPSTracker gpsTracker; + private static final int GPS_ENABLE_REQUEST_CODE = 2001; + private static final int PERMISSIONS_REQUEST_CODE = 100; + String[] REQUIRED_PERMISSIONS = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; + + private MapView mapView; private DatabaseReference databaseReference; private NaverMap naverMap; @@ -43,12 +66,19 @@ public class ShopMap extends Fragment implements OnMapReadyCallback { private OverlayImage image = OverlayImage.fromResource(R.drawable.ic_place_marker); private View view; + private Context mContext; private Button btn; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); mLocationSource = new FusedLocationSource(this, 100); + + mContext = getContext(); + + if (!checkLocationServicesStatus()) { + showDialogForLocationServiceSetting(); + }else { checkRunTimePermission(); } } @Nullable @@ -97,6 +127,9 @@ public void onClick(View v) { double latitude = gpsTracker.getLatitude(); double longitude = gpsTracker.getLongitude(); + String addrStr = getCurrentAddress(latitude, longitude); + System.out.println("addrStr : " + addrStr); + CameraPosition cameraPosition = new CameraPosition(new LatLng(latitude, longitude), 13); naverMap.setCameraPosition(cameraPosition); } @@ -149,4 +182,141 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.actionbar_map_action, menu); } + public String getCurrentAddress( double latitude, double longitude) { + Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault()); + List
addresses; + try { + addresses = geocoder.getFromLocation(latitude, longitude, 7); + } catch (IOException ioException) { + Toast.makeText(getContext(), "지오코더 서비스 사용불가", Toast.LENGTH_LONG).show(); + return "지오코더 서비스 사용불가"; + } catch (IllegalArgumentException illegalArgumentException) { + Toast.makeText(getContext(), "잘못된 GPS 좌표", Toast.LENGTH_LONG).show(); + return "잘못된 GPS 좌표"; + + } + if (addresses == null || addresses.size() == 0) { + Toast.makeText(getContext(), "주소 미발견", Toast.LENGTH_LONG).show(); + return "주소 미발견"; + + } + + Address address = addresses.get(0); + return address.getAddressLine(0).toString()+"\n"; + + } + + @Override + public void onRequestPermissionsResult(int permsRequestCode, @NonNull String[] permissions, @NonNull int[] grandResults) { + + if ( permsRequestCode == PERMISSIONS_REQUEST_CODE && grandResults.length == REQUIRED_PERMISSIONS.length) { + + boolean check_result = true; + + for (int result : grandResults) { + if (result != PackageManager.PERMISSION_GRANTED) { + check_result = false; + break; + } + } + + if ( check_result ) { } + else { + + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[0]) + || ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[1])) { + + Toast.makeText(getContext(), "퍼미션이 거부되었습니다. 앱을 다시 실행하여 퍼미션을 허용해주세요.", Toast.LENGTH_LONG).show(); + + + + }else { + + Toast.makeText(getContext(), "퍼미션이 거부되었습니다. 설정(앱 정보)에서 퍼미션을 허용해야 합니다. ", Toast.LENGTH_LONG).show(); + + } + } + + } + } + + void checkRunTimePermission(){ + int hasFineLocationPermission = ContextCompat.checkSelfPermission(getContext(), + Manifest.permission.ACCESS_FINE_LOCATION); + int hasCoarseLocationPermission = ContextCompat.checkSelfPermission(getContext(), + Manifest.permission.ACCESS_COARSE_LOCATION); + + + if (hasFineLocationPermission == PackageManager.PERMISSION_GRANTED && + hasCoarseLocationPermission == PackageManager.PERMISSION_GRANTED) { + + } else { + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), REQUIRED_PERMISSIONS[0])) { + + Toast.makeText(getContext(), "이 앱을 실행하려면 위치 접근 권한이 필요합니다.", Toast.LENGTH_LONG).show(); + ActivityCompat.requestPermissions(getActivity(), REQUIRED_PERMISSIONS, + PERMISSIONS_REQUEST_CODE); + + } else { + ActivityCompat.requestPermissions(getActivity(), REQUIRED_PERMISSIONS, + PERMISSIONS_REQUEST_CODE); + } + + } + + } + + private void showDialogForLocationServiceSetting() { + + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle("위치 서비스 비활성화"); + builder.setMessage("앱을 사용하기 위해서는 위치 서비스가 필요합니다.\n" + + "위치 설정을 수정하실래요?"); + builder.setCancelable(true); + builder.setPositiveButton("설정", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Intent callGPSSettingIntent + = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); + startActivityForResult(callGPSSettingIntent, GPS_ENABLE_REQUEST_CODE); + } + }); + builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + builder.create().show(); + } + + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + switch (requestCode) { + + case GPS_ENABLE_REQUEST_CODE: + + //사용자가 GPS 활성 시켰는지 검사 + if (checkLocationServicesStatus()) { + if (checkLocationServicesStatus()) { + checkRunTimePermission(); + return; + } + } + + break; + } + } + + public boolean checkLocationServicesStatus() { + LocationManager locationManager; + locationManager = (LocationManager)mContext.getSystemService(LOCATION_SERVICE); + + return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) + || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/media_detail_list.xml b/app/src/main/res/layout/media_detail_list.xml index 073e4eb..4d464ed 100644 --- a/app/src/main/res/layout/media_detail_list.xml +++ b/app/src/main/res/layout/media_detail_list.xml @@ -2,17 +2,17 @@ \ No newline at end of file diff --git a/app/src/main/res/layout/media_detail_view.xml b/app/src/main/res/layout/media_detail_view.xml index 735136f..70bb365 100644 --- a/app/src/main/res/layout/media_detail_view.xml +++ b/app/src/main/res/layout/media_detail_view.xml @@ -25,21 +25,12 @@ - - diff --git a/app/src/main/res/layout/media_list.xml b/app/src/main/res/layout/media_list.xml index d1cb85a..40e5df0 100644 --- a/app/src/main/res/layout/media_list.xml +++ b/app/src/main/res/layout/media_list.xml @@ -36,6 +36,7 @@ android:textSize="18sp" android:fontFamily="@font/medium" android:layout_marginTop="3dp" + android:maxLines="2" android:layout_below="@+id/mediaBackgroundView" android:layout_alignLeft="@+id/mediaBackgroundView" android:layout_alignRight="@+id/mediaBackgroundView"