我四处搜寻并寻找一种检测手表调光的方法。我想写一些代码来在屏幕变暗时更改自定义表面颜色。我怎么能这样做?
答案 0 :(得分:2)
我正在使用这个抽象的Activity来检测手表变暗(实现DisplayManager.DisplayListener)。
public abstract class WatchFaceActivity extends Activity implements DisplayManager.DisplayListener {
private DisplayManager displayManager;
public abstract void onScreenDim();
public abstract void onScreenAwake();
public void onWatchFaceRemoved() {
}
public void onScreenOff() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
displayManager.registerDisplayListener(this, null);
}
@Override
protected void onDestroy() {
super.onDestroy();
displayManager.unregisterDisplayListener(this);
}
@Override
public void onDisplayRemoved(int displayId) {
onWatchFaceRemoved();
}
@Override
public void onDisplayAdded(int displayId) {
}
@Override
public void onDisplayChanged(int displayId) {
switch (displayManager.getDisplay(displayId).getState()) {
case Display.STATE_DOZING:
onScreenDim();
break;
case Display.STATE_OFF:
onScreenOff();
break;
default:
onScreenAwake();
break;
}
}}
此处有更多信息:http://www.binpress.com/tutorial/how-to-create-a-custom-android-wear-watch-face/120