Skip to content

Commit

Permalink
Target Android 10
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Sep 26, 2019
1 parent a2ff7fc commit 93456bf
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 34 deletions.
19 changes: 10 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
applicationId "org.traccar.client"
buildConfigField "boolean", "HIDDEN_APP", "false"
minSdkVersion 15
targetSdkVersion 28
versionCode 56
versionName '5.19'
minSdkVersion 16
targetSdkVersion 29
versionCode 57
versionName '5.20'
}

lintOptions {
Expand All @@ -34,12 +34,13 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.preference:preference:1.1.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.1'
googleImplementation 'com.google.firebase:firebase-core:16.0.8'
googleImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.0'
googleImplementation "com.google.android.gms:play-services-location:16.0.0"
googleImplementation 'com.google.firebase:firebase-core:17.2.0'
googleImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
googleImplementation "com.google.android.gms:play-services-location:17.0.0"
}

if (getGradle().getStartParameter().getTaskRequests().toString().contains("Google")) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/google/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

<application
android:name="org.traccar.client.GoogleMainApplication"
tools:replace="android:name">
tools:replace="android:name"
tools:ignore="GoogleAppIndexingWarning">

</application>

Expand Down
12 changes: 9 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.traccar.client">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Expand All @@ -21,7 +23,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".MainApplication">
android:name=".MainApplication"
tools:ignore="GoogleAppIndexingWarning">

<meta-data
android:name="google_analytics_adid_collection_enabled"
Expand Down Expand Up @@ -56,9 +59,12 @@
</intent-filter>
</activity>

<service android:name=".TrackingService" />
<service
android:name=".TrackingService"
android:foregroundServiceType="location" />

<service android:name=".TrackingService$HideNotificationService" />
<service
android:name=".TrackingService$HideNotificationService" />

<receiver android:name=".AutostartReceiver">
<intent-filter>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/traccar/client/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainFragment()).commit();
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new MainFragment()).commit();
}
}

Expand Down
44 changes: 27 additions & 17 deletions app/src/main/java/org/traccar/client/MainFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 - 2017 Anton Tananaev ([email protected])
* Copyright 2012 - 2019 Anton Tananaev ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,24 +27,27 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.TwoStatePreference;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.TwoStatePreference;

import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.URLUtil;
import android.widget.Toast;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class MainFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
public class MainFragment extends PreferenceFragmentCompat implements OnSharedPreferenceChangeListener {

private static final String TAG = MainFragment.class.getSimpleName();

Expand All @@ -66,15 +69,14 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
private PendingIntent alarmIntent;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (BuildConfig.HIDDEN_APP) {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
if (BuildConfig.HIDDEN_APP && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
removeLauncherIcon();
}

setHasOptionsMenu(true);

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
addPreferencesFromResource(R.xml.preferences);
initPreferences();

Expand Down Expand Up @@ -129,6 +131,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
if (sharedPreferences.getBoolean(KEY_STATUS, false)) {
startTrackingService(true, false);
}

}

private void removeLauncherIcon() {
Expand Down Expand Up @@ -212,24 +215,31 @@ private void initPreferences() {

private void startTrackingService(boolean checkPermission, boolean permission) {
if (checkPermission) {
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
permission = true;
} else {
Set<String> requiredPermissions = new HashSet<>();
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requiredPermissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
&& ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requiredPermissions.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
}
permission = requiredPermissions.isEmpty();
if (!permission) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_LOCATION);
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), PERMISSIONS_REQUEST_LOCATION);
}
return;
}
}

if (permission) {
setPreferencesEnabled(false);
ContextCompat.startForegroundService(getActivity(), new Intent(getActivity(), TrackingService.class));
ContextCompat.startForegroundService(getContext(), new Intent(getActivity(), TrackingService.class));
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
ALARM_MANAGER_INTERVAL, ALARM_MANAGER_INTERVAL, alarmIntent);
} else {
sharedPreferences.edit().putBoolean(KEY_STATUS, false).apply();
TwoStatePreference preference = (TwoStatePreference) findPreference(KEY_STATUS);
TwoStatePreference preference = findPreference(KEY_STATUS);
preference.setChecked(false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

0 comments on commit 93456bf

Please sign in to comment.