1 /* 2 * Copyright (C) 2014 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 android.content.res; 18 19 import com.android.tools.layoutlib.annotations.LayoutlibDelegate; 20 21 import android.util.SparseArray; 22 23 import java.io.IOException; 24 import java.io.InputStream; 25 26 /** 27 * Delegate used to provide implementation of a select few native methods of {@link AssetManager} 28 * <p/> 29 * Through the layoutlib_create tool, the original native methods of AssetManager have been replaced 30 * by calls to methods of the same name in this delegate class. 31 * 32 */ 33 public class AssetManager_Delegate { 34 35 @LayoutlibDelegate 36 public static InputStream open(AssetManager mgr, String fileName) throws IOException { 37 return mgr.open_Original(fileName); 38 } 39 40 @LayoutlibDelegate 41 public static InputStream open(AssetManager mgr, String fileName, int accessMode) 42 throws IOException { 43 if (!(mgr instanceof BridgeAssetManager)) { 44 return mgr.open_Original(fileName, accessMode); 45 } 46 return ((BridgeAssetManager) mgr).getAssetRepository().openAsset(fileName, accessMode); 47 } 48 49 @LayoutlibDelegate 50 /*package*/ static long newTheme(AssetManager manager) { 51 return Resources_Theme_Delegate.getDelegateManager() 52 .addNewDelegate(new Resources_Theme_Delegate()); 53 } 54 55 @LayoutlibDelegate 56 /*package*/ static void deleteTheme(AssetManager manager, long theme) { 57 Resources_Theme_Delegate.getDelegateManager().removeJavaReferenceFor(theme); 58 } 59 60 @LayoutlibDelegate 61 /*package*/ static SparseArray<String> getAssignedPackageIdentifiers(AssetManager manager) { 62 return new SparseArray<>(); 63 } 64 } 65