[英]Android Wear not waking screen
我正在處理表盤及其啟動並運行,但是當我將其放在我的360上時,它對交互的響應會變慢。
我應該注意,當收到通知時,屏幕會喚醒,但當人們轉動手腕看時不會喚醒。
我要做的最后一件事是將代碼從doWork移到CountDownRunner中。 下面是我的代碼:
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Time;
import android.support.wearable.view.WatchViewStub;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Date;
public class ClockActivity extends Activity {
private TextView mTextView;
private Handler mHandler = new Handler();
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clock);
Runnable runnable = new CountDownRunner();
Thread myThread = new Thread(runnable);
myThread.start();
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
mTextView = (TextView) stub.findViewById(R.id.text);
}
});
}
class CountDownRunner implements Runnable{
public void run() {
while(!Thread.currentThread().isInterrupted()){
try {
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + ":" + minutes + ":" + seconds;
img=(ImageView)findViewById(R.id.hand_second);
RotateAnimation rotateAnimation = new RotateAnimation((seconds-1)*6, seconds*6,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
img.startAnimation(rotateAnimation);
runOnUiThread(new Runnable() {
public void run() {
try{
}catch (Exception e) {
}
}
});
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}catch(Exception e){
}
}
}
}
}
您不應實現Runnable
來更改可穿戴設備的時間。 使用BroadcastReceiver
( Intent.ACTION_TIME_TICK
, Intent.ACTION_TIMEZONE_CHANGED
, Intent.ACTION_TIME_CHANGED
),並在時間更改時收到“滴答聲”(消耗更少的電池電量和CPU)。
此外,您必須管理屏幕狀態(屏幕變暗,屏幕清醒等)。
這是適用於Android Wear的Watchface的一個很好的例子: http : //www.binpress.com/tutorial/how-to-create-a-custom-android-wear-watch-face/120
最后一條提示是,只有當可穿戴設備醒着時,才可以管理表面的秒數(例如,賣淫之后,但當可穿戴設備返回睡眠模式時必須殺死)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.