Search in sources :

Example 6 with AppBarLayout

use of android.support.design.widget.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(android.support.design.widget.CoordinatorLayout) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 7 with AppBarLayout

use of android.support.design.widget.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) {
    final 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);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
                if (window.getStatusBarColor() == Color.TRANSPARENT) {
                    ValueAnimator animator = ValueAnimator.ofArgb(Color.TRANSPARENT, statusColor).setDuration(collapsingToolbarLayout.getScrimAnimationDuration());
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                        @Override
                        public void onAnimationUpdate(ValueAnimator valueAnimator) {
                            window.setStatusBarColor((Integer) valueAnimator.getAnimatedValue());
                        }
                    });
                    animator.start();
                }
            } else {
                if (window.getStatusBarColor() == statusColor) {
                    ValueAnimator animator = ValueAnimator.ofArgb(statusColor, Color.TRANSPARENT).setDuration(collapsingToolbarLayout.getScrimAnimationDuration());
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                        @Override
                        public void onAnimationUpdate(ValueAnimator valueAnimator) {
                            window.setStatusBarColor((Integer) valueAnimator.getAnimatedValue());
                        }
                    });
                    animator.start();
                }
            }
        }
    });
    collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
    collapsingToolbarLayout.setStatusBarScrimColor(statusColor);
}
Also used : Window(android.view.Window) ViewGroup(android.view.ViewGroup) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) WindowInsetsCompat(android.support.v4.view.WindowInsetsCompat) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) OnApplyWindowInsetsListener(android.support.v4.view.OnApplyWindowInsetsListener) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 8 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project smooth-app-bar-layout by henrytao-me.

the class BaseBehavior method dispatchOffsetUpdates.

protected void dispatchOffsetUpdates(AppBarLayout layout, int translationOffset) {
    if (layout instanceof SmoothAppBarLayout) {
        List listeners = ((SmoothAppBarLayout) layout).mOffsetChangedListeners;
        int i = 0;
        for (int z = listeners.size(); i < z; ++i) {
            WeakReference ref = (WeakReference) listeners.get(i);
            AppBarLayout.OnOffsetChangedListener listener = ref != null ? (AppBarLayout.OnOffsetChangedListener) ref.get() : null;
            if (listener != null) {
                listener.onOffsetChanged(layout, translationOffset);
            }
        }
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) ArrayList(java.util.ArrayList) List(java.util.List) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 9 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project AntennaPod by AntennaPod.

the class MediaplayerInfoActivity method setupGUI.

@Override
protected void setupGUI() {
    super.setupGUI();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        findViewById(R.id.shadow).setVisibility(View.GONE);
        AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appBar);
        float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
        appBarLayout.setElevation(px);
    }
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navList = (ListView) findViewById(R.id.nav_list);
    navDrawer = findViewById(R.id.nav_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
    drawerToggle.setDrawerIndicatorEnabled(false);
    drawerLayout.setDrawerListener(drawerToggle);
    navAdapter = new NavListAdapter(itemAccess, this);
    navList.setAdapter(navAdapter);
    navList.setOnItemClickListener((parent, view, position, id) -> {
        int viewType = parent.getAdapter().getItemViewType(position);
        if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER) {
            Intent intent = new Intent(MediaplayerInfoActivity.this, MainActivity.class);
            intent.putExtra(MainActivity.EXTRA_NAV_TYPE, viewType);
            intent.putExtra(MainActivity.EXTRA_NAV_INDEX, position);
            startActivity(intent);
        }
        drawerLayout.closeDrawer(navDrawer);
    });
    navList.setOnItemLongClickListener((parent, view, position, id) -> {
        if (position < navAdapter.getTags().size()) {
            showDrawerPreferencesDialog();
            return true;
        } else {
            mPosition = position;
            return false;
        }
    });
    registerForContextMenu(navList);
    drawerToggle.syncState();
    findViewById(R.id.nav_settings).setOnClickListener(v -> {
        drawerLayout.closeDrawer(navDrawer);
        startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceController.getPreferenceActivity()));
    });
    butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed);
    butCastDisconnect = (ImageButton) findViewById(R.id.butCastDisconnect);
    pager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new MediaplayerInfoPagerAdapter(getSupportFragmentManager(), media);
    pagerAdapter.setController(controller);
    pager.setAdapter(pagerAdapter);
    CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator);
    pageIndicator.setViewPager(pager);
    loadLastFragment();
    pager.onSaveInstanceState();
}
Also used : NavListAdapter(de.danoeh.antennapod.adapter.NavListAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) AppBarLayout(android.support.design.widget.AppBarLayout) CirclePageIndicator(com.viewpagerindicator.CirclePageIndicator) Toolbar(android.support.v7.widget.Toolbar)

