From 85f53c3335daf0e55cec757fd66fe560e0b020ef Mon Sep 17 00:00:00 2001 From: Deepanshu Gupta Date: Tue, 22 Apr 2014 17:22:32 -0700 Subject: Fix style warnings in RenderSessionImpl [DO NOT MERGE] Change-Id: I9d3cb23e4ea692f737a3e3d6c18cc8de18b66a3c (cherry-picked from commit 22de7c4c3d44e51aef6937e1b39540703ad01f5c) --- .../layoutlib/bridge/impl/RenderSessionImpl.java | 91 +++++++++++----------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 184efd4..03e7132 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -105,11 +105,10 @@ import java.util.Map; /** * Class implementing the render session. - * + *

* 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 * be done on the layout. - * */ public class RenderSessionImpl extends RenderAction { @@ -176,7 +175,7 @@ public class RenderSessionImpl extends RenderAction { @Override public Result init(long timeout) { Result result = super.init(timeout); - if (result.isSuccess() == false) { + if (!result.isSuccess()) { return result; } @@ -224,10 +223,9 @@ public class RenderSessionImpl extends RenderAction { SessionParams params = getParams(); HardwareConfig hardwareConfig = params.getHardwareConfig(); BridgeContext context = getContext(); - ActionBarLayout actionBar = null; // the view group that receives the window background. - ViewGroup backgroundView = null; + ViewGroup backgroundView; if (mWindowIsFloating || params.isForceNoDecor()) { backgroundView = mViewRoot = mContentRoot = new FrameLayout(context); @@ -259,7 +257,7 @@ public class RenderSessionImpl extends RenderAction { CustomBar navigationBar = createNavigationBar(context, hardwareConfig.getDensity(), hardwareConfig.getScreenSize()); topLayout.addView(navigationBar); - } catch (XmlPullParserException e) { + } catch (XmlPullParserException ignored) { } } @@ -306,7 +304,7 @@ public class RenderSessionImpl extends RenderAction { StatusBar statusBar = createStatusBar(context, hardwareConfig.getDensity()); topLayout.addView(statusBar); - } catch (XmlPullParserException e) { + } catch (XmlPullParserException ignored) { } } @@ -323,20 +321,16 @@ public class RenderSessionImpl extends RenderAction { // if the theme says no title/action bar, then the size will be 0 if (mActionBarSize > 0) { - try { - actionBar = createActionBar(context, params); - backgroundLayout.addView(actionBar); - actionBar.createMenuPopup(); - mContentRoot = actionBar.getContentRoot(); - } catch (XmlPullParserException e) { - - } + ActionBarLayout actionBar = createActionBar(context, params); + backgroundLayout.addView(actionBar); + actionBar.createMenuPopup(); + mContentRoot = actionBar.getContentRoot(); } else if (mTitleBarSize > 0) { try { TitleBar titleBar = createTitleBar(context, hardwareConfig.getDensity(), params.getAppLabel()); backgroundLayout.addView(titleBar); - } catch (XmlPullParserException e) { + } catch (XmlPullParserException ignored) { } } @@ -358,7 +352,7 @@ public class RenderSessionImpl extends RenderAction { CustomBar navigationBar = createNavigationBar(context, hardwareConfig.getDensity(), hardwareConfig.getScreenSize()); topLayout.addView(navigationBar); - } catch (XmlPullParserException e) { + } catch (XmlPullParserException ignored) { } } @@ -383,7 +377,7 @@ public class RenderSessionImpl extends RenderAction { postInflateProcess(view, params.getProjectCallback()); // get the background drawable - if (mWindowBackground != null && backgroundView != null) { + if (mWindowBackground != null) { Drawable d = ResourceHelper.getDrawable(mWindowBackground, context); backgroundView.setBackground(d); } @@ -460,6 +454,7 @@ public class RenderSessionImpl extends RenderAction { // first measure the full layout, with EXACTLY to get the size of the // content as it is inside the decor/dialog + @SuppressWarnings("deprecation") Pair exactMeasure = measureView( mViewRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, MeasureSpec.EXACTLY, @@ -467,6 +462,7 @@ public class RenderSessionImpl extends RenderAction { // now measure the content only using UNSPECIFIED (where applicable, based on // the rendering mode). This will give us the size the content needs. + @SuppressWarnings("deprecation") Pair result = measureView( mContentRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, widthMeasureSpecMode, @@ -542,7 +538,7 @@ public class RenderSessionImpl extends RenderAction { mCanvas.setDensity(hardwareConfig.getDensity().getDpiValue()); } - if (freshRender && newImage == false) { + if (freshRender && !newImage) { Graphics2D gc = mImage.createGraphics(); gc.setComposite(AlphaComposite.Src); @@ -588,6 +584,7 @@ public class RenderSessionImpl extends RenderAction { * @param heightMode the MeasureSpec mode to use for the height. * @return the measured width/height if measuredView is non-null, null otherwise. */ + @SuppressWarnings("deprecation") // For the use of Pair private Pair measureView(ViewGroup viewToMeasure, View measuredView, int width, int widthMode, int height, int heightMode) { int w_spec = MeasureSpec.makeMeasureSpec(width, widthMode); @@ -618,7 +615,7 @@ public class RenderSessionImpl extends RenderAction { BridgeContext context = getContext(); // find the animation file. - ResourceValue animationResource = null; + ResourceValue animationResource; int animationId = 0; if (isFrameworkAnimation) { animationResource = context.getRenderResources().getFrameworkResource( @@ -708,7 +705,7 @@ public class RenderSessionImpl extends RenderAction { // add it to the parentView in the correct location Result result = addView(parentView, child, index); - if (result.isSuccess() == false) { + if (!result.isSuccess()) { return result; } @@ -778,13 +775,13 @@ public class RenderSessionImpl extends RenderAction { public void run() { Result result = moveView(previousParent, newParentView, childView, index, params); - if (result.isSuccess() == false) { + if (!result.isSuccess()) { listener.done(result); } // ready to do the work, acquire the scene. result = acquire(250); - if (result.isSuccess() == false) { + if (!result.isSuccess()) { listener.done(result); return; } @@ -842,7 +839,7 @@ public class RenderSessionImpl extends RenderAction { } Result result = moveView(previousParent, newParentView, childView, index, layoutParams); - if (result.isSuccess() == false) { + if (!result.isSuccess()) { return result; } @@ -976,7 +973,7 @@ public class RenderSessionImpl extends RenderAction { } Result result = removeView(parent, childView); - if (result.isSuccess() == false) { + if (!result.isSuccess()) { return result; } @@ -1004,7 +1001,7 @@ public class RenderSessionImpl extends RenderAction { private void findBackground(RenderResources resources) { - if (getParams().isBgColorOverridden() == false) { + if (!getParams().isBgColorOverridden()) { mWindowBackground = resources.findItemInTheme("windowBackground", true /*isFrameworkAttr*/); if (mWindowBackground != null) { @@ -1024,7 +1021,7 @@ public class RenderSessionImpl extends RenderAction { boolean windowFullscreen = getBooleanThemeValue(resources, "windowFullscreen", false /*defaultValue*/); - if (windowFullscreen == false && mWindowIsFloating == false) { + if (!windowFullscreen && !mWindowIsFloating) { // default value mStatusBarSize = DEFAULT_STATUS_BAR_HEIGHT; @@ -1079,7 +1076,7 @@ public class RenderSessionImpl extends RenderAction { boolean windowNoTitle = getBooleanThemeValue(resources, "windowNoTitle", false /*defaultValue*/); - if (windowNoTitle == false) { + if (!windowNoTitle) { // default size of the window title bar mTitleBarSize = DEFAULT_TITLE_BAR_HEIGHT; @@ -1106,7 +1103,7 @@ public class RenderSessionImpl extends RenderAction { } private void findNavigationBar(RenderResources resources, DisplayMetrics metrics) { - if (hasSoftwareButtons() && mWindowIsFloating == false) { + if (hasSoftwareButtons() && !mWindowIsFloating) { // default value mNavigationBarSize = 48; // ?? @@ -1120,15 +1117,12 @@ public class RenderSessionImpl extends RenderAction { int shortSize = hardwareConfig.getScreenHeight(); // 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 - barOnBottom = false; - } else { - // 600+dp: "tablet" UI with bar on the bottom - barOnBottom = true; - } + // 0-599dp: "phone" UI with bar on the side + // 600+dp: "tablet" UI with bar on the bottom + barOnBottom = shortSizeDp >= 600; } if (barOnBottom) { @@ -1179,13 +1173,15 @@ public class RenderSessionImpl extends RenderAction { } /** - * Post process on a view hierachy that was just inflated. - *

At the moment this only support TabHost: If {@link TabHost} is detected, look for the + * Post process on a view hierarchy that was just inflated. + *

+ * 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 * based on the content of the {@link FrameLayout}. * @param view the root view to process. * @param projectCallback callback to the project. */ + @SuppressWarnings("deprecation") // For the use of Pair private void postInflateProcess(View view, IProjectCallback projectCallback) throws PostInflateException { if (view instanceof TabHost) { @@ -1288,7 +1284,7 @@ public class RenderSessionImpl extends RenderAction { "TabHost requires a TabWidget with id \"android:id/tabs\".\n"); } - if ((v instanceof TabWidget) == false) { + if (!(v instanceof TabWidget)) { throw new PostInflateException(String.format( "TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName())); @@ -1297,12 +1293,14 @@ public class RenderSessionImpl extends RenderAction { v = tabHost.findViewById(android.R.id.tabcontent); 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( "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( "TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName())); @@ -1310,7 +1308,7 @@ public class RenderSessionImpl extends RenderAction { 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(); // this must be called before addTab() so that the TabHost searches its TabWidget @@ -1328,13 +1326,13 @@ public class RenderSessionImpl extends RenderAction { } }); tabHost.addTab(spec); - return; } 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++) { View child = content.getChildAt(i); String tabSpec = String.format("tab_spec%d", i+1); int id = child.getId(); + @SuppressWarnings("deprecation") Pair resource = projectCallback.resolveResourceId(id); String name; if (resource != null) { @@ -1563,8 +1561,7 @@ public class RenderSessionImpl extends RenderAction { /** * Creates the action bar. Also queries the project callback for missing information. */ - private ActionBarLayout createActionBar(BridgeContext context, SessionParams params) - throws XmlPullParserException { + private ActionBarLayout createActionBar(BridgeContext context, SessionParams params) { ActionBarLayout actionBar = new ActionBarLayout(context, params); actionBar.setLayoutParams(new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); -- cgit v1.1