Search in sources :

Example 1 with AppBarLayout

use of com.google.android.material.appbar.AppBarLayout in project materialistic by hidroh.

the class AppUtilsTest method testNavigate.

@Test
public void testNavigate() {
    AppBarLayout appBar = mock(AppBarLayout.class);
    when(appBar.getBottom()).thenReturn(1);
    Navigable navigable = mock(Navigable.class);
    AppUtils.navigate(Navigable.DIRECTION_DOWN, appBar, navigable);
    verify(appBar).setExpanded(eq(false), anyBoolean());
    verify(navigable, never()).onNavigate(anyInt());
    when(appBar.getBottom()).thenReturn(0);
    AppUtils.navigate(Navigable.DIRECTION_DOWN, appBar, navigable);
    verify(navigable).onNavigate(eq(Navigable.DIRECTION_DOWN));
    AppUtils.navigate(Navigable.DIRECTION_RIGHT, appBar, navigable);
    verify(navigable).onNavigate(eq(Navigable.DIRECTION_RIGHT));
    AppUtils.navigate(Navigable.DIRECTION_UP, appBar, navigable);
    verify(navigable).onNavigate(eq(Navigable.DIRECTION_UP));
    AppUtils.navigate(Navigable.DIRECTION_LEFT, appBar, navigable);
    verify(navigable).onNavigate(eq(Navigable.DIRECTION_LEFT));
}
Also used : AppBarLayout(com.google.android.material.appbar.AppBarLayout) Test(org.junit.Test)

Example 2 with AppBarLayout

use of com.google.android.material.appbar.AppBarLayout in project StatusBarCompat by niorgai.

the class StatusBarCompatLollipop method setStatusBarColorForCollapsingToolbar.

/**
 * compat for CollapsingToolbarLayout
 *
 * 1. change to full-screen mode(like translucentStatusBar).
 * 2. cancel CollapsingToolbarLayout's WindowInsets, let it layout as normal(now setStatusBarScrimColor is useless).
 * 3. set View's FitsSystemWindow to false.
 * 4. add Toolbar's height, let it layout from top, then add paddingTop to layout normal.
 * 5. change statusBarColor by AppBarLayout's offset.
 * 6. add Listener to change statusBarColor
 */
static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, final int statusColor) {
    Window window = activity.getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    ViewCompat.setOnApplyWindowInsetsListener(collapsingToolbarLayout, new OnApplyWindowInsetsListener() {

        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return insets;
        }
    });
    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
        ViewCompat.setFitsSystemWindows(mChildView, false);
        ViewCompat.requestApplyInsets(mChildView);
    }
    ((View) appBarLayout.getParent()).setFitsSystemWindows(false);
    appBarLayout.setFitsSystemWindows(false);
    toolbar.setFitsSystemWindows(false);
    if (toolbar.getTag() == null) {
        CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
        int statusBarHeight = getStatusBarHeight(activity);
        lp.height += statusBarHeight;
        toolbar.setLayoutParams(lp);
        toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
        toolbar.setTag(true);
    }
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior();
    if (behavior != null && behavior instanceof AppBarLayout.Behavior) {
        int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset();
        if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
            window.setStatusBarColor(statusColor);
        } else {
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    } else {
        window.setStatusBarColor(Color.TRANSPARENT);
    }
    collapsingToolbarLayout.setFitsSystemWindows(false);
    final WeakReference<Window> windowWeakReference = new WeakReference<>(window);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            Window weakWindow = windowWeakReference.get();
            if (weakWindow != null) {
                if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
                    if (weakWindow.getStatusBarColor() != statusColor) {
                        startColorAnimation(weakWindow.getStatusBarColor(), statusColor, collapsingToolbarLayout.getScrimAnimationDuration(), windowWeakReference);
                    }
                } else {
                    if (weakWindow.getStatusBarColor() != Color.TRANSPARENT) {
                        startColorAnimation(weakWindow.getStatusBarColor(), Color.TRANSPARENT, collapsingToolbarLayout.getScrimAnimationDuration(), windowWeakReference);
                    }
                }
            }
        }
    });
    collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
    collapsingToolbarLayout.setStatusBarScrimColor(statusColor);
}
Also used : Window(android.view.Window) ViewGroup(android.view.ViewGroup) View(android.view.View) WindowInsetsCompat(androidx.core.view.WindowInsetsCompat) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) OnApplyWindowInsetsListener(androidx.core.view.OnApplyWindowInsetsListener) WeakReference(java.lang.ref.WeakReference) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) AppBarLayout(com.google.android.material.appbar.AppBarLayout)

Example 3 with AppBarLayout

use of com.google.android.material.appbar.AppBarLayout in project StatusBarCompat by niorgai.

the class StatusBarCompatKitKat method setStatusBarColorForCollapsingToolbar.

/**
 * compat for CollapsingToolbarLayout
 *
 * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
 * 2. set FitsSystemWindows for views.
 * 3. add Toolbar's height, let it layout from top, then add paddingTop to layout normal.
 * 4. removeFakeStatusBarViewIfExist
 * 5. removeMarginTopOfContentChild
 * 6. add OnOffsetChangedListener to change statusBarView's alpha
 */
