Search in sources :

Example 71 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project RoboBinding by RoboBinding.

the class OnRefreshAttributeTest method setUp.

@Before
public void setUp() throws Exception {
    view = new SwipeRefreshLayout(RuntimeEnvironment.application);
    attribute = new OnRefreshAttribute();
    eventCommand = new EventCommand();
}
Also used : EventCommand(org.robobinding.widget.EventCommand) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Before(org.junit.Before)

Example 72 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project robolectric by robolectric.

the class ShadowSwipeRefreshLayoutTest method getOnRefreshListener_shouldReturnTheListener.

@Test
public void getOnRefreshListener_shouldReturnTheListener() {
    final OnRefreshListener listener = mock(OnRefreshListener.class);
    final SwipeRefreshLayout layout = new SwipeRefreshLayout(RuntimeEnvironment.application);
    layout.setOnRefreshListener(listener);
    assertThat(shadowOf(layout).getOnRefreshListener()).isSameAs(listener);
}
Also used : SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) OnRefreshListener(android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener) Test(org.junit.Test)

Example 73 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project CustomViews by AndroidStudy233.

the class RecyclerViewActivity method fillContentView.

private void fillContentView() {
    View view = View.inflate(this, R.layout.layout_recycler_main, null);
    // 初始化SwipeRefreshLayout
    swipe_main = (SwipeRefreshLayout) view.findViewById(R.id.swipe_recycler_main);
    swipe_main.setColorSchemeResources(R.color.swipe_schema_red, swipe_schema_blue, R.color.swipe_schema_green);
    swipe_main.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            MyApplication.getHandler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    showToast("刷新成功~");
                    swipe_main.setRefreshing(false);
                }
            }, 1500);
        }
    });
    // 初始化RecyclerView
    recycler_main = (RecyclerView) view.findViewById(R.id.recycler_recycler_main);
    // 设置布局管理者,采用线性布局管理者,竖直排列,不用反转(反转就是数据反序)
    recycler_main.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    adapter = new SimpleRecyclerAdapter(this, new SimpleRecyclerAdapter.OnItemClickListener() {

        @Override
        public void onClick(int position, ImgAndText bean) {
            /*
                    这里有个要注意的地方就是,在adapter中设置侦听的时候你要是用onBindViewHolder方法中的参数position
                    那么remove之后会position错乱BUG.这是RecyclerView的一个大坑...要用holder.getAdapterPosition传递
                 */
            System.arraycopy(hits, 1, hits, 0, hits.length - 1);
            hits[hits.length - 1] = SystemClock.uptimeMillis();
            if (hits[0] >= SystemClock.uptimeMillis() - 500) {
                MyLogUtil.debug("position: " + position);
                adapter.removeItem(position);
            } else {
                ToastUtil.toastShort(RecyclerViewActivity.this, "点击了图片");
            }
        }
    });
    // 设置拖拽监听, 首先定义一个callback定义拖拽功能, callback中定义listener与adapter传递事件
    // 然后将callback传给helper, 并由helper绑定recycle
    ItemTouchHelper.Callback callback = new OnRecyclerItemTouchCallBack(adapter);
    ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(recycler_main);
    /*
            细节注意, 上述方式是通过长按条目来实现拖拽, 比如条目右边有个图标, 希望按住图标实现拖拽呢?
            adapter的holder中设置图标触摸事件setOnTouchListener. 这就需要在onTouch方法中调用上面helper的
            onStartDrag方法, 怎么调用呢? adapter定义一个接口OnIconDragHandler. 里边定义
            onHandleDrag(RecyclerView.ViewHolder viewHolder); 然后通过构造传进来.
            这样再让当前activity实现接口, 调用helper的onStartDrag方法. 然后new adapter的时候传过去.
            最后具体一下图标的ouTouch方法
             如果按下
                if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN){
                    回调RecyclerViewActivity中的onHandleDrag方法
                    让mItemTouchHelper执行拖拽操作
                    handler.startDrag(holder);
                }
         */
    // recycler_main.setAdapter(adapter);
    // 使用第三方库中简单的动画来设置适配器,其对象可以setDuration、setInterpolator,甚至可以继续传入形成装饰者
    // recycler_main.setAdapter(new ScaleInAnimationAdapter(adapter));
    recycler_main.setAdapter(new SlideInLeftAnimationAdapter(adapter));
    /*
            这里有个非常重要的问题,如果你想使用增删动画,那么在增删操作的时候
            你就不能使用notifyDataSetChanged,不然动画不会执行的,需要使用notifyItemRemoved(posi)、notifyItemInserted(posi)
         */
    // 设置条目动画,增删的时候会用到
    SlideInLeftAnimator animator = new SlideInLeftAnimator();
    animator.setInterpolator(new OvershootInterpolator());
    recycler_main.setItemAnimator(animator);
    // 将填充好的View放到主页面上
    frame_main.addView(view);
}
Also used : ImgAndText(com.shiqkuangsan.mycustomviews.bean.ImgAndText) OvershootInterpolator(android.view.animation.OvershootInterpolator) SlideInLeftAnimationAdapter(jp.wasabeef.recyclerview.adapters.SlideInLeftAnimationAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) ContentView(org.xutils.view.annotation.ContentView) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SimpleRecyclerAdapter(com.shiqkuangsan.mycustomviews.adapter.SimpleRecyclerAdapter) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) OnRecyclerItemTouchCallBack(com.shiqkuangsan.mycustomviews.ui.custom.OnRecyclerItemTouchCallBack) SlideInLeftAnimator(jp.wasabeef.recyclerview.animators.SlideInLeftAnimator)

