/**
   * Constructs a new swipe touch listener for the given {@link RecyclerView}
   *
   * @param recyclerView The recycler view whose items should be dismissable by swiping.
   * @param listener The listener for the swipe events.
   */
  public SwipeableRecyclerViewTouchListener(RecyclerView recyclerView, SwipeListener listener) {
    ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime =
        recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
    mRecyclerView = recyclerView;
    mSwipeListener = listener;

    /**
     * This will ensure that this SwipeableRecyclerViewTouchListener is paused during list view
     * scrolling. If a scroll listener is already assigned, the caller should still pass scroll
     * changes through to this listener.
     */
    mRecyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            setEnabled(newState != RecyclerView.SCROLL_STATE_DRAGGING);
          }

          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {}
        });
  }
  private void initView() {
    // init RecyclerView
    recyclerView = (RecyclerView) findViewById(R.id.activity_favorites_recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    recyclerView.addItemDecoration(new GridDividerDecoration(recyclerView.getContext()));
    recyclerView.setAdapter(
        new MainActivityFileRecyclerViewAdapter(
            this,
            getFavoriteDataArrayList(),
            MainActivityFileRecyclerViewAdapter.FLAG_FAVORITE,
            user));
    adapter = (MainActivityFileRecyclerViewAdapter) recyclerView.getAdapter();

    // 刷新数据相关
    mSwipeRefreshLayout =
        (SwipeRefreshLayout) findViewById(R.id.activity_favorites_swipe_refresh_layout);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.green_800);

    Map<String, String> params = new HashMap<String, String>();
    params.put("uid", "" + user.getUid());
    params.put("pagenum", pagenum + "");
    pagenum++;
    GetFavoritesFile get = new GetFavoritesFile(this);
    get.execute(params);
  }
Example #3
0
  private void goUp() {
    if (adapter.dataSet.posts != null) {

      int position = 0;
      int currentOrientation = getResources().getConfiguration().orientation;
      RecyclerView.SmoothScroller smoothScroller = null;
      if (rv.getLayoutManager() instanceof LinearLayoutManager
          && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        position = ((LinearLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
        smoothScroller = new TopSnappedSmoothScroller(rv.getContext(), rv.getLayoutManager());

      } else if (rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
        int[] firstVisibleItems = null;
        firstVisibleItems =
            ((CatchStaggeredGridLayoutManager) rv.getLayoutManager())
                .findFirstVisibleItemPositions(firstVisibleItems);
        if (firstVisibleItems != null && firstVisibleItems.length > 0) {
          position = firstVisibleItems[0];
          (rv.getLayoutManager())
              .smoothScrollToPosition(rv, new RecyclerView.State(), position - 1);
          return;
        }
      } else {
        position =
            ((PreCachingLayoutManager) rv.getLayoutManager())
                .findFirstCompletelyVisibleItemPosition();
        smoothScroller = new TopSnappedSmoothScroller(rv.getContext(), rv.getLayoutManager());
      }

      if (smoothScroller != null) {
        smoothScroller.setTargetPosition(position - 1);
        (rv.getLayoutManager()).startSmoothScroll(smoothScroller);
      }
    }
  }
 /**
  * Constructs a new swipe-to-dismiss OnItemTouchListener for RecyclerView
  *
  * @param recyclerView RecyclerView
  * @param callbacks The callback to trigger when the user has indicated that she would like to
  *     dismiss this view.
  */
 public SwipeToDismissTouchListener(RecyclerView recyclerView, DismissCallbacks callbacks) {
   ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 4;
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mRecyclerView = recyclerView;
   mCallbacks = callbacks;
 }
  private void ensureTopGlow(RecyclerView rv) {
    if (mTopGlow == null) {
      mTopGlow = new EdgeEffectCompat(rv.getContext());
    }

    updateGlowSize(rv, mTopGlow);
  }
 private void initViews() {
   nextPageToken = "";
   if (recyclerView == null) {
     recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
     progressWheel = rootView.findViewById(R.id.progress_bar);
     footerProgressWheel = rootView.findViewById(R.id.footer_progress_bar);
     LinearLayoutManager linearLayoutManager = new LinearLayoutManager(recyclerView.getContext());
     recyclerView.setLayoutManager(linearLayoutManager);
     recyclerView.addOnScrollListener(
         new EndlessScrollVideosListener(linearLayoutManager) {
           @Override
           public void onLoadMore(int currentPage) {
             MyLog.e("Current Page: (DailyMotion) " + currentPage);
             if (nextPageToken == null) {
               MyLog.e("End of loading more daily motion video");
             } else {
               loadVideoContent();
             }
           }
         });
   }
   loadVideoContent();
   navIndex = TTApplication.navIndex;
   Utils.sendTracker(Constants.SCREEN_DAILYMOTION_SEARCH_LIST);
 }
Example #7
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.visit);
   RecyclerView recyclerView = (RecyclerView) findViewById(R.id.visit_layout);
   recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
   recyclerView.setAdapter(new VisitDetailsAdapter(getSlots()));
 }
 @Override
 public void smoothScrollToPosition(
     RecyclerView recyclerView, RecyclerView.State state, int position) {
   RecyclerView.SmoothScroller smoothScroller =
       new TopSnappedSmoothScroller(recyclerView.getContext());
   smoothScroller.setTargetPosition(position);
   startSmoothScroll(smoothScroller);
 }
  @Override
  public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    int position = view.getChildAdapterPosition(childView);
    if (childView != null) {
      // Check Preferences
      SharedPreferences sharedPref =
          PreferenceManager.getDefaultSharedPreferences(view.getContext());
      int browseType = Integer.parseInt(sharedPref.getString("pref_browseType", "0"));

      Intent intent = new Intent(view.getContext(), DisplayCardActivity.class);
      Bundle extras = ((Activity) context).getIntent().getExtras();
      ArrayList<String> tagsList = new ArrayList<>();

      intent.putStringArrayListExtra("TAGS", tagsList);
      view.getContext().startActivity(intent);
    }
    return false;
  }
