Search in sources :

Example 11 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project WordPress-Android by wordpress-mobile.

the class ReaderPostListActivity method disableFilteredRecyclerViewToolbar.

/*
    * This method hides the FilteredRecyclerView toolbar with spinner so to disable content filtering, for reusability
    * */
private void disableFilteredRecyclerViewToolbar() {
    // make it invisible - setting height to zero here because setting visibility to View.GONE wouldn't take the
    // occupied space, as otherwise expected
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
    if (appBarLayout != null) {
        CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
        lp.height = 0;
        appBarLayout.setLayoutParams(lp);
    }
    // disabling any CoordinatorLayout behavior for scrolling
    Toolbar toolbarWithSpinner = (Toolbar) findViewById(R.id.toolbar_with_spinner);
    if (toolbarWithSpinner != null) {
        AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) toolbarWithSpinner.getLayoutParams();
        p.setScrollFlags(0);
        toolbarWithSpinner.setLayoutParams(p);
    }
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 12 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project MadMax by deviz92.

the class BarDetailFragment method initCollapsingToolbar.

/* */
/**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
/*
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }*/
// Initializing collapsing toolbar: it will show and hide the toolbar title on scroll
private void initCollapsingToolbar() {
    final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) ((BasicActivity) getActivity()).findViewById(R.id.collapsingToolbar);
    collapsingToolbar.setTitle(" ");
    AppBarLayout appBarLayout = (AppBarLayout) ((BasicActivity) getActivity()).findViewById(R.id.app_bar);
    appBarLayout.setExpanded(true);
    // hiding & showing the title when toolbar expanded & collapsed
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        boolean isShow = false;

        int scrollRange = -1;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (scrollRange == -1) {
                scrollRange = appBarLayout.getTotalScrollRange();
            }
            if (scrollRange + verticalOffset == 0) {
                collapsingToolbar.setTitle(nameTextView.getText());
                isShow = true;
            } else if (isShow) {
                collapsingToolbar.setTitle(" ");
                isShow = false;
            }
        }
    });
}
Also used : CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 13 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project GeekNews by codeestX.

the class ThemeActivity method initEventAndData.

@Override
protected void initEventAndData() {
    Intent intent = getIntent();
    id = intent.getExtras().getInt("id");
    ivProgress.start();
    mList = new ArrayList<>();
    mAdapter = new ThemeChildAdapter(mContext, mList);
    rvThemeChildList.setLayoutManager(new LinearLayoutManager(mContext));
    rvThemeChildList.setAdapter(mAdapter);
    mPresenter.getThemeChildData(id);
    mAdapter.setOnItemClickListener(new ThemeChildAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View shareView) {
            mPresenter.insertReadToDB(mList.get(position).getId());
            mAdapter.setReadState(position, true);
            mAdapter.notifyItemChanged(position);
            Intent intent = new Intent();
            intent.setClass(mContext, ZhihuDetailActivity.class);
            intent.putExtra("id", mList.get(position).getId());
            if (shareView != null) {
                mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext, shareView, "shareView").toBundle());
            } else {
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext).toBundle());
            }
        }
    });
    appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (verticalOffset >= 0) {
                swipeRefresh.setEnabled(true);
            } else {
                swipeRefresh.setEnabled(false);
                float rate = (float) (SystemUtil.dp2px(mContext, 256) + verticalOffset * 2) / SystemUtil.dp2px(mContext, 256);
                if (rate >= 0)
                    ivOrigin.setAlpha(rate);
            }
        }
    });
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mPresenter.getThemeChildData(id);
        }
    });
}
Also used : Intent(android.content.Intent) ThemeChildAdapter(com.codeest.geeknews.ui.zhihu.adapter.ThemeChildAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) ProgressImageView(com.codeest.geeknews.widget.ProgressImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 14 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project GeekNews by codeestX.

the class TechFragment method initEventAndData.

@Override
protected void initEventAndData() {
    mPresenter.getGirlImage();
    mList = new ArrayList<>();
    tech = getArguments().getString(Constants.IT_GANK_TYPE);
    type = getArguments().getInt(Constants.IT_GANK_TYPE_CODE);
    mAdapter = new TechAdapter(mContext, mList, tech);
    rvTechContent.setLayoutManager(new LinearLayoutManager(mContext));
    rvTechContent.setAdapter(mAdapter);
    ivProgress.start();
    mPresenter.getGankData(tech, type);
    mAdapter.setOnItemClickListener(new TechAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View shareView) {
            TechDetailActivity.launch(new TechDetailActivity.Builder().setContext(mContext).setId(mList.get(position).get_id()).setTitle(mList.get(position).getDesc()).setUrl(mList.get(position).getUrl()).setType(type).setAnimConfig(mActivity, shareView));
        }
    });
    rvTechContent.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int lastVisibleItem = ((LinearLayoutManager) rvTechContent.getLayoutManager()).findLastVisibleItemPosition();
            int totalItemCount = rvTechContent.getLayoutManager().getItemCount();
            if (lastVisibleItem >= totalItemCount - 2 && dy > 0) {
                //还剩2个Item时加载更多
                if (!isLoadingMore) {
                    isLoadingMore = true;
                    mPresenter.getMoreGankData(tech);
                }
            }
        }
    });
    appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (verticalOffset >= 0) {
                swipeRefresh.setEnabled(true);
            } else {
                swipeRefresh.setEnabled(false);
                float rate = (float) (SystemUtil.dp2px(mContext, 256) + verticalOffset * 2) / SystemUtil.dp2px(mContext, 256);
                if (rate >= 0)
                    ivOrigin.setAlpha(rate);
            }
        }
    });
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mPresenter.getGankData(tech, type);
        }
    });
}
Also used : TechAdapter(com.codeest.geeknews.ui.gank.adapter.TechAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) ProgressImageView(com.codeest.geeknews.widget.ProgressImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 15 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project Meizhi by drakeet.

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)

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