Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, IntroActivity.class);
MainActivity.this.startActivity(intent);
startActivity(intent);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
viewPager.post(new Runnable() {
@Override
public void run() {
int currentItem = viewPager.getCurrentItem();
messageButtonBehaviourOnPageSelected.pageSelected(currentItem);
nextButtonBehaviour(currentItem, adapter.getItem(currentItem));
if (adapter.slidesCount() == 0) {
finish();
} else {
int currentItem = viewPager.getCurrentItem();
messageButtonBehaviourOnPageSelected.pageSelected(currentItem);
nextButtonBehaviour(currentItem, adapter.getItem(currentItem));
}
}
});
}
Expand All @@ -113,7 +117,7 @@ public void run() {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
SlideFragment fragment = adapter.getItem(viewPager.getCurrentItem());
boolean hasPermissionToGrant = fragment.hasNeededPermissionsToGrant();
if (hasPermissionToGrant == false) {
if (!hasPermissionToGrant) {
viewPager.setAllowedSwipeDirection(SwipeableViewPager.SwipeDirection.all);
nextButtonBehaviour(viewPager.getCurrentItem(), fragment);
messageButtonBehaviourOnPageSelected.pageSelected(viewPager.getCurrentItem());
Expand Down Expand Up @@ -170,7 +174,7 @@ public void pageScrolled(final int position, float offset) {
viewPager.post(new Runnable() {
@Override
public void run() {
if (adapter.getItem(position).hasNeededPermissionsToGrant() || adapter.getItem(position).canMoveFurther() == false) {
if (adapter.getItem(position).hasNeededPermissionsToGrant() || !adapter.getItem(position).canMoveFurther()) {
viewPager.setCurrentItem(position);
pageIndicator.clearJoiningFractions();
}
Expand Down Expand Up @@ -237,6 +241,7 @@ private int color(@ColorRes int color) {
*
* @param slideFragment Fragment to add
*/
@SuppressWarnings("unused")
public void addSlide(SlideFragment slideFragment) {
adapter.addItem(slideFragment);
}
Expand All @@ -247,6 +252,7 @@ public void addSlide(SlideFragment slideFragment) {
* @param slideFragment Fragment to add
* @param messageButtonBehaviour Add behaviour for message button
*/
@SuppressWarnings("unused")
public void addSlide(SlideFragment slideFragment, MessageButtonBehaviour messageButtonBehaviour) {
adapter.addItem(slideFragment);
messageButtonBehaviours.put(adapter.getLastItemPosition(), messageButtonBehaviour);
Expand All @@ -263,8 +269,8 @@ public void setSkipButtonVisible() {
skipButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int position = viewPager.getCurrentItem(); position < adapter.getCalculatedCount(); position++) {
if (adapter.getItem(position).canMoveFurther() == false) {
for (int position = viewPager.getCurrentItem(); position < adapter.slidesCount(); position++) {
if (!adapter.getItem(position).canMoveFurther()) {
viewPager.setCurrentItem(position);
showError(adapter.getItem(position).cantMoveFurtherErrorMessage());
return;
Expand Down Expand Up @@ -313,6 +319,7 @@ public ViewTranslationWrapper getNextButtonTranslationWrapper() {
*
* @return ViewTranslationWrapper
*/
@SuppressWarnings("unused")
public ViewTranslationWrapper getBackButtonTranslationWrapper() {
return backButtonTranslationWrapper;
}
Expand All @@ -322,6 +329,7 @@ public ViewTranslationWrapper getBackButtonTranslationWrapper() {
*
* @return ViewTranslationWrapper
*/
@SuppressWarnings("unused")
public ViewTranslationWrapper getPageIndicatorTranslationWrapper() {
return pageIndicatorTranslationWrapper;
}
Expand All @@ -331,6 +339,7 @@ public ViewTranslationWrapper getPageIndicatorTranslationWrapper() {
*
* @return ViewTranslationWrapper
*/
@SuppressWarnings("unused")
public ViewTranslationWrapper getViewPagerTranslationWrapper() {
return viewPagerTranslationWrapper;
}
Expand All @@ -340,6 +349,7 @@ public ViewTranslationWrapper getViewPagerTranslationWrapper() {
*
* @return ViewTranslationWrapper
*/
@SuppressWarnings("unused")
public ViewTranslationWrapper getSkipButtonTranslationWrapper() {
return skipButtonTranslationWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.view.View;

@SuppressWarnings("unused")
public class MessageButtonBehaviour {
private View.OnClickListener clickListener;
private String messageButtonText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.View;
import android.widget.LinearLayout;

@SuppressWarnings("unused")
public class MoveUpBehaviour extends CoordinatorLayout.Behavior<LinearLayout> {
public MoveUpBehaviour(Context context, AttributeSet attrs) {
super(context, attrs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static SlideFragment createInstance(SlideFragmentBuilder builder) {
}

public static boolean isNotNullOrEmpty(String string) {
return string != null && string.isEmpty() == false;
return string != null && !string.isEmpty();
}

@Nullable
Expand Down Expand Up @@ -93,7 +93,7 @@ public int buttonsColor() {

public boolean hasAnyPermissionsToGrant() {
boolean hasPermissionToGrant = hasPermissionsToGrant(neededPermissions);
if (hasPermissionToGrant == false) {
if (!hasPermissionToGrant) {
hasPermissionToGrant = hasPermissionsToGrant(possiblePermissions);
}
return hasPermissionToGrant;
Expand Down Expand Up @@ -144,14 +144,14 @@ public void askForPermissions() {
}

String[] permissionsToGrant = removeEmptyAndNullStrings(notGrantedPermissions);
ActivityCompat.requestPermissions(this.getActivity(), permissionsToGrant, PERMISSIONS_REQUEST_CODE);
ActivityCompat.requestPermissions(getActivity(), permissionsToGrant, PERMISSIONS_REQUEST_CODE);
}

private boolean hasPermissionsToGrant(String[] permissions) {
if (permissions != null) {
for (int i = 0; i < permissions.length; i++) {
if (isNotNullOrEmpty(permissions[i])) {
if (ContextCompat.checkSelfPermission(getContext(), permissions[i]) != PackageManager.PERMISSION_GRANTED) {
for (String permission : permissions) {
if (isNotNullOrEmpty(permission)) {
if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) {
return true;
}
}
Expand All @@ -160,6 +160,7 @@ private boolean hasPermissionsToGrant(String[] permissions) {
return false;
}

@SuppressWarnings("SuspiciousMethodCalls")
private String[] removeEmptyAndNullStrings(final ArrayList<String> permissions) {
List<String> list = new ArrayList<>(permissions);
list.removeAll(Collections.singleton(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;

@SuppressWarnings({"unused", "WeakerAccess"})
public class SlideFragmentBuilder {
int backgroundColor;
int buttonsColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ public Object instantiateItem(ViewGroup container, int position) {
return fragment;
}

/**
* @return Returns count of fragments in adapter
*/
@Override
public int getCount() {
return fragments.size();
}

public int getCalculatedCount() {
/**
* @return Returns count of fragments in adapter WITHOUT empty slide if is available
*/
public int slidesCount() {
if (isLastItemEmptySlide()) {
return fragments.size() - 1;
} else {
Expand All @@ -42,25 +48,25 @@ public int getCalculatedCount() {
}

public void addItem(SlideFragment fragment) {
fragments.add(getCalculatedCount(), fragment);
this.notifyDataSetChanged();
fragments.add(slidesCount(), fragment);
notifyDataSetChanged();
}

public void addEmptySlide(LastEmptySlideFragment fragment) {
fragments.add(fragment);
this.notifyDataSetChanged();
notifyDataSetChanged();
}

public int getLastItemPosition() {
return getCalculatedCount() - 1;
return slidesCount() - 1;
}

public boolean isLastSlide(int position) {
return position == getCalculatedCount() - 1;
return position == slidesCount() - 1;
}

public boolean shouldFinish(int position) {
return position == getCalculatedCount();
return position == slidesCount();
}

private boolean isLastItemEmptySlide() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ public class ViewTranslationWrapper {
public ViewTranslationWrapper(View view) {
this.view = view;

this.enterTranslation = new NoTranslation();
this.exitTranslation = new NoTranslation();
this.setErrorAnimation(0);
enterTranslation = new NoTranslation();
exitTranslation = new NoTranslation();
setErrorAnimation(0);
}

/**
* Set translation after passing first slide
*
* @param enterTranslation new translation
*/
public ViewTranslationWrapper setEnterTranslation(IViewTranslation enterTranslation) {
Expand All @@ -35,6 +36,7 @@ public ViewTranslationWrapper setEnterTranslation(IViewTranslation enterTranslat

/**
* Set translation after passing last slide
*
* @param exitTranslation new translation
*/
public ViewTranslationWrapper setExitTranslation(IViewTranslation exitTranslation) {
Expand All @@ -44,6 +46,7 @@ public ViewTranslationWrapper setExitTranslation(IViewTranslation exitTranslatio

/**
* Set default translation
*
* @param defaultTranslation new translation
*/
public ViewTranslationWrapper setDefaultTranslation(IViewTranslation defaultTranslation) {
Expand All @@ -53,6 +56,7 @@ public ViewTranslationWrapper setDefaultTranslation(IViewTranslation defaultTran

/**
* Set view on error animation
*
* @param errorAnimation new animation
*/
public ViewTranslationWrapper setErrorAnimation(@AnimRes int errorAnimation) {
Expand All @@ -63,20 +67,20 @@ public ViewTranslationWrapper setErrorAnimation(@AnimRes int errorAnimation) {
}

public void enterTranslate(float percentage) {
this.enterTranslation.translate(view, percentage);
enterTranslation.translate(view, percentage);
}

public void exitTranslate(float percentage) {
this.exitTranslation.translate(view, percentage);
exitTranslation.translate(view, percentage);
}

public void defaultTranslate(float percentage) {
this.defaultTranslation.translate(view, percentage);
defaultTranslation.translate(view, percentage);
}

public void error() {
if (errorAnimation != null) {
this.view.startAnimation(errorAnimation);
view.startAnimation(errorAnimation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BackButtonTranslationWrapper extends ViewTranslationWrapper {
public BackButtonTranslationWrapper(View view) {
super(view);

this.setEnterTranslation(new EnterDefaultTranslation())
setEnterTranslation(new EnterDefaultTranslation())
.setDefaultTranslation(new DefaultPositionTranslation())
.setExitTranslation(new ExitDefaultTranslation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class NextButtonTranslationWrapper extends ViewTranslationWrapper {
public NextButtonTranslationWrapper(View view) {
super(view);

this.setExitTranslation(new ExitDefaultTranslation())
setExitTranslation(new ExitDefaultTranslation())
.setDefaultTranslation(new DefaultPositionTranslation())
.setErrorAnimation(R.anim.shake_it);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PageIndicatorTranslationWrapper extends ViewTranslationWrapper {
public PageIndicatorTranslationWrapper(View view) {
super(view);

this.setDefaultTranslation(new DefaultPositionTranslation())
setDefaultTranslation(new DefaultPositionTranslation())
.setExitTranslation(new ExitDefaultTranslation());
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package agency.tango.materialintroscreen.animations.wrappers;

import android.view.View;
import android.view.View;

import agency.tango.materialintroscreen.animations.ViewTranslationWrapper;
import agency.tango.materialintroscreen.animations.translations.DefaultPositionTranslation;
import agency.tango.materialintroscreen.animations.translations.EnterDefaultTranslation;
import agency.tango.materialintroscreen.animations.translations.ExitDefaultTranslation;
import agency.tango.materialintroscreen.animations.ViewTranslationWrapper;
import agency.tango.materialintroscreen.animations.translations.DefaultPositionTranslation;
import agency.tango.materialintroscreen.animations.translations.EnterDefaultTranslation;
import agency.tango.materialintroscreen.animations.translations.ExitDefaultTranslation;

public class SkipButtonTranslationWrapper extends ViewTranslationWrapper {
public SkipButtonTranslationWrapper(View view) {
super(view);

this.setEnterTranslation(new EnterDefaultTranslation())
setEnterTranslation(new EnterDefaultTranslation())
.setDefaultTranslation(new DefaultPositionTranslation())
.setExitTranslation(new ExitDefaultTranslation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ViewPagerTranslationWrapper extends ViewTranslationWrapper {
public ViewPagerTranslationWrapper(View view) {
super(view);

this.setDefaultTranslation(new DefaultAlphaTranslation())
setDefaultTranslation(new DefaultAlphaTranslation())
.setExitTranslation(new AlphaTranslation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SwipeStateTouchListener(SwipeableViewPager viewPager, SlidesAdapter adapt
@Override
public void process() {
SlideFragment fragment = adapter.getItem(viewPager.getCurrentItem());
if (fragment.canMoveFurther() == false || fragment.hasNeededPermissionsToGrant()) {
if (!fragment.canMoveFurther() || fragment.hasNeededPermissionsToGrant()) {
viewPager.setAllowedSwipeDirection(SwipeableViewPager.SwipeDirection.left);
} else {
viewPager.setAllowedSwipeDirection(SwipeableViewPager.SwipeDirection.all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ParallaxScrollListener(SlidesAdapter adapter) {
@SuppressWarnings("ConstantConditions")
@Override
public void pageScrolled(int position, float offset) {
if (position != adapter.getCalculatedCount()) {
if (position != adapter.slidesCount()) {
Fragment fragment = adapter.getItem(position);
Fragment fragmentNext = getNextFragment(position);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
parallaxLayout = findParallaxLayout(view);
}

@SuppressWarnings("PointlessBooleanExpression")
public Parallaxable findParallaxLayout(View root) {
Queue<View> queue = new LinkedList<>();
queue.add(root);

while (queue.isEmpty() == false) {
while (!queue.isEmpty()) {
View child = queue.remove();

if (child instanceof Parallaxable) {
Expand Down
Loading