Android Wear没有醒来屏幕

时间:2014-10-13 22:50:31

标签: java android wear-os

我在表盘上工作并且正在运行但是当我把它放在我的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){
            }
        }
    }
}

}

1 个答案:

答案 0 :(得分:1)

您不应该实施Runnable来更改可穿戴设备的时间。使用BroadcastReceiverIntent.ACTION_TIME_TICKIntent.ACTION_TIMEZONE_CHANGEDIntent.ACTION_TIME_CHANGED)并在时间变化时收到“勾选”(消耗更少的电池电量和CPU)。

此外,您必须管理屏幕状态(屏幕昏暗,屏幕清醒等)

以下是适用于Android Wear的Watchface的一个很好的例子:http://www.binpress.com/tutorial/how-to-create-a-custom-android-wear-watch-face/120

最后一个提示,只有当你的可穿戴设备处于清醒状态时,你才可以为你的表盘设置秒数(比如postdaleyed但你的可穿戴设备必须在你的可穿戴设备恢复睡眠模式时被杀死)。