static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, int statusColor) {
    Window window = activity.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    View mContentChild = mContentView.getChildAt(0);
    mContentChild.setFitsSystemWindows(false);
    ((View) appBarLayout.getParent()).setFitsSystemWindows(false);
    appBarLayout.setFitsSystemWindows(false);
    collapsingToolbarLayout.setFitsSystemWindows(false);
    collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
    toolbar.setFitsSystemWindows(false);
    if (toolbar.getTag() == null) {
        CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
        int statusBarHeight = getStatusBarHeight(activity);
        lp.height += statusBarHeight;
        toolbar.setLayoutParams(lp);
        toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
        toolbar.setTag(true);
    }
    int statusBarHeight = getStatusBarHeight(activity);
    removeFakeStatusBarViewIfExist(activity);
    removeMarginTopOfContentChild(mContentChild, statusBarHeight);
    final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight);
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior();
    if (behavior != null && behavior instanceof AppBarLayout.Behavior) {
        int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset();
        if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
            statusView.setAlpha(1f);
        } else {
            statusView.setAlpha(0f);
        }
    } else {
        statusView.setAlpha(0f);
    }
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
                if (statusView.getAlpha() == 0) {
                    statusView.animate().cancel();
                    statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start();
                }
            } else {
                if (statusView.getAlpha() == 1) {
                    statusView.animate().cancel();
                    statusView.animate().alpha(0f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start();
                }
            }
        }
    });
}
Also used : Window(android.view.Window) ViewGroup(android.view.ViewGroup) View(android.view.View) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) AppBarLayout(com.google.android.material.appbar.AppBarLayout)

Example 4 with AppBarLayout

use of com.google.android.material.appbar.AppBarLayout in project AntennaPod by AntennaPod.

the class FeedInfoFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.feedinfo, null);
    toolbar = root.findViewById(R.id.toolbar);
    toolbar.setTitle("");
    toolbar.inflateMenu(R.menu.feedinfo);
    toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
    toolbar.setOnMenuItemClickListener(this);
    refreshToolbarState();
    AppBarLayout appBar = root.findViewById(R.id.appBar);
    CollapsingToolbarLayout collapsingToolbar = root.findViewById(R.id.collapsing_toolbar);
    ToolbarIconTintManager iconTintManager = new ToolbarIconTintManager(getContext(), toolbar, collapsingToolbar) {

        @Override
        protected void doTint(Context themedContext) {
            toolbar.getMenu().findItem(R.id.visit_website_item).setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_web));
            toolbar.getMenu().findItem(R.id.share_parent).setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_share));
        }
    };
    iconTintManager.updateTint();
    appBar.addOnOffsetChangedListener(iconTintManager);
    imgvCover = root.findViewById(R.id.imgvCover);
    txtvTitle = root.findViewById(R.id.txtvTitle);
    txtvAuthorHeader = root.findViewById(R.id.txtvAuthor);
    imgvBackground = root.findViewById(R.id.imgvBackground);
    header = root.findViewById(R.id.headerContainer);
    infoContainer = root.findViewById(R.id.infoContainer);
    root.findViewById(R.id.butShowInfo).setVisibility(View.INVISIBLE);
    root.findViewById(R.id.butShowSettings).setVisibility(View.INVISIBLE);
    // https://github.com/bumptech/glide/issues/529
    imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000));
    txtvDescription = root.findViewById(R.id.txtvDescription);
    txtvUrl = root.findViewById(R.id.txtvUrl);
    lblSupport = root.findViewById(R.id.lblSupport);
    txtvFundingUrl = root.findViewById(R.id.txtvFundingUrl);
    txtvUrl.setOnClickListener(copyUrlToClipboard);
    long feedId = getArguments().getLong(EXTRA_FEED_ID);
    getParentFragmentManager().beginTransaction().replace(R.id.statisticsFragmentContainer, FeedStatisticsFragment.newInstance(feedId, false), "feed_statistics_fragment").commitAllowingStateLoss();
    root.findViewById(R.id.btnvOpenStatistics).setOnClickListener(view -> {
        StatisticsFragment fragment = new StatisticsFragment();
        ((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.SLIDE);
    });
    return root;
}
Also used : Context(android.content.Context) StatisticsFragment(de.danoeh.antennapod.fragment.preferences.StatisticsFragment) LightingColorFilter(android.graphics.LightingColorFilter) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) AppBarLayout(com.google.android.material.appbar.AppBarLayout) MainActivity(de.danoeh.antennapod.activity.MainActivity) ToolbarIconTintManager(de.danoeh.antennapod.view.ToolbarIconTintManager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable)

Example 5 with AppBarLayout

use of com.google.android.material.appbar.AppBarLayout in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FloatingAppBarScrollingViewBehavior method onDependentViewChanged.

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    boolean changed = super.onDependentViewChanged(parent, child, dependency);
    if (!initialized && dependency instanceof AppBarLayout) {
        initialized = true;
        AppBarLayout appBarLayout = (AppBarLayout) dependency;
        setAppBarLayoutTransparent(appBarLayout);
    }
    return changed;
}
Also used : AppBarLayout(com.google.android.material.appbar.AppBarLayout)

Aggregations

AppBarLayout (com.google.android.material.appbar.AppBarLayout)14 View (android.view.View)4 CoordinatorLayout (androidx.coordinatorlayout.widget.CoordinatorLayout)4 CollapsingToolbarLayout (com.google.android.material.appbar.CollapsingToolbarLayout)4 Test (org.junit.Test)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Context (android.content.Context)2 ViewGroup (android.view.ViewGroup)2 Window (android.view.Window)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 MainActivity (de.danoeh.antennapod.activity.MainActivity)2 ToolbarIconTintManager (de.danoeh.antennapod.view.ToolbarIconTintManager)2 LightingColorFilter (android.graphics.LightingColorFilter)1 Point (android.graphics.Point)1 Handler (android.os.Handler)1 TextPaint (android.text.TextPaint)1 AdapterView (android.widget.AdapterView)1 OnApplyWindowInsetsListener (androidx.core.view.OnApplyWindowInsetsListener)1