コード例 #1
0
  @NonNull
  public Observable<PageResult<T>> load(
      @NonNull DataConverter<T> dataConverter,
      @NonNull DatabaseQuery databaseQuery,
      @NonNull Observable<Page> pageObservable) {
    final SparseArrayCompat<T> allItems = new SparseArrayCompat<>();
    final Observable<Cursor> cursorObservable =
        database.load(databaseQuery).doOnNext(cursor -> allItems.clear());

    return Observable.combineLatest(
        pageObservable,
        cursorObservable,
        (page, cursor) -> {
          final List<T> pageItems = new ArrayList<>();
          for (int i = page.getStart(),
                  size = Math.min(cursor.getCount(), page.getStart() + page.getSize());
              i < size;
              i++) {
            T item = allItems.get(i);
            if (item == null) {
              cursor.moveToPosition(i);
              item = dataConverter.from(cursor);
              allItems.put(i, item);
            }
            pageItems.add(item);
          }

          return new PageResult<>(cursor, allItems, pageItems, page);
        });
  }
コード例 #2
0
 public void addViewHolderType(int... type) {
   for (int i = 0; i < type.length; i++) {
     if (type[i] == ViewHolder.VIEW_HOLDER_HEADER) {
       titleIndexs.put(i, titleIndexs.size() + 1);
     }
     viewHolderTypes.add(type[i]);
   }
   notifyDataSetChanged();
 }
コード例 #3
0
ファイル: LoaderManagerImpl.java プロジェクト: vovs/GMusic
 void installLoader(LoaderInfo paramLoaderInfo)
 {
   SparseArrayCompat localSparseArrayCompat = this.mLoaders;
   int i = paramLoaderInfo.mId;
   localSparseArrayCompat.put(i, paramLoaderInfo);
   if (!this.mStarted)
     return;
   paramLoaderInfo.start();
 }
コード例 #4
0
 @Override
 public int getItemViewType(int position) {
   if (isHeaderViewPos(position)) {
     return mHeaderViews.keyAt(position);
   } else if (isFooterViewPos(position)) {
     return mFootViews.keyAt(position - getHeadersCount() - getRealItemCount());
   }
   return mInnerAdapter.getItemViewType(position - getHeadersCount());
 }
  @Override
  public void onPageSelected(int position) {
    SparseArrayCompat<ScrollTabHolder> scrollTabHolders = mAdapter.getScrollTabHolders();

    if (scrollTabHolders == null || scrollTabHolders.size() != mNumFragments) {
      return;
    }

    ScrollTabHolder currentHolder = scrollTabHolders.valueAt(position);
    currentHolder.adjustScroll(
        (int) (mHeader.getHeight() + mHeader.getTranslationY()), mHeader.getHeight());
  }
コード例 #6
0
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (mHeaderViews.get(viewType) != null) {
      ViewHolder holder =
          ViewHolder.createViewHolder(parent.getContext(), mHeaderViews.get(viewType));
      return holder;

    } else if (mFootViews.get(viewType) != null) {
      ViewHolder holder =
          ViewHolder.createViewHolder(parent.getContext(), mFootViews.get(viewType));
      return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
  }
コード例 #7
0
 @Override
 public int[] getRemoteStyleableArrayFromLocal(int[] localStyleableArray) {
   int localStyleableId = Arrays.hashCode(localStyleableArray);
   int indexOfRemoteArray = mStyleableArrayMapping.indexOfKey(localStyleableId);
   if (indexOfRemoteArray >= 0) return mStyleableArrayMapping.valueAt(indexOfRemoteArray);
   AddOnImpl addOn = mAddOnWeakReference.get();
   if (addOn == null) return new int[0];
   Context askContext = addOn.mAskAppContext;
   Context remoteContext = addOn.getPackageContext();
   if (remoteContext == null) return new int[0];
   int[] remoteAttrIds =
       Support.createBackwardCompatibleStyleable(
           localStyleableArray, askContext, remoteContext, mAttributesMapping);
   mStyleableArrayMapping.put(localStyleableId, remoteAttrIds);
   return remoteAttrIds;
 }
