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.android.settings.testutils.shadow; 18 19 import android.content.Context; 20 import android.content.IContentProvider; 21 import android.net.Uri; 22 import android.os.Bundle; 23 import android.util.Pair; 24 25 import com.android.settings.R; 26 import com.android.settingslib.drawer.TileUtils; 27 28 import org.robolectric.RuntimeEnvironment; 29 import org.robolectric.annotation.Implementation; 30 import org.robolectric.annotation.Implements; 31 32 import java.util.Map; 33 34 @Implements(TileUtils.class) 35 public class ShadowTileUtils { 36 37 public static final String MOCK_TEXT = "text"; 38 39 private static boolean sChecked; 40 private static Bundle sResult; 41 42 @Implementation getTextFromUri(Context context, Uri uri, Map<String, IContentProvider> providerMap, String key)43 protected static String getTextFromUri(Context context, Uri uri, 44 Map<String, IContentProvider> providerMap, String key) { 45 return MOCK_TEXT; 46 } 47 48 @Implementation getIconFromUri(Context context, String packageName, Uri uri, Map<String, IContentProvider> providerMap)49 protected static Pair<String, Integer> getIconFromUri(Context context, String packageName, 50 Uri uri, Map<String, IContentProvider> providerMap) { 51 return Pair.create(RuntimeEnvironment.application.getPackageName(), 52 R.drawable.ic_settings_accent); 53 } 54 55 @Implementation getBooleanFromUri(Context context, Uri uri, Map<String, IContentProvider> providerMap, String key)56 public static boolean getBooleanFromUri(Context context, Uri uri, 57 Map<String, IContentProvider> providerMap, String key) { 58 return sChecked; 59 } 60 61 @Implementation putBooleanToUriAndGetResult(Context context, Uri uri, Map<String, IContentProvider> providerMap, String key, boolean value)62 public static Bundle putBooleanToUriAndGetResult(Context context, Uri uri, 63 Map<String, IContentProvider> providerMap, String key, boolean value) { 64 sChecked = value; 65 return sResult; 66 } 67 getProviderChecked()68 public static boolean getProviderChecked() { 69 return sChecked; 70 } 71 setProviderChecked(boolean value)72 public static void setProviderChecked(boolean value) { 73 sChecked = value; 74 } 75 setResultBundle(Bundle result)76 public static void setResultBundle(Bundle result) { 77 sResult = result; 78 } 79 } 80