List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:com.money.manager.ex.reports.CategoriesReportFragment.java
public void showChart() { CategoriesReportAdapter adapter = (CategoriesReportAdapter) getListAdapter(); if (adapter == null) return;//from w w w.jav a2s.c o m Cursor cursor = adapter.getCursor(); if (cursor == null) return; if (cursor.getCount() <= 0) return; ArrayList<ValuePieEntry> arrayList = new ArrayList<>(); CurrencyService currencyService = new CurrencyService(getActivity().getApplicationContext()); // Reset cursor to initial position. cursor.moveToPosition(-1); // process cursor while (cursor.moveToNext()) { ValuePieEntry item = new ValuePieEntry(); String category = cursor.getString(cursor.getColumnIndex(ViewMobileData.Category)); if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory)))) { category += " : " + cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory)); } // total double total = Math.abs(cursor.getDouble(cursor.getColumnIndex("TOTAL"))); // check if category is empty if (TextUtils.isEmpty(category)) { category = getString(R.string.empty_category); } item.setText(category); item.setValue(total); item.setValueFormatted(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(total))); // add element arrayList.add(item); } Bundle args = new Bundle(); args.putSerializable(PieChartFragment.KEY_CATEGORIES_VALUES, arrayList); //get fragment manager FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); if (fragmentManager != null) { PieChartFragment fragment; fragment = (PieChartFragment) fragmentManager .findFragmentByTag(IncomeVsExpensesChartFragment.class.getSimpleName()); if (fragment == null) { fragment = new PieChartFragment(); } fragment.setChartArguments(args); fragment.setDisplayHomeAsUpEnabled(true); if (fragment.isVisible()) fragment.onResume(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (((CategoriesReportActivity) getActivity()).mIsDualPanel) { fragmentTransaction.replace(R.id.fragmentChart, fragment, PieChartFragment.class.getSimpleName()); } else { fragmentTransaction.replace(R.id.fragmentMain, fragment, PieChartFragment.class.getSimpleName()); fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); } }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ??//from w w w . j a v a2s. co m * @param messageType ?MMS,SMS,Email * @param folderType * @param index ? * @return ? */ private JSONObject getMessage(String messageType, String folderType, int index) throws JSONException { //TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } JSONObject message = new JSONObject(); try { // ??? String[] projection = new String[] { "_id", "subject", "address", "body", "date", "read" }; folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); ContentResolver resolver = getContext().getContentResolver(); Cursor cursor = resolver.query(uri, projection, null, null, "date desc"); if (null == cursor) { return message; } // ?? if (!cursor.moveToPosition(index)) { cursor.close(); return message; } //TODO:?SIM?? message = getMessageFromCursor(cursor); cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return message; }
From source file:com.ant.sunshine.app.fragments.ForecastFragment.java
@NonNull private ViewTreeObserver.OnPreDrawListener getAddOnPreDrawListener() { return new ViewTreeObserver.OnPreDrawListener() { @Override//from w w w. j av a 2s . c om public boolean onPreDraw() { // Since we know we're going to get items, we keep the listener around until // we see Children. if (mRecyclerView.getChildCount() > 0) { mRecyclerView.getViewTreeObserver().removeOnPreDrawListener(this); int position = mForecastAdapter.getSelectedItemPosition(); if (position == RecyclerView.NO_POSITION && -1 != mInitialSelectedDate) { Cursor data = mForecastAdapter.getCursor(); int count = data.getCount(); int dateColumn = data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_DATE); for (int i = 0; i < count; i++) { data.moveToPosition(i); if (data.getLong(dateColumn) == mInitialSelectedDate) { position = i; break; } } } if (position == RecyclerView.NO_POSITION) { position = 0; } // If we don't need to restart the loader, and there's a desired position to restore // to, do so now. mRecyclerView.smoothScrollToPosition(position); RecyclerView.ViewHolder vh = mRecyclerView.findViewHolderForAdapterPosition(position); if (null != vh && mAutoSelectView) { mForecastAdapter.selectView(vh); } if (mHoldForTransition) { getCurrentActivity().supportStartPostponedEnterTransition(); } return true; } return false; } }; }
From source file:com.iaraby.template.view.fragment.ListFrag.java
@Override public Loader<Cursor> onCreateLoader(int args0, Bundle bundel) { SimpleCursorLoader loader = new SimpleCursorLoader(getActivity()) { @Override// w ww . j av a2 s. c o m public Cursor loadInBackground() { Cursor cursor = null; if (isFav) { try { cursor = FavoriteManager.getInstance(getActivity()).getFavCursor(); } catch (IllegalAccessError ex) { Log.e(Constants.LOG_TAG, ex.toString()); } } else { cursor = MyDataAdapter.getInstance().getCtegories(); } // check if list or favotite mode if (selectedId == Constants.EMPTY_INT && cursor != null && cursor.moveToPosition(selectedPos)) selectedId = cursor.getLong(cursor.getColumnIndex(Category.COL_ID)); if (isSelectDefault) { showDetails(selectedPos, selectedId, true); isSelectDefault = false; } return cursor; } }; return loader; }
From source file:com.supremainc.biostar2.base.BaseListCursorAdapter.java
public void getCheckedItemIds(final OnGetCheckedItem onGetCheckedItemIds, final boolean showWait) { if (onGetCheckedItemIds == null) { return;/*from w ww . ja v a 2 s . c om*/ } if (mPopup != null && showWait) { mPopup.showWait(false); } new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { long start = System.currentTimeMillis(); if (BuildConfig.DEBUG) { Log.i(TAG, "start getCheckedItemIds"); } Cursor cursor = getCursor(); final ArrayList<Integer> selectedItem = new ArrayList<Integer>(); if (mListView.getChoiceMode() == ListView.CHOICE_MODE_SINGLE) { int position = getCheckedItemPosition(); if (position != ListView.INVALID_POSITION) { cursor.moveToPosition(position); int id = cursor.getInt(0); selectedItem.add(id); } } else { for (int i = 0; i < getCount(); i++) { if (isItemChecked(i)) { cursor.moveToPosition(i); int id = cursor.getInt(0); selectedItem.add(id); } } } if (BuildConfig.DEBUG) { Log.i(TAG, "end getCheckedItemIds:" + ((System.currentTimeMillis() - start) / 1000)); } mContext.runOnUiThread(new Runnable() { @Override public void run() { if (mPopup != null && showWait) { mPopup.dismissWiat(); } onGetCheckedItemIds.onReceive(selectedItem); } }); return null; } }.execute(null, null, null); }
From source file:de.vanita5.twittnuker.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);/*from ww w . ja v a 2s . com*/ f.show(getSupportFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<DraftItem>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Where where = Where.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ??// w w w . j ava 2 s . c o m * * @param messageType * ?MMS,SMS,Email * @param folderType * * @param index * ? * @return ? */ private JSONObject getMessage(String messageType, String folderType, int index) throws JSONException { // TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } JSONObject message = new JSONObject(); try { // ??? String[] projection = new String[] { "_id", "subject", "address", "body", "date", "read" }; folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query(uri, projection, null, null, "date desc"); if (null == cursor) { return message; } // ?? if (!cursor.moveToPosition(index)) { cursor.close(); return message; } // TODO:?SIM?? message = getMessageFromCursor(cursor); cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return message; }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ?/*www . j av a 2 s.c o m*/ * @param comparisonMsg ?? * @param folderType * @param startIndex * @param endIndex ? * @return ? */ private JSONArray findMessages(JSONObject comparisonMsg, String folderType, int startIndex, int endIndex) throws JSONException { // TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } ArrayList<String> projections = new ArrayList<String>(); projections.add("_id"); projections.add("subject"); projections.add("address"); projections.add("body"); ArrayList<String> projectionsValue = new ArrayList<String>(); projectionsValue.add(comparisonMsg.optString("messageId")); projectionsValue.add(comparisonMsg.optString("subject")); projectionsValue.add(comparisonMsg.optString("destinationAddresses")); projectionsValue.add(comparisonMsg.optString("body")); StringBuilder selection = XUtils.constructSelectionStatement(projections, projectionsValue); int isRead = comparisonMsg.getInt("isRead"); if (-1 != isRead) { if (null == selection) { selection = new StringBuilder(); } else { selection.append(" AND "); } selection.append("read"); selection.append("="); selection.append(isRead); } String selectionStr = null; if (null != selection) { selectionStr = selection.toString(); } folderType = folderType.toLowerCase(); Uri findUri = Uri.withAppendedPath(mSMSContentUri, folderType); JSONArray messages = new JSONArray(); try { ContentResolver resolver = getContext().getContentResolver(); Cursor cursor = resolver.query(findUri, null, selectionStr, null, null); if (null == cursor) { return messages; } int count = endIndex - startIndex + 1; if (cursor.moveToPosition(startIndex)) { do { JSONObject message = getMessageFromCursor(cursor); messages.put(message); count--; } while (cursor.moveToNext() && count > 0); } cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return messages; }
From source file:org.getlantern.firetweet.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);/*from w w w. j ava 2 s . c o m*/ f.show(getSupportFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Expression where = Expression.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:de.k3b.android.androFotoFinder.imagedetail.ImagePagerAdapterFromCursor.java
/** debug support for logging current cursor content */ private String debugCursor(Cursor cursor, int maxRows, String delim, String... colmnNames) { StringBuilder result = new StringBuilder(); if ((cursor != null) && (!cursor.isClosed())) { int oldPosition = cursor.getPosition(); int last = Math.min(maxRows - 1, cursor.getCount() - 1); for (int position = 0; position <= last; position++) { result.append("#").append(position); cursor.moveToPosition(position); for (String col : colmnNames) { result.append(";").append(cursor.getString(cursor.getColumnIndex(col))); }// w w w . ja v a 2 s . c o m result.append(delim); } } return result.toString(); }