From 62253b6c60b8176edf6af2f0c342fd0668e70dc2 Mon Sep 17 00:00:00 2001 From: Diego Perez Date: Fri, 3 Feb 2017 11:50:59 +0000 Subject: [PATCH] A bit of warning cleanup Test: Covered by existing tests Change-Id: I3f27540efdb47e3c1db02f85c67c81e36d159a79 --- .../layoutlib/bridge/BridgeRenderSession.java | 8 ++--- .../android/layoutlib/bridge/MockView.java | 2 +- .../android/layoutlib/bridge/impl/Layout.java | 2 ++ .../bridge/impl/RenderSessionImpl.java | 33 +++++++++---------- .../bridge/util/NinePatchInputStream.java | 7 ++-- .../bridge/util/ReflectionUtils.java | 4 +-- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java index 77b131fa9d866..4ffb2e2bba9d1 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java @@ -132,7 +132,7 @@ public class BridgeRenderSession extends RenderSession { @Override public Result insertChild(Object parentView, ILayoutPullParser childXml, int index, IAnimationListener listener) { - if (parentView instanceof ViewGroup == false) { + if (!(parentView instanceof ViewGroup)) { throw new IllegalArgumentException("parentView is not a ViewGroup"); } @@ -155,10 +155,10 @@ public class BridgeRenderSession extends RenderSession { @Override public Result moveChild(Object parentView, Object childView, int index, Map layoutParams, IAnimationListener listener) { - if (parentView instanceof ViewGroup == false) { + if (!(parentView instanceof ViewGroup)) { throw new IllegalArgumentException("parentView is not a ViewGroup"); } - if (childView instanceof View == false) { + if (!(childView instanceof View)) { throw new IllegalArgumentException("childView is not a View"); } @@ -179,7 +179,7 @@ public class BridgeRenderSession extends RenderSession { @Override public Result removeChild(Object childView, IAnimationListener listener) { - if (childView instanceof View == false) { + if (!(childView instanceof View)) { throw new IllegalArgumentException("childView is not a View"); } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java index d392f213e5c8d..91668af09f899 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java @@ -100,7 +100,7 @@ public class MockView extends FrameLayout { mView.setText(text); } - public void setGravity(int gravity) { + private void setGravity(int gravity) { mView.setGravity(gravity); } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java index 2fe3ed5dc5ee0..287334c2fc8b1 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java @@ -305,6 +305,7 @@ class Layout extends RelativeLayout { return Bridge.getResourceId(ResourceType.ID, ID_PREFIX + name); } + @SuppressWarnings("deprecation") @Override public void requestFitSystemWindows() { // The framework call would usually bubble up to ViewRootImpl but, in layoutlib, Layout will @@ -416,6 +417,7 @@ class Layout extends RelativeLayout { } } + @SuppressWarnings("SameParameterValue") private int getDimension(String attr, boolean isFramework, int defaultValue) { ResourceValue value = mResources.findItemInTheme(attr, isFramework); value = mResources.resolveResValue(value); 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 85fe2a450e4f9..d21955e35409c 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 @@ -144,7 +144,7 @@ public class RenderSessionImpl extends RenderAction { private static final class PostInflateException extends Exception { private static final long serialVersionUID = 1L; - public PostInflateException(String message) { + private PostInflateException(String message) { super(message); } } @@ -242,11 +242,13 @@ public class RenderSessionImpl extends RenderAction { // Then measure only the content with UNSPECIFIED to see the size difference // and apply this to the screen size. + View measuredView = mContentRoot.getChildAt(0); + // 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), + mViewRoot, measuredView, mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY); @@ -258,6 +260,10 @@ public class RenderSessionImpl extends RenderAction { mMeasuredScreenWidth, widthMeasureSpecMode, mMeasuredScreenHeight, heightMeasureSpecMode); + // If measuredView is not null, exactMeasure nor result will be null. + assert exactMeasure != null; + assert result != null; + // now look at the difference and add what is needed. if (renderingMode.isHorizExpand()) { int measuredWidth = exactMeasure.getFirst(); @@ -406,8 +412,7 @@ public class RenderSessionImpl extends RenderAction { * @param canvas an optional canvas to render the views to. If null, only the measure and * layout steps will be executed. */ - private static Result renderAndBuildResult(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, - @Nullable Canvas canvas, int width, int height) { + private static Result renderAndBuildResult(@NonNull ViewGroup viewRoot, @Nullable Canvas canvas) { if (canvas == null) { return SUCCESS.createResult(); } @@ -551,7 +556,7 @@ public class RenderSessionImpl extends RenderAction { long initialTime = System_Delegate.nanoTime(); if (!mFirstFrameExecuted) { // We need to run an initial draw call to initialize the animations - renderAndBuildResult(getContext(), mViewRoot, NOP_CANVAS, mMeasuredScreenWidth, mMeasuredScreenHeight); + renderAndBuildResult(mViewRoot, NOP_CANVAS); // The first frame will initialize the animations Choreographer_Delegate.doFrame(initialTime); @@ -560,8 +565,7 @@ public class RenderSessionImpl extends RenderAction { // Second frame will move the animations Choreographer_Delegate.doFrame(initialTime + mElapsedFrameTimeNanos); } - renderResult = renderAndBuildResult(getContext(), mViewRoot, mCanvas, mMeasuredScreenWidth, - mMeasuredScreenHeight); + renderResult = renderAndBuildResult(mViewRoot, mCanvas); } mSystemViewInfoList = @@ -1206,7 +1210,7 @@ public class RenderSessionImpl extends RenderAction { * Sets up a {@link TabHost} object. * @param tabHost the TabHost to setup. * @param layoutlibCallback The project callback object to access the project R class. - * @throws PostInflateException + * @throws PostInflateException if TabHost is missing the required ids for TabHost */ private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException { @@ -1254,12 +1258,7 @@ public class RenderSessionImpl extends RenderAction { TabSpec spec = tabHost.newTabSpec("tag") .setIndicator("Tab Label", tabHost.getResources() .getDrawable(android.R.drawable.ic_menu_info_details, null)) - .setContent(new TabHost.TabContentFactory() { - @Override - public View createTabContent(String tag) { - return new LinearLayout(getContext()); - } - }); + .setContent(tag -> new LinearLayout(getContext())); tabHost.addTab(spec); } else { // for each child of the frameLayout, add a new TabSpec @@ -1333,8 +1332,8 @@ public class RenderSessionImpl extends RenderAction { int childCount = viewGroup.getChildCount(); if (viewGroup == mContentRoot) { - List childrenWithoutOffset = new ArrayList(childCount); - List childrenWithOffset = new ArrayList(childCount); + List childrenWithoutOffset = new ArrayList<>(childCount); + List childrenWithOffset = new ArrayList<>(childCount); for (int i = 0; i < childCount; i++) { ViewInfo[] childViewInfo = visitContentRoot(viewGroup.getChildAt(i), hOffset, vOffset, @@ -1345,7 +1344,7 @@ public class RenderSessionImpl extends RenderAction { mViewInfoList = childrenWithOffset; return childrenWithoutOffset; } else { - List children = new ArrayList(childCount); + List children = new ArrayList<>(childCount); for (int i = 0; i < childCount; i++) { children.add(visit(viewGroup.getChildAt(i), hOffset, vOffset, setExtendedInfo, isContentFrame)); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/NinePatchInputStream.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/NinePatchInputStream.java index 96b795a05e089..f149b6cd8ef95 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/NinePatchInputStream.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/NinePatchInputStream.java @@ -34,12 +34,9 @@ public class NinePatchInputStream extends FileInputStream { @Override public boolean markSupported() { - if (mFakeMarkSupport) { - // this is needed so that BitmapFactory doesn't wrap this in a BufferedInputStream. - return true; - } + // this is needed so that BitmapFactory doesn't wrap this in a BufferedInputStream. + return mFakeMarkSupport || super.markSupported(); - return super.markSupported(); } public void disableFakeMarkSupport() { diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/ReflectionUtils.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/ReflectionUtils.java index 040191e859bab..b89718ff5ea67 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/ReflectionUtils.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/ReflectionUtils.java @@ -52,9 +52,7 @@ public class ReflectionUtils { Exception ex; try { return method.invoke(object, args); - } catch (IllegalAccessException e) { - ex = e; - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException e) { ex = e; } throw new ReflectionException(ex);