WatchFace VivoActive

Former Member
Former Member
Hi,

I started creating watchfaces today. I read a lot and start to create my own simple watchface. Now I have a problem. The activity bar won't be drawn. Nearly the same code I used for my battery bar which works fine.

<snip>
var activity = ActivityMonitor.getInfo();
var actStat = (activity.steps/activity.stepGoal)*100;
var actBar = (dc.getWidth()/100)*actStat;
var ActPosY = (dc.getHeight()-3);
dc.setColor(Gfx.COLOR_RED,Gfx.COLOR_WHITE);
dc.drawRectangle(0,ActPosY,actBar,3);
dc.fillRectangle(0,ActPosY,actBar,3);
<snip>


The activity bar I want to create on the bottum of the screen won't be drawed. Some Ideas?



Sorry about my english.

Best regards
Ronny
  • Hi,

    I started creating watchfaces today. I read a lot and start to create my own simple watchface. Now I have a problem. The activity bar won't be drawn. Nearly the same code I used for my battery bar which works fine.

    <snip>
    var activity = ActivityMonitor.getInfo();
    var actStat = (activity.steps/activity.stepGoal)*100;
    var actBar = (dc.getWidth()/100)*actStat;
    var ActPosY = (dc.getHeight()-3);
    dc.setColor(Gfx.COLOR_RED,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    <snip>


    use this for the second line. You basically dealing with ints here so steps/goal will be 0 or 1, and *100 would be 0 or 100 (or more), and nothing else

    var actStat = (activity.steps*100)/activity.stepGoal;
    (this will give you 0 to 100 - or more)

    (consider that steps can be higher than goal, so you'll get more than 100%, unlike battery, where the max is 100%, so you may want to make the bar smarter to handle "over goal" progress..)
  • Former Member
    Former Member over 10 years ago
    use this for the second line. You basically dealing with ints here so steps/goal will be 0 or 1, and *100 would be 0 or 100 (or more), and nothing else

    var actStat = (activity.steps/*100)/activity.stepGoal;
    (this will give you 0 to 100 - or more)

    (consider that steps can be higher than goal, so you'll get more than 100%, unlike battery, where the max is 100%)


    Hi,

    thanks, works great! (after deleting / ) think it was just a careless mistake :)

    var actStat = (activity.steps*100)/activity.stepGoal;
  • The extra slash was a typo on my part. Fixed that in the reply and added a note about being at more than 100% of the step goal.

    Say you are at 200% of goal - you'll be drawing off the screen, and not able to show it's over 100%.
  • Former Member
    Former Member over 10 years ago
    Thx for your response. What is best practive in the case of over 100 percentage? I now draw different coloured rectangles if some goals are reached. I could set the width of the rectangle to dc.getWidth() in case of 100% or more..

    // // Activity Status Bar \\ \\
    // Get the current activity stats
    var activity = ActivityMonitor.getInfo();
    var actStat = (activity.steps*100)/activity.stepGoal;
    var actBar = (dc.getWidth()/100)*actStat;
    var ActPosY = (dc.getHeight()-3);
    //set color for second bar and draw it

    if (actStat<30)
    {
    dc.setColor(Gfx.COLOR_DK_RED,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    }
    else if (actStat <=40)
    {
    dc.setColor(Gfx.COLOR_RED,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    }
    else if (actStat <=50)
    {
    dc.setColor(Gfx.COLOR_ORANGE,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    }
    else if (actStat <=60)
    {
    dc.setColor(Gfx.COLOR_YELLOW,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    }
    else if (actStat <=75)
    {
    dc.setColor(Gfx.COLOR_GREEN,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    }
    else if (actStat <100)
    {
    dc.setColor(Gfx.COLOR_DK_GREEN,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,actBar,3);
    dc.fillRectangle(0,ActPosY,actBar,3);
    }
    else
    {
    dc.setColor(Gfx.COLOR_DK_GREEN,Gfx.COLOR_WHITE);
    dc.drawRectangle(0,ActPosY,dc.getWidth(),3);
    dc.fillRectangle(0,ActPosY,dc.getWidth(),3);
    }



    Works fine for the moment.

    Greetings
  • Former Member
    Former Member over 10 years ago
    Hi,

    next problem -the time in the simulators shows correct minutes as it is given in the code:

    var clockTime = Sys.getClockTime();
    var timeString = Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%.2d")]);


    that means 9:01 will be shown for 9 o'clock and one minute. in the simulator it works but on my vivoactive it doesn't.



    Any Ideas?
    Greets
  • Hi,

    next problem -the time in the simulators shows correct minutes as it is given in the code:

    var clockTime = Sys.getClockTime();
    var timeString = Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%.2d")]);


    that means 9:01 will be shown for 9 o'clock and one minute. in the simulator it works but on my vivoactive it doesn't.



    Any Ideas?
    Greets


    U need to for at it wit 0.2d. U missing the zero
  • U need to for at it wit 0.2d. U missing the zero


    Close. You need "%02d" to be correct everywhere.