コード例 #8
0
 private void initWithArrays(String[] columns, int[] ids) {
   if (columns.length != ids.length) throw new IllegalStateException("Arrays length is not equal");
   map = new SparseArrayCompat<String>(ids.length);
   for (int i = 0; i < ids.length; i++) {
     map.put(ids[i], columns[i]);
   }
 }
コード例 #9
0
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    Object object = super.instantiateItem(container, position);

    mScrollTabHolders.put(position, (ScrollTabHolder) object);

    return object;
  }
  @Override
  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int currentItem = mViewPager.getCurrentItem();
    if (positionOffsetPixels > 0) {
      SparseArrayCompat<ScrollTabHolder> scrollTabHolders = mAdapter.getScrollTabHolders();

      ScrollTabHolder fragmentContent;
      if (position < currentItem) {
        // Revealed the previous page
        fragmentContent = scrollTabHolders.valueAt(position);
      } else {
        // Revealed the next page
        fragmentContent = scrollTabHolders.valueAt(position + 1);
      }

      fragmentContent.adjustScroll(
          (int) (mHeader.getHeight() + mHeader.getTranslationY()), mHeader.getHeight());
    }
  }
コード例 #11
0
    @Override
    public Fragment getItem(int position) {
      Invitationtabholder fragment = (Invitationtabholder) InvitationFragment.newInstance(position);

      mScrollTabHolders.put(position, fragment);
      if (mListener != null) {
        fragment.setScrollTabHolder(mListener);
      }
      return fragment;
    }
コード例 #12
0
 public boolean bindView(View v, Cursor c) {
   int id = v.getId();
   String columnName = map.get(id);
   if (columnName == null) return false;
   String value = c.getString(c.getColumnIndexOrThrow(columnName));
   if (v instanceof TextView) {
     TextView tv = (TextView) v;
     tv.setText((value == null) ? "" : Html.fromHtml(value));
     return true;
   }
   if (v instanceof ImageView) {
     ImageView iv = (ImageView) v;
     if (value.equals("")) {
       iv.setVisibility(View.GONE);
       return true;
     }
     // First, try to find the resource id
     String drawable = value.replace(".jpg", "").replace(".png", "").toLowerCase();
     int bitmapid =
         context.getResources().getIdentifier(drawable, "drawable", context.getPackageName());
     if (bitmapid != 0) {
       iv.setImageResource(bitmapid);
       iv.setVisibility(View.VISIBLE);
       return true;
     }
     try {
       Bitmap pic = BitmapFactory.decodeStream(context.getAssets().open(value));
       if (value.startsWith("Photos")) {
         Matrix mtx = new Matrix();
         mtx.postScale(0.5f, 0.5f);
         mtx.postRotate(-90, pic.getWidth() / 2, pic.getHeight() / 2);
         iv.setImageBitmap(
             Bitmap.createBitmap(
                 pic,
                 (int) (2 * pic.getWidth() / 3),
                 0,
                 pic.getWidth() / 3,
                 pic.getHeight(),
                 mtx,
                 true));
       } else {
         iv.setImageBitmap(pic);
       }
       iv.setVisibility(View.VISIBLE);
       return true;
     } catch (IOException e) {
       e.printStackTrace();
       //				throw new IllegalStateException(e);
     }
   }
   return false;
 }