Example #10
0
  public SwipeableRVTL(RecyclerView recyclerView, SwipeListener listener) {
    ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime =
        recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
    //        mAnimationTime = 50;
    mRecyclerView = recyclerView;
    mSwipeListener = listener;

    // 确保滚动时不能滑动
    mRecyclerView.addOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            setEnabled(newState != RecyclerView.SCROLL_STATE_DRAGGING);
          }
        });
  }
  private void initList() {

    mAdapter = new DeviceListAdapter(mContext, mDataList);
    mAdapter.setOnItemListener(
        new OnItemListener() {
          @Override
          public void onClick(int pos) {
            Intent i = new Intent(mContext, IOListActivity.class);

            i.putExtra(Constant.KEY_ENTITY, mDataList.get(pos));

            i.putExtra(Constant.KEY_APPTYPE_ENTITY, mAppTypeEnt);
            startActivity(i);
          }

          @Override
          public boolean onLongClick(int pos) {
            showLongDialog(pos);
            return false;
          }

          @Override
          public void onCheckedChanged(int pos, boolean b) {}

          @Override
          public boolean onCheckedTouch(int pos, MotionEvent motionEvent) {
            return false;
          }
        });

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mAdapter);

    mLayoutManager = new LinearLayoutManager(mRecyclerView.getContext());
    mRecyclerView.setLayoutManager(mLayoutManager);

    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    refresh_layout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
    refresh_layout.setColorSchemeResources(
        android.R.color.holo_red_light,
        android.R.color.holo_green_light,
        android.R.color.holo_blue_light,
        android.R.color.holo_orange_light);
    refresh_layout.setEnabled(false);
    //        refresh_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //
    //                mMode = MODE_HAND_REFRESH;
    //                loadFirstPage();
    //            }
    //        });
  }
  public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      final View child = parent.getChildAt(i);
      RecyclerView v = new RecyclerView(parent.getContext());
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      final int top = child.getBottom() + params.bottomMargin;
      final int bottom = top + mDivider.getIntrinsicHeight();
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }
  }
Example #13
0
  public OverScrollImpl(final RecyclerView recyclerView) {
    this.recyclerView = recyclerView;

    scrollWeight =
        (int) (scrollWeight * recyclerView.getContext().getResources().getDisplayMetrics().density);

    recyclerView.addOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
              resetOverScroll();
            }
          }
        });
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_todays_meetings, container, false);
    ButterKnife.inject(this, rootView);
    Global = (GlobalApplication) getActivity().getApplication();

    List<ParseObject> todaysMeetings = Global.getTodaysMeetings();
    adapter = new MeetingAdapter(todaysMeetings);
    mRecyclerView.setAdapter(adapter);

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mRecyclerView.getContext());
    mRecyclerView.setLayoutManager(layoutManager);

    mRecyclerView.setHasFixedSize(true);

    return rootView;
  }
