With SCREEN_BRIGHT_WAKE_LOCK deprecated, how can I keep the screen on in Wear OS? - wear-os

For my Wear OS watch face project, I was using the flag SCREEN_BRIGHT_WAKE_LOCK to acquire a wakelock that keeps the screen fully on for one minute (triggered by the user as needed). This flag has been deprecated. The flag PARTIAL_WAKE_LOCK is still valid, but does not keep the screen on. What is the correct way to do this now?

I believe the watch controls this and it's usually a user setting to enable "Always on Display". Even in this mode, it's likely that the app also runs in ambient mode.
For Watchfaces, you can check the drawMode
https://github.com/android/wear-os-samples/blob/main/WatchFaceKotlin/app/src/main/java/com/example/android/wearable/alpha/AnalogWatchCanvasRenderer.kt#L221-L226
override fun render(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {
val backgroundColor = if (renderParameters.drawMode == DrawMode.AMBIENT) {
When it
For Apps
This AlwaysOnKotlin sample demonstrates how to support your app drawing in Ambient mode
It uses Ambient Mode

Related

NSImage does not Change for Light/Dark Appearances

I am developing a Mac Cocoa app. And I have a set of images to adopt for both light and dark modes.
I followed the instructions here: https://developer.apple.com/documentation/uikit/uiimage/providing_images_for_different_appearances
In viewWillLayout(), I set up an image for a view like so:
nsImgaeView.image = NSImage(named: "Image") // Does not change after toggling light/dark mode
ButNSImage(named: "Image") simply does not change its appearance after me toggling light/dark mode in System Preferences.
I am sure that the code was invoked because:
nsImgaeView.image = NSImage(named: "Another_Image") // Changes to another image after toggling
Restarting the app does make it change its appearance. I guess it is because the system caches the image after the initial load?

Aframe/Three/WebXR: disable device orientation in VR mode

I am using AFrame 1.2.0 to develop a VR application and I am struggling with an issue for several days.
My goal is to allow the user to see a specific view that is set programmatically and that is absolutely unrelated to the current device orientation. In other words, I should:
stop the user see the world based on its device orientation;
force the user to see a specific point (which I set programmatically);
These steps basically mean I should be able to:
disable the user-device rotation (UNRESOLVED for VR-Mode )
set the view to a specific position with a "refresh" rate (DONE)
As I wrote, the issue is related to the first point: disabling the user-device orientation and it only affects the VR mode. Indeed, everything works properly when the view is NOT in VR-Mode, but when entering in VR-Mode I can't do it anymore.
I tried managing these framework/library/APIs:
AFrame, look-controls: I know it is possible to disable look-controls with some properties (e.g. enabled, magicWindowTrackingEnabled, magicWindowControls): it works, but only when the view is NOT in VR-Mode; (note that hmdEnabled is no more in AFRAME from 0.8v because, as far as I understood, the introduction of WebXR does not allow to manage device directly from AFrame);
THREE.DeviceOrientationControls: I know that under the hood the look-controls component uses this THREE-element, so I debugged it and tried to manage it directly (e.g. calling disconnect, dispose, enabled=false): again, it works but only when the view is NOT in VR-Mode;
WebXR: at the lowest lever, WebXR is the last API used. I debugged it and I try to manage the WebXR session, but everything is in Read-Only mode and it seems there is no function to activate/deactivate device sensors.
So, here the question: how to disable the device orientation in VR mode with AFrame/THREE/WebXR or whatever?
Thank you all.

Oreo - View layout management has changed?

Don't flame me but prior to Oreo I used to put view in a static and keep it switching from fragments and it worked pretty well. In onCreate I simply check if the value of view is not null and in that case I was not inflating. It allowed me to do long task in a fragment in an async and switch to another fragment waiting for the async to complete.
It still works the same way with O except when I rotate the device. In that case I get a blank screen: no layout, no buttons, no text, etc.
I've read https://developer.android.com/about/versions/oreo/android-8.0-changes but didn't find anything.
Do you have an idea to fix this without changing it all?
From the way I understand it. if the Rotation is locked to portrait mode, rotating the device won't force it into landscape mode if portrait mode is locked.
Check out the following post:
android-p-feature-spotlight-rotation-can-temporarily-locked-landscape-changes
Just as annoying as Android Oreo, and unlike most OEM versions of Android I've used. There are new APIs for screen rotation in Android P so it's not clear whether apps need to implement it to be able to lock to landscape from the first go.
Also check out the Android P preview for more info regarding the rotation changes, for some reason it appears to be relevant for the Android Oreo as well.
Feature Overview
Behaviour Overview

Disable dark mode for mac OSX App in Swift

Is it possible to disable the dark mode for the mac app?
I only want it to show the default style of my app, even if the user uses dark mode on his mac.
I am using a popover.
Tried to use this: self.popover.appearance = NSAppearanceNameAqua but it tells me: cannot assign value of type String to type NSApperance.
You'll need initialize the name first:
popover.appearance = NSAppearance(named: NSAppearanceNameAqua)
You were close.
Edit for Swift 4.1:
popover?.appearance = NSAppearance(named: NSAppearance.Name.aqua)
You can disable support for dark mode in the Info.plist of your app:
Opt Out of Dark Mode
Apps linked against macOS 10.14 or later should
support both light and dark appearances. If you build your app against
an earlier SDK, you can still enable Dark Mode support by including
the NSRequiresAquaSystemAppearance key (with a value of false) in your
app's Info.plis file. Do so only if your app's appearance looks
correct when running in macOS 10.14 and later with Dark Mode enabled.
If you need extra time to work on your app's Dark Mode support, you
can temporarily opt out by including the
NSRequiresAquaSystemAppearance key (with a value of true) in your
app’s Info.plist file. Setting this key to true causes the system to
ignore the user's preference and always apply a light appearance to
your app.
Source: https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app
If you want to force complete dark mode everywhere in your app, you can force it by simply adding NSApp.appearance = NSAppearance(named: .darkAqua) to the AppDelegate method applicationDidFinishLaunching()
Code:
func applicationDidFinishLaunching() {
// Insert code here to initialize your application
NSApp.appearance = NSAppearance(named: .darkAqua)
}
This works for Swift 5.5.

MediaRecorder stops when screen is off

I have an application that use the media recorder with the microphone stream. Everything works fine to one exception. When I turn the display off, it stops recording and when I turn it back on it continue recording. It's as if it was pausing the stream until I unlock the phone again.
I'd like to be able to keep recording even when the display is off. I'm on firefoxOs 1.3.
It is possible to turn the screen off using the PowerManagement API.
First, it is possible to simply turn the screen off using this code:
navigator.mozPower.screenEnabled = false
This will turn the screen off and it also means that the screen will not be responsive to screen touches. I'm not certain to know yet how we can turn the screen on yet. It could be possible to watch for physical buttons event though.
The other way would be to turn the backlight off completely, it has the same effect but the touchscreen is still responding to touch events.
navigator.mozPower.screenBrightness = 0
The only problem is that you need to have access to the setting API to disable the screen.automatic-brightness setting if you want to make sure that the backlight won't constantly get modified.
var lock = navigator.mozSettings.createLock()
var req = lock.get('screen.automatic-brightness')
req.onsuccess = function () {
if (lock.result['screen.automatic-brightness']) {
lock.set({'screen.automatic-brightness': false})
navigator.mozPower.screenBrightness = 0
}
}
The big problem with this solution is that the application need to add two permissions: settings and power.
Honestly, this doesn't sounds terrible for a microphone application that can modify phone wide settings, it can also have access to power management and reboot or turnoff the phone and to a factoryreset. I guess, mozilla could work on better apis to reduce the permissions needed to achieve that. Also those APIs are only available for certified apps, which means that it's not possible to push such app on any market place.

Resources