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.view;
18 
19 import com.android.layoutlib.bridge.impl.DelegateManager;
20 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
21 
22 /**
23  * Delegate implementing the native methods of {@link RenderNode}
24  * <p/>
25  * Through the layoutlib_create tool, some native methods of RenderNode have been replaced by calls
26  * to methods of the same name in this delegate class.
27  *
28  * @see DelegateManager
29  */
30 public class RenderNode_Delegate {
31 
32 
33     // ---- delegate manager ----
34     private static final DelegateManager<RenderNode_Delegate> sManager =
35             new DelegateManager<RenderNode_Delegate>(RenderNode_Delegate.class);
36 
37 
38     private float mLift;
39     @SuppressWarnings("UnusedDeclaration")
40     private String mName;
41 
42     @LayoutlibDelegate
nCreate(String name)43     /*package*/ static long nCreate(String name) {
44         RenderNode_Delegate renderNodeDelegate = new RenderNode_Delegate();
45         renderNodeDelegate.mName = name;
46         return sManager.addNewDelegate(renderNodeDelegate);
47     }
48 
49     @LayoutlibDelegate
nDestroyRenderNode(long renderNode)50     /*package*/ static void nDestroyRenderNode(long renderNode) {
51         sManager.removeJavaReferenceFor(renderNode);
52     }
53 
54     @LayoutlibDelegate
nSetElevation(long renderNode, float lift)55     /*package*/ static boolean nSetElevation(long renderNode, float lift) {
56         RenderNode_Delegate delegate = sManager.getDelegate(renderNode);
57         if (delegate != null && delegate.mLift != lift) {
58             delegate.mLift = lift;
59             return true;
60         }
61         return false;
62     }
63 
64     @LayoutlibDelegate
nGetElevation(long renderNode)65     /*package*/ static float nGetElevation(long renderNode) {
66         RenderNode_Delegate delegate = sManager.getDelegate(renderNode);
67         if (delegate != null) {
68             return delegate.mLift;
69         }
70         return 0f;
71     }
72 }
73