问题描述
我工作的一个表盘和运行起来,但是当我把我的360就变得缓慢,到互动回应。
我要指出,当收到通知,但不是当一个人变成自己的手腕看时间,屏幕唤醒。
最后一件事我所做的就是移动code OUT的doWork,进入CountDownRunner。下面是我的code:
进口android.app.Activity;
进口android.os.Bundle;
进口android.os.Handler;
进口android.text.format.Time;
进口android.support.wearable.view.WatchViewStub;
进口android.view.animation.Animation;
进口android.view.animation.LinearInterpolator;
进口android.view.animation.RotateAnimation;
进口android.widget.ImageView;
进口android.widget.TextView;
进口java.util.Date;公共类ClockActivity延伸活动{私人TextView的mTextView;
私人处理程序mHandler =新的处理程序();
私人ImageView的IMG;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_clock); 可运行的可运行=新CountDownRunner();
线程MyThread的=新主题(可运行);
myThread.start(); 最后WatchViewStub存根=(WatchViewStub)findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(新WatchViewStub.OnLayoutInflatedListener(){
@覆盖
公共无效onLayoutInflated(WatchViewStub存根){
mTextView =(TextView中)stub.findViewById(R.id.text);
}
});
}类CountDownRunner实现Runnable {
公共无效的run(){
而(!Thread.currentThread()。isInterrupted()){
尝试{
日期DT =新的日期();
INT小时= dt.getHours();
INT分钟= dt.getMinutes();
INT秒= dt.getSeconds();
串CURTIME =小时+:+分钟+:+秒; IMG =(ImageView的)findViewById(R.id.hand_second);
RotateAnimation rotateAnimation =新RotateAnimation((秒-1)* 6,秒* 6,
Animation.RELATIVE_TO_SELF,0.5F,Animation.RELATIVE_TO_SELF,
0.5F); rotateAnimation.setInterpolator(新LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(真); img.startAnimation(rotateAnimation);
runOnUiThread(新的Runnable(){
公共无效的run(){
尝试{ }赶上(例外五){ }
}
});
视频下载(1000);
}赶上(InterruptedException的E){
Thread.currentThread()中断()。
}赶上(例外五){
}
}
}
}}
您不应该实施的Runnable
来改变时间的耐磨。使用广播接收器
( Intent.ACTION_TIME_TICK
, Intent.ACTION_TIMEZONE_CHANGED
, Intent.ACTION_TIME_CHANGED
),并收到滴答时,时间的变化(消耗更少的电池电源和CPU)。
此外,你必须管理的屏幕状态(屏幕变暗,屏幕醒等)
下面是表盘的Android Wear的伟大为例:的
和最后的提示,你可以只有当你的耐磨醒(如postdaleyed但是当你的耐磨回去睡觉模式必须被杀死),管理您的表盘秒。
I'm working on a watch face and its up and running but when I put it on my 360 it becomes slow to respond to interactions.
I should note that the screen wakes when a notification is received but not when one turns their wrist to look at the time.
Last thing I did was move code out of doWork and into CountDownRunner. Below is my code:
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){
}
}
}
}
}
You should not implement Runnable
to change time on your wearable. Use BroadcastReceiver
(Intent.ACTION_TIME_TICK
, Intent.ACTION_TIMEZONE_CHANGED
, Intent.ACTION_TIME_CHANGED
) and receive a "tick" when time change (consumes less battery power and CPU).
Moreover, you must managed screen states (screen dim, screen awake, etc.)
Here is a great exemple of Watchface for Android Wear: http://www.binpress.com/tutorial/how-to-create-a-custom-android-wear-watch-face/120
And a last tips, you can manage seconds for your watchface only when your wearable is awake (like postdaleyed but must be killed when your wearable go back to sleep mode).
这篇关于Android Wear的不清醒屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!