List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.mariotaku.twidere.util.Utils.java
public static long[] getActivatedAccountIds(final Context context) { long[] accounts = new long[0]; if (context == null) return accounts; final String[] cols = new String[] { Accounts.ACCOUNT_ID }; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, Accounts.IS_ACTIVATED + "=1", null, Accounts.ACCOUNT_ID); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.ACCOUNT_ID); cur.moveToFirst();// www . j ava2 s.c o m accounts = new long[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getLong(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static String[] getActivatedAccountScreenNames(final Context context) { String[] accounts = new String[0]; if (context == null) return accounts; final String[] cols = new String[] { Accounts.USERNAME }; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, Accounts.IS_ACTIVATED + "=1", null, null); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USERNAME); cur.moveToFirst();/*w ww . j a v a 2 s. c o m*/ accounts = new String[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getString(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getAccountIds(final Context context) { long[] accounts = new long[0]; if (context == null) return accounts; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, new String[] { Accounts.USER_ID }, null, null, null); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USER_ID); cur.moveToFirst();/* ww w . j av a 2 s . c om*/ accounts = new long[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getLong(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getActivatedAccountIds(final Context context) { long[] accounts = new long[0]; if (context == null) return accounts; final String[] cols = new String[] { Accounts.USER_ID }; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, Accounts.IS_ACTIVATED + "=1", null, Accounts.USER_ID); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USER_ID); cur.moveToFirst();/* w ww .ja v a2 s . c om*/ accounts = new long[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getLong(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static List<TabSpec> getTabs(final Context context) { if (context == null) return Collections.emptyList(); final ArrayList<TabSpec> tabs = new ArrayList<TabSpec>(); final ContentResolver resolver = context.getContentResolver(); final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER); if (cur != null) { cur.moveToFirst();/*from w w w. ja v a 2 s . c o m*/ final int idx_name = cur.getColumnIndex(Tabs.NAME), idx_icon = cur.getColumnIndex(Tabs.ICON), idx_type = cur.getColumnIndex(Tabs.TYPE), idx_arguments = cur.getColumnIndex(Tabs.ARGUMENTS), idx_position = cur.getColumnIndex(Tabs.POSITION); while (!cur.isAfterLast()) { final int position = cur.getInt(idx_position) + HomeActivity.TAB_POSITION_MESSAGES + 1; final String icon_type = cur.getString(idx_icon); final String type = cur.getString(idx_type); final String name = cur.getString(idx_name); final Bundle args = parseArguments(cur.getString(idx_arguments)); args.putBoolean(INTENT_KEY_IS_HOME_TAB, true); final Class<? extends Fragment> fragment = CUSTOM_TABS_FRAGMENT_MAP.get(type); if (name != null && fragment != null) { tabs.add(new TabSpec(name, getTabIconObject(icon_type), fragment, args, position)); } cur.moveToNext(); } cur.close(); } return tabs; }
From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java
/** * This will fill the UI elements with information from the database * It also saves information for AsyncTasks to use later and manages the transform/flip button * * @param id the ID of the the card to be displayed * @return true if the UI was filled in, false otherwise *///from w w w.ja va2 s . c o m public void setInfoFromID(final long id) { /* If the views are null, don't attempt to fill them in */ if (mSetTextView == null) { return; } ImageGetter imgGetter = ImageGetterHelper.GlyphGetter(getActivity()); SQLiteDatabase database = DatabaseManager.getInstance(getActivity(), false).openDatabase(false); Cursor cCardById; try { cCardById = CardDbAdapter.fetchCards(new long[] { id }, null, database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } /* http://magiccards.info/scans/en/mt/55.jpg */ mCardName = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME)); mCardCMC = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_CMC)); mSetCode = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)); /* Start building a description */ addToDescription(getString(R.string.search_name), mCardName); try { mSetName = CardDbAdapter.getSetNameFromCode(mSetCode, database); addToDescription(getString(R.string.search_set), mSetName); } catch (FamiliarDbException e) { /* no set for you */ } try { mMagicCardsInfoSetCode = CardDbAdapter .getCodeMtgi(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)), database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } mCardNumber = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)); switch ((char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY))) { case 'C': case 'c': mSetTextView .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_common))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Common)); break; case 'U': case 'u': mSetTextView.setTextColor( ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_uncommon))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Uncommon)); break; case 'R': case 'r': mSetTextView .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_rare))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Rare)); break; case 'M': case 'm': mSetTextView .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_mythic))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Mythic)); break; case 'T': case 't': mSetTextView.setTextColor( ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_timeshifted))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Timeshifted)); break; } String sCost = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_MANACOST)); addToDescription(getString(R.string.search_mana_cost), sCost); CharSequence csCost = ImageGetterHelper.formatStringWithGlyphs(sCost, imgGetter); mCostTextView.setText(csCost); String sAbility = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ABILITY)); addToDescription(getString(R.string.search_text), sAbility); CharSequence csAbility = ImageGetterHelper.formatStringWithGlyphs(sAbility, imgGetter); mAbilityTextView.setText(csAbility); mAbilityTextView.setMovementMethod(LinkMovementMethod.getInstance()); String sFlavor = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_FLAVOR)); addToDescription(getString(R.string.search_flavor_text), sFlavor); CharSequence csFlavor = ImageGetterHelper.formatStringWithGlyphs(sFlavor, imgGetter); mFlavorTextView.setText(csFlavor); mNameTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME))); mCardType = CardDbAdapter.getTypeLine(cCardById); mTypeTextView.setText(mCardType); mSetTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET))); mArtistTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST))); String numberAndRarity = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)) + " (" + (char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY)) + ")"; mNumberTextView.setText(numberAndRarity); addToDescription(getString(R.string.search_type), CardDbAdapter.getTypeLine(cCardById)); addToDescription(getString(R.string.search_artist), cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST))); addToDescription(getString(R.string.search_collectors_number), cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER))); int loyalty = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_LOYALTY)); float p = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_POWER)); float t = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_TOUGHNESS)); if (loyalty != CardDbAdapter.NO_ONE_CARES) { if (loyalty == CardDbAdapter.X) { mPowTouTextView.setText("X"); } else { mPowTouTextView.setText(Integer.valueOf(loyalty).toString()); } } else if (p != CardDbAdapter.NO_ONE_CARES && t != CardDbAdapter.NO_ONE_CARES) { String powTouStr = ""; if (p == CardDbAdapter.STAR) powTouStr += "*"; else if (p == CardDbAdapter.ONE_PLUS_STAR) powTouStr += "1+*"; else if (p == CardDbAdapter.TWO_PLUS_STAR) powTouStr += "2+*"; else if (p == CardDbAdapter.SEVEN_MINUS_STAR) powTouStr += "7-*"; else if (p == CardDbAdapter.STAR_SQUARED) powTouStr += "*^2"; else if (p == CardDbAdapter.X) powTouStr += "X"; else { if (p == (int) p) { powTouStr += (int) p; } else { powTouStr += p; } } powTouStr += "/"; if (t == CardDbAdapter.STAR) powTouStr += "*"; else if (t == CardDbAdapter.ONE_PLUS_STAR) powTouStr += "1+*"; else if (t == CardDbAdapter.TWO_PLUS_STAR) powTouStr += "2+*"; else if (t == CardDbAdapter.SEVEN_MINUS_STAR) powTouStr += "7-*"; else if (t == CardDbAdapter.STAR_SQUARED) powTouStr += "*^2"; else if (t == CardDbAdapter.X) powTouStr += "X"; else { if (t == (int) t) { powTouStr += (int) t; } else { powTouStr += t; } } addToDescription(getString(R.string.search_power), powTouStr); mPowTouTextView.setText(powTouStr); } else { mPowTouTextView.setText(""); } boolean isMultiCard = false; switch (CardDbAdapter.isMultiCard(mCardNumber, cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)))) { case NOPE: isMultiCard = false; mTransformButton.setVisibility(View.GONE); mTransformButtonDivider.setVisibility(View.GONE); break; case TRANSFORM: isMultiCard = true; mTransformButton.setVisibility(View.VISIBLE); mTransformButtonDivider.setVisibility(View.VISIBLE); mTransformButton.setText(R.string.card_view_transform); break; case FUSE: isMultiCard = true; mTransformButton.setVisibility(View.VISIBLE); mTransformButtonDivider.setVisibility(View.VISIBLE); mTransformButton.setText(R.string.card_view_fuse); break; case SPLIT: isMultiCard = true; mTransformButton.setVisibility(View.VISIBLE); mTransformButtonDivider.setVisibility(View.VISIBLE); mTransformButton.setText(R.string.card_view_other_half); break; } if (isMultiCard) { if (mCardNumber.contains("a")) { mTransformCardNumber = mCardNumber.replace("a", "b"); } else if (mCardNumber.contains("b")) { mTransformCardNumber = mCardNumber.replace("b", "a"); } try { mTransformId = CardDbAdapter.getIdFromSetAndNumber(mSetCode, mTransformCardNumber, database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } if (mTransformId == -1) { mTransformButton.setVisibility(View.GONE); mTransformButtonDivider.setVisibility(View.GONE); } else { mTransformButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { releaseImageResources(true); mCardNumber = mTransformCardNumber; setInfoFromID(mTransformId); } }); } } mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_MULTIVERSEID)); /* Do we load the image immediately to the main page, or do it in a dialog later? */ if (mActivity.mPreferenceAdapter.getPicFirst()) { mImageScrollView.setVisibility(View.VISIBLE); mTextScrollView.setVisibility(View.GONE); mActivity.setLoading(); if (mAsyncTask != null) { mAsyncTask.cancel(true); } mAsyncTask = new FetchPictureTask(); ((FetchPictureTask) mAsyncTask).execute(MAIN_PAGE); } else { mImageScrollView.setVisibility(View.GONE); mTextScrollView.setVisibility(View.VISIBLE); } /* Figure out how large the color indicator should be. Medium text is 18sp, with a border its 22sp */ int dimension = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 22, getResources().getDisplayMetrics()); mColorIndicatorLayout.removeAllViews(); ColorIndicatorView civ = new ColorIndicatorView(this.getActivity(), dimension, dimension / 15, cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_COLOR)), sCost); if (civ.shouldInidcatorBeShown()) { mColorIndicatorLayout.setVisibility(View.VISIBLE); mColorIndicatorLayout.addView(civ); } else { mColorIndicatorLayout.setVisibility(View.GONE); } String allLanguageKeys[][] = { { Language.Chinese_Traditional, CardDbAdapter.KEY_NAME_CHINESE_TRADITIONAL, CardDbAdapter.KEY_MULTIVERSEID_CHINESE_TRADITIONAL }, { Language.Chinese_Simplified, CardDbAdapter.KEY_NAME_CHINESE_SIMPLIFIED, CardDbAdapter.KEY_MULTIVERSEID_CHINESE_SIMPLIFIED }, { Language.French, CardDbAdapter.KEY_NAME_FRENCH, CardDbAdapter.KEY_MULTIVERSEID_FRENCH }, { Language.German, CardDbAdapter.KEY_NAME_GERMAN, CardDbAdapter.KEY_MULTIVERSEID_GERMAN }, { Language.Italian, CardDbAdapter.KEY_NAME_ITALIAN, CardDbAdapter.KEY_MULTIVERSEID_ITALIAN }, { Language.Japanese, CardDbAdapter.KEY_NAME_JAPANESE, CardDbAdapter.KEY_MULTIVERSEID_JAPANESE }, { Language.Portuguese_Brazil, CardDbAdapter.KEY_NAME_PORTUGUESE_BRAZIL, CardDbAdapter.KEY_MULTIVERSEID_PORTUGUESE_BRAZIL }, { Language.Russian, CardDbAdapter.KEY_NAME_RUSSIAN, CardDbAdapter.KEY_MULTIVERSEID_RUSSIAN }, { Language.Spanish, CardDbAdapter.KEY_NAME_SPANISH, CardDbAdapter.KEY_MULTIVERSEID_SPANISH }, { Language.Korean, CardDbAdapter.KEY_NAME_KOREAN, CardDbAdapter.KEY_MULTIVERSEID_KOREAN } }; // Clear the translations first mTranslatedNames.clear(); // Add English Card.ForeignPrinting englishPrinting = new Card.ForeignPrinting(); englishPrinting.mLanguageCode = Language.English; englishPrinting.mName = mCardName; englishPrinting.mMultiverseId = mMultiverseId; mTranslatedNames.add(englishPrinting); // Add all the others for (String lang[] : allLanguageKeys) { Card.ForeignPrinting fp = new Card.ForeignPrinting(); fp.mLanguageCode = lang[0]; fp.mName = cCardById.getString(cCardById.getColumnIndex(lang[1])); fp.mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(lang[2])); if (fp.mName != null && !fp.mName.isEmpty()) { mTranslatedNames.add(fp); } } cCardById.close(); /* Find the other sets this card is in ahead of time, so that it can be remove from the menu if there is only one set */ Cursor cCardByName; try { cCardByName = CardDbAdapter.fetchCardByName(mCardName, new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_SET, CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID, CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_NUMBER }, false, database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } mPrintings = new LinkedHashSet<>(); mCardIds = new LinkedHashSet<>(); while (!cCardByName.isAfterLast()) { try { String number = cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_NUMBER)); if (!(number == null || number.length() == 0)) { number = " (" + number + ")"; } else { number = ""; } if (mPrintings.add(CardDbAdapter.getSetNameFromCode( cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_SET)), database) + number)) { mCardIds.add(cCardByName.getLong(cCardByName.getColumnIndex(CardDbAdapter.KEY_ID))); } } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } cCardByName.moveToNext(); } cCardByName.close(); /* If it exists in only one set, remove the button from the menu */ if (mPrintings.size() == 1) { mActivity.supportInvalidateOptionsMenu(); } DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); if (mShouldReportView) { reportAppIndexViewIfAble(); } }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java
/** * Create an {@link AsyncQueryHandler} for use with the * {@link MapInfoWindowAdapter}.//from w w w .j a v a2 s. co m */ private AsyncQueryHandler createInfowindowHandler(ContentResolver contentResolver) { return new AsyncQueryHandler(contentResolver) { StringBuilder mBuffer = new StringBuilder(); Formatter mFormatter = new Formatter(mBuffer, Locale.getDefault()); @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { MarkerModel model = mMarkers.get(cookie); mInfoAdapter.clearData(); if (model == null || cursor == null) { // query did not complete or incorrect data was loaded return; } final long time = UIUtils.getCurrentTime(getActivity()); switch (token) { case SessionAfterQuery._TOKEN: { extractSession(cursor, model, time); } break; case SandboxCompaniesAtQuery._TOKEN: { extractSandbox(cursor, model, time); } } // update the displayed window model.marker.showInfoWindow(); } private void extractSandbox(Cursor cursor, MarkerModel model, long time) { // get tracks data from cache: icon and color TrackModel track = mTracks.get(model.track); int color = (track != null) ? track.color : 0; int iconResId = 0; if (track != null) { iconResId = getResources().getIdentifier("track_" + ParserUtils.sanitizeId(track.name), "drawable", getActivity().getPackageName()); } if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); StringBuilder sb = new StringBuilder(); int count = 0; final int maxCompaniesDisplay = getResources() .getInteger(R.integer.sandbox_company_list_max_display); while (!cursor.isAfterLast() && count < maxCompaniesDisplay) { if (sb.length() > 0) { sb.append(", "); } sb.append(cursor.getString(SandboxCompaniesAtQuery.COMPANY_NAME)); count++; cursor.moveToNext(); } if (count >= maxCompaniesDisplay && !cursor.isAfterLast()) { // Additional sandbox companies to display sb.append(", …"); } mInfoAdapter.setSandbox(model.marker, model.label, color, iconResId, sb.length() > 0 ? sb.toString() : null); } else { // No active sandbox companies mInfoAdapter.setSandbox(model.marker, model.label, color, iconResId, null); } model.marker.showInfoWindow(); } private static final long SHOW_UPCOMING_TIME = 24 * 60 * 60 * 1000; // 24 hours private void extractSession(Cursor cursor, MarkerModel model, long time) { if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); String currentTitle = null; String nextTitle = null; String nextTime = null; final long blockStart = cursor.getLong(SessionAfterQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionAfterQuery.BLOCK_END); boolean inProgress = time >= blockStart && time <= blockEnd; if (inProgress) { // A session is running, display its name and optionally // the next session currentTitle = cursor.getString(SessionAfterQuery.SESSION_TITLE); //move to the next entry cursor.moveToNext(); } if (!cursor.isAfterLast()) { //There is a session coming up next, display only it if it's within 24 hours of the current time final long nextStart = cursor.getLong(SessionAfterQuery.BLOCK_START); if (nextStart < time + SHOW_UPCOMING_TIME) { nextTitle = cursor.getString(SessionAfterQuery.SESSION_TITLE); mBuffer.setLength(0); boolean showWeekday = !DateUtils.isToday(blockStart) && !UIUtils.isSameDayDisplay(UIUtils.getCurrentTime(getActivity()), blockStart, getActivity()); nextTime = DateUtils.formatDateRange(getActivity(), mFormatter, blockStart, blockStart, DateUtils.FORMAT_SHOW_TIME | (showWeekday ? DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY : 0), PrefUtils.getDisplayTimeZone(getActivity()).getID()).toString(); } } // populate the info window adapter mInfoAdapter.setSessionData(model.marker, model.label, currentTitle, nextTitle, nextTime, inProgress); } else { // No entries, display name of room only mInfoAdapter.setMarker(model.marker, model.label); } } }; }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java
/** * Populate the koopman fragment item details item when the loader has finished * @param loader the cursor loader//from w ww .j a v a 2s . c om * @param data data object containing one or more koopman rows with joined sollicitatie data */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { boolean validSollicitatie = false; // get the markt id from the sharedprefs SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); int marktId = settings.getInt(getContext().getString(R.string.sharedpreferences_key_markt_id), 0); // make the koopman details visible mKoopmanDetail.setVisibility(View.VISIBLE); // check koopman status String koopmanStatus = data.getString(data.getColumnIndex("koopman_status")); mMeldingVerwijderd = koopmanStatus.equals(getString(R.string.koopman_status_verwijderd)); // koopman photo Glide.with(getContext()) .load(data.getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL))) .error(R.drawable.no_koopman_image).into(mKoopmanFotoImage); // koopman naam String naam = data.getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS)) + " " + data.getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM)); mKoopmanVoorlettersAchternaamText.setText(naam); // koopman erkenningsnummer mErkenningsnummer = data .getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ERKENNINGSNUMMER)); mErkenningsnummerText.setText(mErkenningsnummer); // koopman sollicitaties View view = getView(); if (view != null) { LayoutInflater layoutInflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout placeholderLayout = (LinearLayout) view.findViewById(R.id.sollicitaties_placeholder); placeholderLayout.removeAllViews(); // get vaste producten for selected markt, and add multiple markt sollicitatie views to the koopman items while (!data.isAfterLast()) { // get vaste producten for selected markt if (marktId > 0 && marktId == data .getInt(data.getColumnIndex(MakkelijkeMarktProvider.Sollicitatie.COL_MARKT_ID))) { String[] productParams = getResources().getStringArray(R.array.array_product_param); for (String product : productParams) { mProducten.put(product, data.getInt(data.getColumnIndex(product))); } } // inflate sollicitatie layout and populate its view items View childLayout = layoutInflater.inflate(R.layout.dagvergunning_koopman_item_sollicitatie, null); // highlight the sollicitatie for the current markt if (data.getCount() > 1 && marktId > 0 && marktId == data .getInt(data.getColumnIndex(MakkelijkeMarktProvider.Sollicitatie.COL_MARKT_ID))) { childLayout.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary)); } // markt afkorting String marktAfkorting = data .getString(data.getColumnIndex(MakkelijkeMarktProvider.Markt.COL_AFKORTING)); TextView marktAfkortingText = (TextView) childLayout .findViewById(R.id.sollicitatie_markt_afkorting); marktAfkortingText.setText(marktAfkorting); // koopman sollicitatienummer String sollicitatienummer = data.getString( data.getColumnIndex(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER)); TextView sollicitatienummerText = (TextView) childLayout .findViewById(R.id.sollicitatie_sollicitatie_nummer); sollicitatienummerText.setText(sollicitatienummer); // koopman sollicitatie status String sollicitatieStatus = data.getString(data.getColumnIndex("sollicitatie_status")); TextView sollicitatieStatusText = (TextView) childLayout.findViewById(R.id.sollicitatie_status); sollicitatieStatusText.setText(sollicitatieStatus); if (sollicitatieStatus != null && !sollicitatieStatus.equals("?") && !sollicitatieStatus.equals("")) { sollicitatieStatusText .setTextColor(ContextCompat.getColor(getContext(), android.R.color.white)); sollicitatieStatusText.setBackgroundColor(ContextCompat.getColor(getContext(), Utility.getSollicitatieStatusColor(getContext(), sollicitatieStatus))); // check if koopman has at least one valid sollicitatie on selected markt if (marktId == data .getInt(data.getColumnIndex(MakkelijkeMarktProvider.Sollicitatie.COL_MARKT_ID))) { validSollicitatie = true; } } // add view and move cursor to next placeholderLayout.addView(childLayout, data.getPosition()); data.moveToNext(); } } // check valid sollicitatie mMeldingNoValidSollicitatie = !validSollicitatie; // get the date of today for the dag param SimpleDateFormat sdf = new SimpleDateFormat(getString(R.string.date_format_dag)); String dag = sdf.format(new Date()); // check multiple dagvergunningen Cursor dagvergunningen = getContext().getContentResolver().query( MakkelijkeMarktProvider.mUriDagvergunningJoined, null, "dagvergunning_doorgehaald != '1' AND " + MakkelijkeMarktProvider.mTableDagvergunning + "." + MakkelijkeMarktProvider.Dagvergunning.COL_MARKT_ID + " = ? AND " + MakkelijkeMarktProvider.Dagvergunning.COL_DAG + " = ? AND " + MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE + " = ? ", new String[] { String.valueOf(marktId), dag, mErkenningsnummer, }, null); mMeldingMultipleDagvergunningen = (dagvergunningen != null && dagvergunningen.moveToFirst()) && (dagvergunningen.getCount() > 1 || mDagvergunningId == -1); if (dagvergunningen != null) { dagvergunningen.close(); } // callback to dagvergunning activity to updaten the meldingen view ((Callback) getActivity()).onMeldingenUpdated(); } }
From source file:org.opendatakit.common.android.utilities.ODKDatabaseUtils.java
/** * Retrieve the list of user-defined columns for a tableId using the metadata * for that table. Returns the unit-of-retention and non-unit-of-retention * (grouping) columns.//w w w. j av a 2 s . c om * * @param db * @param tableId * @return */ public ArrayList<Column> getUserDefinedColumns(SQLiteDatabase db, String tableId) { ArrayList<Column> userDefinedColumns = new ArrayList<Column>(); String selection = ColumnDefinitionsColumns.TABLE_ID + "=?"; String[] selectionArgs = { tableId }; //@formatter:off String[] cols = { ColumnDefinitionsColumns.ELEMENT_KEY, ColumnDefinitionsColumns.ELEMENT_NAME, ColumnDefinitionsColumns.ELEMENT_TYPE, ColumnDefinitionsColumns.LIST_CHILD_ELEMENT_KEYS }; //@formatter:on Cursor c = null; try { c = db.query(DatabaseConstants.COLUMN_DEFINITIONS_TABLE_NAME, cols, selection, selectionArgs, null, null, ColumnDefinitionsColumns.ELEMENT_KEY + " ASC"); int elemKeyIndex = c.getColumnIndexOrThrow(ColumnDefinitionsColumns.ELEMENT_KEY); int elemNameIndex = c.getColumnIndexOrThrow(ColumnDefinitionsColumns.ELEMENT_NAME); int elemTypeIndex = c.getColumnIndexOrThrow(ColumnDefinitionsColumns.ELEMENT_TYPE); int listChildrenIndex = c.getColumnIndexOrThrow(ColumnDefinitionsColumns.LIST_CHILD_ELEMENT_KEYS); c.moveToFirst(); while (!c.isAfterLast()) { String elementKey = getIndexAsString(c, elemKeyIndex); String elementName = getIndexAsString(c, elemNameIndex); String elementType = getIndexAsString(c, elemTypeIndex); String listOfChildren = getIndexAsString(c, listChildrenIndex); userDefinedColumns.add(new Column(elementKey, elementName, elementType, listOfChildren)); c.moveToNext(); } } finally { if (c != null && !c.isClosed()) { c.close(); } } return userDefinedColumns; }