繁体   English   中英

Android Wear无法唤醒屏幕

[英]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来更改可穿戴设备的时间。 使用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

最后一条提示是,只有当可穿戴设备醒着时,才可以管理表面的秒数(例如,卖淫之后,但当可穿戴设备返回睡眠模式时必须杀死)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM