1 /* 2 * Copyright (C) 2016 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.android.settings.testutils.shadow; 18 19 import android.view.inputmethod.InputMethodInfo; 20 import android.view.inputmethod.InputMethodManager; 21 22 import org.robolectric.RuntimeEnvironment; 23 import org.robolectric.annotation.Implementation; 24 import org.robolectric.annotation.Implements; 25 import org.robolectric.shadow.api.Shadow; 26 import org.robolectric.shadows.ShadowInputMethodManager; 27 28 import java.util.Collections; 29 import java.util.List; 30 31 /* 32 * Shadow for {@link InputMethodManager} that has accessors for installed input methods. 33 */ 34 @Implements(InputMethodManager.class) 35 public class ShadowInputMethodManagerWithMethodList extends ShadowInputMethodManager { 36 37 private List<InputMethodInfo> mInputMethodInfos = Collections.emptyList(); 38 private List<InputMethodInfo> mEnabledInputMethodInfos = Collections.emptyList(); 39 40 @Implementation getInstance()41 public static InputMethodManager getInstance() { 42 return ShadowInputMethodManager.peekInstance(); 43 } 44 45 @Implementation getInputMethodList()46 protected List<InputMethodInfo> getInputMethodList() { 47 return mInputMethodInfos; 48 } 49 50 @Implementation getEnabledInputMethodList()51 protected List<InputMethodInfo> getEnabledInputMethodList() { 52 return mEnabledInputMethodInfos; 53 } 54 55 @Implementation getEnabledInputMethodSubtypeList(InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes)56 protected List<InputMethodInfo> getEnabledInputMethodSubtypeList(InputMethodInfo imi, 57 boolean allowsImplicitlySelectedSubtypes) { 58 return Collections.emptyList(); 59 } 60 61 // Non-Android setter. setInputMethodList(List<InputMethodInfo> inputMethodInfos)62 public void setInputMethodList(List<InputMethodInfo> inputMethodInfos) { 63 mInputMethodInfos = inputMethodInfos; 64 } 65 setEnabledInputMethodList(List<InputMethodInfo> inputMethodInfos)66 public void setEnabledInputMethodList(List<InputMethodInfo> inputMethodInfos) { 67 mEnabledInputMethodInfos = inputMethodInfos; 68 } 69 getShadow()70 public static ShadowInputMethodManagerWithMethodList getShadow() { 71 return (ShadowInputMethodManagerWithMethodList) Shadow.extract( 72 RuntimeEnvironment.application.getSystemService(InputMethodManager.class)); 73 } 74 } 75