Example #15
0
  private void initView() {
    // MainActivity的布局文件中的主要控件初始化
    mToolbar = (Toolbar) this.findViewById(R.id.tool_bar);
    mDrawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) this.findViewById(R.id.navigation_view);
    headerView = mNavigationView.getHeaderView(0);
    header_userimg = (CricleImageView) headerView.findViewById(R.id.header_userimg);
    header_username = (TextView) headerView.findViewById(R.id.header_username);
    // 初始化ToolBar
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.all);
    // 对NavigationView添加item的监听事件
    mNavigationView.setNavigationItemSelectedListener(naviListener);
    if (SharedPerferencesUtil.getInstance().getIsLogined()) {
      // 已登陆
      // 个人数据加载
      user = JSON.parseObject(SharedPerferencesUtil.getInstance().getUserJson(), Users.class);
      Log.d(TAG, user.toString());
      initNavigationViewData(user);

      header_userimg.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              // 获取当前的用户ID,发送请求获取最新资料
              usersService.getUserDetailsByID(user.getID());
            }
          });
    } else
      header_userimg.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              startActivity(new Intent(x.app(), LoginActivity.class));
            }
          });
    // 列表
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext()));
    mRecyclerView.setAdapter(new RecyclerViewAdapter(this));
  }
Example #16
0
 private void updateUI(View view) {
   recyclerView = (RecyclerView) view.findViewById(R.id.rv_augur);
   recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
   // 子布局装饰
   recyclerView.addItemDecoration(
       new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
   mAdapter = new AugurAdapter(mycontext, this);
   mAdapter.setMdatas(datas);
   recyclerView.setAdapter(mAdapter);
   // 滑动加载更多的layout
   mSwipeLayout = (VerticalSwipeRefreshLayout) view.findViewById(R.id.swipe_container);
   mSwipeLayout.setColorSchemeResources(
       android.R.color.holo_blue_bright,
       android.R.color.holo_blue_bright,
       android.R.color.holo_blue_bright,
       android.R.color.holo_blue_bright);
   // 需要实现方法
   mSwipeLayout.setOnRefreshListener(this);
   onRefresh();
 }
Example #17
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    String[] strings = {getString(R.string.installed), getString(R.string.all)};

    List<String> list = new ArrayList<>(30);
    Random random = new Random();
    while (list.size() < 30) {
      // list.add(BaseActivity.sCheeseStrings[random.nextInt(BaseActivity.sCheeseStrings.length)]);
      list.add(strings[random.nextInt(strings.length)]);
    }

    RecyclerView recyclerView =
        (RecyclerView) inflater.inflate(R.layout.recycler_view, container, false);
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    recyclerView.addItemDecoration(new SearchDivider(getActivity()));
    recyclerView.setAdapter(new RecyclerViewAdapter(list)); // getActivity(); getContext
    return recyclerView;
  }
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.list, container, false);
    categoryManager = CategoryManager.getInstance(getContext());
    RecyclerView rv = (RecyclerView) layout.findViewById(R.id.itemList);
    rv.setLayoutManager(new LinearLayoutManager(rv.getContext()));

    Bundle bundle = getArguments();

    if (bundle != null && bundle.containsKey("category")) {
      this.category = (Category) bundle.getSerializable("category");
    }

    resources = getResources();

    new FetchItemsTask(rv).execute();

    return layout;
  }
