Skip to content

Instantly share code, notes, and snippets.

@degliwe
Last active February 17, 2017 15:01

Revisions

  1. degliwe revised this gist Jan 9, 2015. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
  2. degliwe revised this gist Dec 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 1_readme.md
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ public void onDraw(Canvas canvas, Rect bounds) {
    ```

    ##Conclusion
    I can already see many sues for this, like realistic lightning to make "classic" wtach face even more realistic and shiny, but also more abstract or experimental animated faces, like a spaceship hud...
    I can already see many use for this, like realistic lightning to make "classic" wtach face even more realistic and shiny, but also more abstract or experimental animated faces, like a spaceship hud...

    This is it, you are all set.
    I can't wait to see the great interactive watch faces you will make and the creative unexpected uses for this.
  3. degliwe revised this gist Dec 22, 2014. 3 changed files with 0 additions and 2 deletions.
    File renamed without changes
    2 changes: 0 additions & 2 deletions 2_readme.md → 1_readme.md
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,6 @@
    Since the early days of Android wear, I wanted to try to make more interactive faces.
    I think the various sensors offer a great opportunity to implement realistic light, giving more depth to your watch face.

    ![animated gif](https://gist.github.com/degliwe/cb115278fbb62065e76e/raw/e9b3c09895b1785615cae936e8d59f2a81ba6f6f/1_sensorface_anim.gif)

    In case you don't know what this is about, you can give it a try here from the sample I've uploaded to the playstore:
    https://play.google.com/store/apps/details?id=com.deglise.sensorface

    Binary file removed z_banner.png
    Binary file not shown.
  4. degliwe revised this gist Dec 22, 2014. 3 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 2_readme.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    Since the early days of Android wear, I wanted to try to make more interactive faces.
    I think the various sensors offer a great opportunity to implement realistic light, giving more depth to your watch face.


    ![animated gif](https://gist.github.com/degliwe/cb115278fbb62065e76e/raw/e9b3c09895b1785615cae936e8d59f2a81ba6f6f/1_sensorface_anim.gif)

    In case you don't know what this is about, you can give it a try here from the sample I've uploaded to the playstore:
    https://play.google.com/store/apps/details?id=com.deglise.sensorface
    File renamed without changes
    File renamed without changes
  5. degliwe revised this gist Dec 22, 2014. 3 changed files with 0 additions and 0 deletions.
    File renamed without changes
    File renamed without changes
    File renamed without changes.
  6. degliwe revised this gist Dec 22, 2014. 2 changed files with 0 additions and 0 deletions.
    Binary file added banner.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added sensorface_anim.gif
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  7. degliwe revised this gist Dec 22, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions anim.gif
    0 additions, 2 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  8. degliwe revised this gist Dec 22, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions anim.gif
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  9. degliwe created this gist Dec 22, 2014.
    92 changes: 92 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    #Add some depth to your WatchFace

    Since the early days of Android wear, I wanted to try to make more interactive faces.
    I think the various sensors offer a great opportunity to implement realistic light, giving more depth to your watch face.



    In case you don't know what this is about, you can give it a try here from the sample I've uploaded to the playstore:
    https://play.google.com/store/apps/details?id=com.deglise.sensorface


    ## Implement SensorEventListener

    The very first thing to do is to implement SensorEventListener, and then declare a SensorManager, sensorX and sensorY as described below.

    ```java
    private class Engine extends CanvasWatchFaceService.Engine implements SensorEventListener{

    SensorManager sensorMgr;
    float sensorX;
    float sensorY;

    ...
    }
    ```

    ## @Override
    Implementing SensorEventListener, requires you to provide onSensorChanged and onAccuracyChanged method as shown below.

    ```java
    @Override
    public void onSensorChanged(SensorEvent event) {

    // Reading raw value
    // todo smoothen things
    sensorX=event.values[0];
    sensorY=event.values[1];

    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    //You can keep it empty
    }
    ```

    ##Register & unregister sensor
    You want the sensor to be on as soon as your watchface is shown but you also don't want your face to lock the sensor when the screen is off or when another app may need the sensor...

    Then onVisibilityChanged seems the best place to achieve that.

    ```java
    @Override
    public void onVisibilityChanged(boolean visible) {
    super.onVisibilityChanged(visible);

    if (visible) {
    registerSensor();
    } else {
    unregisterSensor();
    }
    }

    private void unregisterSensor() {
    sensorMgr.unregisterListener(this);
    }

    private void registerSensor() {
    sensorMgr = (SensorManager) getSystemService(getBaseContext().SENSOR_SERVICE);
    sensorMgr.registerListener(this, sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
    }
    ```

    ##Time to draw!
    From the onDraw method, you can now, access the sensorX,sensorY to alter position of the element on the canvas.

    ```java
    @Override
    public void onDraw(Canvas canvas, Rect bounds) {
    // Draw digital minutes.
    canvas.drawText(minuteString, x+sensorX, mYOffset+sensorY, mShadowPaint);
    canvas.drawText(minuteString, x, mYOffset, mTimePaint);
    }
    ```

    ##Conclusion
    I can already see many sues for this, like realistic lightning to make "classic" wtach face even more realistic and shiny, but also more abstract or experimental animated faces, like a spaceship hud...

    This is it, you are all set.
    I can't wait to see the great interactive watch faces you will make and the creative unexpected uses for this.

    Feel free to share the result of your experiments with me.