Java Code Examples for com.google.android.material.appbar.AppBarLayout#getTotalScrollRange()

The following examples show how to use com.google.android.material.appbar.AppBarLayout#getTotalScrollRange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppBarStateChangeListener.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != AppBarStateChangeListener.State.EXPANDED) {
            onStateChanged(appBarLayout, AppBarStateChangeListener.State.EXPANDED);
        }
        mCurrentState = AppBarStateChangeListener.State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != AppBarStateChangeListener.State.COLLAPSED) {
            onStateChanged(appBarLayout, AppBarStateChangeListener.State.COLLAPSED);
        }
        mCurrentState = AppBarStateChangeListener.State.COLLAPSED;
    } else {
        if (mCurrentState != AppBarStateChangeListener.State.IDLE) {
            onStateChanged(appBarLayout, AppBarStateChangeListener.State.IDLE);
        }
        mCurrentState = AppBarStateChangeListener.State.IDLE;
    }
}
 
Example 2
Source File: AppBarStateChangeListener.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 3
Source File: AppBarStateChangeListener.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
    appBarLayout.addOnOffsetChangedListener(this);
}
 
Example 4
Source File: AppBarStateChangeListener.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
  if (i == 0) {
    if (mCurrentState != State.EXPANDED) {
      onStateChanged(appBarLayout, State.EXPANDED);
    }
    mCurrentState = State.EXPANDED;
  } else if (Math.abs(i) - appBarLayout.getTotalScrollRange() == 0) {
    if (mCurrentState != State.COLLAPSED) {
      onStateChanged(appBarLayout, State.COLLAPSED);
    }
    mCurrentState = State.COLLAPSED;
  } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
    if (mCurrentState != State.MOVING) {
      onStateChanged(appBarLayout, State.MOVING);
    }
    mCurrentState = State.MOVING;
  } else {
    if (mCurrentState != State.IDLE) {
      onStateChanged(appBarLayout, State.IDLE);
    }
    mCurrentState = State.IDLE;
  }
}
 
Example 5
Source File: FabOffsetter.java    From appbarsyncedfab with Apache License 2.0 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    // fab should scroll out down in sync with the appBarLayout scrolling out up.
    // let's see how far along the way the appBarLayout is
    // (if displacementFraction == 0.0f then no displacement, appBar is fully expanded;
    //  if displacementFraction == 1.0f then full displacement, appBar is totally collapsed)
    float displacementFraction = -verticalOffset / (float) appBarLayout.getTotalScrollRange();

    // top position, accounting for translation not coming from this behavior
    float topUntranslatedFromThis = fab.getTop() + fab.getTranslationY() - fabTranslationYByThis;

    // total length to displace by (from position uninfluenced by this behavior) for a full appBar collapse
    float fullDisplacement = parent.getBottom() - topUntranslatedFromThis;

    // calculate new value for displacement coming from this behavior
    float newTranslationYFromThis = fullDisplacement * displacementFraction;

    // update translation value by difference found in this step
    fab.setTranslationY(newTranslationYFromThis - fabTranslationYByThis + fab.getTranslationY());

    // store new value
    fabTranslationYByThis = newTranslationYFromThis;
}
 
Example 6
Source File: AppBarStateChangeListener.java    From maoni with MIT License 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
  if (i == 0) {
    if (mCurrentState != State.EXPANDED) {
      onStateChanged(appBarLayout, State.EXPANDED);
    }
    mCurrentState = State.EXPANDED;
  } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
    if (mCurrentState != State.COLLAPSED) {
      onStateChanged(appBarLayout, State.COLLAPSED);
    }
    mCurrentState = State.COLLAPSED;
  } else {
    if (mCurrentState != State.IDLE) {
      onStateChanged(appBarLayout, State.IDLE);
    }
    mCurrentState = State.IDLE;
  }
}
 
Example 7
Source File: FlexibleSpaceExampleActivity.java    From CoordinatorExamples with Apache License 2.0 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
	if (mMaxScrollSize == 0)
		mMaxScrollSize = appBarLayout.getTotalScrollRange();

	int currentScrollPercentage = (Math.abs(i)) * 100
		/ mMaxScrollSize;

	if (currentScrollPercentage >= PERCENTAGE_TO_SHOW_IMAGE) {
		if (!mIsImageHidden) {
			mIsImageHidden = true;

			ViewCompat.animate(mFab).scaleY(0).scaleX(0).start();
		}
	}

	if (currentScrollPercentage < PERCENTAGE_TO_SHOW_IMAGE) {
		if (mIsImageHidden) {
			mIsImageHidden = false;
			ViewCompat.animate(mFab).scaleY(1).scaleX(1).start();
		}
	}
}
 
