* commit '673d9734c2d9b62ecd41dcac3c730d242952989e': Fix style warnings in RenderSessionImpl [DO NOT MERGE]
This commit is contained in:
@@ -107,11 +107,10 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class implementing the render session.
|
* Class implementing the render session.
|
||||||
*
|
* <p/>
|
||||||
* A session is a stateful representation of a layout file. It is initialized with data coming
|
* A session is a stateful representation of a layout file. It is initialized with data coming
|
||||||
* through the {@link Bridge} API to inflate the layout. Further actions and rendering can then
|
* through the {@link Bridge} API to inflate the layout. Further actions and rendering can then
|
||||||
* be done on the layout.
|
* be done on the layout.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class RenderSessionImpl extends RenderAction<SessionParams> {
|
public class RenderSessionImpl extends RenderAction<SessionParams> {
|
||||||
|
|
||||||
@@ -178,7 +177,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
@Override
|
@Override
|
||||||
public Result init(long timeout) {
|
public Result init(long timeout) {
|
||||||
Result result = super.init(timeout);
|
Result result = super.init(timeout);
|
||||||
if (result.isSuccess() == false) {
|
if (!result.isSuccess()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,10 +233,9 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
SessionParams params = getParams();
|
SessionParams params = getParams();
|
||||||
HardwareConfig hardwareConfig = params.getHardwareConfig();
|
HardwareConfig hardwareConfig = params.getHardwareConfig();
|
||||||
BridgeContext context = getContext();
|
BridgeContext context = getContext();
|
||||||
ActionBarLayout actionBar = null;
|
|
||||||
|
|
||||||
// the view group that receives the window background.
|
// the view group that receives the window background.
|
||||||
ViewGroup backgroundView = null;
|
ViewGroup backgroundView;
|
||||||
|
|
||||||
if (mWindowIsFloating || params.isForceNoDecor()) {
|
if (mWindowIsFloating || params.isForceNoDecor()) {
|
||||||
backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
|
backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
|
||||||
@@ -269,7 +267,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
CustomBar navigationBar = createNavigationBar(context,
|
CustomBar navigationBar = createNavigationBar(context,
|
||||||
hardwareConfig.getDensity(), hardwareConfig.getScreenSize());
|
hardwareConfig.getDensity(), hardwareConfig.getScreenSize());
|
||||||
topLayout.addView(navigationBar);
|
topLayout.addView(navigationBar);
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,7 +314,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
StatusBar statusBar = createStatusBar(context,
|
StatusBar statusBar = createStatusBar(context,
|
||||||
hardwareConfig.getDensity());
|
hardwareConfig.getDensity());
|
||||||
topLayout.addView(statusBar);
|
topLayout.addView(statusBar);
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,20 +331,16 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
|
|
||||||
// if the theme says no title/action bar, then the size will be 0
|
// if the theme says no title/action bar, then the size will be 0
|
||||||
if (mActionBarSize > 0) {
|
if (mActionBarSize > 0) {
|
||||||
try {
|
ActionBarLayout actionBar = createActionBar(context, params);
|
||||||
actionBar = createActionBar(context, params);
|
backgroundLayout.addView(actionBar);
|
||||||
backgroundLayout.addView(actionBar);
|
actionBar.createMenuPopup();
|
||||||
actionBar.createMenuPopup();
|
mContentRoot = actionBar.getContentRoot();
|
||||||
mContentRoot = actionBar.getContentRoot();
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (mTitleBarSize > 0) {
|
} else if (mTitleBarSize > 0) {
|
||||||
try {
|
try {
|
||||||
TitleBar titleBar = createTitleBar(context,
|
TitleBar titleBar = createTitleBar(context,
|
||||||
hardwareConfig.getDensity(), params.getAppLabel());
|
hardwareConfig.getDensity(), params.getAppLabel());
|
||||||
backgroundLayout.addView(titleBar);
|
backgroundLayout.addView(titleBar);
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +362,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
CustomBar navigationBar = createNavigationBar(context,
|
CustomBar navigationBar = createNavigationBar(context,
|
||||||
hardwareConfig.getDensity(), hardwareConfig.getScreenSize());
|
hardwareConfig.getDensity(), hardwareConfig.getScreenSize());
|
||||||
topLayout.addView(navigationBar);
|
topLayout.addView(navigationBar);
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,7 +387,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
postInflateProcess(view, params.getProjectCallback());
|
postInflateProcess(view, params.getProjectCallback());
|
||||||
|
|
||||||
// get the background drawable
|
// get the background drawable
|
||||||
if (mWindowBackground != null && backgroundView != null) {
|
if (mWindowBackground != null) {
|
||||||
Drawable d = ResourceHelper.getDrawable(mWindowBackground, context);
|
Drawable d = ResourceHelper.getDrawable(mWindowBackground, context);
|
||||||
backgroundView.setBackground(d);
|
backgroundView.setBackground(d);
|
||||||
}
|
}
|
||||||
@@ -470,6 +464,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
|
|
||||||
// first measure the full layout, with EXACTLY to get the size of the
|
// first measure the full layout, with EXACTLY to get the size of the
|
||||||
// content as it is inside the decor/dialog
|
// content as it is inside the decor/dialog
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
Pair<Integer, Integer> exactMeasure = measureView(
|
Pair<Integer, Integer> exactMeasure = measureView(
|
||||||
mViewRoot, mContentRoot.getChildAt(0),
|
mViewRoot, mContentRoot.getChildAt(0),
|
||||||
mMeasuredScreenWidth, MeasureSpec.EXACTLY,
|
mMeasuredScreenWidth, MeasureSpec.EXACTLY,
|
||||||
@@ -477,6 +472,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
|
|
||||||
// now measure the content only using UNSPECIFIED (where applicable, based on
|
// now measure the content only using UNSPECIFIED (where applicable, based on
|
||||||
// the rendering mode). This will give us the size the content needs.
|
// the rendering mode). This will give us the size the content needs.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
Pair<Integer, Integer> result = measureView(
|
Pair<Integer, Integer> result = measureView(
|
||||||
mContentRoot, mContentRoot.getChildAt(0),
|
mContentRoot, mContentRoot.getChildAt(0),
|
||||||
mMeasuredScreenWidth, widthMeasureSpecMode,
|
mMeasuredScreenWidth, widthMeasureSpecMode,
|
||||||
@@ -552,7 +548,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
mCanvas.setDensity(hardwareConfig.getDensity().getDpiValue());
|
mCanvas.setDensity(hardwareConfig.getDensity().getDpiValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (freshRender && newImage == false) {
|
if (freshRender && !newImage) {
|
||||||
Graphics2D gc = mImage.createGraphics();
|
Graphics2D gc = mImage.createGraphics();
|
||||||
gc.setComposite(AlphaComposite.Src);
|
gc.setComposite(AlphaComposite.Src);
|
||||||
|
|
||||||
@@ -598,6 +594,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
* @param heightMode the MeasureSpec mode to use for the height.
|
* @param heightMode the MeasureSpec mode to use for the height.
|
||||||
* @return the measured width/height if measuredView is non-null, null otherwise.
|
* @return the measured width/height if measuredView is non-null, null otherwise.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation") // For the use of Pair
|
||||||
private Pair<Integer, Integer> measureView(ViewGroup viewToMeasure, View measuredView,
|
private Pair<Integer, Integer> measureView(ViewGroup viewToMeasure, View measuredView,
|
||||||
int width, int widthMode, int height, int heightMode) {
|
int width, int widthMode, int height, int heightMode) {
|
||||||
int w_spec = MeasureSpec.makeMeasureSpec(width, widthMode);
|
int w_spec = MeasureSpec.makeMeasureSpec(width, widthMode);
|
||||||
@@ -628,7 +625,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
BridgeContext context = getContext();
|
BridgeContext context = getContext();
|
||||||
|
|
||||||
// find the animation file.
|
// find the animation file.
|
||||||
ResourceValue animationResource = null;
|
ResourceValue animationResource;
|
||||||
int animationId = 0;
|
int animationId = 0;
|
||||||
if (isFrameworkAnimation) {
|
if (isFrameworkAnimation) {
|
||||||
animationResource = context.getRenderResources().getFrameworkResource(
|
animationResource = context.getRenderResources().getFrameworkResource(
|
||||||
@@ -718,7 +715,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
|
|
||||||
// add it to the parentView in the correct location
|
// add it to the parentView in the correct location
|
||||||
Result result = addView(parentView, child, index);
|
Result result = addView(parentView, child, index);
|
||||||
if (result.isSuccess() == false) {
|
if (!result.isSuccess()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -788,13 +785,13 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Result result = moveView(previousParent, newParentView, childView, index,
|
Result result = moveView(previousParent, newParentView, childView, index,
|
||||||
params);
|
params);
|
||||||
if (result.isSuccess() == false) {
|
if (!result.isSuccess()) {
|
||||||
listener.done(result);
|
listener.done(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ready to do the work, acquire the scene.
|
// ready to do the work, acquire the scene.
|
||||||
result = acquire(250);
|
result = acquire(250);
|
||||||
if (result.isSuccess() == false) {
|
if (!result.isSuccess()) {
|
||||||
listener.done(result);
|
listener.done(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -852,7 +849,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result result = moveView(previousParent, newParentView, childView, index, layoutParams);
|
Result result = moveView(previousParent, newParentView, childView, index, layoutParams);
|
||||||
if (result.isSuccess() == false) {
|
if (!result.isSuccess()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -986,7 +983,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result result = removeView(parent, childView);
|
Result result = removeView(parent, childView);
|
||||||
if (result.isSuccess() == false) {
|
if (!result.isSuccess()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,7 +1011,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
|
|
||||||
|
|
||||||
private void findBackground(RenderResources resources) {
|
private void findBackground(RenderResources resources) {
|
||||||
if (getParams().isBgColorOverridden() == false) {
|
if (!getParams().isBgColorOverridden()) {
|
||||||
mWindowBackground = resources.findItemInTheme("windowBackground",
|
mWindowBackground = resources.findItemInTheme("windowBackground",
|
||||||
true /*isFrameworkAttr*/);
|
true /*isFrameworkAttr*/);
|
||||||
if (mWindowBackground != null) {
|
if (mWindowBackground != null) {
|
||||||
@@ -1031,7 +1028,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
boolean windowFullscreen = getBooleanThemeValue(resources,
|
boolean windowFullscreen = getBooleanThemeValue(resources,
|
||||||
"windowFullscreen", false /*defaultValue*/);
|
"windowFullscreen", false /*defaultValue*/);
|
||||||
|
|
||||||
if (windowFullscreen == false && mWindowIsFloating == false) {
|
if (!windowFullscreen && !mWindowIsFloating) {
|
||||||
// default value
|
// default value
|
||||||
mStatusBarSize = DEFAULT_STATUS_BAR_HEIGHT;
|
mStatusBarSize = DEFAULT_STATUS_BAR_HEIGHT;
|
||||||
|
|
||||||
@@ -1085,7 +1082,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
boolean windowNoTitle = getBooleanThemeValue(resources,
|
boolean windowNoTitle = getBooleanThemeValue(resources,
|
||||||
"windowNoTitle", false /*defaultValue*/);
|
"windowNoTitle", false /*defaultValue*/);
|
||||||
|
|
||||||
if (windowNoTitle == false) {
|
if (!windowNoTitle) {
|
||||||
|
|
||||||
// default size of the window title bar
|
// default size of the window title bar
|
||||||
mTitleBarSize = DEFAULT_TITLE_BAR_HEIGHT;
|
mTitleBarSize = DEFAULT_TITLE_BAR_HEIGHT;
|
||||||
@@ -1112,7 +1109,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void findNavigationBar(RenderResources resources, DisplayMetrics metrics) {
|
private void findNavigationBar(RenderResources resources, DisplayMetrics metrics) {
|
||||||
if (hasSoftwareButtons() && mWindowIsFloating == false) {
|
if (hasSoftwareButtons() && !mWindowIsFloating) {
|
||||||
|
|
||||||
// default value
|
// default value
|
||||||
mNavigationBarSize = 48; // ??
|
mNavigationBarSize = 48; // ??
|
||||||
@@ -1126,15 +1123,12 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
int shortSize = hardwareConfig.getScreenHeight();
|
int shortSize = hardwareConfig.getScreenHeight();
|
||||||
|
|
||||||
// compute in dp
|
// compute in dp
|
||||||
int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / hardwareConfig.getDensity().getDpiValue();
|
int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT /
|
||||||
|
hardwareConfig.getDensity().getDpiValue();
|
||||||
|
|
||||||
if (shortSizeDp < 600) {
|
// 0-599dp: "phone" UI with bar on the side
|
||||||
// 0-599dp: "phone" UI with bar on the side
|
// 600+dp: "tablet" UI with bar on the bottom
|
||||||
barOnBottom = false;
|
barOnBottom = shortSizeDp >= 600;
|
||||||
} else {
|
|
||||||
// 600+dp: "tablet" UI with bar on the bottom
|
|
||||||
barOnBottom = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barOnBottom) {
|
if (barOnBottom) {
|
||||||
@@ -1185,13 +1179,15 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post process on a view hierachy that was just inflated.
|
* Post process on a view hierarchy that was just inflated.
|
||||||
* <p/>At the moment this only support TabHost: If {@link TabHost} is detected, look for the
|
* <p/>
|
||||||
|
* At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
|
||||||
* {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
|
* {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
|
||||||
* based on the content of the {@link FrameLayout}.
|
* based on the content of the {@link FrameLayout}.
|
||||||
* @param view the root view to process.
|
* @param view the root view to process.
|
||||||
* @param projectCallback callback to the project.
|
* @param projectCallback callback to the project.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation") // For the use of Pair
|
||||||
private void postInflateProcess(View view, IProjectCallback projectCallback)
|
private void postInflateProcess(View view, IProjectCallback projectCallback)
|
||||||
throws PostInflateException {
|
throws PostInflateException {
|
||||||
if (view instanceof TabHost) {
|
if (view instanceof TabHost) {
|
||||||
@@ -1294,7 +1290,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
"TabHost requires a TabWidget with id \"android:id/tabs\".\n");
|
"TabHost requires a TabWidget with id \"android:id/tabs\".\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((v instanceof TabWidget) == false) {
|
if (!(v instanceof TabWidget)) {
|
||||||
throw new PostInflateException(String.format(
|
throw new PostInflateException(String.format(
|
||||||
"TabHost requires a TabWidget with id \"android:id/tabs\".\n" +
|
"TabHost requires a TabWidget with id \"android:id/tabs\".\n" +
|
||||||
"View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
|
"View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
|
||||||
@@ -1303,12 +1299,14 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
v = tabHost.findViewById(android.R.id.tabcontent);
|
v = tabHost.findViewById(android.R.id.tabcontent);
|
||||||
|
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
// TODO: see if we can fake tabs even without the FrameLayout (same below when the framelayout is empty)
|
// TODO: see if we can fake tabs even without the FrameLayout (same below when the frameLayout is empty)
|
||||||
|
//noinspection SpellCheckingInspection
|
||||||
throw new PostInflateException(
|
throw new PostInflateException(
|
||||||
"TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
|
"TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((v instanceof FrameLayout) == false) {
|
if (!(v instanceof FrameLayout)) {
|
||||||
|
//noinspection SpellCheckingInspection
|
||||||
throw new PostInflateException(String.format(
|
throw new PostInflateException(String.format(
|
||||||
"TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" +
|
"TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" +
|
||||||
"View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
|
"View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
|
||||||
@@ -1316,7 +1314,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
|
|
||||||
FrameLayout content = (FrameLayout)v;
|
FrameLayout content = (FrameLayout)v;
|
||||||
|
|
||||||
// now process the content of the framelayout and dynamically create tabs for it.
|
// now process the content of the frameLayout and dynamically create tabs for it.
|
||||||
final int count = content.getChildCount();
|
final int count = content.getChildCount();
|
||||||
|
|
||||||
// this must be called before addTab() so that the TabHost searches its TabWidget
|
// this must be called before addTab() so that the TabHost searches its TabWidget
|
||||||
@@ -1334,13 +1332,13 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
tabHost.addTab(spec);
|
tabHost.addTab(spec);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
// for each child of the framelayout, add a new TabSpec
|
// for each child of the frameLayout, add a new TabSpec
|
||||||
for (int i = 0 ; i < count ; i++) {
|
for (int i = 0 ; i < count ; i++) {
|
||||||
View child = content.getChildAt(i);
|
View child = content.getChildAt(i);
|
||||||
String tabSpec = String.format("tab_spec%d", i+1);
|
String tabSpec = String.format("tab_spec%d", i+1);
|
||||||
int id = child.getId();
|
int id = child.getId();
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
Pair<ResourceType, String> resource = projectCallback.resolveResourceId(id);
|
Pair<ResourceType, String> resource = projectCallback.resolveResourceId(id);
|
||||||
String name;
|
String name;
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
@@ -1569,8 +1567,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
/**
|
/**
|
||||||
* Creates the action bar. Also queries the project callback for missing information.
|
* Creates the action bar. Also queries the project callback for missing information.
|
||||||
*/
|
*/
|
||||||
private ActionBarLayout createActionBar(BridgeContext context, SessionParams params)
|
private ActionBarLayout createActionBar(BridgeContext context, SessionParams params) {
|
||||||
throws XmlPullParserException {
|
|
||||||
ActionBarLayout actionBar = new ActionBarLayout(context, params);
|
ActionBarLayout actionBar = new ActionBarLayout(context, params);
|
||||||
actionBar.setLayoutParams(new LinearLayout.LayoutParams(
|
actionBar.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||||
|
|||||||
Reference in New Issue
Block a user