private void init(Context context) { mViewHolders = new SparseMatrix<>(); mLayoutDirectionHelper = new LayoutDirectionHelper(mLayoutDirection); mHeaderColumnViewHolders = new SparseArrayCompat<>(); mHeaderRowViewHolders = new SparseArrayCompat<>(); mDragAndDropPoints = new DragAndDropPoints(); mState = new AdaptiveTableState(); mManager = new AdaptiveTableManagerRTL(mLayoutDirectionHelper); mLastSwitchHeaderPoint = new Point(); mVisibleArea = new Rect(); // init scroll and fling helpers mScrollerRunnable = new SmoothScrollRunnable(this); mScrollerDragAndDropRunnable = new DragAndDropScrollRunnable(this); mRecycler = new Recycler(); mSettings = new AdaptiveTableLayoutSettings(); mScrollHelper = new ScrollHelper(context); mScrollHelper.setListener(this); mShadowHelper = new ShadowHelper(mLayoutDirectionHelper); }
@TargetApi(11) public void setChoiceMode(int choiceMode) { this.mChoiceMode = choiceMode; if (VERSION.SDK_INT >= 11 && this.mChoiceActionMode != null) { if (VERSION.SDK_INT >= 11) { ((ActionMode) this.mChoiceActionMode).finish(); } this.mChoiceActionMode = null; } if (this.mChoiceMode != 0) { if (this.mCheckStates == null) { this.mCheckStates = new SparseArrayCompat(); } if (this.mCheckedIdStates == null && this.mAdapter != null && this.mAdapter.hasStableIds()) { this.mCheckedIdStates = new LongSparseArray(); } if (VERSION.SDK_INT >= 11 && this.mChoiceMode == 3) { clearChoices(); setLongClickable(true); } } }
@Override public void notifyDataSetChanged() { SparseArrayCompat<Fragment> newFragments = new SparseArrayCompat<>(fragments.size()); for (int i = 0; i < fragments.size(); i++) { final int oldPos = fragments.keyAt(i); final Fragment f = fragments.valueAt(i); final int newPos = getItemPosition(f); if (newPos != POSITION_NONE) { final int pos = (newPos >= 0) ? newPos : oldPos; newFragments.put(pos, f); } } fragments = newFragments; super.notifyDataSetChanged(); }
private void attachChildViewBlock(@NonNull UIKitComponent component, SparseArrayCompat<String> childViewBlockClassNamesArray, int index, View childView) { int childViewChildAtId = childView.getId(); int indexOfKey = childViewBlockClassNamesArray.indexOfKey(childViewChildAtId); if (indexOfKey < 0) { indexOfKey = childViewBlockClassNamesArray.indexOfKey(index); } if (indexOfKey < 0) { return; } String name = childViewBlockClassNamesArray.valueAt(indexOfKey); if (name == null) { return; } ViewBlock parentBlock = component.getViewBlock(); ViewBlock viewBlock = createViewBlock(childView, childViewChildAtId, name); if (viewBlock != null) { addViewBlockToViewBlockManager(viewBlock, parentBlock, component.getViewBlockManager()); } childViewBlockClassNamesArray.removeAt(indexOfKey); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.offset_activity_test); ItemsAdapter adapter = new ItemsAdapter(this); adapter.setList(new ItemPagedList(this)); manage(adapter); SparseArrayCompat<Integer> offsetItems = new SparseArrayCompat<>(); offsetItems.put(1, Integer.MAX_VALUE - 1); offsetItems.put(10, Integer.MAX_VALUE - 2); OffsetTestAdapter offsetAdapter = new OffsetTestAdapter(this, adapter, offsetItems); manage(offsetAdapter); RecyclerView items = (RecyclerView) findViewById(R.id.items); items.setLayoutManager(new LinearLayoutManager(this)); items.setAdapter(offsetAdapter); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.offset_activity_test); ItemsAdapter adapter = new ItemsAdapter(this); adapter.setList(new ItemPagedList(this)); manage(adapter); SparseArrayCompat<Integer> offsetItems = new SparseArrayCompat<>(); offsetItems.put(0, Integer.MAX_VALUE - 1); offsetItems.put(1, Integer.MAX_VALUE - 2); offsetItems.put(2, Integer.MAX_VALUE - 3); OffsetTestAdapter offsetAdapter = new OffsetTestAdapter(this, adapter, offsetItems); manage(offsetAdapter); RecyclerView items = (RecyclerView) findViewById(R.id.items); items.setLayoutManager(new LinearLayoutManager(this)); items.setAdapter(offsetAdapter); }
public void init(Rect bounds, float startFrame, float endFrame, float frameRate, int majorVersion, int minorVersion, int patchVersion, List<Layer> layers, LongSparseArray<Layer> layerMap, Map<String, List<Layer>> precomps, Map<String, LottieImageAsset> images, SparseArrayCompat<FontCharacter> characters, Map<String, Font> fonts) { this.bounds = bounds; this.startFrame = startFrame; this.endFrame = endFrame; this.frameRate = frameRate; this.majorVersion = majorVersion; this.minorVersion = minorVersion; this.patchVersion = patchVersion; this.layers = layers; this.layerMap = layerMap; this.precomps = precomps; this.images = images; this.characters = characters; this.fonts = fonts; }
/** * 设置第二个列表数据 * * @param city */ public void setCity(SparseArrayCompat<List<DataModel>> city) { mCitisDatasMap = city; List<DataModel> temp_city = city.get(mProvinceId); if (temp_city != null) { for (int i = 0; i < temp_city.size(); i++) { DataModel data = temp_city.get(i); if (data.Id == mCityId) { mCityPosition = i; break; } } } updateCities(mCityPosition); // mCity.setCurrentItem(mCityPosition); }
/** * 设置第三个列表数据 * * @param area */ public void setArea(SparseArrayCompat<List<DataModel>> area) { mAreaDatasMap = area; List<DataModel> temp_area = area.get(mCityId); if (temp_area != null) { for (int i = 0; i < temp_area.size(); i++) { DataModel data = temp_area.get(i); if (data.Id == mAreaId) { mAreaPosition = i; break; } } } updateAreas(mAreaPosition); // mArea.setCurrentItem(mAreaPosition); }
@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()); } }
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { int currentItem = mViewPager.getCurrentItem(); if (positionOffsetPixels > 0) { SparseArrayCompat<ScrollHolder> scrollTabHolders = mAdapter.getScrollTabHolders(); ScrollHolder fragmentContent; if (position < currentItem) { fragmentContent = scrollTabHolders.valueAt(position); } else { fragmentContent = scrollTabHolders.valueAt(position + 1); } fragmentContent.adjustScroll((int) (mStickheader.getHeight() + mStickheader.getTranslationY()), mStickheader.getHeight()); } }
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (positionOffsetPixels > 0) { int currentItem = mViewPager.getCurrentItem(); SparseArrayCompat<ScrollTabHolder> scrollTabHolders = mPagerAdapter.getScrollTabHolders(); ScrollTabHolder currentHolder; if (position < currentItem) { currentHolder = scrollTabHolders.valueAt(position); } else { currentHolder = scrollTabHolders.valueAt(position + 1); } if (NEEDS_PROXY) { // TODO is not good currentHolder.adjustScroll(mHeader.getHeight() - mLastY); mHeader.postInvalidate(); } else { currentHolder.adjustScroll((int) (mHeader.getHeight() + mHeader.getTranslationY())); } } }
private void deleteSelectedItems() { SparseArrayCompat<Boolean> checkedItems = listView.getCheckedItemPositions(); ArrayList<Integer> sorted = new ArrayList<Integer>(checkedItems.size()); Log.i(LOG_TAG, "deleting: " + checkedItems.size()); for (int i = 0; i < checkedItems.size(); i++) { if (checkedItems.valueAt(i)) { sorted.add(checkedItems.keyAt(i)); } } Collections.sort(sorted); for (int i = sorted.size() - 1; i >= 0; i--) { int position = sorted.get(i); Log.d(LOG_TAG, "Deleting item at: " + position); mAdapter.mItems.remove(position); } mAdapter.notifyDataSetChanged(); }
protected <T extends View> T getView(View view, int viewId) { SparseArrayCompat<View> viewHolder = (SparseArrayCompat<View>) view.getTag(); if (viewHolder == null) { viewHolder = new SparseArrayCompat<View>(); view.setTag(viewHolder); } View res = viewHolder.get(viewId); if (res == null) { res = view.findViewById(viewId); viewHolder.put(viewId, res); } return (T) res; }
/** * Method switch view holders in map (map with headers view holders). * * @param map header view holder's map * @param fromIndex index from view holder * @param toIndex index to view holder * @param type type of items (column header or row header) */ @SuppressWarnings("unused") private void switchHeaders(SparseArrayCompat<ViewHolder> map, int fromIndex, int toIndex, int type) { ViewHolder fromVh = map.get(fromIndex); if (fromVh != null) { map.remove(fromIndex); if (type == ViewHolderType.COLUMN_HEADER) { fromVh.setColumnIndex(toIndex); } else if (type == ViewHolderType.ROW_HEADER) { fromVh.setRowIndex(toIndex); } } ViewHolder toVh = map.get(toIndex); if (toVh != null) { map.remove(toIndex); if (type == ViewHolderType.COLUMN_HEADER) { toVh.setColumnIndex(fromIndex); } else if (type == ViewHolderType.ROW_HEADER) { toVh.setRowIndex(fromIndex); } } if (fromVh != null) { map.put(toIndex, fromVh); } if (toVh != null) { map.put(fromIndex, toVh); } }
/** * Put item to the matrix in row, column position. * * @param row item row position * @param column item column position * @param item Object */ void put(int row, int column, @NonNull TObj item) { SparseArrayCompat<TObj> array = mData.get(row); if (array == null) { array = new SparseArrayCompat<>(); array.put(column, item); mData.put(row, array); } else { array.put(column, item); } }
/** * Get all row's items * * @param row row index * @return Collection with row's Objects */ @NonNull Collection<TObj> getRowItems(int row) { Collection<TObj> result = new LinkedList<>(); SparseArrayCompat<TObj> array = mData.get(row); for (int count = array.size(), i = 0; i < count; i++) { int key = array.keyAt(i); TObj columnObj = array.get(key); if (columnObj != null) { result.add(columnObj); } } return result; }
/** * Get all matrix's items * * @return Collection with column's Objects */ @NonNull Collection<TObj> getAll() { Collection<TObj> result = new LinkedList<>(); for (int countR = mData.size(), i = 0; i < countR; i++) { int rowKey = mData.keyAt(i); SparseArrayCompat<TObj> columns = mData.get(rowKey); for (int countC = columns.size(), j = 0; j < countC; j++) { int key = columns.keyAt(j); result.add(columns.get(key)); } } return result; }
/** * Remove item in row, column position int the matrix * * @param row item row position * @param column item column position */ void remove(int row, int column) { SparseArrayCompat<TObj> array = mData.get(row); if (array != null) { array.remove(column); } }
@Override public final IViewBinder provideViewBinder(StickyHeaderViewAdapter adapter, SparseArrayCompat<? extends IViewBinder> viewBinderPool, int position) { if (viewBinder == null) { viewBinder = viewBinderPool.get(getItemLayoutId(adapter)); } return viewBinder; }
@Deprecated public long[] getCheckItemIds() { if (this.mAdapter != null && this.mAdapter.hasStableIds()) { return getCheckedItemIds(); } if (this.mChoiceMode == 0 || this.mCheckStates == null || this.mAdapter == null) { return new long[0]; } SparseArrayCompat<Boolean> states = this.mCheckStates; int count = states.size(); long[] ids = new long[count]; ListAdapter adapter = this.mAdapter; int i = 0; int checkedCount = 0; while (i < count) { int checkedCount2; if (((Boolean) states.valueAt(i)).booleanValue()) { checkedCount2 = checkedCount + 1; ids[checkedCount] = adapter.getItemId(states.keyAt(i)); } else { checkedCount2 = checkedCount; } i++; checkedCount = checkedCount2; } if (checkedCount == count) { return ids; } long[] result = new long[checkedCount]; System.arraycopy(ids, 0, result, 0, checkedCount); return result; }
protected void onCreate(@Nullable Bundle savedInstanceState) { List list = null; this.mFragments.attachHost(null); super.onCreate(savedInstanceState); NonConfigurationInstances nc = (NonConfigurationInstances) getLastNonConfigurationInstance(); if (nc != null) { this.mFragments.restoreLoaderNonConfig(nc.loaders); } if (savedInstanceState != null) { Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); FragmentController fragmentController = this.mFragments; if (nc != null) { list = nc.fragments; } fragmentController.restoreAllState(p, list); if (savedInstanceState.containsKey(NEXT_CANDIDATE_REQUEST_INDEX_TAG)) { this.mNextCandidateRequestIndex = savedInstanceState.getInt(NEXT_CANDIDATE_REQUEST_INDEX_TAG); int[] requestCodes = savedInstanceState.getIntArray(ALLOCATED_REQUEST_INDICIES_TAG); String[] fragmentWhos = savedInstanceState.getStringArray(REQUEST_FRAGMENT_WHO_TAG); if (requestCodes == null || fragmentWhos == null || requestCodes.length != fragmentWhos.length) { Log.w(TAG, "Invalid requestCode mapping in savedInstanceState."); } else { this.mPendingFragmentActivityResults = new SparseArrayCompat(requestCodes.length); for (int i = 0; i < requestCodes.length; i++) { this.mPendingFragmentActivityResults.put(requestCodes[i], fragmentWhos[i]); } } } } if (this.mPendingFragmentActivityResults == null) { this.mPendingFragmentActivityResults = new SparseArrayCompat(); this.mNextCandidateRequestIndex = 0; } this.mFragments.dispatchCreate(); }
/** * Returns the set of checked items ids. The result is only valid if the * choice mode has not been set to {@link #CHOICE_MODE_NONE}. * * @return A new array which contains the id of each checked item in the * list. * * @deprecated Use {@link #getCheckedItemIds()} instead. */ @Deprecated public long[] getCheckItemIds() { // Use new behavior that correctly handles stable ID mapping. if (mAdapter != null && mAdapter.hasStableIds()) { return getCheckedItemIds(); } // Old behavior was buggy, but would sort of work for adapters without // stable IDs. // Fall back to it to support legacy apps. if (mChoiceMode != AbsListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { final SparseArrayCompat<Boolean> states = mCheckStates; final int count = states.size(); final long[] ids = new long[count]; final ListAdapter adapter = mAdapter; int checkedCount = 0; for (int i = 0; i < count; i++) { if (states.valueAt(i)) { ids[checkedCount++] = adapter.getItemId(states.keyAt(i)); } } // Trim array if needed. mCheckStates may contain false values // resulting in checkedCount being smaller than count. if (checkedCount == count) { return ids; } else { final long[] result = new long[checkedCount]; System.arraycopy(ids, 0, result, 0, checkedCount); return result; } } return new long[0]; }
/** * Defines the choice behavior for the List. By default, Lists do not have * any choice behavior ({@link #CHOICE_MODE_NONE}). By setting the * choiceMode to {@link #CHOICE_MODE_SINGLE}, the List allows up to one item * to be in a chosen state. By setting the choiceMode to * {@link #CHOICE_MODE_MULTIPLE}, the list allows any number of items to be * chosen. * * @param choiceMode * One of {@link #CHOICE_MODE_NONE}, {@link #CHOICE_MODE_SINGLE}, * or {@link #CHOICE_MODE_MULTIPLE} */ @TargetApi(11) public void setChoiceMode(int choiceMode) { mChoiceMode = choiceMode; if (android.os.Build.VERSION.SDK_INT >= 11) { if (mChoiceActionMode != null) { if (android.os.Build.VERSION.SDK_INT >= 11) { ((ActionMode) mChoiceActionMode).finish(); } mChoiceActionMode = null; } } if (mChoiceMode != AbsListView.CHOICE_MODE_NONE) { if (mCheckStates == null) { mCheckStates = new SparseArrayCompat<Boolean>(); } if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) { mCheckedIdStates = new LongSparseArray<Integer>(); } // Modal multi-choice mode only has choices when the mode is active. // Clear them. if (android.os.Build.VERSION.SDK_INT >= 11) { if (mChoiceMode == AbsListView.CHOICE_MODE_MULTIPLE_MODAL) { clearChoices(); setLongClickable(true); } } } }
private SparseArrayCompat<Boolean> readSparseBooleanArray(Parcel in) { if (LOG_ENABLED) { Log.i(TAG, "readSparseBooleanArray"); } int N = in.readInt(); if (N < 0) { return null; } SparseArrayCompat<Boolean> sa = new SparseArrayCompat<Boolean>(N); readSparseBooleanArrayInternal(sa, in, N); return sa; }
private void readSparseBooleanArrayInternal( SparseArrayCompat<Boolean> outVal, Parcel in, int N) { while (N > 0) { int key = in.readInt(); boolean value = in.readByte() == 1; if (LOG_ENABLED) { Log.i(TAG, "Unmarshalling key=" + key + " value=" + value); } outVal.append(key, value); N--; } }
void onFinishInflateViewBlock(@NonNull UIKitComponent component) { SparseArrayCompat<String> viewBlockClassNamesArray = component.getViewBlockClassNamesArray(); int size = viewBlockClassNamesArray.size(); boolean isEmpty = (size == 0); if (!isEmpty) { int mHostChildCount = mHost.getChildCount(); for (int i = 0; i < mHostChildCount; i++) { View childAt = mHost.getChildAt(i); if (!(childAt instanceof ViewGroup)) { attachChildViewBlock(component, viewBlockClassNamesArray, i, childAt); } } } if (!(component.getActivity() instanceof UIKitActivity)) { ViewGroup parent = component.getParentContainer(); if (parent == null) return; if ((parent).getId() == android.R.id.content) { ViewBlockManager blockManager = UIKit.getViewBlockManager(component.getActivity()); SparseArray<ViewBlock> viewBlocks = blockManager.getViewBlocks(); UIKitActivity.dispatch(viewBlocks, UIKitActivity.ON_CREATE_VIEW); } } }
private void export() { SparseArrayCompat<AppInfo> checkedApps = adapter.getCheckedApps(); final int size = checkedApps.size(); AppInfo[] appInfos = new AppInfo[size]; for (int i = 0; i < size; i++) { appInfos[i] = checkedApps.valueAt(i); } mPresenter.export(appInfos); }
public AbstractViewHolder(final View itemView, final int... ids) { super(itemView); mViewSparseArray = new SparseArrayCompat<>(ids.length); for (final int id : ids) { mViewSparseArray.append(id, itemView.findViewById(id)); } }
/** * If the wrapped adapter has stable IDs, the offset list adapter must have stable IDs too. * * @param context * @param adapter The adapter which we will be wrapping * @param items The items where the key is the position the value will be placed. */ public OffsetListAdapter(Context context, RecyclerView.Adapter<VH> adapter, SparseArrayCompat<T> items) { mObserver = new Observer(); mInflater = LayoutInflater.from(context); super.setHasStableIds(adapter.hasStableIds()); mOriginalAdapter = adapter; mItems = items; adapter.registerAdapterDataObserver(mObserver); buildOffsets(); }
public ViewHolder(Context context, View itemView) { super(itemView); this.mContext = context; this.mConvertView = itemView; this.mConvertView.setTag(R.string.app_name, this); this.mViews = new SparseArrayCompat<View>(); }
public ViewHolder(Context context, View itemView, ViewGroup parent, int position){ this.mViews = new SparseArrayCompat<View>(); this.mPosition = position; this.mConvertView = itemView; this.mContext = context; //setTag mConvertView.setTag(R.string.app_name, this); }
@Override public void onPageSelected(int position) { tabs.onPageSelected(position); reLocation = true; SparseArrayCompat<ScrollTabHolder> scrollTabHolders = adapter.getScrollTabHolders(); ScrollTabHolder currentHolder = scrollTabHolders.valueAt(position); if (NEED_RELAYOUT) { currentHolder.adjustScroll((int) (header.getHeight() + headerTop));// 修正滚出去的偏移量 } else { currentHolder.adjustScroll((int) (header.getHeight() + ViewHelper.getTranslationY(header)));// 修正滚出去的偏移量 } }
public SlidingPagerAdapter(FragmentManager fm, Context context, ViewPager pager) { super(fm); fragments = new ScrollTabHolderFragment[PageAdapterTab.values().length]; this.context = context; mScrollTabHolders = new SparseArrayCompat<ScrollTabHolder>(); init(fm); }
public CircularRevealDrawable() { super(); mPaint = new Paint(); mResources = MyApp.getContext().getResources(); mDefaultColor = ResourcesCompat.getColor(mResources,android.R.color.white,null); mColorMap = new SparseArrayCompat<>(); mCurrentColor = EOF_COLOR; mNextColor = EOF_COLOR; }
public BinderRecyclerViewAdapter(Context context, List<?> items, BinderEnvironment environment, BinderSelectorMapper mapper, StableIdsResolver stableIdsResolver) { mContext = context; mEnvironment = environment; mBinderCache = new SparseArrayCompat<>(); mItems = items; mMapper = mapper; mIdResolver = stableIdsResolver; setHasStableIds(mIdResolver != null); }
public static <E> SubjectFactory<SparseArrayCompatSubject<E>, SparseArrayCompat<E>> type() { return new SubjectFactory<SparseArrayCompatSubject<E>, SparseArrayCompat<E>>() { @Override public SparseArrayCompatSubject<E> getSubject(FailureStrategy fs, SparseArrayCompat<E> that) { return new SparseArrayCompatSubject<E>(fs, that); } }; }