List of usage examples for android.widget ListAdapter getItem
Object getItem(int position);
From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mRootView = container;/*from w w w .ja v a2s . c o m*/ final View view = inflater.inflate(R.layout.playlist_activity, container, false); mSearchView = (SearchView) view.findViewById(R.id.search); mSearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(final String newText) { mFilter = newText; if (newText != null && newText.isEmpty()) { mFilter = null; } if (mFilter != null) { mFilter = mFilter.toLowerCase(); } mList.setDragEnabled(mFilter == null); update(false); return false; } @Override public boolean onQueryTextSubmit(final String query) { // Hide the keyboard and give focus to the list final InputMethodManager imm = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); mList.requestFocus(); return true; } }); mList = (DragSortListView) view.findViewById(android.R.id.list); mList.requestFocus(); mList.setDropListener(mDropListener); mController = new DragSortController(mList); mController.setDragHandleId(R.id.cover); mController.setRemoveEnabled(false); mController.setSortEnabled(true); mController.setDragInitMode(1); mList.setFloatViewManager(mController); mList.setOnTouchListener(mController); mList.setDragEnabled(true); refreshListColorCacheHint(); mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { final SparseBooleanArray checkedItems = mList.getCheckedItemPositions(); final int count = mList.getCount(); final ListAdapter adapter = mList.getAdapter(); final int itemId = item.getItemId(); int j = 0; int[] positions = null; boolean result = true; if (itemId == R.id.menu_delete) { positions = new int[mList.getCheckedItemCount()]; for (int i = 0; i < count && j < positions.length; i++) { if (checkedItems.get(i)) { positions[j] = ((Music) adapter.getItem(i)).getSongId(); j++; } } } else if (itemId == R.id.menu_crop) { positions = new int[mList.getCount() - mList.getCheckedItemCount()]; for (int i = 0; i < count && j < positions.length; i++) { if (!checkedItems.get(i)) { positions[j] = ((Music) adapter.getItem(i)).getSongId(); j++; } } } else { result = false; } if (j > 0) { QueueControl.run(QueueControl.REMOVE_BY_ID, positions); mode.finish(); } return result; } @Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.mpd_queuemenu, menu); return true; } @Override public void onDestroyActionMode(final ActionMode mode) { mActionMode = null; mController.setSortEnabled(true); } @Override public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id, final boolean checked) { final int selectCount = mList.getCheckedItemCount(); if (selectCount == 0) { mode.finish(); } if (selectCount == 1) { mode.setTitle(R.string.actionSongSelected); } else { mode.setTitle(getString(R.string.actionSongsSelected, selectCount)); } } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { mActionMode = mode; mController.setSortEnabled(false); return false; } }); return view; }
From source file:com.juick.android.MessagesFragment.java
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { recentFirstVisibleItem = firstVisibleItem; recentVisibleItemCount = visibleItemCount; int prefetchMessagesSize = prefetchMessages ? 20 : 0; if (visibleItemCount < totalItemCount && (firstVisibleItem + visibleItemCount >= totalItemCount - prefetchMessagesSize) && !loading) { if (messagesSource.canNext()) { loadMore();/*from ww w. ja v a 2 s . c om*/ } } try { JuickMessage jm; if (firstVisibleItem != 0) { ListAdapter listAdapter = getListAdapter(); jm = (JuickMessage) listAdapter.getItem(firstVisibleItem - 1); topMessageId = jm.getMID(); if (firstVisibleItem > 1 && trackLastRead) { final int itemToReport = firstVisibleItem - 1; if (lastItemReported < itemToReport) { for (lastItemReported++; lastItemReported <= itemToReport; lastItemReported++) { final int itemToSave = lastItemReported; if (itemToSave - 1 < listAdapter.getCount()) { // some async delete could happen final JuickMessage item = (JuickMessage) listAdapter.getItem(itemToSave - 1); item.read = true; if (item.Timestamp != null) { databaseGetter.getService(new Utils.ServiceGetter.Receiver<DatabaseService>() { @Override public void withService(DatabaseService service) { if (service != null) { service.markAsRead(new DatabaseService.ReadMarker(item.getMID(), item.replies, item.Timestamp.getTime())); } } }); } } } lastItemReported--; } } } else { if (getListAdapter() != null) { jm = (JuickMessage) getListAdapter().getItem(firstVisibleItem); if (topMessageId instanceof JuickMessageID) { ((JuickMessageID) topMessageId).getNextMid(); // open/closed interval } else { topMessageId = jm.getMID(); // dunno here } } } } catch (Exception ex) { JuickAdvancedApplication.addToGlobalLog("marking read", ex); } if (false && messagesSource.supportsBackwardRefresh()) { // When the refresh view is completely visible, change the text to say // "Release to refresh..." and flip the arrow drawable. if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING) { if (firstVisibleItem == 0) { mRefreshViewImage.setVisibility(View.VISIBLE); if ((mRefreshView.getBottom() >= mRefreshViewHeight + 20 || mRefreshView.getTop() >= 0) && mRefreshState != RELEASE_TO_REFRESH) { mRefreshViewText.setText(R.string.pull_to_refresh_release_label); mRefreshViewImage.clearAnimation(); mRefreshViewImage.startAnimation(mFlipAnimation); mRefreshState = RELEASE_TO_REFRESH; } else if (mRefreshView.getBottom() < mRefreshViewHeight + 20 && mRefreshState != PULL_TO_REFRESH) { mRefreshViewText.setText(R.string.pull_to_refresh_pull_label); if (mRefreshState != TAP_TO_REFRESH) { mRefreshViewImage.clearAnimation(); mRefreshViewImage.startAnimation(mReverseFlipAnimation); } mRefreshState = PULL_TO_REFRESH; } } else { mRefreshViewImage.setVisibility(View.GONE); resetHeader(); } } else if (mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0 && mRefreshState != REFRESHING) { try { setSelection(1); } catch (Exception e) { // Content view is not yet created } mBounceHack = true; } else if (mBounceHack && mCurrentScrollState == SCROLL_STATE_FLING) { try { setSelection(1); } catch (Exception e) { // Content view is not yet created } } } }
From source file:com.juick.android.MessagesFragment.java
public MessageListBackingData getMessageListBackingData() { MessageListBackingData mlbd = new MessageListBackingData(); mlbd.messagesSource = messagesSource; mlbd.topMessageId = topMessageId;//w w w . j a va 2 s.c om ListView lv = null; try { lv = getListView(); ListAdapter adapter = lv.getAdapter(); if (adapter == null) adapter = listAdapter; int firstVisiblePosition = lv.getFirstVisiblePosition(); JuickMessage jm = (JuickMessage) adapter.getItem(firstVisiblePosition); mlbd.topMessageId = jm.getMID(); for (int i = 0; i < lv.getChildCount(); i++) { View thatView = lv.getChildAt(i); int positionForView = lv.getPositionForView(thatView); if (positionForView == firstVisiblePosition) { mlbd.topMessageScrollPos = thatView.getTop(); break; } } } catch (Exception e) { // various conditions } if (lv == null) { return null; } int firstVisiblePosition = Math.max(0, lv.getFirstVisiblePosition() - 120); mlbd.messages = new ArrayList<JuickMessage>(); for (int i = firstVisiblePosition; i < listAdapter.getCount(); i++) { mlbd.messages.add(listAdapter.getItem(i)); } return mlbd; }
From source file:com.juick.android.MessagesFragment.java
private void init(final boolean moveToTop) { if (implicitlyCreated) return;/*from ww w.jav a 2s .com*/ parent.imagePreviewHelper = listAdapter.imagePreviewHelper = new ImagePreviewHelper( (ViewGroup) getView().findViewById(R.id.imagepreview_container), parent); final MessageListBackingData savedMainList = JuickAdvancedApplication.instance.getSavedList(getActivity()); final ListView lv = getListView(); boolean canUseMainList = getActivity() instanceof MainActivity; // if (savedMainList != null && canUseMainList) { messagesSource = savedMainList.messagesSource; initListWithMessages(savedMainList.messages); int selectItem = 0; ListAdapter wrappedAdapter = lv.getAdapter(); for (int i = 0; i < wrappedAdapter.getCount(); i++) { Object ai = wrappedAdapter.getItem(i); if (ai != null && ai instanceof JuickMessage) { if (((JuickMessage) ai).getMID().equals(savedMainList.topMessageId)) { selectItem = i; } } } lv.setSelectionFromTop(selectItem, savedMainList.topMessageScrollPos); JuickAdvancedApplication.instance.setSavedList(null, false); } else { final MessagesLoadNotification messagesLoadNotification = new MessagesLoadNotification(getActivity(), handler); Thread thr = new Thread("Download messages (init)") { public void run() { final MessagesLoadNotification notification = messagesLoadNotification; final Utils.Function<Void, RetainedData> then = new Utils.Function<Void, RetainedData>() { @Override public Void apply(final RetainedData mespos) { handler.post(new Runnable() { @Override public void run() { notification.statusText.setText("Filter and format.."); } }); Log.w("com.juick.advanced", "getFirst: before filter"); final ArrayList<JuickMessage> messages = filterMessages(mespos.messages); Log.w("com.juick.advanced", "getFirst: after filter"); Boolean ownView = null; if (!JuickMessagesAdapter.dontKeepParsed(parent)) { for (JuickMessage juickMessage : messages) { if (ownView == null) { MicroBlog blog = MainActivity.microBlogs .get(juickMessage.getMID().getMicroBlogCode()); ownView = blog instanceof OwnRenderItems; } if (!ownView) { juickMessage.parsedText = JuickMessagesAdapter.formatMessageText(parent, juickMessage, false); } } } final Parcelable listPosition = mespos.viewState; if (isAdded()) { if (messages.size() == 0) { handler.post(new Runnable() { @Override public void run() { if (notification.lastError == null) { notification.statusText .setText(parent.getString(R.string.EmptyList)); } else { notification.statusText.setText( "Error obtaining messages: " + notification.lastError); } notification.progressBar.setVisibility(View.GONE); } }); } final Activity activity = getActivity(); if (activity != null) { final Parcelable finalListPosition = listPosition; activity.runOnUiThread(new Runnable() { public void run() { try { if (isAdded()) { lastPrepareMessages(messages, new Runnable() { @Override public void run() { if (!hasListView()) { handler.postDelayed(this, 300); return; } initListWithMessages(messages); if (moveToTop) { lv.setSelection(0); } else { if (finalListPosition != null) { lv.onRestoreInstanceState(finalListPosition); } else { //setSelection(messagesSource.supportsBackwardRefresh() ? 1 : 0); setSelection(0); } } Log.w("com.juick.advanced", "getFirst: end."); handler.postDelayed(new Runnable() { @Override public void run() { onListLoaded(); } }, 10); } }); } } catch (IllegalStateException e) { Toast.makeText(activity, e.toString(), Toast.LENGTH_LONG).show(); } } }); } } else { Log.w("com.juick.advanced", "getFirst: not added!"); } return null; } }; if (getActivity() != null) messagesSource.setContext(getActivity()); if (restoreData == null) { messagesSource.getFirst(notification, new Utils.Function<Void, ArrayList<JuickMessage>>() { @Override public Void apply(ArrayList<JuickMessage> juickMessages) { return then.apply(new RetainedData(juickMessages, null)); } }); } else { then.apply((RetainedData) restoreData); restoreData = null; } } }; thr.setPriority(Thread.MIN_PRIORITY); thr.start(); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
private void selectAllWifi(boolean flag) { if (this.listview == null) { this.listview = (ListView) this.findViewById(R.id.listview); }/* www . j a va 2 s. co m*/ ListAdapter adapter = listview.getAdapter(); int count = adapter.getCount(), item; if (adapter != null) { for (item = 0; item < count; item++) { PackageInfoData data = (PackageInfoData) adapter.getItem(item); if (data.uid != Api.SPECIAL_UID_ANY) { data.selected_wifi = flag; } setDirty(true); } ((BaseAdapter) adapter).notifyDataSetChanged(); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
private void selectAllLAN(boolean flag) { if (this.listview == null) { this.listview = (ListView) this.findViewById(R.id.listview); }//from w w w .j a v a 2 s . c om ListAdapter adapter = listview.getAdapter(); if (adapter != null) { int count = adapter.getCount(), item; for (item = 0; item < count; item++) { PackageInfoData data = (PackageInfoData) adapter.getItem(item); if (data.uid != Api.SPECIAL_UID_ANY) { data.selected_lan = flag; } setDirty(true); } ((BaseAdapter) adapter).notifyDataSetChanged(); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
private void selectAllVPN(boolean flag) { if (this.listview == null) { this.listview = (ListView) this.findViewById(R.id.listview); }//from ww w. jav a 2 s . c o m ListAdapter adapter = listview.getAdapter(); if (adapter != null) { int count = adapter.getCount(), item; for (item = 0; item < count; item++) { PackageInfoData data = (PackageInfoData) adapter.getItem(item); if (data.uid != Api.SPECIAL_UID_ANY) { data.selected_vpn = flag; } setDirty(true); } ((BaseAdapter) adapter).notifyDataSetChanged(); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
private void selectAllRoam(boolean flag) { if (this.listview == null) { this.listview = (ListView) this.findViewById(R.id.listview); }//w w w. j a v a 2 s . co m ListAdapter adapter = listview.getAdapter(); if (adapter != null) { int count = adapter.getCount(), item; for (item = 0; item < count; item++) { PackageInfoData data = (PackageInfoData) adapter.getItem(item); if (data.uid != Api.SPECIAL_UID_ANY) { data.selected_roam = flag; } setDirty(true); } ((BaseAdapter) adapter).notifyDataSetChanged(); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
private void selectAll3G(boolean flag) { if (this.listview == null) { this.listview = (ListView) this.findViewById(R.id.listview); }/*from w ww . ja v a2 s . c o m*/ ListAdapter adapter = listview.getAdapter(); if (adapter != null) { int count = adapter.getCount(), item; for (item = 0; item < count; item++) { PackageInfoData data = (PackageInfoData) adapter.getItem(item); if (data.uid != Api.SPECIAL_UID_ANY) { data.selected_3g = flag; } setDirty(true); } ((BaseAdapter) adapter).notifyDataSetChanged(); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
private void clearAll() { if (this.listview == null) { this.listview = (ListView) this.findViewById(R.id.listview); }//from w w w. j a v a 2 s . c o m ListAdapter adapter = listview.getAdapter(); if (adapter != null) { int count = adapter.getCount(), item; for (item = 0; item < count; item++) { PackageInfoData data = (PackageInfoData) adapter.getItem(item); data.selected_wifi = false; data.selected_3g = false; data.selected_roam = false; data.selected_vpn = false; data.selected_lan = false; setDirty(true); } ((BaseAdapter) adapter).notifyDataSetChanged(); } }