• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 import com.android.resources.ScreenSize;
21 
22 /**
23  * Base class for rendering parameters. This include the generic parameters but not what needs
24  * to be rendered or additional parameters.
25  *
26  */
27 public abstract class RenderParams {
28 
29     public final static long DEFAULT_TIMEOUT = 250; //ms
30 
31     private final Object mProjectKey;
32     private final int mScreenWidth;
33     private final int mScreenHeight;
34     private final Density mDensity;
35     private final float mXdpi;
36     private final float mYdpi;
37     private final RenderResources mRenderResources;
38     private final IProjectCallback mProjectCallback;
39     private final int mMinSdkVersion;
40     private final int mTargetSdkVersion;
41     private final LayoutLog mLog;
42 
43     private boolean mCustomBackgroundEnabled;
44     private int mCustomBackgroundColor;
45     private long mTimeout;
46 
47     private IImageFactory mImageFactory = null;
48 
49     private ScreenSize mConfigScreenSize = null;
50     private String mAppIcon = null;
51     private String mAppLabel = null;
52     private String mLocale = null;
53     private boolean mForceNoDecor;
54 
55     /**
56      *
57      * @param projectKey An Object identifying the project. This is used for the cache mechanism.
58      * @param screenWidth the screen width
59      * @param screenHeight the screen height
60      * @param density the density factor for the screen.
61      * @param xdpi the screen actual dpi in X
62      * @param ydpi the screen actual dpi in Y
63      * @param themeName The name of the theme to use.
64      * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme.
65      * @param projectResources the resources of the project. The map contains (String, map) pairs
66      * where the string is the type of the resource reference used in the layout file, and the
67      * map contains (String, {@link ResourceValue}) pairs where the key is the resource name,
68      * and the value is the resource value.
69      * @param frameworkResources the framework resources. The map contains (String, map) pairs
70      * where the string is the type of the resource reference used in the layout file, and the map
71      * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the
72      * value is the resource value.
73      * @param projectCallback The {@link IProjectCallback} object to get information from
74      * the project.
75      * @param minSdkVersion the minSdkVersion of the project
76      * @param targetSdkVersion the targetSdkVersion of the project
77      * @param log the object responsible for displaying warning/errors to the user.
78      */
RenderParams( Object projectKey, int screenWidth, int screenHeight, Density density, float xdpi, float ydpi, RenderResources renderResources, IProjectCallback projectCallback, int minSdkVersion, int targetSdkVersion, LayoutLog log)79     public RenderParams(
80             Object projectKey,
81             int screenWidth, int screenHeight,
82             Density density, float xdpi, float ydpi,
83             RenderResources renderResources,
84             IProjectCallback projectCallback,
85             int minSdkVersion, int targetSdkVersion,
86             LayoutLog log) {
87         mProjectKey = projectKey;
88         mScreenWidth = screenWidth;
89         mScreenHeight = screenHeight;
90         mDensity = density;
91         mXdpi = xdpi;
92         mYdpi = ydpi;
93         mRenderResources = renderResources;
94         mProjectCallback = projectCallback;
95         mMinSdkVersion = minSdkVersion;
96         mTargetSdkVersion = targetSdkVersion;
97         mLog = log;
98         mCustomBackgroundEnabled = false;
99         mTimeout = DEFAULT_TIMEOUT;
100     }
101 
102     /**
103      * Copy constructor.
104      */
RenderParams(RenderParams params)105     public RenderParams(RenderParams params) {
106         mProjectKey = params.mProjectKey;
107         mScreenWidth = params.mScreenWidth;
108         mScreenHeight = params.mScreenHeight;
109         mDensity = params.mDensity;
110         mXdpi = params.mXdpi;
111         mYdpi = params.mYdpi;
112         mRenderResources = params.mRenderResources;
113         mProjectCallback = params.mProjectCallback;
114         mMinSdkVersion = params.mMinSdkVersion;
115         mTargetSdkVersion = params.mTargetSdkVersion;
116         mLog = params.mLog;
117         mCustomBackgroundEnabled = params.mCustomBackgroundEnabled;
118         mCustomBackgroundColor = params.mCustomBackgroundColor;
119         mTimeout = params.mTimeout;
120         mImageFactory = params.mImageFactory;
121         mConfigScreenSize = params.mConfigScreenSize;
122         mAppIcon = params.mAppIcon;
123         mAppLabel = params.mAppLabel;
124         mLocale = params.mLocale;
125         mForceNoDecor = params.mForceNoDecor;
126     }
127 
setOverrideBgColor(int color)128     public void setOverrideBgColor(int color) {
129         mCustomBackgroundEnabled = true;
130         mCustomBackgroundColor = color;
131     }
132 
setTimeout(long timeout)133     public void setTimeout(long timeout) {
134         mTimeout = timeout;
135     }
136 
setImageFactory(IImageFactory imageFactory)137     public void setImageFactory(IImageFactory imageFactory) {
138         mImageFactory = imageFactory;
139     }
140 
setConfigScreenSize(ScreenSize size)141     public void setConfigScreenSize(ScreenSize size) {
142         mConfigScreenSize  = size;
143     }
144 
setAppIcon(String appIcon)145     public void setAppIcon(String appIcon) {
146         mAppIcon = appIcon;
147     }
148 
setAppLabel(String appLabel)149     public void setAppLabel(String appLabel) {
150         mAppLabel = appLabel;
151     }
152 
setLocale(String locale)153     public void setLocale(String locale) {
154         mLocale = locale;
155     }
156 
setForceNoDecor()157     public void setForceNoDecor() {
158         mForceNoDecor = true;
159     }
160 
getProjectKey()161     public Object getProjectKey() {
162         return mProjectKey;
163     }
164 
getMinSdkVersion()165     public int getMinSdkVersion() {
166         return mMinSdkVersion;
167     }
168 
getTargetSdkVersion()169     public int getTargetSdkVersion() {
170         return mTargetSdkVersion;
171     }
172 
getScreenWidth()173     public int getScreenWidth() {
174         return mScreenWidth;
175     }
176 
getScreenHeight()177     public int getScreenHeight() {
178         return mScreenHeight;
179     }
180 
getDensity()181     public Density getDensity() {
182         return mDensity;
183     }
184 
getXdpi()185     public float getXdpi() {
186         return mXdpi;
187     }
188 
getYdpi()189     public float getYdpi() {
190         return mYdpi;
191     }
192 
getResources()193     public RenderResources getResources() {
194         return mRenderResources;
195     }
196 
getProjectCallback()197     public IProjectCallback getProjectCallback() {
198         return mProjectCallback;
199     }
200 
getLog()201     public LayoutLog getLog() {
202         return mLog;
203     }
204 
isBgColorOverridden()205     public boolean isBgColorOverridden() {
206         return mCustomBackgroundEnabled;
207     }
208 
getOverrideBgColor()209     public int getOverrideBgColor() {
210         return mCustomBackgroundColor;
211     }
212 
getTimeout()213     public long getTimeout() {
214         return mTimeout;
215     }
216 
getImageFactory()217     public IImageFactory getImageFactory() {
218         return mImageFactory;
219     }
220 
getConfigScreenSize()221     public ScreenSize getConfigScreenSize() {
222         return mConfigScreenSize;
223     }
224 
getAppIcon()225     public String getAppIcon() {
226         return mAppIcon;
227     }
228 
getAppLabel()229     public String getAppLabel() {
230         return mAppLabel;
231     }
232 
getLocale()233     public String getLocale() {
234         return mLocale;
235     }
236 
isForceNoDecor()237     public boolean isForceNoDecor() {
238         return mForceNoDecor;
239     }
240 }
241