public void testLayout() throws InterruptedException {
   MockLayoutManager layoutManager = new MockLayoutManager();
   mRecyclerView.setLayoutManager(layoutManager);
   mRecyclerView.setAdapter(new MockAdapter(3));
   layout();
   assertEquals(
       "when both layout manager and activity is set, recycler view should call"
           + " layout manager's layout method",
       1,
       layoutManager.mLayoutCount);
 }
  public void testObservingAdapters() {
    MockAdapter adapterOld = new MockAdapter(1);
    mRecyclerView.setAdapter(adapterOld);
    assertTrue("attached adapter should have observables", adapterOld.hasObservers());

    MockAdapter adapterNew = new MockAdapter(2);
    mRecyclerView.setAdapter(adapterNew);
    assertFalse("detached adapter should lose observable", adapterOld.hasObservers());
    assertTrue("new adapter should have observers", adapterNew.hasObservers());

    mRecyclerView.setAdapter(null);
    assertNull("adapter should be removed successfully", mRecyclerView.getAdapter());
    assertFalse(
        "when adapter is removed, observables should be removed too", adapterNew.hasObservers());
  }
  public void testAdapterChangeCallbacks() {
    MockLayoutManager layoutManager = new MockLayoutManager();
    mRecyclerView.setLayoutManager(layoutManager);
    MockAdapter adapterOld = new MockAdapter(1);
    mRecyclerView.setAdapter(adapterOld);
    layoutManager.assertPrevNextAdapters(null, adapterOld);

    MockAdapter adapterNew = new MockAdapter(2);
    mRecyclerView.setAdapter(adapterNew);
    layoutManager.assertPrevNextAdapters(
        "switching adapters should trigger correct callbacks", adapterOld, adapterNew);

    mRecyclerView.setAdapter(null);
    layoutManager.assertPrevNextAdapters(
        "Setting adapter null should trigger correct callbacks", adapterNew, null);
  }
 public final int getAdapterPosition()
 {
   if (mOwnerRecyclerView == null) {
     return -1;
   }
   return RecyclerView.access$5700(mOwnerRecyclerView, this);
 }
  public void testSavedState() throws InterruptedException {
    MockLayoutManager mlm = new MockLayoutManager();
    mRecyclerView.setLayoutManager(mlm);
    mRecyclerView.setAdapter(new MockAdapter(3));
    layout();
    Parcelable savedState = mRecyclerView.onSaveInstanceState();
    // we append a suffix to the parcelable to test out of bounds
    String parcelSuffix = UUID.randomUUID().toString();
    Parcel parcel = Parcel.obtain();
    savedState.writeToParcel(parcel, 0);
    parcel.writeString(parcelSuffix);

    // reset for reading
    parcel.setDataPosition(0);
    // re-create
    savedState = RecyclerView.SavedState.CREATOR.createFromParcel(parcel);

    RecyclerView restored = new RecyclerView(mContext);
    MockLayoutManager mlmRestored = new MockLayoutManager();
    restored.setLayoutManager(mlmRestored);
    restored.setAdapter(new MockAdapter(3));
    restored.onRestoreInstanceState(savedState);

    assertEquals("Parcel reading should not go out of bounds", parcelSuffix, parcel.readString());
    assertEquals("When unmarshalling, all of the parcel should be read", 0, parcel.dataAvail());
    assertEquals(
        "uuid in layout manager should be preserved properly", mlm.mUuid, mlmRestored.mUuid);
    assertNotSame(
        "stateless parameter should not be preserved", mlm.mLayoutCount, mlmRestored.mLayoutCount);
    layout();
  }
  public void testSavedStateWithStatelessLayoutManager() throws InterruptedException {
    mRecyclerView.setLayoutManager(
        new MockLayoutManager() {
          @Override
          public Parcelable onSaveInstanceState() {
            return null;
          }
        });
    mRecyclerView.setAdapter(new MockAdapter(3));
    Parcel parcel = Parcel.obtain();
    String parcelSuffix = UUID.randomUUID().toString();
    Parcelable savedState = mRecyclerView.onSaveInstanceState();
    savedState.writeToParcel(parcel, 0);
    parcel.writeString(parcelSuffix);

    // reset position for reading
    parcel.setDataPosition(0);
    RecyclerView restored = new RecyclerView(mContext);
    restored.setLayoutManager(new MockLayoutManager());
    mRecyclerView.setAdapter(new MockAdapter(3));
    // restore
    savedState = RecyclerView.SavedState.CREATOR.createFromParcel(parcel);
    restored.onRestoreInstanceState(savedState);

    assertEquals("Parcel reading should not go out of bounds", parcelSuffix, parcel.readString());
    assertEquals("When unmarshalling, all of the parcel should be read", 0, parcel.dataAvail());
  }
 public void testLayoutWithoutAdapter() throws InterruptedException {
   MockLayoutManager layoutManager = new MockLayoutManager();
   mRecyclerView.setLayoutManager(layoutManager);
   layout();
   assertEquals(
       "layout manager should not be called if there is no adapter attached",
       0,
       layoutManager.mLayoutCount);
 }