Example 74 with SwipeRefreshLayout

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

the class ParentFragment method configureRecyclerViewAsGrid.

public void configureRecyclerViewAsGrid(View rootView, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, int emptyViewStringResId, final int span, View.OnClickListener emptyImageListener, Drawable... emptyImage) {
    final int cardPadding = getResources().getDimensionPixelOffset(R.dimen.card_outer_margin);
    EmptyViewInterface emptyViewInterface = (EmptyViewInterface) rootView.findViewById(emptyViewResId);
    final PandaRecyclerView recyclerView = (PandaRecyclerView) rootView.findViewById(recyclerViewResId);
    emptyViewInterface.emptyViewText(emptyViewStringResId);
    emptyViewInterface.setNoConnectionText(getString(R.string.noConnection));
    if (emptyImage != null && emptyImage.length > 0) {
        emptyViewInterface.emptyViewImage(emptyImage[0]);
        if (emptyImageListener != null && emptyViewInterface.getEmptyViewImage() != null) {
            emptyViewInterface.getEmptyViewImage().setOnClickListener(emptyImageListener);
        }
    }
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 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 span;
                }
            } else {
                // if something goes wrong it will take up the entire space, but at least it won't crash
                return span;
            }
            return 1;
        }
    });
    if (mSpacingDecoration != null) {
        recyclerView.removeItemDecoration(mSpacingDecoration);
    }
    if (baseRecyclerAdapter instanceof ExpandableRecyclerAdapter) {
        mSpacingDecoration = new ExpandableGridSpacingDecorator(cardPadding);
    } else {
        mSpacingDecoration = new GridSpacingDecorator(cardPadding);
    }
    recyclerView.addItemDecoration(mSpacingDecoration);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new ExpandCollapseItemAnimator());
    recyclerView.setEmptyView(emptyViewInterface);
    recyclerView.setAdapter(baseRecyclerAdapter);
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(swipeRefreshLayoutResId);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(getContext())) {
                mSwipeRefreshLayout.setRefreshing(false);
            } else {
                baseRecyclerAdapter.refresh();
            }
        }
    });
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) GridSpacingDecorator(com.instructure.speedgrader.decorations.GridSpacingDecorator) ExpandableGridSpacingDecorator(com.instructure.speedgrader.decorations.ExpandableGridSpacingDecorator) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) ExpandCollapseItemAnimator(com.instructure.speedgrader.animators.ExpandCollapseItemAnimator) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) ExpandableGridSpacingDecorator(com.instructure.speedgrader.decorations.ExpandableGridSpacingDecorator) ExpandableRecyclerAdapter(com.instructure.speedgrader.adapters.ExpandableRecyclerAdapter) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Point(android.graphics.Point)

Example 75 with SwipeRefreshLayout

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

the class FragmentAppList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_app_list, container, false);
    dataBase = AppDataBase.getAppDatabase(this.getActivity());
    pb = v.findViewById(R.id.progressBar);
    txtNoData = v.findViewById(R.id.txtNoData);
    final SwipeRefreshLayout swipeLayout = v.findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            swipeLayout.setRefreshing(false);
            loadData();
        }
    });
    lst = v.findViewById(R.id.lst);
    lst.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Application app = apps[i];
            Intent intent = new Intent(FragmentAppList.this.getContext(), InstallAppActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("APP_ID", app.appId);
            intent.putExtra("APP_PATH", app.appPath);
            FragmentAppList.this.getContext().startActivity(intent);
        }
    });
    loadData();
    return v;
}
Also used : AdapterView(android.widget.AdapterView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Application(org.flyve.mdm.agent.room.entity.Application)

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