diff --git a/Android/app/src/main/java/io/github/project_travel_mate/login/LoginActivity.java b/Android/app/src/main/java/io/github/project_travel_mate/login/LoginActivity.java index a10b149575..cdb41a8855 100644 --- a/Android/app/src/main/java/io/github/project_travel_mate/login/LoginActivity.java +++ b/Android/app/src/main/java/io/github/project_travel_mate/login/LoginActivity.java @@ -303,22 +303,23 @@ public void getRunTimePermissions() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(LoginActivity.this, Manifest.permission.CAMERA) + != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(LoginActivity.this, + Manifest.permission.READ_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(LoginActivity.this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(LoginActivity.this, + Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN, - Manifest.permission.READ_CONTACTS, - Manifest.permission.WRITE_CONTACTS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.WAKE_LOCK, Manifest.permission.INTERNET, Manifest.permission.ACCESS_NETWORK_STATE, - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.VIBRATE, - }, 0); } } diff --git a/Android/app/src/main/java/io/github/project_travel_mate/travel/ListViewRealTimeActivity.java b/Android/app/src/main/java/io/github/project_travel_mate/travel/ListViewRealTimeActivity.java index 936f3b0414..4a615a49ea 100644 --- a/Android/app/src/main/java/io/github/project_travel_mate/travel/ListViewRealTimeActivity.java +++ b/Android/app/src/main/java/io/github/project_travel_mate/travel/ListViewRealTimeActivity.java @@ -1,16 +1,23 @@ package io.github.project_travel_mate.travel; +import android.Manifest; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; +import android.widget.Toast; import org.osmdroid.views.MapView; @@ -44,6 +51,41 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_list_real_time); ButterKnife.bind(this); + getRunTimePermission(); + } + + private void getRunTimePermission() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED && + ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) + == PackageManager.PERMISSION_GRANTED) { + getLocation(); + } else { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION}, 100); + } + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, + @NonNull int[] grantResults) { + if (requestCode != 100) { + return; + } + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED + && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) + == PackageManager.PERMISSION_GRANTED) { + getLocation(); + } else { + Toast.makeText(this , "Permissions Denied" , Toast.LENGTH_SHORT).show(); + } + } + + public void getLocation() { // Get user's current location mTracker = new GPSTracker(this); MapView mMap = findViewById(R.id.action_map_view); diff --git a/Android/app/src/main/java/io/github/project_travel_mate/travel/MapViewRealTimeActivity.java b/Android/app/src/main/java/io/github/project_travel_mate/travel/MapViewRealTimeActivity.java index 550ee8d446..60de68b361 100644 --- a/Android/app/src/main/java/io/github/project_travel_mate/travel/MapViewRealTimeActivity.java +++ b/Android/app/src/main/java/io/github/project_travel_mate/travel/MapViewRealTimeActivity.java @@ -7,11 +7,14 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; +import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; +import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -23,6 +26,7 @@ import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.TextView; +import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import com.airbnb.lottie.LottieAnimationView; @@ -100,6 +104,41 @@ protected void onCreate(Bundle savedInstanceState) { setTitle("Map View"); + getRunTimePermission(); + } + + private void getRunTimePermission() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED && + ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) + == PackageManager.PERMISSION_GRANTED) { + getLocation(); + } else { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION}, 100); + } + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, + @NonNull int[] grantResults) { + if (requestCode != 100) { + return; + } + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED + && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) + == PackageManager.PERMISSION_GRANTED) { + getLocation(); + } else { + Toast.makeText(this, "Permissions Denied", Toast.LENGTH_SHORT).show(); + } + } + + private void getLocation() { // Get user's current location tracker = new GPSTracker(this); if (!tracker.canGetLocation()) { diff --git a/Android/app/src/main/java/utils/GPSTracker.java b/Android/app/src/main/java/utils/GPSTracker.java index e4587fbcaa..572efecb78 100644 --- a/Android/app/src/main/java/utils/GPSTracker.java +++ b/Android/app/src/main/java/utils/GPSTracker.java @@ -1,13 +1,16 @@ package utils; +import android.Manifest; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; +import android.support.v4.app.ActivityCompat; import android.util.Log; import org.osmdroid.views.MapView; @@ -56,7 +59,10 @@ private Location getLocation() { if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled - } else { + } else if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) + == PackageManager.PERMISSION_GRANTED) { this.mCanGetLocation = true; // First get mLocation from Network Provider if (isNetworkEnabled) { @@ -156,4 +162,5 @@ public void displayLocationRequest(Context context, MapView mapView) { mLocationOverlay.enableMyLocation(); mapView.getOverlays().add(mLocationOverlay); } -} \ No newline at end of file +} + diff --git a/Android/app/src/main/res/layout/hotel_listitem.xml b/Android/app/src/main/res/layout/hotel_listitem.xml index d72be0d06b..3256529e21 100755 --- a/Android/app/src/main/res/layout/hotel_listitem.xml +++ b/Android/app/src/main/res/layout/hotel_listitem.xml @@ -26,7 +26,6 @@ android:layout_width="match_parent" android:layout_height="70dp" android:layout_alignParentStart="true" - android:layout_alignParentTop="true" app:srcCompat="@color/colorAccent" />