Skip to content

Commit

Permalink
* new Flashlight complication
Browse files Browse the repository at this point in the history
* World Clock / UTC renamed to World Clock 1 - uses Timezone 1 ID
* World Clock 2 - uses Timezone 2 ID
* Gradle version 7.4.1
  • Loading branch information
amoledwatchfaces committed Feb 11, 2023
1 parent e3ec8ab commit 58e7393
Show file tree
Hide file tree
Showing 28 changed files with 377 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}

Expand Down
1 change: 1 addition & 0 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
namespace 'com.weartools.weekdayutccomp'
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.weartools.weekdayutccomp"
android:versionCode="1"
android:versionName="1.0">

Expand Down
1 change: 1 addition & 0 deletions wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ android {
buildFeatures {
viewBinding true
}
namespace 'com.weartools.weekdayutccomp'
}

dependencies {
Expand Down
24 changes: 22 additions & 2 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.weartools.weekdayutccomp">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
Expand Down Expand Up @@ -229,5 +228,26 @@
android:value="SHORT_TEXT,ICON,SMALL_IMAGE,RANGED_VALUE" />
</service>


<activity
android:name=".FlashlightActivity"
android:exported="true">
</activity>

<service
android:name="com.weartools.weekdayutccomp.FlashlightComplicationService"
android:exported="true"
android:icon="@drawable/ic_flashlight"
android:label="@string/flashlight_comp_name"
android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">
<intent-filter>
<action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST" />
</intent-filter>

<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="ICON,SMALL_IMAGE" />
</service>

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.weartools.weekdayutccomp

import android.app.Activity
import android.os.Bundle
import android.view.WindowManager
import com.weartools.weekdayutccomp.databinding.FlashlightBinding


class FlashlightActivity : Activity() {

private lateinit var binding: FlashlightBinding
private var flashlightstate: Int = 1

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = FlashlightBinding.inflate(layoutInflater)
setContentView(binding.root)

val lp: WindowManager.LayoutParams = this@FlashlightActivity.window.attributes
val brightness = 1.0f
lp.screenBrightness = brightness
this@FlashlightActivity.window.attributes = lp
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
flashlightstate = 1

binding.flashlightContainer.setOnClickListener {
changeImage()
}
}

override fun onResume() {
super.onResume()
when (flashlightstate) {
3 -> {
val lp: WindowManager.LayoutParams = this@FlashlightActivity.window.attributes
val brightness = 1.0f
lp.screenBrightness = brightness
this@FlashlightActivity.window.attributes = lp
binding.flashlightContainer.setBackgroundResource(R.drawable.bg_white)
binding.flashlightImage.setImageResource(R.drawable.ic_flashlight_on_1)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // Keep screen -> ON
flashlightstate = 1
}
}

}

private fun changeImage() {
when (flashlightstate) {
1 -> {
binding.flashlightContainer.setBackgroundResource(R.drawable.bg_red)
binding.flashlightImage.setImageResource(R.drawable.ic_flashlight_on_2)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // Keep screen -> ON
flashlightstate = 2
}
2 -> {
val lp: WindowManager.LayoutParams = this@FlashlightActivity.window.attributes
val brightness = 0.2f
lp.screenBrightness = brightness
this@FlashlightActivity.window.attributes = lp
binding.flashlightContainer.setBackgroundResource(R.drawable.bg_black)
binding.flashlightImage.setImageResource(R.drawable.ic_flashlight_off)
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // Keep screen -> OFF
flashlightstate = 3
}
else -> {
val lp: WindowManager.LayoutParams = this@FlashlightActivity.window.attributes
val brightness = 1.0f
lp.screenBrightness = brightness
this@FlashlightActivity.window.attributes = lp
binding.flashlightContainer.setBackgroundResource(R.drawable.bg_white)
binding.flashlightImage.setImageResource(R.drawable.ic_flashlight_on_1)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // Keep screen -> ON
flashlightstate = 1
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright 2022 amoledwatchfaces™
* [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.weartools.weekdayutccomp

import android.app.PendingIntent
import android.content.Intent
import android.graphics.drawable.Icon.createWithResource
import android.util.Log
import androidx.wear.watchface.complications.data.*
import androidx.wear.watchface.complications.datasource.ComplicationRequest
import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService
import com.weartools.weekdayutccomp.R.drawable

class FlashlightComplicationService : SuspendingComplicationDataSourceService() {

override fun onComplicationActivated(
complicationInstanceId: Int,
type: ComplicationType
) {
Log.d(TAG, "onComplicationActivated(): $complicationInstanceId")
}

private fun openScreen(): PendingIntent? {

val intent = Intent(this, FlashlightActivity::class.java)
//
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

return PendingIntent.getActivity(
this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE

)
}

override fun getPreviewData(type: ComplicationType): ComplicationData? {
return when (type) {
ComplicationType.MONOCHROMATIC_IMAGE -> MonochromaticImageComplicationData.Builder(
monochromaticImage = MonochromaticImage.Builder(
createWithResource(this, drawable.ic_flashlight)
)
.setAmbientImage(createWithResource(this, drawable.ic_flashlight))
.build(),
contentDescription = PlainComplicationText.Builder(text = "Flashlight").build()
)
.setTapAction(null)
.build()
ComplicationType.SMALL_IMAGE -> SmallImageComplicationData.Builder(
smallImage = SmallImage.Builder(
image = createWithResource(this, drawable.ic_flashlight),
type = SmallImageType.ICON
).build(),
contentDescription = PlainComplicationText.Builder(text = "Flashlight").build()
)
.setTapAction(null)
.build()
else -> {null}
}
}

override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
Log.d(TAG, "onComplicationRequest() id: ${request.complicationInstanceId}")

return when (request.complicationType) {

ComplicationType.MONOCHROMATIC_IMAGE -> MonochromaticImageComplicationData.Builder(
monochromaticImage = MonochromaticImage.Builder(
createWithResource(this, drawable.ic_flashlight)
)
.setAmbientImage(createWithResource(this, drawable.ic_flashlight))
.build(),
contentDescription = PlainComplicationText.Builder(text = "Flashlight").build()
)
.setTapAction(openScreen())
.build()


ComplicationType.SMALL_IMAGE -> SmallImageComplicationData.Builder(
smallImage = SmallImage.Builder(
image = createWithResource(this, drawable.ic_flashlight),
type = SmallImageType.ICON
).build(),
contentDescription = PlainComplicationText.Builder(text = "Flashlight").build()
)
.setTapAction(openScreen())
.build()

else -> {
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Unexpected complication type ${request.complicationType}")
}
null
}

}
}

override fun onComplicationDeactivated(complicationInstanceId: Int) {
Log.d(TAG, "onComplicationDeactivated(): $complicationInstanceId")
}

companion object {
private const val TAG = "FlashlightComplication"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.weartools.weekdayutccomp

import android.app.PendingIntent
import android.content.Intent
import android.icu.util.TimeZone
import android.util.Log
import androidx.preference.PreferenceManager
Expand All @@ -36,7 +37,8 @@ class UTC2ComplicationService : SuspendingComplicationDataSourceService() {

private fun openScreen(): PendingIntent? {

val intent = packageManager.getLaunchIntentForPackage("com.weartools.weekdayutccomp")
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

return PendingIntent.getActivity(
this, 0, intent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.weartools.weekdayutccomp

import android.app.PendingIntent
import android.content.Intent
import android.icu.util.TimeZone
import android.util.Log
import androidx.preference.PreferenceManager
Expand All @@ -35,7 +36,8 @@ class UTCComplicationService : SuspendingComplicationDataSourceService() {

private fun openScreen(): PendingIntent? {

val intent = packageManager.getLaunchIntentForPackage("com.weartools.weekdayutccomp")
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

return PendingIntent.getActivity(
this, 0, intent,
Expand Down
3 changes: 3 additions & 0 deletions wear/src/main/res/drawable/bg_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<color android:color="#000"
xmlns:android="http://schemas.android.com/apk/res/android" />
11 changes: 11 additions & 0 deletions wear/src/main/res/drawable/bg_red.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="192.0dip"
android:width="192.0dip"
android:viewportWidth="192.0"
android:viewportHeight="192.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@drawable/bg_red_0"
android:pathData="M96,192a96,96 0,1 0,0 -192a96,96 0,1 0,0 192z" />
</vector>
11 changes: 11 additions & 0 deletions wear/src/main/res/drawable/bg_red_0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<gradient
android:type="radial"
android:centerX="96.0"
android:centerY="96.0"
android:gradientRadius="96.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FF0000" android:offset="0.0" />
<item android:color="#FF0000" android:offset="0.874762" />
<item android:color="#00FF0000" android:offset="1.0" />
</gradient>
11 changes: 11 additions & 0 deletions wear/src/main/res/drawable/bg_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="192.0dip"
android:width="192.0dip"
android:viewportWidth="192.0"
android:viewportHeight="192.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@drawable/bg_white_0"
android:pathData="M96,192a96,96 0,1 0,0 -192a96,96 0,1 0,0 192z" />
</vector>
11 changes: 11 additions & 0 deletions wear/src/main/res/drawable/bg_white_0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<gradient
android:type="radial"
android:centerX="96.0"
android:centerY="96.0"
android:gradientRadius="96.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#fff" android:offset="0.0" />
<item android:color="#fff" android:offset="0.874762" />
<item android:color="#00FFFFFF" android:offset="1.0" />
</gradient>
11 changes: 11 additions & 0 deletions wear/src/main/res/drawable/ic_flashlight.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:tint="#fff"
android:height="32.0dip"
android:width="32.0dip"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#fff" android:pathData="M18,2L6,2v6l2,3v11h8L16,11l2,-3L18,2zM16,4v1L8,5L8,4h8zM14,10.4L14,20h-4v-9.61l-2,-3L8,7h8v0.39l-2,3.01z" />
<path android:fillColor="#fff" android:pathData="M12,14m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0" />
</vector>
10 changes: 10 additions & 0 deletions wear/src/main/res/drawable/ic_flashlight_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:tint="#fff"
android:height="32.0dip"
android:width="32.0dip"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#fff" android:pathData="M21.19,21.19L2.81,2.81 1.39,4.22 8,10.83L8,22h8v-3.17l3.78,3.78 1.41,-1.42zM14,20h-4v-7.17l4,4L14,20zM16,7v0.39l-2,3v0.78l2,2L16,11l2,-3L18,2L6,2v1.17L9.83,7L16,7zM8,4h8v1L8,5L8,4zM10.5,14c0,-0.2 0.04,-0.39 0.11,-0.56l1.95,1.95c-0.17,0.07 -0.36,0.11 -0.56,0.11 -0.83,0 -1.5,-0.67 -1.5,-1.5z" />
</vector>
Loading

0 comments on commit 58e7393

Please sign in to comment.