Search in sources :

Example 71 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project UltimateAndroid by cymcsg.

the class SimpleAdapter method onCreateViewHolder.

@Override
public UltimateRecyclerviewViewHolder onCreateViewHolder(ViewGroup parent) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_adapter, parent, false);
    ViewHolder vh = new ViewHolder(v);
    return vh;
}
Also used : UltimateRecyclerviewViewHolder(com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 72 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project UltimateRecyclerView by cymcsg.

the class LauncherActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    ultimateRecyclerView = (UltimateRecyclerView) findViewById(R.id.ultimate_recycler_view);
    ultimateRecyclerView.setHasFixedSize(false);
    final List<String> stringList = new ArrayList<>();
    stringList.add("111");
    stringList.add("aaa");
    stringList.add("222");
    stringList.add("33");
    stringList.add("44");
    stringList.add("55");
    stringList.add("66");
    stringList.add("11771");
    simpleRecyclerViewAdapter = new SimpleAdapter(stringList);
    linearLayoutManager = new LinearLayoutManager(this);
    ultimateRecyclerView.setLayoutManager(linearLayoutManager);
    StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(simpleRecyclerViewAdapter);
    ultimateRecyclerView.addItemDecoration(headersDecor);
    ////        ultimateRecyclerView.setEmptyView(getResources().getIdentifier("empty_view","layout",getPackageName()));
    //        ultimateRecyclerView.showEmptyView();
    //  ultimateRecyclerView.enableLoadmore();
    //simpleRecyclerViewAdapter.setCustomLoadMoreView(LayoutInflater.from(this)
    //        .inflate(R.layout.custom_bottom_progressbar, null));
    ultimateRecyclerView.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.custom_bottom_progressbar, null));
    ultimateRecyclerView.setParallaxHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
    //        //   ultimateRecyclerView.setNormalHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
    ultimateRecyclerView.setOnParallaxScroll(new UltimateRecyclerView.OnParallaxScroll() {

        @Override
        public void onParallaxScroll(float percentage, float offset, View parallax) {
            Drawable c = toolbar.getBackground();
            c.setAlpha(Math.round(127 + percentage * 128));
            toolbar.setBackgroundDrawable(c);
        }
    });
    ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff"));
    ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

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

                @Override
                public void run() {
                    simpleRecyclerViewAdapter.insert(moreNum++ + "  Refresh things", 0);
                    ultimateRecyclerView.setRefreshing(false);
                    //   ultimateRecyclerView.scrollBy(0, -50);
                    linearLayoutManager.scrollToPosition(0);
                //                        ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
                //                        simpleRecyclerViewAdapter.notifyDataSetChanged();
                }
            }, 1000);
        }
    });
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(simpleRecyclerViewAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(ultimateRecyclerView.mRecyclerView);
    simpleRecyclerViewAdapter.setOnDragStartListener(new SimpleAdapter.OnStartDragListener() {

        @Override
        public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
            mItemTouchHelper.startDrag(viewHolder);
        }
    });
    ultimateRecyclerView.reenableLoadmore();
    ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
    ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {

        @Override
        public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                public void run() {
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                // linearLayoutManager.scrollToPositionWithOffset(maxLastVisiblePosition,-1);
                //   linearLayoutManager.scrollToPosition(maxLastVisiblePosition);
                }
            }, 1000);
        }
    });
    //        ultimateRecyclerView.setDefaultSwipeToRefreshColorScheme(getResources().getColor(android.R.color.holo_blue_bright),
    //                getResources().getColor(android.R.color.holo_green_light),
    //                getResources().getColor(android.R.color.holo_orange_light),
    //                getResources().getColor(android.R.color.holo_red_light));
    //        ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
    //            @Override
    //            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    //
    //            }
    //
    //            @Override
    //            public void onDownMotionEvent() {
    //
    //            }
    //
    //            @Override
    //            public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
    ////                if (observableScrollState == ObservableScrollState.DOWN) {
    ////                    ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    ////                    ultimateRecyclerView.showFloatingActionMenu();
    ////                } else if (observableScrollState == ObservableScrollState.UP) {
    ////                    ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    ////                    ultimateRecyclerView.hideFloatingActionMenu();
    ////                } else if (observableScrollState == ObservableScrollState.STOP) {
    ////                }
    //                URLogs.d("onUpOrCancelMotionEvent");
    //                if (observableScrollState == ObservableScrollState.UP) {
    //                    ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    //                    ultimateRecyclerView.hideFloatingActionMenu();
    //                } else if (observableScrollState == ObservableScrollState.DOWN) {
    //                    ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    //                    ultimateRecyclerView.showFloatingActionMenu();
    //                }
    //            }
    //        });
    ultimateRecyclerView.showFloatingButtonView();
    //
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
    for (Type type : Type.values()) {
        spinnerAdapter.add(type.name());
    }
    spinner.setAdapter(spinnerAdapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ultimateRecyclerView.setItemAnimator(Type.values()[position].getAnimator());
            ultimateRecyclerView.getItemAnimator().setAddDuration(500);
            ultimateRecyclerView.getItemAnimator().setRemoveDuration(500);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleRecyclerViewAdapter.insert("newly added item", 1);
        }
    });
    findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleRecyclerViewAdapter.remove(1);
        }
    });