Example #19
0
  /** Setup recycler view. */
  private void setupRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    adapter = new MessageAdapter(this.getActivity());
    recyclerView.setAdapter(adapter);

    // Add this.
    // Two scroller could have problem.
    recyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView view, int scrollState) {}

          @Override
          public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            int topRowVerticalPosition =
                (recyclerView == null || recyclerView.getChildCount() == 0)
                    ? 0
                    : recyclerView.getChildAt(0).getTop();
            swipeLayout.setEnabled(topRowVerticalPosition >= 0);
          }
        });
  }
  private static int canScrollUp(RecyclerView argRecyclerView) {
    int lastItemPos =
        ((LinearLayoutManager) argRecyclerView.getLayoutManager())
            .findLastCompletelyVisibleItemPosition();

    View v = (argRecyclerView.getLayoutManager()).findViewByPosition(lastItemPos);

    if (v == null) return -1;

    int[] loc = new int[2];
    v.getLocationOnScreen(loc);

    Context context = argRecyclerView.getContext();

    int screen = UIUtils.getScreenHeight(context);
    int navBar = UIUtils.NavigationBarHeight(context);

    int realloc = (int) (loc[1] + argRecyclerView.getTranslationY());
    int realloc2 = loc[1] + v.getHeight();

    return (realloc2 + navBar) - screen; //
  }
  /**
   * Constructs a new swipe touch listener for the given {@link RecyclerView}
   *
   * @param recyclerView The recycler view whose items should be dismissable by swiping.
   * @param listener The listener for the swipe events.
   */
  public SwipeToCheckTouchListener(
      RecyclerView recyclerView, int fgID, int BgID, SwipeListener listener) {
    mFgID = fgID;
    mBgID = BgID;
    ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mRecyclerView = recyclerView;
    mSwipeListener = listener;

    /**
     * This will ensure that this SwipeToDismissTouchListener is paused during list view scrolling.
     * If a scroll listener is already assigned, the caller should still pass scroll changes through
     * to this listener.
     */
    mRecyclerView.addOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            setEnabled(newState != RecyclerView.SCROLL_STATE_DRAGGING);
          }
        });
  }
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_box_office_list, container, false);

    rv = (RecyclerView) view.findViewById(R.id.recyclerview);
    rv.setLayoutManager(new LinearLayoutManager(rv.getContext()));
    context = getActivity();

    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            fetchBoxOfficeMovies();
          }
        });

    // fetchBoxOfficeMoviesWithDummyData();
    fetchBoxOfficeMovies();

    return view;
  }
  private void setupAlignment(RecyclerView recycler) {
    if (!mAlreadyAligned) {
      // setting alignment of header
      ViewGroup.LayoutParams currentParams = getLayoutParams();
      FrameLayout.LayoutParams newHeaderParams;
      int width = ViewGroup.LayoutParams.WRAP_CONTENT;
      int height = ViewGroup.LayoutParams.WRAP_CONTENT;
      int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL;
      if (currentParams != null) {
        newHeaderParams =
            new FrameLayout.LayoutParams(getLayoutParams()); // to copy all the margins
        newHeaderParams.width = width;
        newHeaderParams.height = height;
        newHeaderParams.gravity = gravity;
      } else {
        newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity);
      }
      RecyclerViewHeader.this.setLayoutParams(newHeaderParams);

      // setting alignment of recycler
      FrameLayout newRootParent = new FrameLayout(recycler.getContext());
      newRootParent.setLayoutParams(recycler.getLayoutParams());
      ViewParent currentParent = recycler.getParent();
      if (currentParent instanceof ViewGroup) {
        int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler);

        ((ViewGroup) currentParent).removeViewAt(indexWithinParent);
        recycler.setLayoutParams(
            new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        newRootParent.addView(recycler);
        newRootParent.addView(RecyclerViewHeader.this);
        ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent);
      }
    }
  }
 /** @param recyclerView pasamos el recyclerview para asignarle su configuración */
 private void setUpRecyclerView(RecyclerView recyclerView) {
   recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
   recyclerView.setAdapter(tweetAdapter);
 }
 private void setupRecyclerView(RecyclerView recyclerView) {
   recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
   recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(RecyclerViewActivity.this));
   recyclerView.setItemAnimator(new DefaultItemAnimator());
 }
 @SuppressWarnings("UnusedDeclaration")
 public MyLinearLayoutManager(RecyclerView view, int orientation, boolean reverseLayout) {
   super(view.getContext(), orientation, reverseLayout);
   this.view = view;
   this.overScrollMode = ViewCompat.getOverScrollMode(view);
 }
 @SuppressWarnings("UnusedDeclaration")
 public MyLinearLayoutManager(RecyclerView view) {
   super(view.getContext());
   this.view = view;
   this.overScrollMode = ViewCompat.getOverScrollMode(view);
 }
