Search in sources :

Example 1 with CollapsingToolbarLayout

use of com.google.android.material.appbar.CollapsingToolbarLayout 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 2 with CollapsingToolbarLayout

use of com.google.android.material.appbar.CollapsingToolbarLayout 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 3 with CollapsingToolbarLayout

use of com.google.android.material.appbar.CollapsingToolbarLayout 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 4 with CollapsingToolbarLayout

use of com.google.android.material.appbar.CollapsingToolbarLayout in project xabber-android by redsolution.

the class AboutActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(AboutActivity.this);
        }
    });
    findViewById(R.id.about_github).setOnClickListener(this);
    findViewById(R.id.about_twitter).setOnClickListener(this);
    findViewById(R.id.about_redsolution).setOnClickListener(this);
    findViewById(R.id.about_text_xmpp_protocol).setOnClickListener(this);
    ((TextView) findViewById(R.id.about_text_developers)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) findViewById(R.id.about_text_translators)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) findViewById(R.id.about_text_license)).setMovementMethod(LinkMovementMethod.getInstance());
    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(getString(R.string.application_title_short));
    ((TextView) findViewById(R.id.about_version)).setText(Application.getInstance().getVersionName());
    loadBackdrop();
}
Also used : CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Example 5 with CollapsingToolbarLayout

use of com.google.android.material.appbar.CollapsingToolbarLayout in project IITB-App by wncc.

the class ComplaintsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_complaints, container, false);
    Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
    toolbar.setTitle("Complaints/Suggestions");
    Utils.setSelectedMenuItem(getActivity(), R.id.nav_complaint);
    Bundle bundle = getArguments();
    userID = bundle.getString(Constants.USER_ID);
    userProfileUrl = bundle.getString(Constants.CURRENT_USER_PROFILE_PICTURE);
    CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);
    collapsingToolbarLayout.setTitleEnabled(false);
    ViewPager viewPager = view.findViewById(R.id.tab_viewpager);
    slidingTabLayout = view.findViewById(R.id.sliding_tab_layout);
    Button buttonVentIssues = view.findViewById(R.id.buttonVentIssues);
    buttonVentIssues.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FileComplaintFragment fileComplaintFragment = new FileComplaintFragment();
            fileComplaintFragment.setArguments(getArguments());
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.framelayout_for_fragment, fileComplaintFragment, Utils.getTag(fileComplaintFragment));
            fragmentTransaction.addToBackStack("Complaint Fragment").commit();
        }
    });
    slidingTabLayout = view.findViewById(R.id.sliding_tab_layout);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }
    return view;
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) Button(android.widget.Button) Bundle(android.os.Bundle) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

View (android.view.View)6 CollapsingToolbarLayout (com.google.android.material.appbar.CollapsingToolbarLayout)6 AppBarLayout (com.google.android.material.appbar.AppBarLayout)4 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 Context (android.content.Context)2 ViewGroup (android.view.ViewGroup)2 Window (android.view.Window)2 Nullable (androidx.annotation.Nullable)2 Toolbar (androidx.appcompat.widget.Toolbar)2 CoordinatorLayout (androidx.coordinatorlayout.widget.CoordinatorLayout)2 MainActivity (de.danoeh.antennapod.activity.MainActivity)2 ToolbarIconTintManager (de.danoeh.antennapod.view.ToolbarIconTintManager)2 LightingColorFilter (android.graphics.LightingColorFilter)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 OnApplyWindowInsetsListener (androidx.core.view.OnApplyWindowInsetsListener)1 WindowInsetsCompat (androidx.core.view.WindowInsetsCompat)1