//
}
Also used : SimpleItemTouchHelperCallback(com.marshalchen.ultimaterecyclerview.itemTouchHelper.SimpleItemTouchHelperCallback) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) StickyRecyclerHeadersDecoration(com.marshalchen.ultimaterecyclerview.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 73 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project UltimateRecyclerView by cymcsg.

the class SimpleAdapter method onCreateViewHolder.

@Override
public UltimateRecyclerviewViewHolder onCreateViewHolder(ViewGroup parent) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_adapter, parent, false);
    ViewHolder vh = new ViewHolder(v);
    return vh;
}
Also used : UltimateRecyclerviewViewHolder(com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder) ItemTouchHelperViewHolder(com.marshalchen.ultimaterecyclerview.itemTouchHelper.ItemTouchHelperViewHolder) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 74 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project AndroidSwipeLayout by daimajia.

the class RecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
    String item = mDataset.get(position);
    viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
    viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {

        @Override
        public void onOpen(SwipeLayout layout) {
            YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
        }
    });
    viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {

        @Override
        public void onDoubleClick(SwipeLayout layout, boolean surface) {
            Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
        }
    });
    viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mItemManger.removeShownLayouts(viewHolder.swipeLayout);
            mDataset.remove(position);
            notifyItemRemoved(position);
            notifyItemRangeChanged(position, mDataset.size());
            mItemManger.closeAllItems();
            Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewData.getText().toString() + "!", Toast.LENGTH_SHORT).show();
        }
    });
    viewHolder.textViewPos.setText((position + 1) + ".");
    viewHolder.textViewData.setText(item);
    mItemManger.bind(viewHolder.itemView, position);
}
Also used : SimpleSwipeListener(com.daimajia.swipe.SimpleSwipeListener) SwipeLayout(com.daimajia.swipe.SwipeLayout) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 75 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method runRemoveAnimation.

//1st Remove
private void runRemoveAnimation() {
    // Reverse sorting removal animations
    Collections.sort(mPendingRemovals, new Comparator<ViewHolder>() {

        @Override
        public int compare(ViewHolder vh1, ViewHolder vh2) {
            return (int) (vh2.getItemId() - vh1.getItemId());
        }
    });
    Runnable remover = new Runnable() {

        @Override
        public void run() {
            int index = 0;
            for (ViewHolder holder : mPendingRemovals) {
                doAnimateRemove(holder, index++);
            }
            mPendingRemovals.clear();
        }
    };
    remover.run();
}
Also used : AnimatedViewHolder(eu.davidea.viewholders.AnimatedViewHolder) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)265 View (android.view.View)248 TextView (android.widget.TextView)129 ImageView (android.widget.ImageView)95 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)47 LayoutInflater (android.view.LayoutInflater)34 ViewGroup (android.view.ViewGroup)32 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)28 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)25 Context (android.content.Context)21 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)17 BindView (butterknife.BindView)17 CardView (android.support.v7.widget.CardView)15 Paint (android.graphics.Paint)11 ParallaxRecyclerAdapter (com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter)8 ExampleData (de.madcyph3r.example.data.ExampleData)8 Drawable (android.graphics.drawable.Drawable)7 Test (org.junit.Test)7