Skip to content

Commit bae6bd5

Browse files
committed
SleepTimer: add WearOS module
* MinSDK 21 (Lollipop) * Move SleepTimer wear module from SimpleWear to here as its own app
1 parent 5d684be commit bae6bd5

File tree

169 files changed

+4312
-447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+4312
-447
lines changed

Diff for: .idea/compiler.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/gradle.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/jarRepositories.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/runConfigurations.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: app/build.gradle

+38-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
// that the app's state is completely cleared between tests.
1919
testInstrumentationRunnerArguments clearPackageData: 'true'
2020

21-
minSdkVersion 16
21+
minSdkVersion 21
2222
targetSdkVersion 29
2323
// NOTE: Version Code Format (TargetSDK, Version Name, Build Number, Variant Code (Android: 00, WearOS: 01)
2424
versionCode 291010200
@@ -33,39 +33,64 @@ android {
3333
debuggable true
3434
minifyEnabled false
3535
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36-
manifestPlaceholders = [idPrefix: 'com.thewizrd.simplesleeptimer.debug']
3736
}
3837
release {
3938
minifyEnabled true
4039
shrinkResources true
4140
crunchPngs true
4241
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
43-
manifestPlaceholders = [idPrefix: 'com.thewizrd.simplesleeptimer']
4442
}
4543
}
4644

4745
buildFeatures {
4846
dataBinding = true
4947
viewBinding = true
5048
}
49+
50+
compileOptions {
51+
// Flag to enable support for the new language APIs
52+
//coreLibraryDesugaringEnabled true
53+
// Sets Java compatibility to Java 8
54+
sourceCompatibility JavaVersion.VERSION_1_8
55+
targetCompatibility JavaVersion.VERSION_1_8
56+
}
57+
58+
kotlinOptions {
59+
jvmTarget = "1.8"
60+
}
5161
}
5262

5363
dependencies {
54-
implementation fileTree(dir: 'libs', include: ['*.jar'])
64+
implementation project(":shared_resources")
65+
wearApp project(':wear')
5566
implementation project(":circularseekbar")
5667

57-
// JUnit
58-
testImplementation 'junit:junit:4.13.1'
68+
// Unit Testing
69+
androidTestImplementation 'androidx.test:core:1.3.0'
70+
71+
// AndroidJUnitRunner and JUnit Rules
72+
androidTestImplementation 'androidx.test:runner:1.3.0'
73+
androidTestImplementation 'androidx.test:rules:1.3.0'
74+
75+
// Assertions
5976
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
60-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
77+
androidTestImplementation 'androidx.test.ext:truth:1.3.0'
78+
androidTestImplementation 'com.google.truth:truth:1.1.3'
6179

62-
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10'
63-
implementation 'androidx.appcompat:appcompat:1.2.0'
64-
implementation 'androidx.core:core-ktx:1.3.2'
65-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
66-
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
80+
// Kotlin
81+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32'
82+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
83+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
84+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.4.0'
85+
implementation 'androidx.core:core-ktx:1.5.0'
86+
implementation 'androidx.preference:preference-ktx:1.1.1'
87+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
6788

68-
implementation 'com.google.android.material:material:1.2.1'
89+
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
90+
91+
implementation 'androidx.appcompat:appcompat:1.3.0'
92+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
93+
implementation 'com.google.android.material:material:1.3.0'
6994

7095
implementation 'androidx.palette:palette-ktx:1.0.0'
7196
}

Diff for: app/src/main/AndroidManifest.xml

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="com.thewizrd.simplesleeptimer">
45

56
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
7+
<uses-permission android:name="android.permission.BLUETOOTH" />
8+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
69

7-
<permission
8-
android:name="${idPrefix}.permission.SLEEP_TIMER"
9-
android:protectionLevel="signature" />
10-
<uses-permission android:name="${idPrefix}.permission.SLEEP_TIMER" />
10+
<uses-permission
11+
android:name="android.permission.QUERY_ALL_PACKAGES"
12+
tools:ignore="QueryAllPackagesPermission" />
13+
14+
<uses-feature
15+
android:name="android.software.companion_device_setup"
16+
android:required="false" />
1117

1218
<application
1319
android:name=".App"
@@ -16,24 +22,42 @@
1622
android:label="@string/app_name"
1723
android:roundIcon="@mipmap/ic_launcher_round"
1824
android:supportsRtl="true"
19-
android:theme="@style/AppTheme.Launcher">
25+
android:theme="@style/AppTheme.Launcher"
26+
tools:ignore="GoogleAppIndexingWarning">
27+
2028
<activity android:name=".LaunchActivity">
2129
<intent-filter>
2230
<action android:name="android.intent.action.MAIN" />
2331
<category android:name="android.intent.category.LAUNCHER" />
2432
</intent-filter>
2533
</activity>
34+
2635
<activity
2736
android:name=".MainActivity"
2837
android:label="@string/title_sleeptimer"
29-
android:theme="@style/AppTheme"
30-
android:launchMode="singleTop" />
38+
android:theme="@style/AppTheme" />
39+
40+
<activity
41+
android:name=".wearable.WearPermissionsActivity"
42+
android:theme="@style/AppTheme.Toolbar" />
3143

