Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5ed880e

Browse files
committed
Upgrade to Android S, bug fixes and dependency upgrade
Changes: - dependencies upgrade - permission changes to ask for coarse and fine GPS at the same time - permissions for the Android S - schedule exact alarm, sampling frequency and GPS - notifications updated for the Android S with PendingIntent.FLAG_MUTABLE - wear permission update for Android R - wear adapters updated with new positioning - wear synchronization is being done by coroutines, not services - wear updated UI - titles and BoxLayouts
1 parent 87a4cf9 commit 5ed880e

File tree

31 files changed

+351
-271
lines changed

31 files changed

+351
-271
lines changed

CountDownDialog/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 30
5+
compileSdkVersion 31
66
buildToolsVersion "30.0.2"
77

88
defaultConfig {
99
minSdkVersion 19
10-
targetSdkVersion 30
10+
targetSdkVersion 31
1111
versionCode 1
1212
versionName "1.0"
1313

@@ -34,7 +34,7 @@ dependencies {
3434
implementation fileTree(dir: "libs", include: ["*.jar"])
3535
implementation 'androidx.core:core-ktx:1.6.0'
3636
implementation 'androidx.appcompat:appcompat:1.3.1'
37-
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
37+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
3838
implementation 'com.google.android.material:material:1.4.0'
3939
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
4040
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

WearOsLib/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 30
5+
compileSdkVersion 31
66
buildToolsVersion "30.0.2"
77

88
defaultConfig {
99
minSdkVersion 19
10-
targetSdkVersion 30
10+
targetSdkVersion 31
1111
versionCode 1
1212
versionName "1.0"
1313

@@ -38,14 +38,14 @@ dependencies {
3838
implementation 'androidx.preference:preference-ktx:1.1.1'
3939
implementation 'androidx.core:core-ktx:1.6.0'
4040
implementation 'androidx.appcompat:appcompat:1.3.1'
41-
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
41+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
4242

4343
testImplementation 'junit:junit:4.13.2'
4444
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4545
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
4646

4747
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
48-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
48+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt'
4949

5050
implementation 'com.github.GrenderG:Toasty:1.5.0'
5151
}

WearOsLib/src/main/java/com/motionapps/wearoslib/WearOsConstants.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ object WearOsConstants {
4242
const val SAMPLE_PATH_TIME = "/com.motionapps.sensorbox.sample.time"
4343
const val FILE_TO_TRANSFER_PATH = "/com.motionapps.sensorbox.file_to_transfer"
4444

45-
4645
}

WearOsLib/src/main/java/com/motionapps/wearoslib/WearOsNotify.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.motionapps.wearoslib
22

3+
import android.annotation.SuppressLint
34
import android.app.Notification
45
import android.app.NotificationChannel
56
import android.app.NotificationManager
@@ -29,6 +30,7 @@ object WearOsNotify {
2930
* @param importance - importance
3031
* @return - built notification
3132
*/
33+
@SuppressLint("UnspecifiedImmutableFlag")
3234
fun createProgressNotification(
3335
context: Context,
3436
count: Int,
@@ -58,14 +60,25 @@ object WearOsNotify {
5860
builder.setSmallIcon(R.drawable.ic_graph)
5961
builder.color = ContextCompat.getColor(context, R.color.black_color)
6062
val stopIntent = Intent(STOP_SYNC)
61-
builder.addAction(
62-
R.drawable.ic_baseline_stop,
63-
context.getString(R.string.text_stop),
64-
PendingIntent.getBroadcast(
65-
context,
66-
25, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT
63+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
64+
builder.addAction(
65+
R.drawable.ic_baseline_stop,
66+
context.getString(R.string.text_stop),
67+
PendingIntent.getBroadcast(
68+
context,
69+
25, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
70+
)
6771
)
68-
)
72+
}else{
73+
builder.addAction(
74+
R.drawable.ic_baseline_stop,
75+
context.getString(R.string.text_stop),
76+
PendingIntent.getBroadcast(
77+
context,
78+
25, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT
79+
)
80+
)
81+
}
6982
}
7083
return builder.build()
7184
}

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ apply plugin: 'com.google.gms.google-services'
77
apply plugin: 'com.google.firebase.crashlytics'
88

99
android {
10-
compileSdkVersion 30
10+
compileSdkVersion 31
1111
buildToolsVersion "30.0.2"
1212

1313

1414
defaultConfig {
1515
applicationId "motionapps.sensorbox"
1616
minSdkVersion 19
17-
targetSdkVersion 30
17+
targetSdkVersion 31
1818
versionCode 62
1919
versionName "4.2.2"
2020
multiDexEnabled true
@@ -64,7 +64,7 @@ dependencies {
6464
implementation 'androidx.core:core-ktx:1.6.0'
6565
implementation 'androidx.appcompat:appcompat:1.3.1'
6666
implementation 'com.google.android.material:material:1.4.0'
67-
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
67+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
6868

6969
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
7070
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
@@ -79,8 +79,8 @@ dependencies {
7979
implementation 'com.google.firebase:firebase-analytics-ktx:19.0.1'
8080
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.1'
8181

82-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
83-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
82+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt'
83+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2-native-mt'
8484

8585
implementation 'androidx.fragment:fragment-ktx:1.3.6'
8686

@@ -99,8 +99,8 @@ dependencies {
9999
implementation 'io.github.ShawnLin013:number-picker:2.4.13'
100100
implementation 'com.jaredrummler:material-spinner:1.3.1'
101101
implementation 'io.github.medyo:android-about-page:2.0.0'
102-
implementation 'de.psdev.licensesdialog:licensesdialog:2.1.0'
103-
implementation 'com.github.GrenderG:Toasty:1.5.0'
102+
implementation 'de.psdev.licensesdialog:licensesdialog:2.2.0'
103+
implementation 'com.github.GrenderG:Toasty:1.5.2'
104104

105105
testImplementation 'junit:junit:4.13.2'
106106
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package="com.motionapps.sensorbox" >
55

66
<uses-permission android:name="android.permission.WAKE_LOCK" />
7+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
78
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
89
<uses-permission android:name="android.permission.INTERNET" />
910
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
@@ -121,14 +122,16 @@
121122
android:name=".activities.MainActivity"
122123
android:label="@string/app_name"
123124
android:launchMode="singleTask"
124-
android:theme="@style/AppTheme" >
125+
android:theme="@style/AppTheme"
126+
android:exported="true">
125127
<intent-filter>
126128
<action android:name="android.intent.action.MAIN" />
127129
<category android:name="android.intent.category.LAUNCHER" />
128130
</intent-filter>
129131
</activity>
130132

131-
<service android:name=".MsgListener" >
133+
<service android:name=".MsgListener"
134+
android:exported="true">
132135
<intent-filter>
133136
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
134137
<data

app/src/main/java/com/motionapps/sensorbox/fragments/HomeFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ open class HomeFragment : Fragment() {
215215

216216
infoButton.setOnClickListener {
217217

218-
if(permissionHandler.checkGPSPermission(this)){
218+
if(!permissionHandler.checkGPSPermission(this)){
219219
return@setOnClickListener
220220
}
221221
val action: NavDirections = HomeFragmentDirections.homeInfoAction(SensorNeeds.GPS)
@@ -233,7 +233,7 @@ open class HomeFragment : Fragment() {
233233

234234
imageButton.setOnClickListener {
235235

236-
if(permissionHandler.checkGPSPermission(this)){
236+
if(!permissionHandler.checkGPSPermission(this)){
237237
return@setOnClickListener
238238
}
239239

app/src/main/java/com/motionapps/sensorbox/permissions/PermissionHandler.kt

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.motionapps.sensorbox.permissions
22

33

44
import android.Manifest
5+
import android.content.Context
56
import android.content.pm.PackageManager
67
import android.graphics.Color
78
import android.hardware.Sensor
@@ -62,6 +63,33 @@ class PermissionHandler(fragment: Fragment) {
6263
}
6364
}
6465

66+
@RequiresApi(Build.VERSION_CODES.S)
67+
val gpsCallbackS = fragment.registerForActivityResult(
68+
ActivityResultContracts.RequestMultiplePermissions()
69+
) { permissions ->
70+
when {
71+
permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) -> {
72+
// Precise location access granted.
73+
val action: NavDirections = HomeFragmentDirections.homeInfoAction(SensorNeeds.GPS)
74+
Navigation.findNavController(fragment.requireView()).navigate(action)
75+
}
76+
permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) -> {
77+
// Only approximate location access granted.
78+
val action: NavDirections = HomeFragmentDirections.homeInfoAction(SensorNeeds.GPS)
79+
Navigation.findNavController(fragment.requireView()).navigate(action)
80+
}
81+
else -> {
82+
// permission is denied
83+
if (permissions.keys.any { fragment.shouldShowRequestPermissionRationale(it) }) {
84+
showDialogFineLocation(fragment)
85+
} else {
86+
// R.string.permission_gps_show,
87+
PermissionSettingsDialog.showSettings(fragment.requireContext())
88+
}
89+
}
90+
}
91+
}
92+
6593
@RequiresApi(Build.VERSION_CODES.M)
6694
val bodySensors = fragment.registerForActivityResult(
6795
ActivityResultContracts.RequestPermission()
@@ -87,54 +115,61 @@ class PermissionHandler(fragment: Fragment) {
87115

88116
fun checkGPSPermission(fragment: Fragment): Boolean {
89117
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
90-
if (ActivityCompat.checkSelfPermission(
91-
fragment.requireContext(),
92-
Manifest.permission.ACCESS_FINE_LOCATION
93-
) != PackageManager.PERMISSION_GRANTED
94-
) {
118+
if (!isAnyGpsPermission(fragment.requireContext())) {
95119
showDialogFineLocation(fragment)
96-
return true
120+
return false
97121
}
122+
return true
98123
}
99-
return false
124+
return true
100125
}
101126

127+
private fun isAnyGpsPermission(context: Context): Boolean {
128+
val coarse = ActivityCompat.checkSelfPermission(
129+
context,
130+
Manifest.permission.ACCESS_COARSE_LOCATION
131+
) == PackageManager.PERMISSION_GRANTED
132+
val fine = ActivityCompat.checkSelfPermission(
133+
context,
134+
Manifest.permission.ACCESS_FINE_LOCATION
135+
) == PackageManager.PERMISSION_GRANTED
136+
137+
return coarse || fine
138+
}
102139

103140
/**
104-
* Creates prominent disclosure for GPS for apps under Android Q
141+
* Creates prominent disclosure for GPS for apps - modified for Android S
142+
* Asks for fine location for Android below SDK 31
105143
*
106144
* @return material dialog
107145
*/
108146
@RequiresApi(Build.VERSION_CODES.M)
109147
@ExperimentalCoroutinesApi
110148
@InternalCoroutinesApi
111149
fun showDialogFineLocation(fragment: Fragment) {
112-
dialog = PermissionSettingsDialog.showPermissionRational(
113-
permissionCallback = gpsCallback,
114-
fragment = fragment,
115-
messageText = R.string.permission_gps,
116-
permission = Manifest.permission.ACCESS_FINE_LOCATION,
117-
icon = R.drawable.ic_baseline_location,
118-
)
150+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
151+
dialog = PermissionSettingsDialog.showPermissionRational(
152+
permissionCallback = gpsCallback,
153+
fragment = fragment,
154+
messageText = R.string.permission_gps,
155+
permission = Manifest.permission.ACCESS_FINE_LOCATION,
156+
icon = R.drawable.ic_baseline_location,
157+
)
158+
} else {
159+
dialog = PermissionSettingsDialog.showPermissionRational(
160+
permissionCallback = gpsCallbackS,
161+
fragment = fragment,
162+
messageText = R.string.permission_gps,
163+
permissions = arrayOf(
164+
Manifest.permission.ACCESS_FINE_LOCATION,
165+
Manifest.permission.ACCESS_COARSE_LOCATION
166+
),
167+
icon = R.drawable.ic_baseline_location,
168+
)
169+
}
170+
119171
}
120172

121-
// /**
122-
// * Creates prominent disclosure for GPS for apps for Android Q and above
123-
// *
124-
// * @return material dialog
125-
// */
126-
// @RequiresApi(Build.VERSION_CODES.Q)
127-
// @ExperimentalCoroutinesApi
128-
// @InternalCoroutinesApi
129-
// fun showDialogBackgroundLocation(
130-
// fragment: Fragment,
131-
// ) {
132-
// dialog = PermissionSettingsDialog.showPermissionSettings(
133-
// fragment = fragment,
134-
// messageText = R.string.permission_gps_android_Q,
135-
// icon = R.drawable.ic_baseline_location,
136-
// )
137-
// }
138173

139174
fun checkHeartRateSensor(fragment: Fragment, sensorId: Int): Boolean {
140175
if (sensorId == Sensor.TYPE_HEART_RATE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH && ActivityCompat.checkSelfPermission(

0 commit comments

Comments
 (0)