Fix warnings in SuwLib
Fix various issues flagged by compiler and ErrorProne, including raw types, unchecked casts, missing overrides and others. Test: Existing tests pass. `./gradlew connectedAndroidTest test` Change-Id: I4008504430760b436d6dc6c52a9dfb169dcfa49b
This commit is contained in:
parent
eb7c2d1e90
commit
9ac3d54040
|
@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.Build.VERSION_CODES;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.Adapter;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -128,14 +129,14 @@ public class GlifRecyclerLayout extends GlifLayout {
|
|||
/**
|
||||
* @see RecyclerMixin#setAdapter(Adapter)
|
||||
*/
|
||||
public void setAdapter(Adapter adapter) {
|
||||
public void setAdapter(Adapter<? extends ViewHolder> adapter) {
|
||||
mRecyclerMixin.setAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RecyclerMixin#getAdapter()
|
||||
*/
|
||||
public Adapter getAdapter() {
|
||||
public Adapter<? extends ViewHolder> getAdapter() {
|
||||
return mRecyclerMixin.getAdapter();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.Adapter;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -76,14 +77,14 @@ public class SetupWizardRecyclerLayout extends SetupWizardLayout {
|
|||
/**
|
||||
* @see RecyclerMixin#getAdapter()
|
||||
*/
|
||||
public Adapter getAdapter() {
|
||||
public Adapter<? extends ViewHolder> getAdapter() {
|
||||
return mRecyclerMixin.getAdapter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RecyclerMixin#setAdapter(Adapter)
|
||||
*/
|
||||
public void setAdapter(Adapter adapter) {
|
||||
public void setAdapter(Adapter<? extends ViewHolder> adapter) {
|
||||
mRecyclerMixin.setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.support.annotation.Nullable;
|
|||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.Adapter;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
|
@ -155,10 +156,11 @@ public class RecyclerMixin implements Mixin {
|
|||
*
|
||||
* @return The adapter, or {@code null} if the recycler view has no adapter.
|
||||
*/
|
||||
public Adapter getAdapter() {
|
||||
final RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
|
||||
public <VH extends ViewHolder> Adapter<VH> getAdapter() {
|
||||
@SuppressWarnings("unchecked") // RecyclerView.getAdapter returns raw type :(
|
||||
final RecyclerView.Adapter<VH> adapter = (Adapter<VH>) mRecyclerView.getAdapter();
|
||||
if (adapter instanceof HeaderRecyclerView.HeaderAdapter) {
|
||||
return ((HeaderRecyclerView.HeaderAdapter) adapter).getWrappedAdapter();
|
||||
return ((HeaderRecyclerView.HeaderAdapter<VH>) adapter).getWrappedAdapter();
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
@ -166,7 +168,7 @@ public class RecyclerMixin implements Mixin {
|
|||
/**
|
||||
* Sets the adapter on the recycler view in this layout.
|
||||
*/
|
||||
public void setAdapter(Adapter adapter) {
|
||||
public void setAdapter(Adapter<? extends ViewHolder> adapter) {
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.annotation.SuppressLint;
|
|||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -59,12 +58,15 @@ public class HeaderRecyclerView extends RecyclerView {
|
|||
|
||||
/**
|
||||
* An adapter that can optionally add one header item to the RecyclerView.
|
||||
*
|
||||
* @param <CVH> Type of the content view holder. i.e. view holder type of the wrapped adapter.
|
||||
*/
|
||||
public static class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public static class HeaderAdapter<CVH extends ViewHolder>
|
||||
extends RecyclerView.Adapter<ViewHolder> {
|
||||
|
||||
private static final int HEADER_VIEW_TYPE = Integer.MAX_VALUE;
|
||||
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
private RecyclerView.Adapter<CVH> mAdapter;
|
||||
private View mHeader;
|
||||
|
||||
private final AdapterDataObserver mObserver = new AdapterDataObserver() {
|
||||
|
@ -111,7 +113,7 @@ public class HeaderRecyclerView extends RecyclerView {
|
|||
}
|
||||
};
|
||||
|
||||
public HeaderAdapter(RecyclerView.Adapter adapter) {
|
||||
public HeaderAdapter(RecyclerView.Adapter<CVH> adapter) {
|
||||
mAdapter = adapter;
|
||||
mAdapter.registerAdapterDataObserver(mObserver);
|
||||
setHasStableIds(mAdapter.hasStableIds());
|
||||
|
@ -142,20 +144,23 @@ public class HeaderRecyclerView extends RecyclerView {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("unchecked") // Non-header position always return type CVH
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
if (mHeader != null) {
|
||||
position--;
|
||||
}
|
||||
|
||||
if (holder instanceof HeaderViewHolder) {
|
||||
if (mHeader == null) {
|
||||
throw new IllegalStateException("HeaderViewHolder cannot find mHeader");
|
||||
}
|
||||
if (mHeader.getParent() != null) {
|
||||
((ViewGroup) mHeader.getParent()).removeView(mHeader);
|
||||
}
|
||||
FrameLayout mHeaderParent = (FrameLayout) holder.itemView;
|
||||
mHeaderParent.addView(mHeader);
|
||||
} else {
|
||||
mAdapter.onBindViewHolder(holder, position);
|
||||
mAdapter.onBindViewHolder((CVH) holder, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,8 +199,7 @@ public class HeaderRecyclerView extends RecyclerView {
|
|||
mHeader = header;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public RecyclerView.Adapter getWrappedAdapter() {
|
||||
public RecyclerView.Adapter<CVH> getWrappedAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
}
|
||||
|
@ -266,6 +270,7 @@ public class HeaderRecyclerView extends RecyclerView {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes,unchecked") // RecyclerView.setAdapter uses raw type :(
|
||||
public void setAdapter(Adapter adapter) {
|
||||
if (mHeader != null && adapter != null) {
|
||||
final HeaderAdapter headerAdapter = new HeaderAdapter(adapter);
|
||||
|
|
|
@ -116,6 +116,7 @@ public class Item extends AbstractItem {
|
|||
return mVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewId() {
|
||||
return getId();
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ public abstract class ReflectionInflater<T> extends SimpleInflater<T> {
|
|||
|
||||
/* static section */
|
||||
|
||||
private static final Class[] CONSTRUCTOR_SIGNATURE =
|
||||
new Class[] {Context.class, AttributeSet.class};
|
||||
private static final Class<?>[] CONSTRUCTOR_SIGNATURE =
|
||||
new Class<?>[] {Context.class, AttributeSet.class};
|
||||
|
||||
private static final HashMap<String, Constructor<?>> sConstructorMap = new HashMap<>();
|
||||
|
||||
|
@ -87,13 +87,16 @@ public abstract class ReflectionInflater<T> extends SimpleInflater<T> {
|
|||
if (prefix != null && qualifiedName.indexOf('.') == -1) {
|
||||
qualifiedName = prefix.concat(qualifiedName);
|
||||
}
|
||||
Constructor constructor = sConstructorMap.get(qualifiedName);
|
||||
@SuppressWarnings("unchecked") // qualifiedName should correspond to a subclass of T
|
||||
Constructor<? extends T> constructor =
|
||||
(Constructor<? extends T>) sConstructorMap.get(qualifiedName);
|
||||
|
||||
try {
|
||||
if (constructor == null) {
|
||||
// Class not found in the cache, see if it's real,
|
||||
// and try to add it
|
||||
Class<?> clazz = mContext.getClassLoader().loadClass(qualifiedName);
|
||||
// Class not found in the cache, see if it's real, and try to add it
|
||||
@SuppressWarnings("unchecked") // qualifiedName should correspond to a subclass of T
|
||||
Class<? extends T> clazz =
|
||||
(Class<? extends T>) mContext.getClassLoader().loadClass(qualifiedName);
|
||||
constructor = clazz.getConstructor(CONSTRUCTOR_SIGNATURE);
|
||||
constructor.setAccessible(true);
|
||||
sConstructorMap.put(tagName, constructor);
|
||||
|
@ -101,8 +104,7 @@ public abstract class ReflectionInflater<T> extends SimpleInflater<T> {
|
|||
|
||||
mTempConstructorArgs[0] = mContext;
|
||||
mTempConstructorArgs[1] = attrs;
|
||||
// noinspection unchecked
|
||||
final T item = (T) constructor.newInstance(mTempConstructorArgs);
|
||||
final T item = constructor.newInstance(mTempConstructorArgs);
|
||||
mTempConstructorArgs[0] = null;
|
||||
mTempConstructorArgs[1] = null;
|
||||
return item;
|
||||
|
|
|
@ -19,8 +19,8 @@ package com.android.setupwizardlib.template;
|
|||
/**
|
||||
* Marker interface to indicate Mixin classes.
|
||||
*
|
||||
* @see TemplateLayout#registerMixin(Class, Mixin)
|
||||
* @see TemplateLayout#getMixin(Class)
|
||||
* @see com.android.setupwizardlib.TemplateLayout#registerMixin(Class, Mixin)
|
||||
* @see com.android.setupwizardlib.TemplateLayout#getMixin(Class)
|
||||
*/
|
||||
public interface Mixin {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue