Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's new in Android Wear 2.0

What's new in Android Wear 2.0

This deck is showing some of the new features introduced with the version 2.0 of Android Wear, including:
- new notifications design and user interactions
- standalone wearable applications
- new UI elements
- Complications API

danybony

April 06, 2017
Tweet

More Decks by danybony

Other Decks in Programming

Transcript

  1. Notifications Wear 1.x Wear 2.0 Large icon Content Text Content

    Title Small Icon http://developer.android.com/wear
  2. Stand-alone apps android { publishNonDefault true ... productFlavors { wear1

    { minSdkVersion 23 } wear2 { minSdkVersion 25 } } }
  3. Linear scroll public class CircularChildLayoutManager extends CurvedChildLayoutManager {
 
 //

    ...
 
 @Override
 public void updateChild(View child, WearableRecyclerView parent) {
 super.updateChild(child, parent);
 
 child.setScaleX(...);
 child.setScaleY(...);
 }
 }
  4. Multi-function Buttons @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (event.getRepeatCount() == 0) { if (keyCode == KeyEvent.KEYCODE_STEM_1) {
 // Do stuff return true;
 } } return super.onKeyDown(keyCode, event);
 }
  5. Rotatory input public class CustomView extends View { // ...

    @Override
 public boolean onGenericMotionEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_SCROLL && RotaryEncoder.isFromRotaryEncoder(event)) { float delta = -RotaryEncoder.getRotaryAxisValue(event) * RotaryEncoder.getScaledScrollFactor(getContext());
 // Update view depending on delta return true; } return super.onGenericMotionEvent(event);
 } // ... }
  6. AndroidManifest.xml <service android:name=".CustomComplicationProviderService"
 android:label="@string/complications_provider_label"
 android:icon=“@drawable/complications_provider_icon" android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">
 
 <intent-filter>
 <action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"/>


    </intent-filter>
 
 <meta-data android:name="android.support.wearable.complications.SUPPORTED_TYPES"
 android:value=“SHORT_TEXT, ICON"/>
 
 <meta-data android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
 android:value=“360"/> 
 </service>
  7. CustomComplicationProviderService @Override public void onComplicationActivated( int complicationId, int dataType, ComplicationManager

    manager) { ... }
 @Override
 public void onComplicationUpdate( int complicationId, int dataType, ComplicationManager manager) { ... }
 @Override
 public void onComplicationDeactivated( int complicationId) { ... }
  8. CustomComplicationProviderService @Override public void onComplicationUpdate( int complicationId, int dataType, ComplicationManager

    manager) { if (dataType == ComplicationData.TYPE_SHORT_TEXT) {
 ComplicationData data = new ComplicationData.Builder(dataType)
 .setShortText(ComplicationText.plainText(“Hello!”))
 .setIcon(Icon.createWithResource( getPackageName(), R.drawable.action_item_background))
 .build(); 
 manager.updateComplicationData(complicationId, data);
 } }

  9. complication id = 1 Ranged value Short text Icon complication

    id = 3 Ranged value Long text Short text Icon complication id = 2 Ranged value Short text Icon
  10. WatchFaceConfigActivity Intent intent = ComplicationHelperActivity.createProviderChooserHelperIntent( context,
 watchFaceComponentName,
 complicationId,
 ComplicationData.TYPE_RANGED_VALUE,
 ComplicationData.TYPE_SHORT_TEXT,


    ComplicationData.TYPE_ICON
 );
 
 startActivityForResult(intent, REQUEST_CODE); com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA
 Requires permission:
  11. ComplicationWatchFaceService.Engine @Override
 public void onCreate(SurfaceHolder holder) { ...
 setActiveComplications(LEFT_DIAL_COMPLICATION, RIGHT_DIAL_COMPLICATION);

    }
 
 @Override
 public void onComplicationDataUpdate(
 int complicationId, ComplicationData complicationData) {
 // store the data to display it
 }
  12. ComplicationWatchFaceService.Engine @Override
 public void onDraw(Canvas canvas, Rect bounds) { ...

    if (complicationData.isActive(currentTimeMillis)) {
 // draw the complication
 } ...
 }
  13. ComplicationWatchFaceService.Engine @Override
 public void onTapCommand(int tapType, int x, int y,

    long eventTime) {
 
 ...
 // get the complication data related to the tapped placeholder
 ... 
 if (complicationData.getTapAction() != null) {
 try {
 complicationData.getTapAction().send();
 } catch (PendingIntent.CanceledException e) {
 Log.d(TAG, "On complication tap action error " + e);
 }
 }
 }
  14. More info Building Apps for Wearables https://developer.android.com/training/building-wearables.html Android Wear design

    specs https://www.google.com/design/spec-wear/android-wear/ introduction.html