• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.ide.common.rendering.api;
18 
19 import com.android.resources.Density;
20 
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24 
25 /**
26  * Rendering parameters for a {@link RenderSession}.
27  */
28 public class SessionParams extends RenderParams {
29 
30     public static enum RenderingMode {
31         NORMAL(false, false),
32         V_SCROLL(false, true),
33         H_SCROLL(true, false),
34         FULL_EXPAND(true, true);
35 
36         private final boolean mHorizExpand;
37         private final boolean mVertExpand;
38 
RenderingMode(boolean horizExpand, boolean vertExpand)39         private RenderingMode(boolean horizExpand, boolean vertExpand) {
40             mHorizExpand = horizExpand;
41             mVertExpand = vertExpand;
42         }
43 
isHorizExpand()44         public boolean isHorizExpand() {
45             return mHorizExpand;
46         }
47 
isVertExpand()48         public boolean isVertExpand() {
49             return mVertExpand;
50         }
51     }
52 
53     private final ILayoutPullParser mLayoutDescription;
54     private final RenderingMode mRenderingMode;
55     private boolean mLayoutOnly = false;
56     private Map<ResourceReference, AdapterBinding> mAdapterBindingMap;
57     private boolean mExtendedViewInfoMode = false;
58 
59     /**
60      *
61      * @param layoutDescription the {@link ILayoutPullParser} letting the LayoutLib Bridge visit the
62      * layout file.
63      * @param renderingMode The rendering mode.
64      * @param projectKey An Object identifying the project. This is used for the cache mechanism.
65      * @param screenWidth the screen width
66      * @param screenHeight the screen height
67      * @param density the density factor for the screen.
68      * @param xdpi the screen actual dpi in X
69      * @param ydpi the screen actual dpi in Y
70      * @param themeName The name of the theme to use.
71      * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme.
72      * @param projectResources the resources of the project. The map contains (String, map) pairs
73      * where the string is the type of the resource reference used in the layout file, and the
74      * map contains (String, {@link ResourceValue}) pairs where the key is the resource name,
75      * and the value is the resource value.
76      * @param frameworkResources the framework resources. The map contains (String, map) pairs
77      * where the string is the type of the resource reference used in the layout file, and the map
78      * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the
79      * value is the resource value.
80      * @param projectCallback The {@link IProjectCallback} object to get information from
81      * the project.
82      * @param minSdkVersion the minSdkVersion of the project
83      * @param targetSdkVersion the targetSdkVersion of the project
84      * @param log the object responsible for displaying warning/errors to the user.
85      */
SessionParams( ILayoutPullParser layoutDescription, RenderingMode renderingMode, Object projectKey, int screenWidth, int screenHeight, Density density, float xdpi, float ydpi, RenderResources renderResources, IProjectCallback projectCallback, int minSdkVersion, int targetSdkVersion, LayoutLog log)86     public SessionParams(
87             ILayoutPullParser layoutDescription,
88             RenderingMode renderingMode,
89             Object projectKey,
90             int screenWidth, int screenHeight,
91             Density density, float xdpi, float ydpi,
92             RenderResources renderResources,
93             IProjectCallback projectCallback,
94             int minSdkVersion, int targetSdkVersion,
95             LayoutLog log) {
96         super(projectKey, screenWidth, screenHeight, density, xdpi, ydpi,
97                 renderResources, projectCallback, minSdkVersion, targetSdkVersion, log);
98 
99         mLayoutDescription = layoutDescription;
100         mRenderingMode = renderingMode;
101     }
102 
SessionParams(SessionParams params)103     public SessionParams(SessionParams params) {
104         super(params);
105         mLayoutDescription = params.mLayoutDescription;
106         mRenderingMode = params.mRenderingMode;
107         if (params.mAdapterBindingMap != null) {
108             mAdapterBindingMap = new HashMap<ResourceReference, AdapterBinding>(
109                     params.mAdapterBindingMap);
110         }
111         mExtendedViewInfoMode = params.mExtendedViewInfoMode;
112     }
113 
getLayoutDescription()114     public ILayoutPullParser getLayoutDescription() {
115         return mLayoutDescription;
116     }
117 
getRenderingMode()118     public RenderingMode getRenderingMode() {
119         return mRenderingMode;
120     }
121 
setLayoutOnly()122     public void setLayoutOnly() {
123         mLayoutOnly = true;
124     }
125 
isLayoutOnly()126     public boolean isLayoutOnly() {
127         return mLayoutOnly;
128     }
129 
addAdapterBinding(ResourceReference reference, AdapterBinding data)130     public void addAdapterBinding(ResourceReference reference, AdapterBinding data) {
131         if (mAdapterBindingMap == null) {
132             mAdapterBindingMap = new HashMap<ResourceReference, AdapterBinding>();
133         }
134 
135         mAdapterBindingMap.put(reference, data);
136     }
137 
getAdapterBindings()138     public Map<ResourceReference, AdapterBinding> getAdapterBindings() {
139         if (mAdapterBindingMap == null) {
140             return Collections.emptyMap();
141         }
142 
143         return Collections.unmodifiableMap(mAdapterBindingMap);
144     }
145 
setExtendedViewInfoMode(boolean mode)146     public void setExtendedViewInfoMode(boolean mode) {
147         mExtendedViewInfoMode = mode;
148     }
149 
getExtendedViewInfoMode()150     public boolean getExtendedViewInfoMode() {
151         return mExtendedViewInfoMode;
152     }
153 }
154