List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final ViewHolder h = (ViewHolder) view.getTag(); final Time validTo = FormatUtil.timeFrom3339(cursor.getString(iValidTo)); final int status = getValidityStatus(cursor.getInt(iStatus), validTo); view.setTag(R.id.swipe_enabled, (status == Tickets.STATUS_EXPIRED)); AnimationUtil.setFlipAnimation(h.vIndicator, h.animator, getPrimaryIndicatorImage(status), getSecondaryIndicatorImage(status), c); h.vStatus.setText(getValidityString(status, validTo)); h.vStatus.setTextColor(getValidityColor(status)); h.vCity.setText(cursor.getString(iCity)); h.vTicket.setBackgroundResource(getTicketBackground(status)); if (cursor.getLong(iId) == mActiveId) { final int position = cursor.getPosition(); if (status != Tickets.STATUS_WAITING) { h.vValidFrom.setText(FormatUtil.formatDate3339(cursor.getString(iValidFrom))); h.vValidFrom.setTextColor(getActiveDetailColor(status)); h.vValidTo.setText(FormatUtil.formatDate3339(cursor.getString(iValidTo))); h.vValidTo.setTextColor(getActiveDetailColor(status)); h.vValidToLabel.setTextColor(getActiveDetailColor(status)); h.vCode.setText(cursor.getString(iHash)); h.vCode.setTextColor(getActiveDetailColor(status)); h.vCodeLabel.setTextColor(getActiveDetailColor(status)); h.vShowSms.setTextColor(getShowSmsColor(status)); h.vValidFromLabel.setText(R.string.tickets_valid_from); h.vValidFromLabel.setVisibility(View.VISIBLE); h.vCodeLabel.setVisibility(View.VISIBLE); h.vShowSms.setVisibility(View.VISIBLE); } else {/*from w w w . java2 s . c o m*/ h.vValidFromLabel.setText(R.string.tickets_waiting_info); h.vValidToLabel.setVisibility(View.INVISIBLE); h.vCodeLabel.setVisibility(View.INVISIBLE); h.vShowSms.setVisibility(View.INVISIBLE); } if (status == Tickets.STATUS_EXPIRED || status == Tickets.STATUS_WAITING) { h.vDelete.setImageResource(getDeleteImage(status)); h.vDelete.setContentDescription(c.getString(R.string.desc_delete_ticket)); if (status == Tickets.STATUS_EXPIRED) { h.vDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.forceDismiss(position); } }); } else { // waiting gets deleted, not archived h.vDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteTicket(position); } }); } } else { h.vDelete.setImageResource(getCollapseImage(status)); h.vDelete.setContentDescription(c.getString(R.string.desc_collapse_ticket)); h.vDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.collapseUncollapseTicket(mActiveId, mShowSms); } }); } h.vValidFromLabel.setTextColor(getActiveDetailColor(status)); h.vCollapse.setImageResource(getCollapseImage(status)); h.vSeparator1.setBackgroundResource(getSeparatorImage(status)); h.vSeparator2.setBackgroundResource(getSeparatorImage(status)); h.vSeparator3.setBackgroundResource(getSeparatorImage(status)); } else { h.vWhenExpired.setText(getValidToText(status, validTo.toMillis(false))); h.vWhenExpired.setVisibility(View.VISIBLE); } }
From source file:com.money.manager.ex.reports.PayeeReportAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView txtColumn1 = (TextView) view.findViewById(R.id.textViewColumn1); TextView txtColumn2 = (TextView) view.findViewById(R.id.textViewColumn2); double total = cursor.getDouble(cursor.getColumnIndex("TOTAL")); if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)))) { txtColumn1.setText(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE))); } else {//from w ww .ja va2s . c o m txtColumn1.setText(context.getString(R.string.empty_payee)); } CurrencyService currencyService = new CurrencyService(mContext); txtColumn2.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(total))); Core core = new Core(context); UIHelper uiHelper = new UIHelper(context); if (total < 0) { txtColumn2.setTextColor( ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_red_color_theme))); } else { txtColumn2.setTextColor( ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_green_color_theme))); } view.setBackgroundColor(core.resolveColorAttribute( cursor.getPosition() % 2 == 1 ? R.attr.row_dark_theme : R.attr.row_light_theme)); }
From source file:de.elanev.studip.android.app.frontend.courses.CourseAttendeesFragment.java
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null) { return;//from ww w. jav a 2s. c o m } List<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>(); cursor.moveToFirst(); int prevRole = -1; int currRole = -1; while (!cursor.isAfterLast()) { currRole = cursor .getInt(cursor.getColumnIndex(CoursesContract.Columns.CourseUsers.COURSE_USER_USER_ROLE)); if (currRole != prevRole) { String role = null; switch (currRole) { case CoursesContract.USER_ROLE_TEACHER: role = getString(R.string.Teacher); break; case CoursesContract.USER_ROLE_TUTOR: role = getString(R.string.Tutor); break; case CoursesContract.USER_ROLE_STUDENT: role = getString(R.string.Student); break; default: throw new UnknownError("unknown role type"); } sections.add(new SectionedCursorAdapter.Section(cursor.getPosition(), role)); } prevRole = currRole; cursor.moveToNext(); } mUsersAdapter.setSections(sections); mUsersAdapter.changeCursor(cursor); setLoadingViewVisible(false); }
From source file:com.polyvi.xface.extension.contact.XContactsExt.java
/** * ????json.//from w w w. j a v a 2s . c o m * * @param requiredField * ???? * @param c * * @param contactsMaxNum * ? * @return ? JSON */ private JSONArray populateContactArray(HashSet<String> requiredField, Cursor c, int contactsMaxNum) { String oldContactId = ""; boolean newContact = true; JSONArray contacts = new JSONArray(); JSONObject contact = new JSONObject(); HashMap<String, Object> contactMap = new HashMap<String, Object>(); // ?? mContactAccessor.initQuantityOfFields(contactMap); if (c.getCount() > 0) { while (c.moveToNext() && (contacts.length() <= (contactsMaxNum - 1))) { String contactId = mContactAccessor.getContactId(c); String rawId = mContactAccessor.getRawId(c); try { // oldContactId if (c.getPosition() == 0) { oldContactId = contactId; } // contact ID? // ?Contact object contacts // Contact object if (!oldContactId.equals(contactId)) { hashMapToJson(requiredField, contactMap, contact); contacts.put(contact); // contact = new JSONObject(); contactMap.clear(); // ?? mContactAccessor.initQuantityOfFields(contactMap); newContact = true; } // ? ID display name // ???? if (newContact) { newContact = false; contact.put(XContactAccessor.LOGIC_FIELD_ID, contactId); contact.put(XContactAccessor.LOGIC_FIELD_RAWID, rawId); } mContactAccessor.cursorToHashMap(contactMap, c); } catch (JSONException e) { XLog.e(CLASS_NAME, e.getMessage(), e); } oldContactId = contactId; } // Push?? contacts if (contacts.length() < contactsMaxNum) { hashMapToJson(requiredField, contactMap, contact); contacts.put(contact); } } return contacts; }
From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java
/** * Returns the call types for the given number of items in the cursor. * <p>/*from ww w.j a v a2 s . c o m*/ * It uses the next {@code count} rows in the cursor to extract the types. * <p> * It position in the cursor is unchanged by this function. */ private int[] getCallTypes(Cursor cursor, int count) { int position = cursor.getPosition(); int[] callTypes = new int[count]; for (int index = 0; index < count; ++index) { callTypes[index] = cursor.getInt(CallLogQuery.CALL_TYPE); cursor.moveToNext(); } cursor.moveToPosition(position); return callTypes; }
From source file:com.conferenceengineer.android.iosched.ui.ScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (!isAdded()) { return;/*from w w w . jav a 2s . c o m*/ } Context context = getActivity(); long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; String displayTimeZone = PrefUtils.getDisplayTimeZone(context).getID(); List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDayDisplay(previousBlockStart, blockStart, context)) { mBuffer.setLength(0); sections.add( new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils .formatDateRange(context, mFormatter, blockStart, blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, displayTimeZone) .toString())); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.swapCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java
/** * Retrieves the day group of the previous call in the call log. Used to determine if the day * group has changed and to trigger display of the day group text. * * @param cursor The call log cursor.// w w w .j a v a 2 s.com * @return The previous day group, or DAY_GROUP_NONE if this is the first call. */ private int getPreviousDayGroup(Cursor cursor) { // We want to restore the position in the cursor at the end. int startingPosition = cursor.getPosition(); int dayGroup = CallLogGroupBuilder.DAY_GROUP_NONE; if (cursor.moveToPrevious()) { long previousRowId = cursor.getLong(CallLogQuery.ID); dayGroup = getDayGroupForCall(previousRowId); } cursor.moveToPosition(startingPosition); return dayGroup; }
From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java
/** * Retrieves the call Ids represented by the current call log row. * * @param cursor Call log cursor to retrieve call Ids from. * @param groupSize Number of calls associated with the current call log row. * @return Array of call Ids./*w ww.j a v a 2 s .c o m*/ */ private long[] getCallIds(final Cursor cursor, final int groupSize) { // We want to restore the position in the cursor at the end. int startingPosition = cursor.getPosition(); long[] ids = new long[groupSize]; // Copy the ids of the rows in the group. for (int index = 0; index < groupSize; ++index) { ids[index] = cursor.getLong(CallLogQuery.ID); cursor.moveToNext(); } cursor.moveToPosition(startingPosition); return ids; }
From source file:com.hybris.mobile.app.commerce.adapter.ProductListAdapterBase.java
@Override public void bindView(View rowView, final Context context, final Cursor cursor) { // When clicking outside a EditText, hide keyboard, remove focus and // reset to the default value // Clicking on the main view rowView.setOnTouchListener(new OnTouchListener() { @Override//w w w. j av a2s . co m public boolean onTouch(View v, MotionEvent event) { UIUtils.hideKeyboard(getContext()); v.performClick(); return false; } }); final ProductViewHolder productViewHolder = (ProductViewHolder) rowView.getTag(); final ProductBase product = getData(); if (mCurrentSelectedPosition == cursor.getPosition()) { //TODO when item is in scrapview, index changed and wrong item is opened //createExpandedView(mProductViewHolder, cursor.getPosition()); } else { // Populate name and code for a product when row collapsed productViewHolder.productName.setText(product.getName()); productViewHolder.productNo.setText(product.getCode()); productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty)); String rangeFormattedPrice = product.getPriceRangeFormattedValue(); if (product.getPriceRange().getMaxPrice() != null) { rangeFormattedPrice = StringUtils .isNotBlank(product.getPriceRange().getMaxPrice().getFormattedValue()) && StringUtils.isNotBlank(product.getPriceRange().getMinPrice().getFormattedValue()) ? product.getPriceRangeFormattedValue() : ""; if (StringUtils.isBlank(rangeFormattedPrice)) { if (product.getPriceRange().getMaxPrice().getValue() != null && product.getPriceRange().getMinPrice().getValue() != null) { rangeFormattedPrice = "$" + product.getPriceRange().getMinPrice().getValue() + ".00 - " + "$" + product.getPriceRange().getMaxPrice().getValue() + ".00"; } } } productViewHolder.productPrice.setText(rangeFormattedPrice); //Rating if (product.getAverageRating() != null) { productViewHolder.productItemRating.setVisibility(View.VISIBLE); productViewHolder.productItemRating.setRating(product.getAverageRating().floatValue()); productViewHolder.productItemRatingExpanded.setVisibility(View.VISIBLE); productViewHolder.productItemRatingExpanded.setRating(product.getAverageRating().floatValue()); } else { productViewHolder.productItemRating.setVisibility(View.GONE); productViewHolder.productItemRatingExpanded.setVisibility(View.GONE); } // Loading the product image loadProductImage(product.getImageThumbnailUrl(), productViewHolder.productImage, productViewHolder.productImageLoading, product.getCode()); productViewHolder.collapse(); if (product.getMultidimensional() != null && product.getMultidimensional()) { // Show arrow down with variants productViewHolder.productPriceTotal.setVisibility(View.GONE); productViewHolder.productImageViewCartIcon.setVisibility(View.GONE); productViewHolder.productImageViewExpandIcon.setVisibility(View.VISIBLE); productViewHolder.productItemAddQuantityLayout.setVisibility(View.GONE); productViewHolder.quantityEditText.setVisibility(View.GONE); productViewHolder.productAvailability.setVisibility(View.GONE); productViewHolder.productItemInStock.setVisibility(View.GONE); productViewHolder.productImageLoadingExpanded.setVisibility(View.VISIBLE); productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.VISIBLE); productViewHolder.productImageExpanded.setVisibility(View.GONE); productViewHolder.productAvailabilityExpanded.setVisibility(View.GONE); /** * Gray out button */ productViewHolder.setAddCartButton(true); } else { // Show cart icon without variants productViewHolder.productItemAddQuantityLayout.setVisibility(View.VISIBLE); productViewHolder.productPriceTotal.setVisibility(View.VISIBLE); productViewHolder.productPriceTotal.setText(productViewHolder.setTotalPrice(product.getPrice(), productViewHolder.quantityEditText.getText().toString())); productViewHolder.productImageViewCartIcon.setVisibility(View.VISIBLE); productViewHolder.productImageViewExpandIcon.setVisibility(View.GONE); productViewHolder.quantityEditText.setEnabled(true); productViewHolder.quantityEditText.setVisibility(View.VISIBLE); productViewHolder.productAvailability.setText(product.getStock().getStockLevel() + ""); productViewHolder.productItemInStock.setVisibility(View.VISIBLE); productViewHolder.setAddCartButton(true); if (product.isLowStock() || product.isOutOfStock()) { productViewHolder.productAvailability .setTextColor(getContext().getResources().getColor(R.color.product_item_low_stock)); productViewHolder.productItemInStock .setTextColor(getContext().getResources().getColor(R.color.product_item_low_stock)); productViewHolder.productAvailability .setContentDescription(getContext().getString(R.string.product_item_low_stock)); if (product.isOutOfStock()) { productViewHolder.quantityEditText.setEnabled(false); productViewHolder.quantityEditText.setText(""); } } if (product.isInStock()) { productViewHolder.productAvailability.setText(""); productViewHolder.productItemInStock .setTextColor(getContext().getResources().getColor(R.color.product_item_in_stock)); } } } /** * Product item row is collapsed and user click the arrow down icon to expand */ productViewHolder.productImageViewExpandIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Expanded getContext().getLoaderManager().restartLoader(0, null, getProductLoaderExpandView(product, getContext(), CommerceApplication.getContentServiceHelper(), new OnRequestListener() { @Override public void beforeRequest() { // Expanded productViewHolder.productImageLoadingExpanded.setVisibility(View.VISIBLE); productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.VISIBLE); productViewHolder.productImageExpanded.setVisibility(View.GONE); productViewHolder.productAvailabilityExpanded.setVisibility(View.GONE); UIUtils.showLoadingActionBar(getContext(), true); } @Override public void afterRequestBeforeResponse() { if (mCurrentSelectedViewHolder != null) { mCurrentSelectedViewHolder.collapse(); } mCurrentSelectedPosition = cursor.getPosition(); mCurrentSelectedViewHolder = productViewHolder; } @Override public void afterRequest(boolean isDataSynced) { productViewHolder.productImageLoadingExpanded.setVisibility(View.GONE); productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.GONE); productViewHolder.productImageExpanded.setVisibility(View.VISIBLE); productViewHolder.productAvailabilityExpanded.setVisibility(View.VISIBLE); productViewHolder.productImageLoading.setVisibility(View.GONE); UIUtils.showLoadingActionBar(getContext(), false); } }, new OnProductLoaded() { @Override public void onProductLoaded(ProductBase productBase, String productCodeFirstVariant) { if (productBase != null) { createExpandedView(mCurrentSelectedViewHolder, productBase); if (!mTriggerSpinnerOnChange) { mNbVariantLevels = populateVariants(mSpinnersVariants, productBase); if (StringUtils.isNotBlank(productCodeFirstVariant)) { selectVariant(productCodeFirstVariant); } } } } })); } }); /** * Detect when text is changed */ productViewHolder.quantityEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { if (cursor.getCount() > cursor.getPosition() && product != null) { if (product.getPrice() != null) { productViewHolder.productPriceTotal.setText(productViewHolder.setTotalPrice( product.getPrice(), productViewHolder.quantityEditText.getText().toString())); } } productViewHolder.setAddCartButton(true); } catch (NumberFormatException e) { Log.e(TAG, e.getLocalizedMessage()); } } @Override public void afterTextChanged(Editable s) { } }); /** * Detect when text is changed */ productViewHolder.quantityEditTextExpanded.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { if (cursor.getCount() > cursor.getPosition() && product.getPrice() != null) { productViewHolder.productPriceTotalExpanded .setText(productViewHolder.setTotalPrice(product.getPrice(), productViewHolder.quantityEditTextExpanded.getText().toString())); } productViewHolder.setAddCartButton(true); } catch (NumberFormatException e) { Log.e(TAG, e.getLocalizedMessage()); } } @Override public void afterTextChanged(Editable s) { } }); /** * Add to cart when user click on cartIcon in Product item collapsed row */ productViewHolder.productImageViewCartIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { addToCart(product.getCode(), productViewHolder.quantityEditText.getText().toString(), productViewHolder); productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty)); } }); productViewHolder.quantityEditText.setOnEditorActionListener(new SubmitListener() { @Override public void onSubmitAction() { addToCart(product.getCode(), productViewHolder.quantityEditText.getText().toString(), productViewHolder); productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty)); } }); /** * Product item row is expanded and user click the arrow up icon to collapse */ productViewHolder.productItemButtonCollpaseLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // collapsed productViewHolder.collapse(); mCurrentSelectedViewHolder.collapse(); } }); /** * Product item row is collapsed and user click on the main part of the row to navigate to the product detail page */ productViewHolder.productItemClickableLayoutCollapsed.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ProductHelper.redirectToProductDetail(getContext(), StringUtils.isNotBlank(getFirstVariantCode(product)) ? getFirstVariantCode(product) : product.getCode()); } }); /** * Product item row is collapsed and user click on the main part of the row to navigate to the product detail page */ productViewHolder.productItemClickableLayoutExpanded.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ProductHelper.redirectToProductDetail(getContext(), StringUtils.isNotBlank(getFirstVariantCode(product)) ? getFirstVariantCode(product) : product.getCode()); } }); }
From source file:com.syncedsynapse.kore2.ui.TVShowEpisodeListFragment.java
/** {@inheritDoc} */ @Override/* w w w . ja v a2s. c om*/ public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { LogUtils.LOGD(TAG, "onLoadFinished, Loader id: " + cursorLoader.getId() + ". Rows: " + cursor.getCount()); switch (cursorLoader.getId()) { case LOADER_SEASONS: adapter.setGroupCursor(cursor); if (cursor.getCount() == 1) { // Force collapse and expand the group, to force a reload of the episodes // cursor, otherwise if it is already expanded it won't reload (and won't // apply the filters to the episodes list) seasonsEpisodesListView.collapseGroup(0); seasonsEpisodesListView.expandGroup(0); } else if (cursor.getCount() > 0) { // Expand the first season that has unseen episodes cursor.moveToFirst(); do { int unwatched = cursor.getInt(SeasonsListQuery.EPISODE) - cursor.getInt(SeasonsListQuery.WATCHEDEPISODES); if (unwatched > 0) { LogUtils.LOGD(TAG, "Expanding group: " + cursor.getPosition()); seasonsEpisodesListView.collapseGroup(cursor.getPosition()); seasonsEpisodesListView.expandGroup(cursor.getPosition()); break; } } while (cursor.moveToNext()); } // To prevent the empty text from appearing on the first load, set it now emptyView.setText(getString(R.string.no_episodes_found)); break; default: // Check if the group cursor is set before setting the children cursor // Somehow, when poping the back stack, the children cursor are reloaded first... if (adapter.getCursor() != null) { adapter.setChildrenCursor(cursorLoader.getId(), cursor); } break; } }