Better permission management
Add copyright for the map Fix old maps parameters to be at the same place after come back to map
This commit is contained in:
parent
83e7ac84fc
commit
8359aa27fb
4 changed files with 83 additions and 15 deletions
|
@ -39,11 +39,18 @@ import android.app.Fragment;
|
|||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
|
@ -58,7 +65,6 @@ import android.view.View;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -73,6 +79,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
private int postCode;
|
||||
private List<Long> notifications;
|
||||
private Menu optionMenu;
|
||||
private Snackbar barWrite;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -132,7 +139,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull final String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if(requestCode == 1 && grantResults.length == 2 && (grantResults[0] == PackageManager.PERMISSION_GRANTED || grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
|
||||
FragmentManager manager = getFragmentManager();
|
||||
|
@ -140,9 +147,38 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
if(frag instanceof MapsFragment) {
|
||||
((MapsFragment)frag).startUpdateLocations();
|
||||
}
|
||||
} else if (requestCode == 1 && grantResults.length == 2) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean("deactivate_localisation", true);
|
||||
editor.apply();
|
||||
}
|
||||
if(requestCode == 2 && grantResults.length == 1 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this,R.string.need_write,Toast.LENGTH_LONG).show();
|
||||
barWrite = Snackbar.make(findViewById(R.id.fragment_container),R.string.need_write,Snackbar.LENGTH_INDEFINITE);
|
||||
barWrite.setAction(R.string.retry, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager manager = getFragmentManager();
|
||||
Fragment fragment = manager.findFragmentById(R.id.fragment_container);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if(!shouldShowRequestPermissionRationale(permissions[0])) {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(intent, 5);
|
||||
dismissSnackBar();
|
||||
} else {
|
||||
if(fragment instanceof MapsFragment)
|
||||
((MapsFragment)fragment).askWritePermission();
|
||||
}
|
||||
} else {
|
||||
if (fragment instanceof MapsFragment)
|
||||
((MapsFragment) fragment).askWritePermission();
|
||||
}
|
||||
dismissSnackBar();
|
||||
}
|
||||
});
|
||||
barWrite.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,25 +381,31 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.nav_my_donation:
|
||||
showDonation();
|
||||
dismissSnackBar();
|
||||
break;
|
||||
case R.id.nav_user_information:
|
||||
showDonationInfo();
|
||||
dismissSnackBar();
|
||||
break;
|
||||
case R.id.nav_legend:
|
||||
openLegendDialog();
|
||||
break;
|
||||
case R.id.nav_preferences:
|
||||
showPrefs();
|
||||
dismissSnackBar();
|
||||
break;
|
||||
case R.id.nav_post_don:
|
||||
openPostDonationDialog();
|
||||
break;
|
||||
case R.id.nav_about:
|
||||
showAbout();
|
||||
dismissSnackBar();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -373,6 +415,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
return true;
|
||||
}
|
||||
|
||||
private void dismissSnackBar() {
|
||||
if(barWrite != null) {
|
||||
barWrite.dismiss();
|
||||
barWrite = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
|
|
|
@ -29,7 +29,6 @@ import android.location.LocationListener;
|
|||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
|
@ -39,7 +38,6 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.car2go.maps.AnyMap;
|
||||
import com.car2go.maps.OnMapReadyCallback;
|
||||
|
@ -150,6 +148,7 @@ public class MapsFragment extends Fragment implements OnMapReadyCallback {
|
|||
postCode = savedInstanceState.getInt("posteCode");
|
||||
previousLocation = new LatLng(latitude,longitude);
|
||||
previousZoom = zoom;
|
||||
myLocation = savedInstanceState.getParcelable("myLocation");
|
||||
} else {
|
||||
isFirstLocation = true;
|
||||
postCode = -1;
|
||||
|
@ -161,6 +160,8 @@ public class MapsFragment extends Fragment implements OnMapReadyCallback {
|
|||
locationListener = new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if(location == null)
|
||||
return;
|
||||
myLocation = location;
|
||||
myLocationBt.setVisibility(View.VISIBLE);
|
||||
if(map != null) {
|
||||
|
@ -283,6 +284,7 @@ public class MapsFragment extends Fragment implements OnMapReadyCallback {
|
|||
stopUpdateLocations();
|
||||
return;
|
||||
}
|
||||
locationListener.onLocationChanged(myLocation);
|
||||
|
||||
LocationManager manager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
|
||||
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
|
||||
|
@ -331,22 +333,31 @@ public class MapsFragment extends Fragment implements OnMapReadyCallback {
|
|||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if(mapView != null) {
|
||||
mapView.onSaveInstanceState(outState);
|
||||
outState.putBoolean("isFirstLocation",isFirstLocation);
|
||||
outState.putDouble("locationLatitude",previousLocation.latitude);
|
||||
outState.putDouble("locationLongitude",previousLocation.longitude);
|
||||
outState.putFloat("locationZoom",previousZoom);
|
||||
outState.putInt("posteCode",postCode);
|
||||
outState.putParcelable("myLocation",myLocation);
|
||||
}
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
public void askWritePermission() {
|
||||
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
|
||||
ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
ActivityCompat.requestPermissions(getActivity(),permissions,2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(AnyMap anyMap) {
|
||||
map = anyMap;
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
|
||||
ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
ActivityCompat.requestPermissions(getActivity(),permissions,2);
|
||||
}
|
||||
|
||||
askWritePermission();
|
||||
map.animateCamera(CameraUpdateFactory.getInstance().newLatLngZoom(previousLocation,previousZoom));
|
||||
startUpdateLocations();
|
||||
|
||||
country = Country.FRANCE;
|
||||
|
@ -413,7 +424,6 @@ public class MapsFragment extends Fragment implements OnMapReadyCallback {
|
|||
selectedSite = -1;
|
||||
}
|
||||
});
|
||||
startUpdateLocations();
|
||||
|
||||
initPosition();
|
||||
BootReceiver.startNextChecking(getActivity(), false);
|
||||
|
|
|
@ -9,6 +9,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
<TextView
|
||||
android:text="@string/osm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentStart="true"
|
||||
/>
|
||||
<ImageButton
|
||||
android:id="@+id/move_to_user_location"
|
||||
android:contentDescription="@string/my_location"
|
||||
|
|
|
@ -89,8 +89,9 @@
|
|||
<string name="anymaps_licence">Copyright 2017 car2go group GmbH\nReleased under the MIT license.\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</string>
|
||||
<string name="blood_donation_licence">Copyright © 2017 Anthony Chomienne, anthony@mob–dev.fr\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110–1301, USA.</string>
|
||||
<string name="my_location">Centrer sur ma position</string>
|
||||
<string name="osm">Données © OpenStreetMap/ODbL\nRendu OSM France</string>
|
||||
<string name="osm">Données © OpenStreetMap</string>
|
||||
<string name="need_write">La Carte à besoin des droits en écriture/lecture sur le stockage externe</string>
|
||||
<string name="retry">Réessayer</string>
|
||||
|
||||
|
||||
<string-array name="gender_array">
|
||||
|
|
Loading…
Reference in a new issue