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.layoutlib.bridge.impl.DelegateManager;
20 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
21 
22 import android.util.SparseArray;
23 
24 /**
25  * Delegate used to provide implementation of a select few native methods of {@link AssetManager}
26  * <p/>
27  * Through the layoutlib_create tool, the original native methods of AssetManager have been replaced
28  * by calls to methods of the same name in this delegate class.
29  *
30  */
31 public class AssetManager_Delegate {
32 
33     // ---- delegate manager ----
34 
35     private static final DelegateManager<AssetManager_Delegate> sManager =
36             new DelegateManager<>(AssetManager_Delegate.class);
37 
38     // ---- delegate methods. ----
39 
40     @LayoutlibDelegate
nativeCreate()41     /*package*/ static long nativeCreate() {
42         AssetManager_Delegate delegate = new AssetManager_Delegate();
43         return sManager.addNewDelegate(delegate);
44     }
45 
46     @LayoutlibDelegate
nativeDestroy(long ptr)47     /*package*/ static void nativeDestroy(long ptr) {
48         sManager.removeJavaReferenceFor(ptr);
49     }
50 
51     @LayoutlibDelegate
nativeThemeCreate(long ptr)52     /*package*/ static long nativeThemeCreate(long ptr) {
53         return Resources_Theme_Delegate.getDelegateManager()
54                 .addNewDelegate(new Resources_Theme_Delegate());
55     }
56 
57     @LayoutlibDelegate
nativeThemeDestroy(long theme)58     /*package*/ static void nativeThemeDestroy(long theme) {
59         Resources_Theme_Delegate.getDelegateManager().removeJavaReferenceFor(theme);
60     }
61 
62     @LayoutlibDelegate
getAssignedPackageIdentifiers(AssetManager manager)63     /*package*/ static SparseArray<String> getAssignedPackageIdentifiers(AssetManager manager) {
64         return new SparseArray<>();
65     }
66 
67     @LayoutlibDelegate
getAssignedPackageIdentifiers(AssetManager manager, boolean includeOverlays, boolean includeLoaders)68     /*package*/ static SparseArray<String> getAssignedPackageIdentifiers(AssetManager manager,
69             boolean includeOverlays, boolean includeLoaders) {
70         return new SparseArray<>();
71     }
72 
73     @LayoutlibDelegate
nativeCreateIdmapsForStaticOverlaysTargetingAndroid()74     /*package*/ static String[] nativeCreateIdmapsForStaticOverlaysTargetingAndroid() {
75         // AssetManager requires this not to be null
76         return new String[0];
77     }
78 }
79