@Override public View getView(int position, final View convertView, final ViewGroup parent) { int sectionNum = 0; for (final String sectionName : sectionMap.keySet()) { final Adapter adapter = sectionMap.get(sectionName); final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0); if (position == 0 && hasSectionHeader) return sectionAdapter.getView(sectionNum, convertView, parent); if (position < size) return adapter.getView(position - 1, convertView, parent); position -= size; sectionNum++; } return null; }
/** */ @Override public boolean isScrolledAtEnd() { final int childCount = mScrollableView.getChildCount(); if (childCount == 0) { return true; } final Adapter adapter = mScrollableView.getAdapter(); final int adapterCount = adapter != null ? adapter.getCount() : 0; if (adapterCount == 0) { return true; } final int lastVisiblePos = mScrollableView.getLastVisiblePosition(); if (lastVisiblePos == (adapterCount - 1)) { final View lastChild = mScrollableView.getChildAt(childCount - 1); return lastChild != null && lastChild.getBottom() == mScrollableView.getHeight(); } return false; }
private boolean isFirstItemVisible() { final Adapter adapter = mRefreshableView.getAdapter(); if (null == adapter || adapter.isEmpty()) { if (DEBUG) { Log.d(LOG_TAG, "isFirstItemVisible. Empty View."); } return true; } else { /** * This check should really just be: * mRefreshableView.getFirstVisiblePosition() == 0, but PtRListView * internally use a HeaderView which messes the positions up. For * now we'll just add one to account for it and rely on the inner * condition which checks getTop(). */ if (mRefreshableView.getFirstVisiblePosition() <= 1) { final View firstVisibleChild = mRefreshableView.getChildAt(0); if (firstVisibleChild != null) { return firstVisibleChild.getTop() >= mRefreshableView.getTop(); } } } return false; }
public void setSelectedItem(int position) { Adapter adapter = mSpinnerListView.getAdapter(); if (adapter instanceof ISpinnerSelectedView) { View selectedView = ((ISpinnerSelectedView) adapter).getSelectedView(position); mCurrSelectedView = new SelectedView(selectedView, position, selectedView.getId()); mSpinnerListView.setSelection(position); } else { TextView textView = new TextView(mContext); textView.setText(mRevealEmptyText); mCurrSelectedView = new SelectedView(textView, -1, 0); mRevealItem.addView(textView); } if (mCurrSelectedView == null) { if (mOnItemSelected != null) mOnItemSelected.onNothingSelected(); } else if (mCurrSelectedView != null) { mRevealItem.removeAllViews(); mSpinnerListView.removeViewInLayout(mCurrSelectedView.getView()); mRevealItem.addView(mCurrSelectedView.getView()); ((BaseAdapter) mSpinnerListView.getAdapter()).notifyDataSetChanged(); if (mOnItemSelected != null) mOnItemSelected.onItemSelected(mCurrSelectedView.getView(), mCurrSelectedView.getPosition(), mCurrSelectedView.getId()); } hideEdit(); }
@Override public void setAdapter(Adapter adapter) { // release previous adapter's bitmaps if (null!=mAdapter && adapter!=mAdapter) { if (adapter instanceof MuPDFPageAdapter){ ((MuPDFPageAdapter) adapter).releaseBitmaps(); } } mAdapter = adapter; //mChildViews.clear(); //removeAllViewsInLayout(); requestLayout(); }
private void tryRestoreInstanceState(HashSet<Long> idsToCheckOnRestore) { if (idsToCheckOnRestore == null || mListView.getAdapter() == null) { return; } boolean idsFound = false; Adapter adapter = mListView.getAdapter(); for (int pos = adapter.getCount() - 1; pos >= 0; pos--) { if (idsToCheckOnRestore.contains(adapter.getItemId(pos))) { idsFound = true; if (mItemsToCheck == null) { mItemsToCheck = new HashSet<Pair<Integer, Long>>(); } mItemsToCheck.add(new Pair<Integer, Long>(pos, adapter.getItemId(pos))); } } if (idsFound) { // We found some IDs that were checked. Let's now restore the multi-selection // state. mActionMode = mActivity.startSupportActionMode(mCallbacks); } }
@Override public int getItemViewType(int position) { int type = 1; for (final Object section : sectionMap.keySet()) { final Adapter adapter = sectionMap.get(section); final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0); if (position == 0 && hasSectionHeader) return TYPE_SECTION_HEADER; if (position < size) return type + adapter.getItemViewType(position - 1); position -= size; type += adapter.getViewTypeCount(); } return -1; }
@Override public Object getItem(int position) { for (final Map.Entry<String,Adapter> entry : sectionMap.entrySet()) { final Adapter adapter = entry.getValue(); final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0); if (position == 0 && hasSectionHeader) return entry.getKey(); if (position < size) return adapter.getItem(position - 1); position -= size; } return null; }
public Adapter getAdapter(int position) { for (final Adapter adapter : sectionMap.values()) { final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0); if (position == 0 && hasSectionHeader) return null; if (position < size) return adapter; position -= size; } return null; }
public int indexOf(Object object) { int idx = 0; for (final Map.Entry<String,Adapter> entry : sectionMap.entrySet()) { final Adapter adapter = entry.getValue(); if (object.equals(entry.getKey())) return idx; for (int i = 0; i < adapter.getCount(); i++) { if (object.equals(adapter.getItem(i))) return idx + (hasSectionHeader ? 1 : 0) + i; } idx += adapter.getCount() + (hasSectionHeader ? 1 : 0); } return -1; }
@Override public void onNewLog(String logPath) throws RemoteException { File file = new File(logPath); if(file.exists() && file.isFile()) { try { final BlockInfoEx blockInfoEx = BlockInfoEx.newInstance(file); runOnUiThread(new Runnable() { @Override public void run() { mBlockInfoEntries.add(0, blockInfoEx); while (mBlockInfoEntries.size() > sMaxStoreBlockCount) { mBlockInfoEntries.remove(mBlockInfoEntries.size() - 1); } Adapter adapter = mListView.getAdapter(); if (adapter instanceof BlockListAdapter) { ((BlockListAdapter) adapter).notifyDataSetChanged(); } } }); } catch (Exception e) { Log.e(TAG, "block info parse failed:" + e); } } }
public static Matcher<View> withAdaptedData(final Matcher<String> dataMatcher) { return new TypeSafeMatcher<View>() { @Override public void describeTo(Description description) { description.appendText("with class name: "); dataMatcher.describeTo(description); } @Override public boolean matchesSafely(View view) { if (!(view instanceof AdapterView)) { return false; } @SuppressWarnings("rawtypes") Adapter adapter = ((AdapterView) view).getAdapter(); for (int i = 0; i < adapter.getCount(); i++) { if (dataMatcher.matches(adapter.getItem(i))) { return true; } } return false; } }; }
void rememberSyncState() { if (getChildCount() > 0) { this.mNeedSync = true; this.mSyncHeight = this.mLayoutHeight; View localView; if (this.mSelectedPosition >= 0) { localView = getChildAt(this.mSelectedPosition - this.mFirstPosition); this.mSyncRowId = this.mNextSelectedRowId; this.mSyncPosition = this.mNextSelectedPosition; if (localView != null) this.mSpecificTop = localView.getTop(); this.mSyncMode = 0; } else { localView = getChildAt(0); Adapter localAdapter = getAdapter(); if ((this.mFirstPosition >= 0) && (this.mFirstPosition < localAdapter.getCount())) this.mSyncRowId = localAdapter.getItemId(this.mFirstPosition); else this.mSyncRowId = -1L; this.mSyncPosition = this.mFirstPosition; if (localView != null) this.mSpecificTop = localView.getTop(); this.mSyncMode = 1; } } }
private boolean isLastItemVisible() { Adapter adapter = ((AbsListView) this.mRefreshableView).getAdapter(); if (adapter == null || adapter.isEmpty()) { return true; } int lastItemPosition = ((AbsListView) this.mRefreshableView).getCount() - 1; int lastVisiblePosition = ((AbsListView) this.mRefreshableView).getLastVisiblePosition(); if (lastVisiblePosition >= lastItemPosition - 1) { View lastVisibleChild = ((AbsListView) this.mRefreshableView).getChildAt (lastVisiblePosition - ((AbsListView) this.mRefreshableView) .getFirstVisiblePosition()); if (lastVisibleChild != null) { return lastVisibleChild.getBottom() <= ((AbsListView) this.mRefreshableView) .getBottom(); } } return false; }
@Override public View getView(int position, View convertView, ViewGroup parent) { int sectionnum = 0; for(Object section : this.sections.keySet()) { Adapter adapter = sections.get(section); int size = adapter.getCount() + 1; // check if position inside this section if(position == 0) return headers.getView(sectionnum, convertView, parent); if(position < size) return adapter.getView(position - 1, convertView, parent); // otherwise jump into next section position -= size; sectionnum++; } return null; }
public static void assertEquals(Adapter expected, Adapter actual) { AndroidTestCase.assertNotNull(actual); if (expected == null) { AndroidTestCase.assertEquals(0, actual.getCount()); return; } AndroidTestCase.assertEquals(expected.getCount(), actual.getCount()); final int count = expected.getCount(); for (int i = 0; i < count; i++) { AndroidTestCase.assertEquals( expected.getItem(i), actual.getItem(i)); } }
private boolean isFirstItemVisible() { final Adapter adapter = mRootView.getAdapter(); if (null == adapter || adapter.isEmpty()) { return true; } else { /** * This check should really just be: * mRootView.getFirstVisiblePosition() == 0, but PtRListView * internally use a HeaderView which messes the positions up. For * now we'll just add one to account for it and rely on the inner * condition which checks getTop(). */ if (mRootView.getFirstVisiblePosition() <= 1) { final View firstVisibleChild = mRootView.getChildAt(0); if (firstVisibleChild != null) { return firstVisibleChild.getTop() >= mRootView.getTop(); } } } return false; }
public void setAdapter(Adapter adapter, int initialPosition) { if (mAdapter != null) { mAdapter.unregisterDataSetObserver(mDataSetObserver); } mAdapter = adapter; if (mAdapter != null) { mDataSetObserver = new AdapterDataSetObserver(); mAdapter.registerDataSetObserver(mDataSetObserver); } if (mAdapter == null || mAdapter.getCount() == 0) return; setSelection(initialPosition); }
private void saveNote(){ Adapter a = lvItemList.getAdapter(); JSONArray jsonArray = new JSONArray(); try { CheckListItem temp; for (int i = 0; i < itemNamesList.size(); i++) { temp = (CheckListItem) a.getItem(i); JSONObject jsonObject = new JSONObject(); jsonObject.put("name", temp.getName()); jsonObject.put("checked", temp.isChecked()); jsonArray.put(jsonObject); } fillNameIfEmpty(); id = DbAccess.addNote(getBaseContext(), etName.getText().toString(), jsonArray.toString(), DbContract.NoteEntry.TYPE_CHECKLIST, currentCat); Toast.makeText(getApplicationContext(), R.string.toast_saved, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void setAdapter(Adapter adapter) { if (mAdapter != null) { mAdapter.unregisterDataSetObserver(mDataSetObserver); } if (adapter instanceof AbsWaterAdapter) { mAdapter = (AbsWaterAdapter) adapter; if (mAdapter != null) { mDataSetObserver = new AdapterDataSetObserver(); mAdapter.registerDataSetObserver(mDataSetObserver); } if (mAdapter == null || mAdapter.getCount() == 0) return; resetFocus(); } else { throw new IllegalArgumentException("WaterAdapter requred"); } }
/** * if working in {@link AdapterView}, we should response {@link Adapter} * isEnable(int position). * * @return true when item is enabled, else disabled. */ private boolean isEnabledInAdapterView() { AdapterView adapterView = getAdapterView(); boolean enable = true; if (adapterView != null) { Adapter adapter = adapterView.getAdapter(); if (adapter != null) { int p = adapterView.getPositionForView(SwipeLayout.this); if (adapter instanceof BaseAdapter) { enable = ((BaseAdapter) adapter).isEnabled(p); } else if (adapter instanceof ListAdapter) { enable = ((ListAdapter) adapter).isEnabled(p); } } } return enable; }
@Override public int getItemViewType(int position) { int type = 1; for (Object section : this.sections.keySet()) { Adapter adapter = sections.get(section); int size = adapter.getCount() + 1; // check if position inside this section if (position == 0) return TYPE_SECTION_HEADER; if (position < size) return type + adapter.getItemViewType(position - 1); // otherwise jump into next section position -= size; type += adapter.getViewTypeCount(); } return -1; }
@Override public View getView(int position, View convertView, ViewGroup parent) { int sectionnum = 0; for (Object section : this.sections.keySet()) { Adapter adapter = sections.get(section); int size = adapter.getCount() + 1; if (position == 0) return headers.getView(sectionnum, convertView, parent); if (position < size) return adapter.getView(position - 1, convertView, parent); // otherwise jump into next section position -= size; sectionnum++; } return null; }
@Override public int getItemViewType(int position) { if (!mHasReturnedViewTypeCount) { mHasReturnedViewTypeCount = true; } final Preference preference = this.getItem(position); mTempPreferenceLayout = createPreferenceLayout(preference, mTempPreferenceLayout); int viewType = Collections.binarySearch(mPreferenceLayouts, mTempPreferenceLayout); if (viewType < 0) { // This is a class that was seen after we returned the count, so // don't recycle it. return Adapter.IGNORE_ITEM_VIEW_TYPE; } else { return viewType; } }
public void setAdapter(Adapter adapter, int initialPosition) { if (this.adapter != null) { this.adapter.unregisterDataSetObserver(adapterDataObserver); } Assert.assertNotNull("adapter should not be null", adapter); this.adapter = adapter; adapterDataCount = adapter.getCount(); adapterDataObserver = new MyDataSetObserver(); this.adapter.registerDataSetObserver(adapterDataObserver); if (adapterDataCount > 0) { setSelection(initialPosition); } }
private void updateNote(){ Adapter a = lvItemList.getAdapter(); JSONArray jsonArray = new JSONArray(); try { CheckListItem temp; for (int i = 0; i < itemNamesList.size(); i++) { temp = (CheckListItem) a.getItem(i); JSONObject jsonObject = new JSONObject(); jsonObject.put("name", temp.getName()); jsonObject.put("checked", temp.isChecked()); jsonArray.put(jsonObject); } fillNameIfEmpty(); DbAccess.updateNote(getBaseContext(), id, etName.getText().toString(), jsonArray.toString(), currentCat); Toast.makeText(getApplicationContext(), R.string.toast_updated, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } }
protected boolean isReadyForDragEnd(){ final Adapter adapter = dragableView.getAdapter(); if (null == adapter || adapter.isEmpty()) { return true; } else { final int lastItemPosition = dragableView.getCount() - 1; final int lastVisiblePosition = dragableView.getLastVisiblePosition(); if (lastVisiblePosition >= lastItemPosition - 1) { final int childIndex = lastVisiblePosition - dragableView.getFirstVisiblePosition(); final View lastVisibleChild = dragableView.getChildAt(childIndex); if (lastVisibleChild != null) { return lastVisibleChild.getBottom() <= dragableView.getBottom(); } } } return false; }
/** * A shortcut method to set both the listeners and the adapter. * * @param context The activity context which extends onFlingListener, OnItemClickListener or both * @param mAdapter The adapter you have to set. */ public void init(final Context context, Adapter mAdapter) { if(context instanceof onFlingListener) { mFlingListener = (onFlingListener) context; }else{ throw new RuntimeException("Activity does not implement SwipeFlingAdapterView.onFlingListener"); } if(context instanceof OnItemClickListener){ mOnItemClickListener = (OnItemClickListener) context; } setAdapter(mAdapter); }
@Override public void setAdapter(Adapter adapter) { if (mAdapter != null && mDataSetObserver != null) { mAdapter.unregisterDataSetObserver(mDataSetObserver); mDataSetObserver = null; } mAdapter = adapter; if (mAdapter != null && mDataSetObserver == null) { mDataSetObserver = new AdapterDataSetObserver(); mAdapter.registerDataSetObserver(mDataSetObserver); } }
/** */ @Override public Parcelable onSaveInstanceState() { final Adapter adapter = getAdapter(); if (adapter != null) { final Parcelable adapterState = saveAdapterState(adapter); if (adapterState != null) { final CollectionSavedState savedState = new CollectionSavedState(super.onSaveInstanceState()); savedState.mAdapterState = adapterState; return savedState; } } return super.onSaveInstanceState(); }
/** * Saves the current state of the specified <var>adapter</var>. * * @param adapter The adapter of which state to save. Should be instance of {@link StatefulAdapter} * or one of wrapper adapter ({@link android.widget.WrapperListAdapter}) implementations. * @return Adapter's saved state or {@code null} or empty state if the adapter does not save its * state or it is not a stateful adapter. */ private Parcelable saveAdapterState(Adapter adapter) { if (adapter instanceof StatefulAdapter) { return ((StatefulAdapter) adapter).saveInstanceState(); } else if (adapter instanceof WrapperListAdapter) { return saveAdapterState(((WrapperListAdapter) adapter).getWrappedAdapter()); } return null; }
/** */ @Override public void onRestoreInstanceState(Parcelable state) { if (!(state instanceof CollectionSavedState)) { super.onRestoreInstanceState(state); return; } final CollectionSavedState savedState = (CollectionSavedState) state; super.onRestoreInstanceState(savedState.getSuperState()); final Adapter adapter = getAdapter(); if (adapter != null && savedState.mAdapterState != null) { this.restoreAdapterState(adapter, savedState.mAdapterState); } }
/** * Restores the saved state of the specified <var>adapter</var>. * * @param adapter The adapter of which state to restore. Should be instance of {@link StatefulAdapter} * or one of wrapper adapter ({@link android.widget.WrapperListAdapter}) implementations. * @param adapterState The previously saved adapter state via {@link #saveAdapterState(Adapter)}. */ private void restoreAdapterState(Adapter adapter, Parcelable adapterState) { if (adapter instanceof StatefulAdapter) { ((StatefulAdapter) adapter).restoreInstanceState(adapterState); } else if (adapter instanceof WrapperListAdapter) { restoreAdapterState(((WrapperListAdapter) adapter).getWrappedAdapter(), adapterState); } }