From 63cdc5ccb7f1f61d0e752e38d7e57c690658a0ac Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Wed, 23 Nov 2016 11:37:38 -0800 Subject: [PATCH] [SuwLib] Turn on fatal lint Fix (or suppress) lint warnings and make it fatal again in the build process. Additionally, warnings are treated as errors now. If there are warnings that are not applicable, add @SuppressLint or tools:ignore to suppress the warning, so code reviewers can be aware of the lint issue too. Test: ./gradlew lint Change-Id: I63c83ff1b95a0817dc2ac777adce0fa9f9ebd45a --- .../res/drawable/suw_card_bg_dark.xml | 5 ++-- .../res/drawable/suw_card_bg_light.xml | 5 ++-- .../res/drawable/suw_navbar_btn_bg_dark.xml | 6 ++-- .../res/drawable/suw_navbar_btn_bg_light.xml | 7 +++-- .../setupwizardlib/test/RichTextViewTest.java | 3 ++ .../suw_glif_preference_template_header.xml | 5 +++- library/full-support/res/values/layouts.xml | 9 ++++-- .../view/HeaderRecyclerView.java | 3 ++ library/main/AndroidManifest.xml | 7 +---- .../animator-ldrtl-v11/suw_slide_back_in.xml | 5 +++- .../animator-ldrtl-v11/suw_slide_back_out.xml | 5 +++- .../animator-ldrtl-v11/suw_slide_next_in.xml | 5 +++- .../animator-ldrtl-v11/suw_slide_next_out.xml | 5 +++- library/main/res/drawable-v21/suw_card_bg.xml | 5 +++- library/main/res/layout/suw_items_default.xml | 4 ++- .../main/res/layout/suw_items_description.xml | 5 +++- library/main/res/layout/suw_items_verbose.xml | 8 +++-- library/main/res/layout/suw_navbar_view.xml | 18 +++++++++--- .../layout/suw_no_scroll_template_header.xml | 4 ++- library/main/res/values/dimens.xml | 26 ++++++++++------- library/main/res/values/layouts.xml | 29 +++++++++++++++---- library/main/res/values/styles.xml | 20 ++++++++----- .../android/setupwizardlib/GlifLayout.java | 2 ++ .../setupwizardlib/SetupWizardLayout.java | 2 +- .../util/DrawableLayoutDirectionHelper.java | 6 +++- library/self.gradle | 4 +-- .../DrawableLayoutDirectionHelperTest.java | 4 +++ .../test/SetupWizardLayoutTest.java | 19 ++++++------ 28 files changed, 157 insertions(+), 69 deletions(-) diff --git a/library/eclair-mr1/res/drawable/suw_card_bg_dark.xml b/library/eclair-mr1/res/drawable/suw_card_bg_dark.xml index e3d29d7..cd115cf 100644 --- a/library/eclair-mr1/res/drawable/suw_card_bg_dark.xml +++ b/library/eclair-mr1/res/drawable/suw_card_bg_dark.xml @@ -16,12 +16,13 @@ --> + xmlns:tools="http://schemas.android.com/tools" android:shape="rectangle"> - + + diff --git a/library/eclair-mr1/res/drawable/suw_card_bg_light.xml b/library/eclair-mr1/res/drawable/suw_card_bg_light.xml index b6d6233..cd40dbe 100644 --- a/library/eclair-mr1/res/drawable/suw_card_bg_light.xml +++ b/library/eclair-mr1/res/drawable/suw_card_bg_light.xml @@ -16,12 +16,13 @@ --> + xmlns:tools="http://schemas.android.com/tools" android:shape="rectangle"> - + + diff --git a/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_dark.xml b/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_dark.xml index 7f7f378..f4131e5 100644 --- a/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_dark.xml +++ b/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_dark.xml @@ -15,10 +15,12 @@ limitations under the License. --> - + - + + diff --git a/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_light.xml b/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_light.xml index 15b567c..5d3bcfa 100644 --- a/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_light.xml +++ b/library/eclair-mr1/res/drawable/suw_navbar_btn_bg_light.xml @@ -15,10 +15,13 @@ limitations under the License. --> - + - + + diff --git a/library/eclair-mr1/test/src/com/android/setupwizardlib/test/RichTextViewTest.java b/library/eclair-mr1/test/src/com/android/setupwizardlib/test/RichTextViewTest.java index 31b9561..2e2b01e 100644 --- a/library/eclair-mr1/test/src/com/android/setupwizardlib/test/RichTextViewTest.java +++ b/library/eclair-mr1/test/src/com/android/setupwizardlib/test/RichTextViewTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import android.annotation.SuppressLint; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -96,6 +97,7 @@ public class RichTextViewTest { } + @SuppressLint("SetTextI18n") // It's OK. This is just a test. @Test public void testTextContainingNoLinksAreNotFocusable() { RichTextView textView = new RichTextView(InstrumentationRegistry.getContext()); @@ -108,6 +110,7 @@ public class RichTextViewTest { // Based on the text contents of the text view, the "focusable" property of the element // should also be automatically changed. + @SuppressLint("SetTextI18n") // It's OK. This is just a test. @Test public void testRichTxtViewFocusChangesWithTextChange() { RichTextView textView = new RichTextView(InstrumentationRegistry.getContext()); diff --git a/library/full-support/res/layout/suw_glif_preference_template_header.xml b/library/full-support/res/layout/suw_glif_preference_template_header.xml index 6377616..b870251 100644 --- a/library/full-support/res/layout/suw_glif_preference_template_header.xml +++ b/library/full-support/res/layout/suw_glif_preference_template_header.xml @@ -16,9 +16,12 @@ --> + android:orientation="vertical" + tools:ignore="UnusedResources"> + - + @layout/suw_preference_recycler_view_header @layout/suw_preference_template_header @layout/suw_recycler_template_header - @layout/suw_recycler_template_header_collapsed + + @layout/suw_recycler_template_header_collapsed + @layout/suw_glif_blank_template_compact @layout/suw_glif_recycler_template_compact diff --git a/library/full-support/src/com/android/setupwizardlib/view/HeaderRecyclerView.java b/library/full-support/src/com/android/setupwizardlib/view/HeaderRecyclerView.java index f9f1b2b..8eae9c0 100644 --- a/library/full-support/src/com/android/setupwizardlib/view/HeaderRecyclerView.java +++ b/library/full-support/src/com/android/setupwizardlib/view/HeaderRecyclerView.java @@ -16,6 +16,7 @@ package com.android.setupwizardlib.view; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.os.Build; @@ -116,6 +117,8 @@ public class HeaderRecyclerView extends RecyclerView { setHasStableIds(mAdapter.hasStableIds()); } + @SuppressLint("InlinedApi") // MATCH_PARENT is the same constant as FILL_PARENT available + // on earlier versions. @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { /* diff --git a/library/main/AndroidManifest.xml b/library/main/AndroidManifest.xml index 308a7e5..1c9c5ee 100644 --- a/library/main/AndroidManifest.xml +++ b/library/main/AndroidManifest.xml @@ -15,11 +15,6 @@ limitations under the License. --> - - - + diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml b/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml index 195c8b1..a01dcd8 100644 --- a/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml +++ b/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml @@ -19,8 +19,11 @@ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are not stripped out by proguard. --> + android:valueTo="0" + tools:ignore="UnusedResources" /> + diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml b/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml index a910233..59760ca 100644 --- a/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml +++ b/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml @@ -19,8 +19,11 @@ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are not stripped out by proguard. --> + android:valueTo="-1.0" + tools:ignore="UnusedResources" /> + diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml b/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml index 1b8c68e..a673f40 100644 --- a/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml +++ b/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml @@ -19,8 +19,11 @@ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are not stripped out by proguard. --> + android:valueTo="0" + tools:ignore="UnusedResources" /> + diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml b/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml index 9442096..262e085 100644 --- a/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml +++ b/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml @@ -19,8 +19,11 @@ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are not stripped out by proguard. --> + android:valueTo="1.0" + tools:ignore="UnusedResources" /> + diff --git a/library/main/res/drawable-v21/suw_card_bg.xml b/library/main/res/drawable-v21/suw_card_bg.xml index 13d1d4e..f79ca4c 100644 --- a/library/main/res/drawable-v21/suw_card_bg.xml +++ b/library/main/res/drawable-v21/suw_card_bg.xml @@ -15,8 +15,11 @@ limitations under the License. --> + + xmlns:tools="http://schemas.android.com/tools" + android:shape="rectangle" + tools:ignore="UnusedResources"> + android:orientation="horizontal" + tools:ignore="DisableBaselineAlignment"> + + android:orientation="horizontal" + tools:ignore="DisableBaselineAlignment,UnusedResources"> + + + android:orientation="horizontal" + tools:ignore="DisableBaselineAlignment,UnusedResources"> + + + android:layout_height="wrap_content" + android:contentDescription="@null" /> diff --git a/library/main/res/layout/suw_navbar_view.xml b/library/main/res/layout/suw_navbar_view.xml index 38d0ce6..9a57a32 100644 --- a/library/main/res/layout/suw_navbar_view.xml +++ b/library/main/res/layout/suw_navbar_view.xml @@ -15,7 +15,8 @@ limitations under the License. --> - + + android:drawableStart="@drawable/suw_navbar_ic_back" + tools:ignore="RtlHardcoded" /> + + android:visibility="gone" + tools:ignore="RtlHardcoded" /> + + android:text="@string/suw_next_button_label" + tools:ignore="RtlHardcoded" /> + diff --git a/library/main/res/layout/suw_no_scroll_template_header.xml b/library/main/res/layout/suw_no_scroll_template_header.xml index 413b329..48049a1 100644 --- a/library/main/res/layout/suw_no_scroll_template_header.xml +++ b/library/main/res/layout/suw_no_scroll_template_header.xml @@ -56,7 +56,9 @@ android:id="@+id/suw_layout_content" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_weight="1" /> + android:layout_weight="1" + tools:ignore="NestedWeights" /> + diff --git a/library/main/res/values/dimens.xml b/library/main/res/values/dimens.xml index ef2471e..a7c42de 100644 --- a/library/main/res/values/dimens.xml +++ b/library/main/res/values/dimens.xml @@ -15,7 +15,7 @@ limitations under the License. --> - + 40dp @@ -28,7 +28,6 @@ 1dp 24dp 15dp - 16sp 0dp 16dp @@ -60,8 +59,6 @@ 16dp 28dp - 256dp - 0dp @@ -95,11 +92,15 @@ 15dp 20dp - 88dp - 40dp + + 88dp + + 40dp - 72dp - 24dp + + 72dp + + 24dp 1dp @@ -107,7 +108,8 @@ 56dp - 6dp + + 6dp 10dp 56dp 24dp @@ -119,7 +121,9 @@ -7dp 7dp - 16dp - 0dp + + 16dp + + 0dp diff --git a/library/main/res/values/layouts.xml b/library/main/res/values/layouts.xml index 74a6479..08fdef4 100644 --- a/library/main/res/values/layouts.xml +++ b/library/main/res/values/layouts.xml @@ -15,18 +15,35 @@ limitations under the License. --> - + @layout/suw_template_header - @layout/suw_template_header_collapsed + + + + @layout/suw_template_header_collapsed + @layout/suw_list_template_header - @layout/suw_list_template_header_collapsed - @layout/suw_no_scroll_template_header - @layout/suw_no_scroll_template_header_collapsed + + + + @layout/suw_list_template_header_collapsed + + + + @layout/suw_no_scroll_template_header + + + + @layout/suw_no_scroll_template_header_collapsed @layout/suw_glif_template_compact + @layout/suw_glif_list_template_compact - @layout/suw_glif_blank_template_compact + + + + @layout/suw_glif_blank_template_compact diff --git a/library/main/res/values/styles.xml b/library/main/res/values/styles.xml index 731f5a1..e248515 100644 --- a/library/main/res/values/styles.xml +++ b/library/main/res/values/styles.xml @@ -28,7 +28,8 @@ - - - @@ -57,7 +60,8 @@ ?android:attr/textColorSecondary - - - @@ -103,7 +109,7 @@ diff --git a/library/main/src/com/android/setupwizardlib/GlifLayout.java b/library/main/src/com/android/setupwizardlib/GlifLayout.java index 4a38cad..13d35fe 100644 --- a/library/main/src/com/android/setupwizardlib/GlifLayout.java +++ b/library/main/src/com/android/setupwizardlib/GlifLayout.java @@ -16,6 +16,7 @@ package com.android.setupwizardlib; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; @@ -220,6 +221,7 @@ public class GlifLayout extends TemplateLayout { return mPrimaryColor; } + @SuppressLint("InlinedApi") // View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN is guarded by SDK check private void setGlifPatternColor(ColorStateList color) { if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); diff --git a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java index ce4896f..79d9222 100644 --- a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java +++ b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java @@ -122,7 +122,7 @@ public class SetupWizardLayout extends TemplateLayout { // Set the illustration aspect ratio. See Illustration.setAspectRatio(float). This will - // override suwIllustrationPaddingTop if its value is not 0. + // override suwDecorPaddingTop if its value is not 0. float illustrationAspectRatio = a.getFloat( R.styleable.SuwSetupWizardLayout_suwIllustrationAspectRatio, -1f); if (illustrationAspectRatio == -1f) { diff --git a/library/main/src/com/android/setupwizardlib/util/DrawableLayoutDirectionHelper.java b/library/main/src/com/android/setupwizardlib/util/DrawableLayoutDirectionHelper.java index bf4c0c2..b0afaba 100644 --- a/library/main/src/com/android/setupwizardlib/util/DrawableLayoutDirectionHelper.java +++ b/library/main/src/com/android/setupwizardlib/util/DrawableLayoutDirectionHelper.java @@ -16,6 +16,7 @@ package com.android.setupwizardlib.util; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.drawable.Drawable; import android.graphics.drawable.InsetDrawable; @@ -31,6 +32,7 @@ public class DrawableLayoutDirectionHelper { * Creates an {@link android.graphics.drawable.InsetDrawable} according to the layout direction * of {@code view}. */ + @SuppressLint("InlinedApi") // Use of View.LAYOUT_DIRECTION_RTL is guarded by version check public static InsetDrawable createRelativeInsetDrawable(Drawable drawable, int insetStart, int insetTop, int insetEnd, int insetBottom, View view) { boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 @@ -43,6 +45,7 @@ public class DrawableLayoutDirectionHelper { * Creates an {@link android.graphics.drawable.InsetDrawable} according to the layout direction * of {@code context}. */ + @SuppressLint("InlinedApi") // Use of View.LAYOUT_DIRECTION_RTL is guarded by version check public static InsetDrawable createRelativeInsetDrawable(Drawable drawable, int insetStart, int insetTop, int insetEnd, int insetBottom, Context context) { boolean isRtl = false; @@ -59,9 +62,10 @@ public class DrawableLayoutDirectionHelper { * Creates an {@link android.graphics.drawable.InsetDrawable} according to * {@code layoutDirection}. */ + @SuppressLint("InlinedApi") // Given layoutDirection will not be View.LAYOUT_DIRECTION_RTL if + // SDK version doesn't support it. public static InsetDrawable createRelativeInsetDrawable(Drawable drawable, int insetStart, int insetTop, int insetEnd, int insetBottom, int layoutDirection) { - //noinspection AndroidLintInlinedApi return createRelativeInsetDrawable(drawable, insetStart, insetTop, insetEnd, insetBottom, layoutDirection == View.LAYOUT_DIRECTION_RTL); } diff --git a/library/self.gradle b/library/self.gradle index e155fee..26020a6 100644 --- a/library/self.gradle +++ b/library/self.gradle @@ -35,11 +35,11 @@ android.sourceSets { android.defaultConfig.testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" android.lintOptions { - // TODO: Fix lint errors and re-enable fatal lint - abortOnError false + abortOnError true htmlReport true textOutput 'stderr' textReport true + warningsAsErrors true xmlReport false } diff --git a/library/test/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java b/library/test/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java index 2038a70..1aba00c 100644 --- a/library/test/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java +++ b/library/test/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java @@ -19,6 +19,7 @@ package com.android.setupwizardlib.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Configuration; import android.graphics.Color; @@ -46,6 +47,7 @@ public class DrawableLayoutDirectionHelperTest { @Test public void testCreateRelativeInsetDrawableLtr() { final Drawable drawable = new ColorDrawable(Color.RED); + @SuppressLint("InlinedApi") // Testing with inlined constant is OK here final InsetDrawable insetDrawable = DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable, 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */, @@ -63,6 +65,7 @@ public class DrawableLayoutDirectionHelperTest { @Test public void testCreateRelativeInsetDrawableRtl() { final Drawable drawable = new ColorDrawable(Color.RED); + @SuppressLint("InlinedApi") // Testing with inlined constant is OK here final InsetDrawable insetDrawable = DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable, 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */, @@ -133,6 +136,7 @@ public class DrawableLayoutDirectionHelperTest { } @Override + @SuppressLint("InlinedApi") // Testing with inlined constant is OK here public int getLayoutDirection() { return View.LAYOUT_DIRECTION_RTL; } diff --git a/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java b/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java index 72ab637..1e74bad 100644 --- a/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java +++ b/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java @@ -28,6 +28,7 @@ import android.content.Context; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Parcelable; +import android.support.annotation.IdRes; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -51,6 +52,9 @@ import org.junit.runner.RunWith; @SmallTest public class SetupWizardLayoutTest { + @IdRes + private static final int ID1234 = 1234; + private Context mContext; @Before @@ -179,15 +183,13 @@ public class SetupWizardLayoutTest { @Test public void testOnRestoreFromInstanceState() { final SetupWizardLayout layout = new SetupWizardLayout(mContext); - // noinspection ResourceType - layout.setId(1234); + layout.setId(ID1234); SparseArray container = new SparseArray<>(); layout.saveHierarchyState(container); final SetupWizardLayout layout2 = new SetupWizardLayout(mContext); - // noinspection ResourceType - layout2.setId(1234); + layout2.setId(ID1234); layout2.restoreHierarchyState(container); assertFalse("Progress bar should not be shown", layout2.isProgressBarShown()); @@ -196,8 +198,7 @@ public class SetupWizardLayoutTest { @Test public void testOnRestoreFromInstanceStateProgressBarShown() { final SetupWizardLayout layout = new SetupWizardLayout(mContext); - // noinspection ResourceType - layout.setId(1234); + layout.setId(ID1234); layout.setProgressBarShown(true); @@ -205,8 +206,7 @@ public class SetupWizardLayoutTest { layout.saveHierarchyState(container); final SetupWizardLayout layout2 = new SetupWizardLayout(mContext); - // noinspection ResourceType - layout2.setId(1234); + layout2.setId(ID1234); layout2.restoreHierarchyState(container); assertTrue("Progress bar should be shown", layout2.isProgressBarShown()); @@ -215,8 +215,7 @@ public class SetupWizardLayoutTest { @Test public void testOnRestoreFromIncompatibleInstanceState() { final SetupWizardLayout layout = new SetupWizardLayout(mContext); - // noinspection ResourceType - layout.setId(1234); + layout.setId(ID1234); SparseArray container = new SparseArray<>(); container.put(1234, AbsSavedState.EMPTY_STATE);