Exemplo n.º 8
0
 public final void run() {
   if (RecyclerView.a(a)) {
     if (RecyclerView.b(a)) {
       TraceCompat.beginSection("RV FullInvalidate");
       a.e();
       TraceCompat.endSection();
       return;
     }
     if (a.b.d()) {
       TraceCompat.beginSection("RV PartialInvalidate");
       a.d();
       a.b.b();
       if (!RecyclerView.c(a)) {
         a.f();
       }
       a.a(true);
       TraceCompat.endSection();
       return;
     }
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow().setStatusBarColor(getResources().getColor(R.color.holo_blue_bright));
    }
    listmain = new ArrayList<ConRecItem>();
    tm = (EditText) findViewById(R.id.setext);
    final RecycleItemClickListener itemClickListener =
        new RecycleItemClickListener() {
          @Override
          public void onItemClick(View view, int position) {
            switch (position) {
              default:
                Intent intent = new Intent(searchActivity.this, conActivity.class);
                Data data = new Data();
                File fl = new File("/storage/sdcard0/M++/data/slist.txt");
                String spos = data.getData(fl, position + 1);
                int pos = Integer.valueOf(spos);
                intent.putExtra("pos", pos);
                startActivity(intent);
                break;
            }
          }
        };
    int displayWidth = 0;
    int displayHeight = 0;
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    displayWidth = displayMetrics.widthPixels;
    displayHeight = displayMetrics.heightPixels;
    final int rpos = displayWidth / 320;
    listmain = new ArrayList<ConRecItem>();
    ConRecAdapter adapter = new ConRecAdapter(listmain, itemClickListener);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
    recyclerView.setLayoutManager(
        new StaggeredGridLayoutManager(rpos, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(adapter);
    tm.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void beforeTextChanged(CharSequence p1, int p2, int p3, int p4) {
            // TODO: Implement this method
          }

          @Override
          public void onTextChanged(CharSequence p1, int p2, int p3, int p4) {
            // TODO: Implement this method
          }

          @Override
          public void afterTextChanged(Editable edit) {

            // TODO
            listmain = new ArrayList<ConRecItem>();
            System.out.println("okokok");
            File fs = new File("/storage/sdcard0/M++/data/fs_con.txt");
            File fl = new File("/storage/sdcard0/M++/data/slist.txt");
            String text = tm.getText().toString();
            if (fs.exists()) {
              listmain = new ArrayList<ConRecItem>();
              if (fl.exists()) {
                fl.delete();
              }

              try {
                fl.createNewFile();

                String reg = ".*" + text + ".*";

                FileReader fr = new FileReader(fs);

                BufferedReader br = new BufferedReader(fr);

                String temp = null;
                String s = "";

                while ((temp = br.readLine()) != null) {
                  s += temp + "\n";
                }

                String[] ss = s.split("\n");
                for (int i = 0; i <= ss.length; i++) {
                  try {
                    if (ss[10 * i].matches(reg)) {
                      ConRecItem p = new ConRecItem(ss[10 * i + 1], ss[10 * i]);
                      listmain.add(p);
                      String spos = String.valueOf(i);
                      Data data = new Data();
                      data.writeData(fl, spos + "\n", false);
                    }
                  } catch (ArrayIndexOutOfBoundsException e) {
                  }
                }
                ConRecAdapter adapter = new ConRecAdapter(listmain, itemClickListener);
                RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
                recyclerView.setLayoutManager(
                    new StaggeredGridLayoutManager(rpos, StaggeredGridLayoutManager.VERTICAL));
                recyclerView.setAdapter(adapter);

              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          };
        });
  }
Exemplo n.º 10
0
 public void testSmoothScrollToPositionWithoutLayoutManager() throws InterruptedException {
   mRecyclerView.setAdapter(new MockAdapter(20));
   measure();
   layout();
   mRecyclerView.smoothScrollToPosition(5);
 }
Exemplo n.º 11
0
 public void testScrollWithoutLayoutManager() throws InterruptedException {
   mRecyclerView.setAdapter(new MockAdapter(20));
   measure();
   layout();
   mRecyclerView.scrollBy(10, 10);
 }
Exemplo n.º 12
0
 public void testFocusWithoutLayoutManager() throws InterruptedException {
   mRecyclerView.setAdapter(new MockAdapter(20));
   measure();
   layout();
   focusSearch();
 }
Exemplo n.º 13
0
 private void focusSearch() {
   mRecyclerView.focusSearch(1);
 }
Exemplo n.º 14
0
 private void layout() {
   mRecyclerView.layout(0, 0, 320, 320);
 }
Exemplo n.º 15
0
 private void measure() {
   mRecyclerView.measure(View.MeasureSpec.AT_MOST | 320, View.MeasureSpec.AT_MOST | 240);
 }