Ejemplo n.º 1
0
 @Override
 public void onBeaconChanged(BeaconLocation changedBeacon) {
   BeaconsViewHolder viewHolder =
       (BeaconsViewHolder)
           mRecyclerView.findViewHolderForAdapterPosition(
               mAdapter.getBeaconsList().indexOf(changedBeacon));
   if (viewHolder != null) viewHolder.vRSSI_details.setText(String.valueOf(changedBeacon.RSSI));
   //        mAdapter.notifyItemChanged(mAdapter.getBeaconsList().indexOf(changedBeacon));
 }
 @Override
 public boolean onInterceptTouchEvent(android.support.v7.widget.RecyclerView rv, MotionEvent e) {
   View child = rv.findChildViewUnder(e.getX(), e.getY());
   RecyclerView.ViewHolder finalChild =
       rv.findViewHolderForAdapterPosition(rv.getChildAdapterPosition(child));
   if (child != null && clickListener != null && gestureDetector.onTouchEvent(e) == true) {
     clickListener.onClick(finalChild, rv.getChildPosition(child));
   }
   return false;
 }
 @Test
 public void testOnItemClick_startsFullPhotoViewIntent() {
   subject.setupPhotoList();
   RecyclerView recyclerView = subject.getPhotoRecyclerView();
   recyclerView.measure(0, 0);
   recyclerView.layout(0, 0, 100, 1000);
   RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(0);
   View view = viewHolder.itemView;
   view.performClick();
   Intent expectedIntent = new Intent(subject, PhotoFullScreenActivity.class);
   ShadowActivity shadowActivity = Shadows.shadowOf(subject);
   Intent actualIntent = shadowActivity.getNextStartedActivity();
   Assertions.assertThat(actualIntent).isNotNull();
   assertTrue(actualIntent.filterEquals(expectedIntent));
 }
  @Test
  public void givenRemindersWhenTheFragmentIsCreatedThenTheViewShouldBePopulated() {
    Reminder reminder = new Reminder(0, "test");
    List<Reminder> reminders = new ArrayList<Reminder>();
    reminders.add(reminder);

    ReminderListFragment reminderListFragment = ReminderListFragment.newInstance(reminders);
    startFragment(activity, reminderListFragment);

    RecyclerView reminderRecyclerView =
        getRecyclerView(reminderListFragment, R.id.reminders_recycler_view);
    ReminderListViewHolder reminderListViewHolder =
        (ReminderListViewHolder) reminderRecyclerView.findViewHolderForAdapterPosition(0);

    TextView reminderText =
        (TextView) reminderListViewHolder.itemView.findViewById(R.id.reminders_text_view);
    assertEquals(reminderText.getText(), "test");
  }
 @Override
 public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
   if (i == VIEW_TYPES.HEADER && mHeader != null) {
     return new ViewHolder(mHeader);
   }
   if (i == VIEW_TYPES.FIRST_VIEW && mHeader != null && mRecyclerView != null) {
     final RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(0);
     if (holder != null) {
       translateHeader(-holder.itemView.getTop());
     }
   }
   final RecyclerView.ViewHolder holder = onCreateViewHolderImpl(viewGroup, this, i);
   if (mOnClickEvent != null) {
     holder.itemView.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             mOnClickEvent.onClick(v, holder.getAdapterPosition() - (mHeader == null ? 0 : 1));
           }
         });
   }
   return holder;
 }
 /**
  * Translates the adapter in Y
  *
  * @param of offset in px
  */
 public void translateHeader(float of) {
   float ofCalculated = of * mScrollMultiplier;
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && of < mHeader.getHeight()) {
     mHeader.setTranslationY(ofCalculated);
   } else if (of < mHeader.getHeight()) {
     TranslateAnimation anim = new TranslateAnimation(0, 0, ofCalculated, ofCalculated);
     anim.setFillAfter(true);
     anim.setDuration(0);
     mHeader.startAnimation(anim);
   }
   mHeader.setClipY(Math.round(ofCalculated));
   if (mParallaxScroll != null) {
     final RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(0);
     float left;
     if (holder != null) {
       left = Math.min(1, ((ofCalculated) / (mHeader.getHeight() * mScrollMultiplier)));
     } else {
       left = 1;
     }
     mParallaxScroll.onParallaxScroll(left, of, mHeader);
   }
 }