Example #28
0
  private void initView() {

    mToolbar = (Toolbar) this.findViewById(R.id.tool_bar);
    mDrawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) this.findViewById(R.id.navigation_view);

    // 初始化ToolBar
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    getSupportActionBar().setHomeButtonEnabled(true); // 设置返回键可用
    // actionBar.setHomeAsUpIndicator(android.R.drawable.ic_dialog_alert);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // 开启应用默认打开DrawerLayout
    // mDrawerLayout.openDrawer(mNavigationView);
    // mNavigationView.setNavigationItemSelectedListener(naviListener);
    ActionBarDrawerToggle mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, mToolbar, R.string.app_name, R.string.app_name);
    mDrawerToggle.syncState();
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    mRecyclerView = (MyRecView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext()));
    /*        mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //不是item的onTouch item onclick的时候不会执行到这
            Log.d("ZYS", "onTouch");
           // if(canclick)
            //    return super.onTouch(v,event);
            return !canclick;
        }
    });*/
    RecyclerViewAdapter mAdapter = new RecyclerViewAdapter(this);
    mAdapter.setOnItemClickLitener(
        new RecyclerViewAdapter.OnItemClickLitener() {
          CardView v;
          // 可以吧canclick相关判断转移到onitemtouch中,当返回true这些click事件不会被触发因为click等都基于onTouchEvent,
          // 而ontouch先于onTouchEvent,如果ontouch返回true则不执行onTouchEvent
          @Override
          public void onItemClick(View view, int position) {
            Log.d("ZYS", "onItemClick");
            if (canclick) {
              canclick = false;

              v = (CardView) view;
              Log.d("ZYS", "Y:" + v.getTop() + " X:" + v.getLeft());
              int[] pos = new int[2];
              v.getLocationInWindow(pos);
              Log.d("ZYS", "getLocationInWindow:" + pos[0] + "," + pos[1]);

              // v.setCardBackgroundColor(MainActivity.this.getResources().getColor(R.color.colorAccent));
              //  Toast.makeText(MainActivity.this, position + " click " + view,
              //        Toast.LENGTH_SHORT).show();

              // 开启Fragment事务
              FragmentTransaction transaction = fragmentManager.beginTransaction();
              if (of2 == null) {
                // 如果MessageFragment为空,则创建一个并添加到界面上
                of2 = new oFragment2();
                of2.setttop(v.getTop(), "Thing " + position);
                transaction.add(R.id.content, of2);
              } else {
                //   如果MessageFragment不为空,则直接将它显示出来
                of2.setttop(v.getTop(), "Thing " + position);
                transaction.show(of2);
              }
              transaction.commit();
              verticalRun();
              selectedFragment = of2;
            }
          }

          @Override
          public boolean onItemLongClick(View view, int position) {
            if (canclick) {
              //   canclick=false;
              v = (CardView) view;
              v.setCardBackgroundColor(
                  MainActivity.this.getResources().getColor(R.color.colorPrimary));
              //   Toast.makeText(MainActivity.this, position + " long click",
              //          Toast.LENGTH_SHORT).show();

            }
            return true;
          };
        });
    mAdapter.setOnItemTouchLitener(
        new RecyclerViewAdapter.OnItemTouchLitener() {

          @Override
          public boolean onItemTouch(View view, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
              case MotionEvent.ACTION_DOWN:
                Log.d("ZYS", "2:onTouch action:ACTION_DOWN");
                // view.getParent().requestDisallowInterceptTouchEvent(true);
                return false;

              case MotionEvent.ACTION_MOVE:
                Log.d("ZYS", "2:onTouch action:ACTION_MOVE");
                break;
              case MotionEvent.ACTION_UP:
                Log.d("ZYS", "2:onTouch action:ACTION_UP");
                break;
              case MotionEvent.ACTION_CANCEL:
                Log.d("ZYS", "2:onTouch action:ACTION_CANCEL");
                break;
            }
            return false;
          }
        });
    mRecyclerView.setAdapter(mAdapter);
  }
Example #29
0
 /**
  * Init RecyclerView (~= ListView) related things
  *
  * @param recyclerView
  * @param beerListItemAdapter
  */
 private void setUpRecyclerView(
     final RecyclerView recyclerView, BeerListItemAdapter beerListItemAdapter) {
   recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
   recyclerView.setHasFixedSize(true);
   recyclerView.setAdapter(beerListItemAdapter);
 }
 public HistoryAdapter(RecyclerView rv, List<Weight> weights) {
   this.ctx = rv.getContext();
   this.rv = rv;
   this.weights = weights;
   li = LayoutInflater.from(ctx);
 }