Add background location disclosure

Этот коммит содержится в:
Anton Tananaev
2020-12-13 22:00:44 -08:00
родитель 52e3b839ae
Коммит 0bbee716a6
5 изменённых файлов: 33 добавлений и 5 удалений
+2 -4
Просмотреть файл
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Anton Tananaev (anton@traccar.org)
* Copyright 2017 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,9 +24,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new MainFragment()).commit();
}
setContentView(R.layout.main);
}
}
+15
Просмотреть файл
@@ -47,6 +47,8 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.TwoStatePreference;
import com.google.android.material.snackbar.Snackbar;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
@@ -69,6 +71,7 @@ public class MainFragment extends PreferenceFragmentCompat implements OnSharedPr
public static final String KEY_WAKELOCK = "wakelock";
private static final int PERMISSIONS_REQUEST_LOCATION = 2;
private static final String KEY_DISCLOSURE_SHOWN = "disclosureShown";
private SharedPreferences sharedPreferences;
@@ -77,6 +80,7 @@ public class MainFragment extends PreferenceFragmentCompat implements OnSharedPr
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
if (BuildConfig.HIDDEN_APP && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
removeLauncherIcon();
}
@@ -191,6 +195,17 @@ public class MainFragment extends PreferenceFragmentCompat implements OnSharedPr
public void onResume() {
super.onResume();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
if (!sharedPreferences.getBoolean(KEY_DISCLOSURE_SHOWN, false)) {
Snackbar.make(getView(), R.string.disclosure_location, Snackbar.LENGTH_INDEFINITE)
.addCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
sharedPreferences.edit().putBoolean(KEY_DISCLOSURE_SHOWN, true).apply();
}
})
.show();
}
}
@Override
+13
Просмотреть файл
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="org.traccar.client.MainFragment" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+1
Просмотреть файл
@@ -46,4 +46,5 @@
<string name="hidden_app_name">Device Settings</string>
<string name="hidden_alert">The app has been hidden. To open it again please dial 8722227 (TRACCAR).</string>
<string name="error_msg_invalid_url">Please enter a valid http:// or https:// URL</string>
<string name="disclosure_location">This app collects location data to enable live tracking even when the app is closed or not in use.</string>
</resources>