Example 8
Source File: MaterialUpConceptActivity.java    From CoordinatorExamples with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_material_up_concept);

	TabLayout tabLayout = (TabLayout) findViewById(R.id.materialup_tabs);
	ViewPager viewPager  = (ViewPager) findViewById(R.id.materialup_viewpager);
	AppBarLayout appbarLayout = (AppBarLayout) findViewById(R.id.materialup_appbar);
	mProfileImage = (ImageView) findViewById(R.id.materialup_profile_image);

	Toolbar toolbar = (Toolbar) findViewById(R.id.materialup_toolbar);
	toolbar.setNavigationOnClickListener(new View.OnClickListener() {
		@Override public void onClick(View v) {
			onBackPressed();
		}
	});

	appbarLayout.addOnOffsetChangedListener(this);
	mMaxScrollSize = appbarLayout.getTotalScrollRange();

	viewPager.setAdapter(new TabsAdapter(getSupportFragmentManager()));
	tabLayout.setupWithViewPager(viewPager);
}
 
Example 9
Source File: MaterialUpConceptActivity.java    From CoordinatorExamples with Apache License 2.0 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
	if (mMaxScrollSize == 0)
		mMaxScrollSize = appBarLayout.getTotalScrollRange();

	int percentage = (Math.abs(i)) * 100 / mMaxScrollSize;

	if (percentage >= PERCENTAGE_TO_ANIMATE_AVATAR && mIsAvatarShown) {
		mIsAvatarShown = false;

		mProfileImage.animate()
			.scaleY(0).scaleX(0)
			.setDuration(200)
			.start();
	}

	if (percentage <= PERCENTAGE_TO_ANIMATE_AVATAR && !mIsAvatarShown) {
		mIsAvatarShown = true;

		mProfileImage.animate()
			.scaleY(1).scaleX(1)
			.start();
	}
}
 
Example 10
Source File: GroupSettingsCoordinatorLayoutBehavior.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
  AppBarLayout appBarLayout = (AppBarLayout) dependency;
  int          range        = appBarLayout.getTotalScrollRange();
  float        factor       = INTERPOLATOR.getInterpolation(-appBarLayout.getY() / range);

  updateAvatarPositionAndScale(parent, child, factor);
  updateNamePosition(parent, factor);

  return true;
}
 
Example 11
Source File: HomeFragment.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
private void handleAppbarOffsetChangedListener(AppBarLayout appBarLayout, int verticalOffset) {
    final int totalScrollRange = appBarLayout.getTotalScrollRange();
    final float percent = Math.abs(verticalOffset * 1.0f / totalScrollRange);
    mRefresh.setEnabled(verticalOffset == 0);
    final int color = getColor(R.color.colorPrimary);
    mTitle.setTextColor((int) mArgbEvaluator.evaluate(percent, color, Color.WHITE));
    if (mNavigationIcon != null) {
        mNavigationIcon.setColorFilter((int) mArgbEvaluator.evaluate(percent, color, Color.WHITE), PorterDuff.Mode.SRC_IN);
    }
}
 
Example 12
Source File: HomeActivity.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
private void handleAppbarOffsetChangedListener(AppBarLayout appBarLayout, int verticalOffset) {
    final int totalScrollRange = appBarLayout.getTotalScrollRange();
    final float percent = Math.abs(verticalOffset * 1.0f / totalScrollRange);
    mRefresh.setEnabled(verticalOffset == 0);
    final int color = ContextCompat.getColor(this, R.color.colorPrimary);
    mTitle.setTextColor((int) mArgbEvaluator.evaluate(percent, color, Color.BLACK));
    if (mNavigationIcon != null) {
        mNavigationIcon.setColorFilter((int) mArgbEvaluator.evaluate(percent, color, Color.BLACK), PorterDuff.Mode.SRC_IN);
    }
}
 
Example 13
Source File: FloatingActionButtonBehavior.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    if (!enabled) {
        return;
    }

    if (verticalOffset == 0 && !visible) {
        showButton();
    } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange() && visible) {
        hideButton();
    }
}
 
Example 14
Source File: AppBarLayoutMatchers.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Returns a matcher that matches AppBarLayouts which are collapsed. */
public static Matcher<View> isCollapsed() {
  return new BoundedMatcher<View, AppBarLayout>(AppBarLayout.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("AppBarLayout is collapsed");
    }

    @Override
    protected boolean matchesSafely(AppBarLayout item) {
      return item.getBottom() == (item.getHeight() - item.getTotalScrollRange());
    }
  };
}
 
Example 15
Source File: ViewTaskFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int offset)
{
    mAppBarOffset = offset;
    int maxScroll = appBarLayout.getTotalScrollRange();
    float percentage = (float) Math.abs(offset) / (float) maxScroll;

    handleAlphaOnTitle(percentage);

    if (mIsTheTitleContainerVisible)
    {
        mAppBar.findViewById(R.id.toolbar_content).setAlpha(1 - percentage);
    }
}
 
Example 16
Source File: AppBarLayoutUtil.java    From SmoothRefreshLayout with MIT License 4 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    mFullyExpanded = verticalOffset >= 0;
    mFullyCollapsed = appBarLayout.getTotalScrollRange() + verticalOffset <= 0;
}