static fixes

This commit is contained in:
Gavriil Sitnikov 2017-02-21 12:51:54 +03:00
parent 80b8ad0eaa
commit 959c055655
21 changed files with 77 additions and 60 deletions

View File

@ -25,6 +25,7 @@ import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
@ -88,7 +89,7 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec
* @return String The string data associated with the resource.
*/
@NonNull
public String getString(@StringRes final int resId, final Object... formatArgs) {
public String getString(@StringRes final int resId, @Nullable final Object... formatArgs) {
return itemView.getResources().getString(resId, formatArgs);
}

View File

@ -402,7 +402,7 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
@SuppressWarnings("PMD.DefaultPackage")
@Deprecated
//it is for internal use only
void setAdapter(@Nullable final ObservableCollectionAdapter adapter) {
private void setAdapter(@Nullable final ObservableCollectionAdapter adapter) {
this.adapter = adapter;
}
@ -425,7 +425,7 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
* @return Requested String that matches with provided string resource id.
*/
@NonNull
public String getString(@StringRes final int stringRes, final Object... formatArgs) {
public String getString(@StringRes final int stringRes, @Nullable final Object... formatArgs) {
return itemView.getContext().getString(stringRes, formatArgs);
}

View File

@ -2,6 +2,7 @@ package ru.touchin.roboswag.components.navigation;
import android.os.Bundle;
import android.os.Parcel;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.IOException;
@ -40,7 +41,7 @@ public class SerializableBundle implements Serializable {
this.bundle = bundle;
}
private void writeObject(final ObjectOutputStream outputStream) throws IOException {
private void writeObject(@NonNull final ObjectOutputStream outputStream) throws IOException {
if (bundle != null) {
final Parcel parcel = Parcel.obtain();
parcel.writeBundle(bundle);
@ -53,7 +54,7 @@ public class SerializableBundle implements Serializable {
}
}
private void readObject(final ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
private void readObject(@NonNull final ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
final int size = inputStream.readInt();
if (size > 0) {
final byte[] bytes = new byte[size];

View File

@ -206,7 +206,7 @@ public class SimpleActionBarDrawerToggle extends ActionBarDrawerToggle
}
@Override
public void onDrawerClosed(final View view) {
public void onDrawerClosed(@NonNull final View view) {
activity.supportInvalidateOptionsMenu();
}
@ -220,13 +220,13 @@ public class SimpleActionBarDrawerToggle extends ActionBarDrawerToggle
}
@Override
public void onDrawerOpened(final View drawerView) {
public void onDrawerOpened(@NonNull final View drawerView) {
activity.hideSoftInput();
activity.supportInvalidateOptionsMenu();
}
@Override
public void onDrawerSlide(final View drawerView, final float slideOffset) {
public void onDrawerSlide(@NonNull final View drawerView, final float slideOffset) {
if (slideOffset >= this.slideOffset && slideOffset <= this.slidePosition
|| slideOffset <= this.slideOffset && slideOffset >= this.slidePosition) {
this.slideOffset = slideOffset;

View File

@ -415,7 +415,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
@Nullable final String backStackTag,
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
addToStack(StatelessViewControllerFragment.class, targetFragment,
StatelessViewControllerFragment.createState(viewControllerClass, null), backStackTag, transactionSetup);
StatelessViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
}
/**
@ -456,7 +456,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
@Nullable final String backStackTag,
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
addToStack(StatelessTargetedViewControllerFragment.class, targetFragment,
StatelessTargetedViewControllerFragment.createState(viewControllerClass, null), backStackTag, transactionSetup);
StatelessTargetedViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
}
/**

View File

@ -93,7 +93,7 @@ public abstract class BaseActivity extends AppCompatActivity
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
protected void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UiUtils.UI_LIFECYCLE_LC_GROUP.i(Lc.getCodePoint(this) + " requestCode: " + requestCode + "; resultCode: " + resultCode);
if (resultCode == RESULT_OK) {

View File

@ -52,6 +52,7 @@ public abstract class ViewControllerActivity<TLogic extends Logic> extends BaseA
*
* @return Object which represents application's logic.
*/
@NonNull
public TLogic getLogic() {
synchronized (ViewControllerActivity.class) {
if (reference == null) {

View File

@ -48,7 +48,7 @@ public class SimpleViewControllerFragment<TState extends AbstractState, TActivit
*/
@NonNull
public static Bundle createState(@NonNull final Class<? extends ViewController> viewControllerClass,
@Nullable final AbstractState state) {
@NonNull final AbstractState state) {
final Bundle result = createState(state);
result.putSerializable(VIEW_CONTROLLER_CLASS_EXTRA, viewControllerClass);
return result;
@ -72,4 +72,8 @@ public class SimpleViewControllerFragment<TState extends AbstractState, TActivit
? extends ViewControllerFragment<TState, TActivity>>>) getArguments().getSerializable(VIEW_CONTROLLER_CLASS_EXTRA);
}
protected static class DefaultState extends AbstractState {
// just default implementation
}
}

View File

@ -21,7 +21,6 @@ package ru.touchin.roboswag.components.navigation.fragments;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import ru.touchin.roboswag.components.navigation.AbstractState;
import ru.touchin.roboswag.components.navigation.ViewController;
@ -49,14 +48,14 @@ public class StatelessTargetedViewControllerFragment<TTargetState extends Abstra
*/
@NonNull
public static Bundle createState(@NonNull final Class<? extends ViewController> viewControllerClass) {
return createState(viewControllerClass, null);
return createState(viewControllerClass, new DefaultState());
}
@Nullable
@NonNull
@Override
public AbstractState getState() {
Lc.assertion("Trying to access to state of stateless fragment of " + getViewControllerClass());
return null;
return super.getState();
}
}

View File

@ -21,7 +21,6 @@ package ru.touchin.roboswag.components.navigation.fragments;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import ru.touchin.roboswag.components.navigation.AbstractState;
import ru.touchin.roboswag.components.navigation.ViewController;
@ -47,14 +46,14 @@ public class StatelessViewControllerFragment<TActivity extends ViewControllerAct
*/
@NonNull
public static Bundle createState(@NonNull final Class<? extends ViewController> viewControllerClass) {
return createState(viewControllerClass, null);
return createState(viewControllerClass, new DefaultState());
}
@Nullable
@NonNull
@Override
public AbstractState getState() {
Lc.assertion("Trying to access to state of stateless fragment of " + getViewControllerClass());
return null;
return super.getState();
}
}

View File

@ -110,7 +110,9 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
return result;
}
@NonNull
private final BehaviorSubject<TActivity> activitySubject = BehaviorSubject.create();
@NonNull
private final BehaviorSubject<Pair<PlaceholderView, Bundle>> viewSubject = BehaviorSubject.create();
@Nullable
private ViewController viewController;
@ -123,6 +125,7 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
*
* @return Object represents state.
*/
@NonNull
public TState getState() {
return state;
}
@ -151,6 +154,8 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
state = reserialize(state);
}
state.onCreate();
} else {
Lc.assertion("State is null");
}
viewControllerSubscription = Observable
.combineLatest(activitySubject.distinctUntilChanged(), viewSubject.distinctUntilChanged(),

View File

@ -27,6 +27,7 @@ import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
import rx.Observable;
/**
@ -75,16 +76,17 @@ public class Logic {
return result;
}
@NonNull
@SuppressWarnings("unchecked")
private static <T extends Logic> T constructLogic(@NonNull final Context context, @NonNull final Class<T> logicClass) {
if (logicClass.getConstructors().length != 1 || logicClass.getConstructors()[0].getParameterTypes().length != 1) {
throw new IllegalArgumentException("There should be only one public constructor(Context) for class " + logicClass);
throw new ShouldNotHappenException("There should be only one public constructor(Context) for class " + logicClass);
}
final Constructor<?> constructor = logicClass.getConstructors()[0];
try {
return (T) constructor.newInstance(context);
} catch (final Exception exception) {
throw new IllegalStateException(exception);
throw new ShouldNotHappenException(exception);
}
}

View File

@ -88,7 +88,7 @@ public final class Typefaces {
*/
@NonNull
public static Typeface getFromAttributes(@NonNull final Context context, @NonNull final AttributeSet attrs,
@StyleableRes final int[] styleableId, @StyleableRes final int attributeId) {
@NonNull @StyleableRes final int[] styleableId, @StyleableRes final int attributeId) {
final TypedArray typedArray = context.obtainStyledAttributes(attrs, styleableId);
final String customTypeface = typedArray.getString(attributeId);
typedArray.recycle();

View File

@ -100,7 +100,7 @@ public final class HeadsetStateObserver {
}
@Override
public void onReceive(final Context context, final Intent intent) {
public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction()) && !isInitialStickyBroadcast()) {
isWiredConnectedChangedEvent.onNext(intent.getIntExtra("state", 0) != 0);
}

View File

@ -41,13 +41,13 @@ public class TypefaceSpan extends MetricAffectingSpan {
}
@Override
public void updateMeasureState(final TextPaint textPaint) {
public void updateMeasureState(@NonNull final TextPaint textPaint) {
textPaint.setTypeface(typeface);
textPaint.setFlags(textPaint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
@Override
public void updateDrawState(final TextPaint textPaint) {
public void updateDrawState(@NonNull final TextPaint textPaint) {
textPaint.setTypeface(typeface);
textPaint.setFlags(textPaint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}

View File

@ -223,13 +223,16 @@ public final class PreferenceUtils {
public static <T extends Enum<T>> NonNullSafeStorable<String, T, String> enumStorable(@NonNull final String name,
@NonNull final Class<T> enumClass,
@NonNull final SharedPreferences preferences,
final T defaultValue) {
@NonNull final T defaultValue) {
return new Storable.Builder<String, T, String>(name, enumClass)
.setSafeStore(String.class, new PreferenceStore<>(preferences), new EnumToStringConverter<>())
.setDefaultValue(defaultValue)
.build();
}
private PreferenceUtils() {
}
private static class EnumToStringConverter<T extends Enum<T>> implements SafeConverter<T, String> {
@Nullable
@ -245,7 +248,4 @@ public final class PreferenceUtils {
}
}
private PreferenceUtils() {
}
}

View File

@ -22,6 +22,8 @@ package ru.touchin.roboswag.components.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Point;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
@ -44,6 +46,28 @@ public class AspectRatioFrameLayout extends FrameLayout {
private float aspectRatio;
private boolean wrapToContent;
public AspectRatioFrameLayout(@NonNull final Context context) {
this(context, null);
}
public AspectRatioFrameLayout(@NonNull final Context context, @Nullable final AttributeSet attrs) {
this(context, attrs, 0);
}
public AspectRatioFrameLayout(@NonNull final Context context, @Nullable final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
if (attrs == null) {
wrapToContent = false;
aspectRatio = DEFAULT_ASPECT_RATIO;
} else {
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AspectRatioFrameLayout);
wrapToContent = typedArray.getBoolean(R.styleable.AspectRatioFrameLayout_wrapToContent, false);
aspectRatio = typedArray.getFloat(R.styleable.AspectRatioFrameLayout_aspectRatio, DEFAULT_ASPECT_RATIO);
typedArray.recycle();
}
}
/* Returns aspect ratio of layout */
public float getAspectRatio() {
return aspectRatio;
@ -86,28 +110,6 @@ public class AspectRatioFrameLayout extends FrameLayout {
requestLayout();
}
public AspectRatioFrameLayout(final Context context) {
this(context, null);
}
public AspectRatioFrameLayout(final Context context, final AttributeSet attrs) {
this(context, attrs, 0);
}
public AspectRatioFrameLayout(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
if (attrs == null) {
wrapToContent = false;
aspectRatio = DEFAULT_ASPECT_RATIO;
} else {
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AspectRatioFrameLayout);
wrapToContent = typedArray.getBoolean(R.styleable.AspectRatioFrameLayout_wrapToContent, false);
aspectRatio = typedArray.getFloat(R.styleable.AspectRatioFrameLayout_aspectRatio, DEFAULT_ASPECT_RATIO);
typedArray.recycle();
}
}
private void setMeasuredDimensionWithAspectOfLesser(final int measuredWidth, final int measuredHeight) {
final float heightBasedOnMw = measuredWidth / aspectRatio;
if (heightBasedOnMw > measuredHeight) {
@ -126,6 +128,7 @@ public class AspectRatioFrameLayout extends FrameLayout {
}
}
@NonNull
private Point measureWrapChildren(final int widthMeasureSpec, final int heightMeasureSpec) {
final Point result = new Point();
for (int i = 0; i < getChildCount(); i++) {

View File

@ -32,6 +32,7 @@ import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import ru.touchin.roboswag.components.utils.UiUtils;
@ -133,7 +134,7 @@ public class MaterialProgressDrawable extends Drawable implements Runnable, Anim
}
@Override
protected void onBoundsChange(final Rect bounds) {
protected void onBoundsChange(@NonNull final Rect bounds) {
super.onBoundsChange(bounds);
updateArcBounds();
}
@ -171,7 +172,7 @@ public class MaterialProgressDrawable extends Drawable implements Runnable, Anim
}
@Override
public void setColorFilter(final ColorFilter colorFilter) {
public void setColorFilter(@Nullable final ColorFilter colorFilter) {
paint.setColorFilter(colorFilter);
invalidateSelf();
}

View File

@ -194,19 +194,19 @@ public class TypefacedEditText extends AppCompatEditText {
addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(final CharSequence oldText, final int start, final int count, final int after) {
public void beforeTextChanged(@NonNull final CharSequence oldText, final int start, final int count, final int after) {
//do nothing
}
@Override
public void onTextChanged(final CharSequence inputText, final int start, final int before, final int count) {
public void onTextChanged(@NonNull final CharSequence inputText, final int start, final int before, final int count) {
if (onTextChangedListener != null) {
onTextChangedListener.onTextChanged(inputText);
}
}
@Override
public void afterTextChanged(final Editable editable) {
public void afterTextChanged(@NonNull final Editable editable) {
//do nothing
}
@ -292,7 +292,7 @@ public class TypefacedEditText extends AppCompatEditText {
}
@Override
public void setEllipsize(final TextUtils.TruncateAt ellipsis) {
public void setEllipsize(@NonNull final TextUtils.TruncateAt ellipsis) {
if (!constructed) {
return;
}

View File

@ -302,7 +302,7 @@ public class TypefacedTextView extends AppCompatTextView {
}
@Override
public void setEllipsize(final TextUtils.TruncateAt ellipsize) {
public void setEllipsize(@NonNull final TextUtils.TruncateAt ellipsize) {
if (!constructed) {
return;
}
@ -319,7 +319,7 @@ public class TypefacedTextView extends AppCompatTextView {
}
@Override
public void setText(final CharSequence text, final BufferType type) {
public void setText(@Nullable final CharSequence text, @Nullable final BufferType type) {
super.setText(text, type);
if (constructed && lineStrategy.scalable) {
requestLayout();

View File

@ -50,6 +50,7 @@ public final class AttributesUtils {
* @throws NoSuchFieldException Throws on reflection call;
* @throws IllegalAccessException Throws on reflection call.
*/
@NonNull
@SuppressWarnings("unchecked")
public static <T> T getField(@NonNull final Class resourcesClass, @NonNull final String fieldName)
throws NoSuchFieldException, IllegalAccessException {