Home | History | Annotate | Download | only in watch-faces
      1 page.title=Addressing Common Issues
      2 
      3 @jd:body
      4 
      5 <div id="tb-wrapper">
      6 <div id="tb">
      7 <h2>This lesson teaches you to</h2>
      8 <ol>
      9   <li><a href="#ScreenShape">Detect the Shape of the Screen</a></li>
     10   <li><a href="#PeekCards">Accomodate Peek Cards</a></li>
     11   <li><a href="#RelativeMeasurements">Use Relative Measurements</a></li>
     12 </ol>
     13 <h2>You should also read</h2>
     14 <ul>
     15   <li><a href="{@docRoot}design/wear/watchfaces.html">Watch Faces for Android Wear</a></li>
     16 </ul>
     17 </div>
     18 </div>
     19 
     20 <p>Creating a custom watch face for Android Wear is substantially different from creating
     21 notifications and wearable-specific activities. This class shows you how to resolve some
     22 issues that you may encounter as you implement your first few watch faces.</p>
     23 
     24 
     25 
     26 <h2 id="ScreenShape">Detect the Shape of the Screen</h2>
     27 
     28 <p>Some Android Wear devices have square screens, while others have round screens. Devices with
     29 round screens can contain an inset (or "chin") at the bottom of the screen. Your watch face
     30 should adapt to and take advantage of the particular shape of the screen, as described in the
     31 <a href="{@docRoot}design/wear/watchfaces.html">design guidelines</a>.</p>
     32 
     33 <p>Android Wear lets your watch face determine the screen shape at runtime. To detect whether
     34 the screen is square or round, override the <code>onApplyWindowInsets()</code> method in the
     35 <code>CanvasWatchFaceService.Engine</code> class as follows:</p>
     36 
     37 <pre>
     38 private class Engine extends CanvasWatchFaceService.Engine {
     39     boolean mIsRound;
     40     int mChinSize;
     41 
     42     &#64;Override
     43     public void onApplyWindowInsets(WindowInsets insets) {
     44         super.onApplyWindowInsets(insets);
     45         mIsRound = insets.isRound();
     46         mChinSize = insets.getSystemWindowInsetBottom();
     47     }
     48     ...
     49 }
     50 </pre>
     51 
     52 <p>To adapt your design when you draw your watch face, check the value of the
     53 <code>mIsRound</code> and <code>mChinSize</code> member variables.</p>
     54 
     55 
     56 
     57 <h2 id="PeekCards">Accomodate Peek Cards</h2>
     58 
     59 <div style="float:right;margin-left:30px;width:340px">
     60 <img src="{@docRoot}training/wearables/watch-faces/images/AnalogNoCard.png" alt=""
     61      width="160" height="145" style="margin-right:7px"/>
     62 <img src="{@docRoot}training/wearables/watch-faces/images/AnalogWithCard.png" alt=""
     63      width="160" height="145"/>
     64 <p class="img-caption"><strong>Figure 1.</strong> Some analog watch faces require adjustments
     65 when notification cards appear.</p>
     66 </div>
     67 
     68 <p>When users receive a notification, the notification card may cover a significant portion of the
     69 screen, depending on the
     70 <a href="{@docRoot}training/wearables/watch-faces/drawing.html#SystemUI">system UI style</a>. Your
     71 watch face should adapt to these situations by ensuring that users can still tell the time while
     72 the notification card is present.</p>
     73 
     74 <p>Analog watch faces can make adjustments when a notification card is present, like scaling
     75 down the watch face to fit inside the portion of the screen not covered by the peek card. Digital
     76 watch faces that display the time in the area of the screen not covered by peek cards do not
     77 usually require adjustments. To determine the free space above the peek card so you can adapt
     78 your watch face, use the <code>WatchFaceService.getPeekCardPosition()</code> method.</p>
     79 
     80 <p>In ambient mode, peek cards have a transparent background. If your watch face contains details
     81 near the card in ambient mode, consider drawing a black rectangle over them to ensure that users
     82 can read the contents of the card.</p>
     83 
     84 
     85 
     86 <h2 id="SystemIndicators">Configure the System Indicators</h2>
     87 
     88 <div style="width:200px;float:right;margin-left:10px">
     89 <img src="{@docRoot}training/wearables/watch-faces/images/Indicators_Cropped.png" alt=""
     90      width="200" height="195"/>
     91 <p class="img-caption" style="margin-left:25px;margin-top:-25px">
     92 <strong>Figure 2.</strong> The status bar.</p>
     93 </div>
     94 
     95 <p>To ensure that the system indicators remain visible, you can configure their position on the
     96 screen and whether they need background protection when you create a <code>WatchFaceStyle</code>
     97 instance:</p>
     98 
     99 <ul>
    100 <li>To set the position of the status bar, use the <code>setStatusBarGravity()</code> method.</li>
    101 <li>To set the position of the hotword, use the <code>setHotwordIndicatorGravity()</code>
    102 method.</li>
    103 <li>To protect the status bar and hotword with a semi-transparent gray background, use the
    104 <code>setViewProtection()</code> method. This is usually necessary if your watch face has a
    105 light background, since the system indicators are white.</li>
    106 </ul>
    107 
    108 <p>For more information about the system indicators, see <a
    109 href="{@docRoot}training/wearables/watch-faces/drawing.html#SystemUI">Configure the System UI</a>
    110 and read the <a href="{@docRoot}design/wear/watchfaces.html">design guidelines</a>.</p>
    111 
    112 
    113 
    114 <h2 id="RelativeMeasurements">Use Relative Measurements</h2>
    115 
    116 <p>Android Wear devices from different manufacturers feature screens with a variety of sizes and
    117 resolutions. Your watch face should adapt to these variations by using relative measurements
    118 instead of absolute pixel values.</p>
    119 
    120 <p>When you draw your watch face, obtain the size of the canvas with the {@link
    121 android.graphics.Canvas#getWidth Canvas.getWidth()} and {@link
    122 android.graphics.Canvas#getHeight Canvas.getHeight()} methods and set the positions of your
    123 graphic elements using values that are some fraction of the detected screen size. If you resize
    124 the elements of your watch face in response to a peek card, use values that are some fraction
    125 of the remaining space above the card to redraw your watch face.</p>
    126