Android watch second hand

I am new to Android development and I was wondering if it is possible to add a “second hand” to the default analog clock in Android?

I already have working hours with hours, minutes and minutes. I searched around and I came across some reports that you need a service running in the background to update the clock every second. This was for the clock widget, albeit a mine for the app.

Can this be done?

+3
source share
4 answers

Here's how to do it: http://developer.android.com/resources/articles/timed-ui-updates.html

Warning: doing this will drain the battery very quickly!

+1
source

, ? , , .

0

yes you can put a second bet on the analog Android watch that I made that in my application, please see how this will help you if you find any error here than a comment. here is the link you can find it here in the link

0
source
private ImageView img;
 Handler mHandler;

 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  Thread myThread = null;

  Runnable runnable = new CountDownRunner();
  myThread = new Thread(runnable);
  myThread.start();

 }

 public void doRotate() {

  runOnUiThread(new Runnable() {
   public void run() {
    try {

     Date dt = new Date();
     int hours = dt.getHours();
     int minutes = dt.getMinutes();
     int seconds = dt.getSeconds();
     String curTime = hours + ":" + minutes + "::" + seconds;
     Log.v("log_tag", "Log is here Time is now" + curTime);
     img = (ImageView) findViewById(R.id.imgsecond);
     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);
    } catch (Exception e) {

    }
   }
  });
 }

 class CountDownRunner implements Runnable {
  // @Override
  public void run() {
   while (!Thread.currentThread().isInterrupted()) {
    try {

     doRotate();
     Thread.sleep(1000);
    } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
    } catch (Exception e) {
     Log.e("log_tag", "Error is " + e.toString());
    }
   }
  }
 }
0
source

Source: https://habr.com/ru/post/1786471/


All Articles