1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.example.android.wearable.datalayer; 17 18 import android.graphics.Bitmap; 19 20 import androidx.recyclerview.widget.RecyclerView.ViewHolder; 21 22 /** 23 * Classes representing data used for each custom {@link ViewHolder} in {@link 24 * CustomRecyclerAdapter}. 25 */ 26 public class DataLayerScreen { 27 28 public static final int TYPE_IMAGE_ASSET = 0; 29 public static final int TYPE_EVENT_LOGGING = 1; 30 public static final int TYPE_CAPABILITY_DISCOVERY = 2; 31 32 /** 33 * All classes representing data for {@link ViewHolder} must implement this interface so {@link 34 * CustomRecyclerAdapter} knows what type of {@link ViewHolder} to inflate. 35 */ 36 public interface DataLayerScreenData { getType()37 int getType(); 38 } 39 40 /** 41 * Represents {@link Bitmap} passed to Wear device via {@link 42 * com.google.android.gms.wearable.Asset} data layer API. 43 */ 44 public static class ImageAssetData implements DataLayerScreenData { 45 46 private Bitmap mBitmap; 47 ImageAssetData(Bitmap bitmap)48 ImageAssetData(Bitmap bitmap) { 49 mBitmap = bitmap; 50 } 51 52 @Override getType()53 public int getType() { 54 return TYPE_IMAGE_ASSET; 55 } 56 getBitmap()57 public Bitmap getBitmap() { 58 return mBitmap; 59 } 60 setBitmap(Bitmap bitmap)61 public void setBitmap(Bitmap bitmap) { 62 mBitmap = bitmap; 63 } 64 } 65 66 /** 67 * Represents message event logs passed to Wear device via {@link 68 * com.google.android.gms.wearable.MessageClient} data layer API. 69 */ 70 public static class EventLoggingData implements DataLayerScreenData { 71 72 private StringBuilder mLogBuilder; 73 EventLoggingData()74 EventLoggingData() { 75 mLogBuilder = new StringBuilder(); 76 } 77 78 @Override getType()79 public int getType() { 80 return TYPE_EVENT_LOGGING; 81 } 82 getLog()83 public String getLog() { 84 return mLogBuilder.toString(); 85 } 86 addEventLog(String eventName, String data)87 public void addEventLog(String eventName, String data) { 88 mLogBuilder.append("\n" + eventName + "\n" + data); 89 } 90 } 91 92 /** 93 * No extra data needed as the {@link ViewHolder} only contains buttons checking capabilities of 94 * devices via the {@link com.google.android.gms.wearable.CapabilityClient} data layer API. 95 */ 96 public static class CapabilityDiscoveryData implements DataLayerScreenData { 97 98 @Override getType()99 public int getType() { 100 return TYPE_CAPABILITY_DISCOVERY; 101 } 102 } 103 } 104