1 /* 2 * Copyright (C) 2017 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 17 package com.google.android.wearable.compat; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 22 /** 23 * Mock version of {@link WearableActivityController}. During instrumentation testing, the tests 24 * would end up using this instead of the version implemented on device. 25 */ 26 public class WearableActivityController { 27 28 private static WearableActivityController sLastInstance; 29 getLastInstance()30 public static WearableActivityController getLastInstance() { 31 return sLastInstance; 32 } 33 34 private AmbientCallback mCallback; 35 private boolean mAmbientEnabled = false; 36 private boolean mAutoResumeEnabled = true; 37 private boolean mAmbient = false; 38 WearableActivityController(String tag, Activity activity, AmbientCallback callback)39 public WearableActivityController(String tag, Activity activity, AmbientCallback callback) { 40 sLastInstance = this; 41 mCallback = callback; 42 } 43 44 // Methods required by the stub but not currently used in tests. onCreate()45 public void onCreate() {} onResume()46 public void onResume() {} onPause()47 public void onPause() {} onStop()48 public void onStop() {} onDestroy()49 public void onDestroy() {} 50 enterAmbient()51 public void enterAmbient() { 52 mCallback.onEnterAmbient(null); 53 } 54 exitAmbient()55 public void exitAmbient() { 56 mCallback.onExitAmbient(); 57 } 58 updateAmbient()59 public void updateAmbient() { 60 mCallback.onUpdateAmbient(); 61 } 62 setAmbientEnabled()63 public void setAmbientEnabled() { 64 mAmbientEnabled = true; 65 } 66 isAmbientEnabled()67 public boolean isAmbientEnabled() { 68 return mAmbientEnabled; 69 } 70 setAutoResumeEnabled(boolean enabled)71 public void setAutoResumeEnabled(boolean enabled) { 72 mAutoResumeEnabled = enabled; 73 } 74 isAutoResumeEnabled()75 public boolean isAutoResumeEnabled() { 76 return mAutoResumeEnabled; 77 } 78 isAmbient()79 public final boolean isAmbient() { 80 return mAmbient; 81 } 82 setAmbient(boolean ambient)83 public void setAmbient(boolean ambient) { 84 mAmbient = ambient; 85 } 86 87 /** Stub version of {@link WearableActivityController.AmbientCallback}. */ 88 public static class AmbientCallback { onEnterAmbient(Bundle ambientDetails)89 public void onEnterAmbient(Bundle ambientDetails) {} 90 onExitAmbient()91 public void onExitAmbient() {} 92 onUpdateAmbient()93 public void onUpdateAmbient() {} 94 } 95 } 96