コード例 #13
0
 public void initWithResources(String fieldArrayResourceName, String viewIdArrayResourceName) {
   int fieldArrayId =
       context
           .getResources()
           .getIdentifier(fieldArrayResourceName, "array", context.getPackageName());
   int viewArrayId =
       context
           .getResources()
           .getIdentifier(viewIdArrayResourceName, "array", context.getPackageName());
   String[] fieldArray = context.getResources().getStringArray(fieldArrayId);
   String[] viewArray = context.getResources().getStringArray(viewArrayId);
   if (fieldArray.length != viewArray.length)
     throw new IllegalStateException(
         "Arrays length is not equal: " + fieldArrayResourceName + " " + viewIdArrayResourceName);
   map = new SparseArrayCompat<String>(fieldArray.length);
   for (int i = 0; i < fieldArray.length; i++) {
     int resourceId =
         context.getResources().getIdentifier(viewArray[i], "id", context.getPackageName());
     map.put(resourceId, fieldArray[i]);
   }
 }
コード例 #14
0
 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
   if (holder instanceof ViewHolderHeader) {
     ((ViewHolderHeader) holder).setTitle(titleIndexs.get(position));
   }
 }
コード例 #15
0
 public int getFootersCount() {
   return mFootViews.size();
 }
コード例 #16
0
 public int getHeadersCount() {
   return mHeaderViews.size();
 }
コード例 #17
0
 public void addFootView(View view) {
   mFootViews.put(mFootViews.size() + BASE_ITEM_TYPE_FOOTER, view);
 }
コード例 #18
0
 public void addHeaderView(View view) {
   mHeaderViews.put(mHeaderViews.size() + BASE_ITEM_TYPE_HEADER, view);
 }
コード例 #19
0
ファイル: LoaderManagerImpl.java プロジェクト: vovs/GMusic
 public void onLoadComplete(Loader<Object> paramLoader, Object paramObject)
 {
   if (LoaderManagerImpl.DEBUG)
   {
     String str1 = "onLoadComplete: " + this;
     int i = Log.v("LoaderManager", str1);
   }
   if (this.mDestroyed)
   {
     if (!LoaderManagerImpl.DEBUG)
       return;
     int j = Log.v("LoaderManager", "  Ignoring load complete -- destroyed");
     return;
   }
   SparseArrayCompat localSparseArrayCompat1 = LoaderManagerImpl.this.mLoaders;
   int k = this.mId;
   if (localSparseArrayCompat1.get(k) != this)
   {
     if (!LoaderManagerImpl.DEBUG)
       return;
     int m = Log.v("LoaderManager", "  Ignoring load complete -- not active");
     return;
   }
   LoaderInfo localLoaderInfo1 = this.mPendingLoader;
   if (localLoaderInfo1 != null)
   {
     if (LoaderManagerImpl.DEBUG)
     {
       String str2 = "  Switching to pending loader: " + localLoaderInfo1;
       int n = Log.v("LoaderManager", str2);
     }
     this.mPendingLoader = null;
     SparseArrayCompat localSparseArrayCompat2 = LoaderManagerImpl.this.mLoaders;
     int i1 = this.mId;
     localSparseArrayCompat2.put(i1, null);
     destroy();
     LoaderManagerImpl.this.installLoader(localLoaderInfo1);
     return;
   }
   if ((this.mData != paramObject) || (!this.mHaveData))
   {
     this.mData = paramObject;
     this.mHaveData = true;
     if (this.mStarted)
       callOnLoadFinished(paramLoader, paramObject);
   }
   SparseArrayCompat localSparseArrayCompat3 = LoaderManagerImpl.this.mInactiveLoaders;
   int i2 = this.mId;
   LoaderInfo localLoaderInfo2 = (LoaderInfo)localSparseArrayCompat3.get(i2);
   if ((localLoaderInfo2 != null) && (localLoaderInfo2 != this))
   {
     localLoaderInfo2.mDeliveredData = false;
     localLoaderInfo2.destroy();
     SparseArrayCompat localSparseArrayCompat4 = LoaderManagerImpl.this.mInactiveLoaders;
     int i3 = this.mId;
     localSparseArrayCompat4.remove(i3);
   }
   if (LoaderManagerImpl.this.mActivity == null)
     return;
   if (LoaderManagerImpl.this.hasRunningLoaders())
     return;
   LoaderManagerImpl.this.mActivity.mFragments.startPendingDeferredFragments();
 }