Monitoring Android Wear
I am using the official android watchdog API and I want to keep the screen for a couple of seconds during animation so that the screen does not go into ambient mode during animation and once the animation is over I want to reset everything back to normal, is that possible ? My class is extending CanvasWatchFaceService and I am also extending CanvasWatchFaceService.Engine So I want something similar to this, but for observation:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Then this:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON).
source to share
You need to explicitly lock the lock: http://developer.android.com/reference/android/os/PowerManager.WakeLock.html
Get a tracking lock that holds the screen and releases it when you're done animating.
Here is a doc on how to keep the device awake: https://developer.android.com/training/scheduling/wakelock.html
And here's an example:
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
"WatchFaceWakelockTag"); // note WakeLock spelling
wakeLock.acquire();
source to share
You can also use the setKeepScreenOn (true) method to enable the screen, let's say you have a (Root) RelativeLayout where your animation takes place:
private RelativeLayout rLayout;
In OnCreate (), get the desired layout:
final WatchViewStub stub = (WatchViewStub)
findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new
WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
// rLayout is the root layout where your animation takes place
rLayout = (RelativeLayout) stub. findViewById(R.id.your_layout); relativeLayout.setKeepScreenOn(true);
Then you can set the AnimationListener in your animation to setKeepScreenOn (false) again:
yourAnimation.setAnimationListener(new
Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if(animation.hasEnded())
rLayout.setKeepScreenOn(false);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
source to share