Search in sources :

Example 76 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project android-mdm-agent by flyve-mdm.

the class FragmentLog method onCreateView.

/**
 * Called to have the fragments instantiate its user interface View
 * @param inflater the object that can be used to inflate any views
 * @param container the parent View
 * @param savedInstanceState if non-null, this fragment is being reconstructed from a previous saved state
 * @return View the fragment's UI
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_log, container, false);
    txtMessage = v.findViewById(R.id.txtMessage);
    pb = v.findViewById(R.id.progressBar);
    FloatingActionButton btnDelete = v.findViewById(R.id.btnDelete);
    btnDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FlyveLog.clearLog(FlyveLog.FILE_NAME_LOG);
            arrData.clear();
            loadLogFile();
        }
    });
    arrData = new ArrayList<>();
    final SwipeRefreshLayout swipeLayout = v.findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            swipeLayout.setRefreshing(false);
            arrData.clear();
            loadLogFile();
        }
    });
    lst = v.findViewById(R.id.lst);
    loadLogFile();
    return v;
}
Also used : FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 77 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project instructure-android by instructure.

the class RecyclerViewUtils method configureRecyclerViewAsGrid.

public static PandaRecyclerView configureRecyclerViewAsGrid(View rootView, final Context context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, final int span, String emptyViewString) {
    EmptyViewInterface emptyViewInterface = (EmptyViewInterface) rootView.findViewById(emptyViewResId);
    final PandaRecyclerView recyclerView = (PandaRecyclerView) rootView.findViewById(recyclerViewResId);
    emptyViewInterface.emptyViewText(emptyViewString);
    emptyViewInterface.setNoConnectionText(context.getString(R.string.noConnection));
    GridLayoutManager layoutManager = new GridLayoutManager(context, span, GridLayoutManager.VERTICAL, false);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (position < recyclerView.getAdapter().getItemCount()) {
                int viewType = recyclerView.getAdapter().getItemViewType(position);
                if (Types.TYPE_HEADER == viewType || PaginatedRecyclerAdapter.LOADING_FOOTER_TYPE == viewType) {
                    return 1;
                }
            } else {
                // if something goes wrong it will take up the entire space, but at least it won't crash
                return 1;
            }
            return 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setEmptyView(emptyViewInterface);
    recyclerView.setAdapter(baseRecyclerAdapter);
    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(swipeRefreshLayoutResId);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(context)) {
                swipeRefreshLayout.setRefreshing(false);
            } else {
                baseRecyclerAdapter.refresh();
            }
        }
    });
    return recyclerView;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 78 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project instructure-android by instructure.

the class RecyclerViewUtils method configureRecyclerViewAsGrid.

public static PandaRecyclerView configureRecyclerViewAsGrid(final Activity context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, final int span, String emptyViewString) {
    EmptyViewInterface emptyViewInterface = (EmptyViewInterface) context.findViewById(emptyViewResId);
    final PandaRecyclerView recyclerView = (PandaRecyclerView) context.findViewById(recyclerViewResId);
    emptyViewInterface.emptyViewText(emptyViewString);
    emptyViewInterface.setNoConnectionText(context.getString(R.string.noConnection));
    GridLayoutManager layoutManager = new GridLayoutManager(context, span, GridLayoutManager.VERTICAL, false);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (position < recyclerView.getAdapter().getItemCount()) {
                int viewType = recyclerView.getAdapter().getItemViewType(position);
                if (Types.TYPE_HEADER == viewType || PaginatedRecyclerAdapter.LOADING_FOOTER_TYPE == viewType) {
                    return 1;
                }
            } else {
                // if something goes wrong it will take up the entire space, but at least it won't crash
                return 1;
            }
            return 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setEmptyView(emptyViewInterface);
    recyclerView.setAdapter(baseRecyclerAdapter);
    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) context.findViewById(swipeRefreshLayoutResId);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(context)) {
                swipeRefreshLayout.setRefreshing(false);
            } else {
                baseRecyclerAdapter.refresh();
            }
        }
    });
    return recyclerView;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 79 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project instructure-android by instructure.

the class RecyclerViewUtils method buildRecyclerView.

public static RecyclerView buildRecyclerView(final Context context, final ListRecyclerAdapter recyclerAdapter, final ListPresenter presenter, final SwipeRefreshLayout swipeRefreshLayout, final RecyclerView recyclerView, final EmptyInterface emptyInterface, String emptyViewText) {
    emptyInterface.setTitleText(emptyViewText);
    emptyInterface.setNoConnectionText(context.getString(R.string.noConnection));
    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(recyclerAdapter);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(context)) {
                swipeRefreshLayout.setRefreshing(false);
            } else {
                presenter.refresh(true);
            }
        }
    });
    return recyclerView;
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 80 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project SherlockAdapter by EvilBT.

the class ExpandableActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mGridLayoutManager = new GridLayoutManager(this, 2);
    mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
    mAdapter = new MyExpandableAdapter();
    // mAdapter.setAlwaysShowFoot(true);
    // mAdapter.setAlwaysShowHead(true);
    mAdapter.addHeadLayout(R.layout.item_head);
    mAdapter.addFootLayout(R.layout.item_foot2);
    // 设置DiffUtil效果
    mAdapter.setCallback(new DiffUtilCallback<IMultiItem>() {

        @Override
        public boolean areItemsTheSame(IMultiItem oldItem, IMultiItem newItem) {
            if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
                return TextUtils.equals(((ImageLabel) oldItem).getData(), ((ImageLabel) newItem).getData());
            }
            if (oldItem instanceof Card && newItem instanceof Card) {
                return ((Card) oldItem).getData().mImageResId == ((Card) newItem).getData().mImageResId;
            }
            return false;
        }

        @Override
        public boolean areContentsTheSame(IMultiItem oldItem, IMultiItem newItem) {
            if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
                return true;
            }
            if (oldItem instanceof Card && newItem instanceof Card) {
                return TextUtils.equals(((Card) oldItem).getData().mImageTitle, ((Card) newItem).getData().mImageTitle);
            }
            return false;
        }
    });
    mRecyclerView.setAdapter(mAdapter);
    // 屏障默认的Change动画
    ((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    // 点击展开/折叠事件
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(@NonNull View view, int adapterPosition) {
            if (view.getId() == R.id.label_root) {
                IMultiItem item = mAdapter.getData(adapterPosition);
                if (item instanceof IExpandable) {
                    IExpandable expandable = (IExpandable) item;
                    if (expandable.isExpandable()) {
                        // 修复issue#2
                        // 这个支持包的bug: https://issuetracker.google.com/issues/37034096
                        mStaggeredGridLayoutManager.invalidateSpanAssignments();
                        mAdapter.collapseAll(adapterPosition);
                    } else {
                        mAdapter.expandAll(adapterPosition);
                    }
                }
            }
        }
    });
    mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(@NonNull View view, int adapterPosition) {
            mAdapter.removeData(adapterPosition);
            return true;
        }
    });
    final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
    refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshData();
            refresh.setRefreshing(false);
        }
    });
    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshData();
        }
    });
    initData();
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) OnItemClickListener(xyz.zpayh.adapter.OnItemClickListener) ImageLabel(xyz.zpayh.myadapter.data.ImageLabel) IExpandable(xyz.zpayh.adapter.IExpandable) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) IMultiItem(xyz.zpayh.adapter.IMultiItem) OnItemLongClickListener(xyz.zpayh.adapter.OnItemLongClickListener) Card(xyz.zpayh.myadapter.data.Card) ImageCard(xyz.zpayh.myadapter.data.ImageCard) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) MyExpandableAdapter(xyz.zpayh.myadapter.adapter.MyExpandableAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)115 View (android.view.View)65 RecyclerView (android.support.v7.widget.RecyclerView)58 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)43 TextView (android.widget.TextView)30 Bundle (android.os.Bundle)21 Intent (android.content.Intent)20 Handler (android.os.Handler)17 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)16 Toolbar (android.support.v7.widget.Toolbar)16 ArrayList (java.util.ArrayList)16 AdapterView (android.widget.AdapterView)14 ListView (android.widget.ListView)12 ImageView (android.widget.ImageView)11 GridLayoutManager (android.support.v7.widget.GridLayoutManager)10 Context (android.content.Context)9 LayoutInflater (android.view.LayoutInflater)9 ViewGroup (android.view.ViewGroup)9 DialogInterface (android.content.DialogInterface)8 FrameLayout (android.widget.FrameLayout)7