in a watch widget I am trying to make some scrolling.
it works but the refresh is slow and the scroll speed also !
what are the best way to do it.
in a watch widget I am trying to make some scrolling.
it works but the refresh is slow and the scroll speed also !
what are the best way to do it.
If you mean scrolling text horizontally, I've had ok results using a 50 ms update timer (which is the fastest timer possible), and scrolling by 2 pixels for every update. (This is on the lower-resolution MIP devices - on AMOLED devices, you may have to scroll by more 2 than pixels per update to get an acceptable scroll speed.)
Here's some example code and a video captured from the simulator:
Here's a video of a real device:
here are the main parts :
function onUpdate(dc) { //System.println("view hour onUpdate"); // Call the parent onUpdate function to redraw the layout View.onUpdate(dc); // clear the screen dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK); dc.clear(); // drawing ! dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT); //TODO: check scroll bug ? var tides = _tideData[5]["data"]; if (tides != null) { var y = _scrollpos; //System.println("elem : "+ tides.size()); for(var h = 0; h < tides.size(); h++) { // color for current hur y = drawHourly(dc,mWidth * 0.1 , y /* h *30 + _scrollpos /*64*/ , tides[h]); } } //System.println("view hour onUpdate - out"); }
and more elements :
function scrollup() { _scrollpos += 60; if (_scrollpos> 0) { // 24*80 ? _scrollpos = 0; } System.println("scroll : " + _scrollpos); WatchUi.requestUpdate(); } function scrolldown() { _scrollpos -= 60; if (_scrollpos< -1900) { _scrollpos = -1900; } System.println("scroll : " +_scrollpos); WatchUi.requestUpdate(); } // scroll down function onNextPage() { //System.println("openTideWidgetHourViewDelegate scroll down"); _view.scrolldown(); return true; }
hope this can help
This looks pretty optimized to me. A suggestion would be to define your `tides` variable somewhere other than onUpdate(), so that you don't have to keep retrieving the same value every time the user scrolls.
If the scroll is taking a long time, your drawHourly function must be doing some pretty time consuming things. Have you tried optimizing that?
How can I profile to optimisze it ?