3244
<service
3345
android:name=".services.TimerService"
34-
android:exported="true"
35-
android:enabled="true"
36-
android:permission="${idPrefix}.permission.SLEEP_TIMER" />
46+
android:exported="false"
47+
android:enabled="true" />
48+
49+
<service
50+
android:name=".wearable.WearableDataListenerService"
51+
android:enabled="true">
52+
<intent-filter>
53+
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
54+
55+
<data
56+
android:scheme="wear"
57+
android:host="*" />
58+
</intent-filter>
59+
</service>
60+
3761
</application>
3862

3963
</manifest>

Diff for: app/src/main/java/com/thewizrd/simplesleeptimer/App.kt

+23-33
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@ import android.content.Context
77
import android.os.Build
88
import android.os.Bundle
99
import androidx.appcompat.app.AppCompatDelegate
10+
import com.thewizrd.shared_resources.ApplicationLib
11+
import com.thewizrd.shared_resources.SimpleLibrary
12+
import com.thewizrd.shared_resources.helpers.AppState
1013

11-
class App : Application(), ActivityLifecycleCallbacks {
12-
private lateinit var context: Context
13-
private lateinit var applicationState: AppState
14-
private var mActivitiesStarted: Int = 0
15-
14+
class App : Application(), ApplicationLib, ActivityLifecycleCallbacks {
1615
companion object {
17-
private lateinit var instance: App
18-
fun getInstance(): App {
19-
return instance
20-
}
16+
@JvmStatic
17+
lateinit var instance: ApplicationLib
18+
private set
2119
}
2220

23-
fun getAppContext(): Context {
24-
return context
25-
}
21+
override lateinit var appContext: Context
22+
private set
23+
override lateinit var applicationState: AppState
24+
private set
25+
override val isPhone: Boolean = true
2626

27-
fun getAppState(): AppState {
28-
return applicationState
29-
}
27+
private var mActivitiesStarted: Int = 0
3028

3129
override fun onCreate() {
3230
super.onCreate()
33-
context = applicationContext
31+
appContext = applicationContext
3432
instance = this
35-
3633
registerActivityLifecycleCallbacks(this)
3734
applicationState = AppState.CLOSED
3835
mActivitiesStarted = 0
3936

37+
// Init shared library
38+
SimpleLibrary.initialize(this)
39+
4040
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
4141
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
4242
else
4343
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
4444
}
4545

4646
override fun onTerminate() {
47+
SimpleLibrary.unregister()
4748
super.onTerminate()
48-
unregisterActivityLifecycleCallbacks(this)
4949
}
5050

5151
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
@@ -57,28 +57,18 @@ class App : Application(), ActivityLifecycleCallbacks {
5757
}
5858

5959
override fun onActivityStarted(activity: Activity) {
60-
if (mActivitiesStarted == 0)
61-
applicationState = AppState.FOREGROUND
62-
60+
if (mActivitiesStarted == 0) applicationState = AppState.FOREGROUND
6361
mActivitiesStarted++
6462
}
6563

66-
override fun onActivityResumed(activity: Activity) {
67-
}
68-
69-
override fun onActivityPaused(activity: Activity) {
70-
}
71-
64+
override fun onActivityResumed(activity: Activity) {}
65+
override fun onActivityPaused(activity: Activity) {}
7266
override fun onActivityStopped(activity: Activity) {
7367
mActivitiesStarted--
74-
75-
if (mActivitiesStarted == 0)
76-
applicationState = AppState.BACKGROUND
77-
}
78-
79-
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
68+
if (mActivitiesStarted == 0) applicationState = AppState.BACKGROUND
8069
}
8170

71+
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
8272
override fun onActivityDestroyed(activity: Activity) {
8373
if (activity.localClassName.contains("MainActivity")) {
8474
applicationState = AppState.CLOSED

Diff for: app/src/main/java/com/thewizrd/simplesleeptimer/MainActivity.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.core.content.ContextCompat
99
import androidx.core.util.ObjectsCompat
1010
import androidx.core.view.ViewCompat
1111
import androidx.lifecycle.ViewModelProvider
12+
import androidx.localbroadcastmanager.content.LocalBroadcastManager
1213
import com.google.android.material.bottomsheet.BottomSheetBehavior
1314
import com.thewizrd.simplesleeptimer.databinding.ActivityMainBinding
1415
import com.thewizrd.simplesleeptimer.services.TimerService
@@ -138,9 +139,10 @@ class MainActivity : AppCompatActivity() {
138139
addAction(TimerService.ACTION_START_TIMER)
139140
addAction(TimerService.ACTION_CANCEL_TIMER)
140141
}
141-
registerReceiver(
142-
mBroadcastReceiver, filter
143-
)
142+
LocalBroadcastManager.getInstance(this)
143+
.registerReceiver(
144+
mBroadcastReceiver, filter
145+
)
144146
}
145147

146148
private fun showStartTimerFragment() {
@@ -170,7 +172,8 @@ class MainActivity : AppCompatActivity() {
170172
}
171173

172174
override fun onPause() {
173-
unregisterReceiver(mBroadcastReceiver)
175+
LocalBroadcastManager.getInstance(this)
176+
.unregisterReceiver(mBroadcastReceiver)
174177
super.onPause()
175178
}
176179

0 commit comments

Comments
 (0)