Java Code Examples for com.google.android.material.appbar.AppBarLayout#addOnOffsetChangedListener()
The following examples show how to use
com.google.android.material.appbar.AppBarLayout#addOnOffsetChangedListener() .
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 GSYVideoPlayer with Apache License 2.0 | 6 votes |
@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 2
Source File: ScrollingActivity.java From GSYVideoPlayer with Apache License 2.0 | 6 votes |
private void initView() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); detailPlayer = (LandLayoutVideo) findViewById(R.id.detail_player); root = (CoordinatorLayout) findViewById(R.id.root_layout); setSupportActionBar(toolbar); toolBarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout); toolBarLayout.setTitle(getTitle()); fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { detailPlayer.startPlayLogic(); root.removeView(fab); } }); appBar = (AppBarLayout) findViewById(R.id.app_bar); appBar.addOnOffsetChangedListener(appBarStateChangeListener); }
Example 3
Source File: FlexibleSpaceExampleActivity.java From CoordinatorExamples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flexible_space); mFab = findViewById(R.id.flexible_example_fab); Toolbar toolbar = (Toolbar) findViewById(R.id.flexible_example_toolbar); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); AppBarLayout appbar = (AppBarLayout) findViewById(R.id.flexible_example_appbar); appbar.addOnOffsetChangedListener(this); }
Example 4
Source File: MaterialUpConceptActivity.java From CoordinatorExamples with Apache License 2.0 | 6 votes |
@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 5
Source File: CollapsingToolbarLayoutActivity.java From Android-skin-support with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_collapsing_toolbar_layout); mIvPlaceholder = (ImageView) findViewById(R.id.main_iv_placeholder); mLlTitleContainer = (LinearLayout) findViewById(R.id.main_ll_title_container); mFlTitleContainer = (FrameLayout) findViewById(R.id.main_fl_title); mAblAppBar = (AppBarLayout) findViewById(R.id.main_abl_app_bar); mTvToolbarTitle = (TextView) findViewById(R.id.main_tv_toolbar_title); mTbToolbar = (Toolbar) findViewById(R.id.main_tb_toolbar); mTbToolbar.setTitle(""); // AppBar的监听 mAblAppBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { int maxScroll = appBarLayout.getTotalScrollRange(); float percentage = (float) Math.abs(verticalOffset) / (float) maxScroll; handleAlphaOnTitle(percentage); handleToolbarTitleVisibility(percentage); } }); findViewById(R.id.small_photo).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(CollapsingToolbarLayoutActivity.this, SettingsActivity.class)); } }); initParallaxValues(); // 自动滑动效果 }
Example 6
Source File: AppBarSwipeRefreshLayout.java From materialistic with Apache License 2.0 | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (getContext() instanceof Activity) { mAppBar = (AppBarLayout) ((Activity) getContext()).findViewById(R.id.appbar); if (mAppBar != null) { mAppBar.addOnOffsetChangedListener(this); } } }
Example 7
Source File: AppBarLayoutUtil.java From SmoothRefreshLayout with MIT License | 4 votes |
public AppBarLayoutUtil(View view) { if (view instanceof AppBarLayout) { mAppBarLayout = (AppBarLayout) view; mAppBarLayout.addOnOffsetChangedListener(mListener); } }
Example 8
Source File: TransitionMusicAlbumDemoFragment.java From material-components-android with Apache License 2.0 | 4 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) { View container = view.findViewById(R.id.container); Toolbar toolbar = view.findViewById(R.id.toolbar); AppBarLayout appBarLayout = view.findViewById(R.id.app_bar_layout); FloatingActionButton fab = view.findViewById(R.id.fab); ImageView albumImage = view.findViewById(R.id.album_image); TextView albumTitle = view.findViewById(R.id.album_title); TextView albumArtist = view.findViewById(R.id.album_artist); RecyclerView songRecyclerView = view.findViewById(R.id.song_recycler_view); long albumId = getArguments().getLong(ALBUM_ID_KEY, 0L); Album album = MusicData.getAlbumById(albumId); // Set the transition name which matches the list/grid item to be transitioned from for // the shared element transition. ViewCompat.setTransitionName(container, album.title); appBarLayout.addOnOffsetChangedListener( (appBarLayout1, verticalOffset) -> { float verticalOffsetPercentage = (float) Math.abs(verticalOffset) / (float) appBarLayout1.getTotalScrollRange(); if (verticalOffsetPercentage > 0.2F && fab.isOrWillBeShown()) { fab.hide(); } else if (verticalOffsetPercentage <= 0.2F && fab.isOrWillBeHidden()) { fab.show(); } }); // Set up toolbar ViewCompat.setElevation(toolbar, 0F); toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed()); // Set up album info area albumImage.setImageResource(album.cover); albumTitle.setText(album.title); albumArtist.setText(album.artist); // Set up track list songRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext())); TrackAdapter adapter = new TrackAdapter(); songRecyclerView.setAdapter(adapter); adapter.submitList(album.tracks); }
Example 9
Source File: LibraryFragment.java From Jockey with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { mBinding = FragmentLibraryBinding.inflate(inflater, container, false); mViewModel = new LibraryViewModel(getContext(), getFragmentManager(), mPrefStore, mThemeStore); mBinding.setViewModel(mViewModel); if (savedInstanceState != null) { mViewModel.setPage(savedInstanceState.getInt(KEY_SAVED_PAGE, mViewModel.getPage())); } Observable.combineLatest(mMusicStore.isLoading(), mPlaylistStore.isLoading(), (musicLoading, playlistLoading) -> { return musicLoading || playlistLoading; }) .compose(bindToLifecycle()) .subscribe(mViewModel::setLibraryRefreshing, throwable -> { Timber.e(throwable, "Failed to update refresh indicator"); }); mMusicStore.loadAll(); mPlaylistStore.loadPlaylists(); ViewPager pager = mBinding.libraryPager; AppBarLayout appBarLayout = mBinding.libraryAppBarLayout; appBarLayout.addOnOffsetChangedListener((layout, verticalOffset) -> pager.setPadding(pager.getPaddingLeft(), pager.getPaddingTop(), pager.getPaddingRight(), layout.getTotalScrollRange() + verticalOffset)); mBinding.libraryTabs.setupWithViewPager(mBinding.libraryPager); setupToolbar(mBinding.toolbar); setHasOptionsMenu(true); return mBinding.getRoot(); }
Example 10
Source File: ViewTaskFragment.java From opentasks with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mShowFloatingActionButton = !getResources().getBoolean(R.bool.has_two_panes); mRootView = inflater.inflate(R.layout.fragment_task_view_detail, container, false); mContent = (ViewGroup) mRootView.findViewById(R.id.content); mDetailView = (TaskView) inflater.inflate(R.layout.task_view, mContent, false); mContent.addView(mDetailView); mAppBar = (AppBarLayout) mRootView.findViewById(R.id.appbar); mToolBar = (Toolbar) mRootView.findViewById(R.id.toolbar); mToolBar.setOnMenuItemClickListener(this); mToolBar.setTitle(""); mAppBar.addOnOffsetChangedListener(this); animate(mToolBar.findViewById(R.id.toolbar_title), 0, View.INVISIBLE); mFloatingActionButton = (FloatingActionButton) mRootView.findViewById(R.id.floating_action_button); showFloatingActionButton(false); mFloatingActionButton.setOnClickListener(v -> completeTask()); // Update the toolbar color until the actual is loaded for the task mListColor = new ValueColor(getArguments().getInt(ARG_STARTING_COLOR)).argb(); updateColor(); mRestored = savedInstanceState != null; if (savedInstanceState != null) { if (mContent != null && mContentSet != null) { // register for content updates mContentSet.addOnChangeListener(this, null, true); // register observer if (mTaskUri != null) { mAppContext.getContentResolver().registerContentObserver(mTaskUri, false, mObserver); } } } else if (mTaskUri != null) { Uri uri = mTaskUri; // pretend we didn't load anything yet mTaskUri = null; loadUri(uri); } return mRootView; }