Example 10 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project bilibili-android-client by HotBitmapGG.

the class VideoDetailsActivity method initViews.

@Override
public void initViews(Bundle savedInstanceState) {
    Intent intent = getIntent();
    if (intent != null) {
        av = intent.getIntExtra(ConstantUtil.EXTRA_AV, -1);
        imgUrl = intent.getStringExtra(ConstantUtil.EXTRA_IMG_URL);
    }
    Glide.with(VideoDetailsActivity.this).load(UrlHelper.getClearVideoPreviewUrl(imgUrl)).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.bili_default_image_tv).dontAnimate().into(mVideoPreview);
    loadData();
    mFAB.setClickable(false);
    mFAB.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.gray_20)));
    mFAB.setTranslationY(-getResources().getDimension(R.dimen.floating_action_button_size_half));
    mFAB.setOnClickListener(v -> VideoPlayerActivity.launch(VideoDetailsActivity.this, mVideoDetailsInfo.getPages().get(0).getCid(), mVideoDetailsInfo.getTitle()));
    mAppBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> setViewsTranslation(verticalOffset));
    mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeEvent() {

        @Override
        public void onStateChanged(AppBarLayout appBarLayout, State state, int verticalOffset) {
            if (state == State.EXPANDED) {
                //展开状态
                mTvPlayer.setVisibility(View.GONE);
                mAvText.setVisibility(View.VISIBLE);
                mToolbar.setContentInsetsRelative(DisplayUtil.dp2px(VideoDetailsActivity.this, 15), 0);
            } else if (state == State.COLLAPSED) {
                //折叠状态
                mTvPlayer.setVisibility(View.VISIBLE);
                mAvText.setVisibility(View.GONE);
                mToolbar.setContentInsetsRelative(DisplayUtil.dp2px(VideoDetailsActivity.this, 150), 0);
            } else {
                mTvPlayer.setVisibility(View.GONE);
                mAvText.setVisibility(View.VISIBLE);
                mToolbar.setContentInsetsRelative(DisplayUtil.dp2px(VideoDetailsActivity.this, 15), 0);
            }
        }
    });
}
Also used : AppBarStateChangeEvent(com.hotbitmapgg.bilibili.event.AppBarStateChangeEvent) Intent(android.content.Intent) AppBarLayout(android.support.design.widget.AppBarLayout) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint)

Aggregations

AppBarLayout (android.support.design.widget.AppBarLayout)27 View (android.view.View)15 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)11 RecyclerView (android.support.v7.widget.RecyclerView)7 Intent (android.content.Intent)6 ViewGroup (android.view.ViewGroup)6 ImageView (android.widget.ImageView)6 TabLayout (android.support.design.widget.TabLayout)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 Toolbar (android.support.v7.widget.Toolbar)5 TextView (android.widget.TextView)5 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)4 ViewPager (android.support.v4.view.ViewPager)4 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)4 PagerAdapter (android.support.v4.view.PagerAdapter)3 NestedScrollView (android.support.v4.widget.NestedScrollView)3 ActionBar (android.support.v7.app.ActionBar)3 ViewParent (android.view.ViewParent)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2