List of usage examples for android.database Cursor isNull
boolean isNull(int columnIndex);
true
if the value in the indicated column is null. From source file:com.rener.sea.DBHelper.java
private JSONArray getFlowchart() { JSONArray data;//from w ww .j a va2 s. c o m data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_FLOWCHART, new String[] { DBSchema.FLOWCHART_ID, DBSchema.FLOWCHART_FIRST_ID, DBSchema.FLOWCHART_NAME, DBSchema.FLOWCHART_END_ID, DBSchema.FLOWCHART_CREATOR_ID, DBSchema.FLOWCHART_VERSION }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.FLOWCHART_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.FLOWCHART_FIRST_ID, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.FLOWCHART_NAME, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.FLOWCHART_END_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.FLOWCHART_CREATOR_ID, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.FLOWCHART_VERSION, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getAppointments() { JSONArray data;/* ww w . j av a 2 s. c o m*/ data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_APPOINTMENTS, new String[] { DBSchema.APPOINTMENT_ID, DBSchema.APPOINTMENT_DATE, DBSchema.APPOINTMENT_TIME, DBSchema.APPOINTMENT_REPORT_ID, DBSchema.APPOINTMENT_PURPOSE, DBSchema.APPOINTMENT_MAKER_ID }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.APPOINTMENT_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.APPOINTMENT_DATE, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.APPOINTMENT_TIME, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.APPOINTMENT_REPORT_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.APPOINTMENT_PURPOSE, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.APPOINTMENT_MAKER_ID, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getLocation() { JSONArray data;//w w w . java 2 s .com data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_LOCATION, new String[] { DBSchema.LOCATION_ID, DBSchema.LOCATION_NAME, DBSchema.LOCATION_ADDRESS_ID, DBSchema.LOCATION_OWNER_ID, DBSchema.LOCATION_MANAGER_ID, DBSchema.LOCATION_LICENSE, DBSchema.LOCATION_AGENT_ID }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.LOCATION_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.LOCATION_NAME, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.LOCATION_ADDRESS_ID, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.LOCATION_OWNER_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.LOCATION_MANAGER_ID, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.LOCATION_LICENSE, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(6)) map.put(DBSchema.LOCATION_AGENT_ID, cursor.getString(6)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getPerson() { JSONArray data;//from w w w. j a v a2 s .c o m data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_PERSON, new String[] { DBSchema.PERSON_ID, DBSchema.PERSON_LAST_NAME1, DBSchema.PERSON_FIRST_NAME, DBSchema.PERSON_EMAIL, // DBSchema.PERSON_SPEC_ID, DBSchema.PERSON_LAST_NAME2, DBSchema.PERSON_MIDDLE_INITIAL, DBSchema.PERSON_PHONE_NUMBER }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.PERSON_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.PERSON_LAST_NAME1, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.PERSON_FIRST_NAME, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.PERSON_EMAIL, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } // try { // if (!cursor.isNull(4)) // map.put(DBSchema.PERSON_SPEC_ID, cursor.getString(4)); // } catch (JSONException e) { // e.printStackTrace(); // } try { if (!cursor.isNull(4)) map.put(DBSchema.PERSON_LAST_NAME2, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.PERSON_MIDDLE_INITIAL, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(6)) map.put(DBSchema.PERSON_PHONE_NUMBER, cursor.getString(6)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getReport() { JSONArray data;// ww w.jav a 2s . c o m data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_REPORT, new String[] { DBSchema.REPORT_ID, DBSchema.REPORT_CREATOR_ID, DBSchema.REPORT_LOCATION_ID, // DBSchema.REPORT_SUBJECT_ID, DBSchema.REPORT_FLOWCHART_ID, DBSchema.REPORT_NOTE, DBSchema.REPORT_DATE_FILED, DBSchema.REPORT_NAME, DBSchema.REPORT_STATUS }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.REPORT_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.REPORT_CREATOR_ID, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.REPORT_LOCATION_ID, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } // try { // if (!cursor.isNull(3)) // map.put(DBSchema.REPORT_SUBJECT_ID, cursor.getString(3)); // } catch (JSONException e) { // e.printStackTrace(); // } try { if (!cursor.isNull(3)) map.put(DBSchema.REPORT_FLOWCHART_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.REPORT_NOTE, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.REPORT_DATE_FILED, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(6)) map.put(DBSchema.REPORT_NAME, cursor.getString(6)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(7)) map.put(DBSchema.REPORT_STATUS, cursor.getString(7)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView vKeyId = (TextView) view.findViewById(R.id.subkey_item_key_id); TextView vKeyDetails = (TextView) view.findViewById(R.id.subkey_item_details); TextView vKeyExpiry = (TextView) view.findViewById(R.id.subkey_item_expiry); ImageView vCertifyIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_certify); ImageView vSignIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_sign); ImageView vEncryptIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_encrypt); ImageView vAuthenticateIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_authenticate); ImageView vEditImage = (ImageView) view.findViewById(R.id.subkey_item_edit_image); ImageView vStatus = (ImageView) view.findViewById(R.id.subkey_item_status); // not used:/* w w w. ja v a 2 s. c o m*/ ImageView deleteImage = (ImageView) view.findViewById(R.id.subkey_item_delete_button); deleteImage.setVisibility(View.GONE); long keyId = cursor.getLong(INDEX_KEY_ID); vKeyId.setText(KeyFormattingUtils.beautifyKeyId(keyId)); // may be set with additional "stripped" later on SpannableStringBuilder algorithmStr = new SpannableStringBuilder(); algorithmStr.append(KeyFormattingUtils.getAlgorithmInfo(context, cursor.getInt(INDEX_ALGORITHM), cursor.getInt(INDEX_KEY_SIZE), cursor.getString(INDEX_KEY_CURVE_OID))); SubkeyChange change = mSaveKeyringParcel != null ? mSaveKeyringParcel.getSubkeyChange(keyId) : null; if (change != null && (change.mDummyStrip || change.mMoveKeyToSecurityToken)) { if (change.mDummyStrip) { algorithmStr.append(", "); final SpannableString boldStripped = new SpannableString(context.getString(R.string.key_stripped)); boldStripped.setSpan(new StyleSpan(Typeface.BOLD), 0, boldStripped.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); algorithmStr.append(boldStripped); } if (change.mMoveKeyToSecurityToken) { algorithmStr.append(", "); final SpannableString boldDivert = new SpannableString(context.getString(R.string.key_divert)); boldDivert.setSpan(new StyleSpan(Typeface.BOLD), 0, boldDivert.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); algorithmStr.append(boldDivert); } } else { switch (SecretKeyType.fromNum(cursor.getInt(INDEX_HAS_SECRET))) { case GNU_DUMMY: algorithmStr.append(", "); algorithmStr.append(context.getString(R.string.key_stripped)); break; case DIVERT_TO_CARD: algorithmStr.append(", "); algorithmStr.append(context.getString(R.string.key_divert)); break; case PASSPHRASE_EMPTY: algorithmStr.append(", "); algorithmStr.append(context.getString(R.string.key_no_passphrase)); break; case UNAVAILABLE: // don't show this on pub keys //algorithmStr += ", " + context.getString(R.string.key_unavailable); break; } } vKeyDetails.setText(algorithmStr, TextView.BufferType.SPANNABLE); boolean isMasterKey = cursor.getInt(INDEX_RANK) == 0; if (isMasterKey) { vKeyId.setTypeface(null, Typeface.BOLD); } else { vKeyId.setTypeface(null, Typeface.NORMAL); } // Set icons according to properties vCertifyIcon.setVisibility(cursor.getInt(INDEX_CAN_CERTIFY) != 0 ? View.VISIBLE : View.GONE); vEncryptIcon.setVisibility(cursor.getInt(INDEX_CAN_ENCRYPT) != 0 ? View.VISIBLE : View.GONE); vSignIcon.setVisibility(cursor.getInt(INDEX_CAN_SIGN) != 0 ? View.VISIBLE : View.GONE); vAuthenticateIcon.setVisibility(cursor.getInt(INDEX_CAN_AUTHENTICATE) != 0 ? View.VISIBLE : View.GONE); boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; Date expiryDate = null; if (!cursor.isNull(INDEX_EXPIRY)) { expiryDate = new Date(cursor.getLong(INDEX_EXPIRY) * 1000); } // for edit key if (mSaveKeyringParcel != null) { boolean revokeThisSubkey = (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId)); if (revokeThisSubkey) { if (!isRevoked) { isRevoked = true; } } SaveKeyringParcel.SubkeyChange subkeyChange = mSaveKeyringParcel.getSubkeyChange(keyId); if (subkeyChange != null) { if (subkeyChange.mExpiry == null || subkeyChange.mExpiry == 0L) { expiryDate = null; } else { expiryDate = new Date(subkeyChange.mExpiry * 1000); } } vEditImage.setVisibility(View.VISIBLE); } else { vEditImage.setVisibility(View.GONE); } boolean isExpired; if (expiryDate != null) { isExpired = expiryDate.before(new Date()); Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiryCal.setTime(expiryDate); // convert from UTC to time zone of device expiryCal.setTimeZone(TimeZone.getDefault()); vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + DateFormat.getDateFormat(context).format(expiryCal.getTime())); } else { isExpired = false; vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none)); } // if key is expired or revoked... boolean isInvalid = isRevoked || isExpired; if (isInvalid) { vStatus.setVisibility(View.VISIBLE); vCertifyIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vSignIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vEncryptIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vAuthenticateIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); if (isRevoked) { vStatus.setImageResource(R.drawable.status_signature_revoked_cutout_24dp); vStatus.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); } else if (isExpired) { vStatus.setImageResource(R.drawable.status_signature_expired_cutout_24dp); vStatus.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); } } else { vStatus.setVisibility(View.GONE); vKeyId.setTextColor(mDefaultTextColor); vKeyDetails.setTextColor(mDefaultTextColor); vKeyExpiry.setTextColor(mDefaultTextColor); vCertifyIcon.clearColorFilter(); vSignIcon.clearColorFilter(); vEncryptIcon.clearColorFilter(); vAuthenticateIcon.clearColorFilter(); } vKeyId.setEnabled(!isInvalid); vKeyDetails.setEnabled(!isInvalid); vKeyExpiry.setEnabled(!isInvalid); }
From source file:com.rener.sea.DBHelper.java
public List<Person> getAllPersons() { SQLiteDatabase db = getReadableDatabase(); // Cursor cursor = db.query(DBSchema.TABLE_PERSON, new String[]{DBSchema.PERSON_ID}, // null, null, null, null, DBSchema.PERSON_FIRST_NAME + " COLLATE NOCASE", null); Cursor cursor = db.rawQuery("SELECT " + DBSchema.PERSON_ID + ", " + DBSchema.PERSON_FIRST_NAME + ", " + DBSchema.PERSON_MIDDLE_INITIAL + ", " + DBSchema.PERSON_LAST_NAME1 + ", " + DBSchema.PERSON_LAST_NAME2 + " " + "FROM " + DBSchema.TABLE_PERSON + " WHERE " + DBSchema.STATUS + " !=? AND " + DBSchema.PERSON_ID + " NOT IN (SELECT " + DBSchema.USER_PERSON_ID + " FROM " + DBSchema.TABLE_USERS + ") " + "ORDER BY " + DBSchema.PERSON_FIRST_NAME + " COLLATE NOCASE", new String[] { String.valueOf(-1) }); ArrayList<Person> persons; persons = new ArrayList<>(); // Log.i(this.toString(), "Cursor " + cursor); // Log.i(this.toString(), "Cursor count " + cursor.getCount()); if ((cursor != null) && (cursor.getCount() > 0)) { // Log.i(this.toString(), "Inside if"); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { persons.add(new Person(cursor.getLong(0), cursor.getString(1), (cursor.isNull(2) ? "" : cursor.getString(2)), cursor.getString(3), (cursor.isNull(4) ? "" : cursor.getString(4)), this)); // Log.i(this.toString(), "People created " + cursor.getLong(0)); }// w ww .j a v a 2 s . c o m db.close(); cursor.close(); } // Log.i(this.toString(), "persons not found"); return persons; }
From source file:org.restcomm.app.qoslib.Utils.QosInfo.java
/** * Called Internally to initialize all of the current measurements for every type of connected newtork * This is like a snapshot of everything at this moment in time * The information comes from various sources and it mainly fetched from the database for this call, or from APIs such as WiFi *///from w w w . j a v a2 s. co m private void updateFromDB() { Cursor sig_cursor = null; Cursor cell_cursor = null; try { Uri signalUri = UriMatch.SIGNAL_STRENGTHS.getContentUri(); Uri limitSignalUri = signalUri.buildUpon().appendQueryParameter("limit", "1").build(); // sig_cursor = managedQuery( Provider dbProvider = ReportManager.getInstance(context.getApplicationContext()).getDBProvider(); if (dbProvider == null) { return; } sig_cursor = dbProvider.query(UriMatch.SIGNAL_STRENGTHS.getContentUri(), null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC"); sig_cursor.moveToFirst(); Uri baseStationTable = (UriMatch.BASE_STATIONS .getContentUri()/*telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA ? UriMatchOld.BASE_STATIONS_CDMA.getContentUri() : UriMatchOld.BASE_STATIONS_GSM.getContentUri()*/ ); Uri limitBSUri = baseStationTable.buildUpon().appendQueryParameter("limit", "1").build(); // Cursor cell_cursor = managedQuery( cell_cursor = dbProvider.query(limitBSUri, null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC"); cell_cursor.moveToFirst(); int LowIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_LOW); int MidIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_MID); int HighIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_HIGH); int CodeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CODE); int BandIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_BAND); int ChanIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CHAN); int netTypeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.NET_TYPE); String netType = cell_cursor.getString(netTypeIndex); int bsLow = cell_cursor.getInt(LowIndex); int bsMid = cell_cursor.getInt(MidIndex); int bsHigh = cell_cursor.getInt(HighIndex); int bsCode = cell_cursor.getInt(CodeIndex); int bsBand = cell_cursor.getInt(BandIndex); int bsChan = cell_cursor.getInt(ChanIndex); if (netType.equals("cdma")) { if (LowIndex != -1) BID = bsLow; if (MidIndex != -1) NID = bsMid; if (HighIndex != -1) SID = bsHigh; } else if (netType.equals("gsm")) { if (LowIndex != -1) { RNC = bsMid; CellID = cell_cursor.getInt(LowIndex); } // the network Id is kept 0 for gsm phones if (HighIndex != -1) LAC = bsHigh; if (bsCode > 0 && bsCode < 1000) PSC = bsCode; else PSC = 0; if (bsBand > 0) Band = bsBand; else Band = 0; if (bsChan > 0) Channel = bsChan; else Channel = 0; } if (sig_cursor.getCount() != 0) { int signalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL); int signal2GIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL2G); int rsrpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRP); int rsrqIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRQ); int lteSnrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SNR); int lteSignalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SIGNAL); int lteCqiIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_CQI); int ecioIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECI0); int ecnoIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECN0); int snrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SNR); int berIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.BER); int rscpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.RSCP); int tierIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.COVERAGE); Integer tier = sig_cursor.isNull(tierIndex) ? null : sig_cursor.getInt(tierIndex); Integer rssi = sig_cursor.isNull(signalIndex) ? null : sig_cursor.getInt(signalIndex); Integer rssi2G = sig_cursor.isNull(signal2GIndex) ? null : sig_cursor.getInt(signal2GIndex); Integer rsrp = sig_cursor.isNull(rsrpIndex) ? null : sig_cursor.getInt(rsrpIndex); Float lteSnr = (sig_cursor.isNull(lteSnrIndex) ? null : (float) sig_cursor.getInt(lteSnrIndex)); Integer lteSignal = sig_cursor.isNull(lteSignalIndex) ? null : sig_cursor.getInt(lteSignalIndex); Integer lteCqi = sig_cursor.isNull(lteCqiIndex) ? null : sig_cursor.getInt(lteCqiIndex); Integer rsrq = sig_cursor.isNull(rsrqIndex) ? null : sig_cursor.getInt(rsrqIndex); Integer eci0 = sig_cursor.isNull(ecioIndex) ? null : sig_cursor.getInt(ecioIndex); Integer ecn0 = sig_cursor.isNull(ecnoIndex) ? null : sig_cursor.getInt(ecnoIndex); Integer snr = sig_cursor.isNull(snrIndex) ? null : sig_cursor.getInt(snrIndex); Integer ber = sig_cursor.isNull(berIndex) ? null : sig_cursor.getInt(berIndex); Integer rscp = sig_cursor.isNull(rscpIndex) ? null : sig_cursor.getInt(rscpIndex); if (eci0 != null && (netType.equals("cdma") || netType.equals("lte")) && eci0 <= -30) eci0 = (eci0 / 10); else if (ecn0 != null && ecn0 > 1 && ecn0 < 60 && netType.equals("gsm")) ecn0 = -(ecn0 / 2); else if (eci0 != null && eci0 > 1 && eci0 < 60 && netType.equals("gsm")) eci0 = -(eci0 / 2); // if (lteSnr != null && lteSnr > 1 && lteSnr < 500) // lteSnr = (lteSnr+5)/10; if (lteSignal != null && lteSignal > -120 && lteSignal < -20) // rssi == lteSignal) { LTE_RSSI = simpleValidate(lteSignal); RSSI = 0; } else if (rssi == null || rssi == -255) RSSI = 0; else if (rssi == -256) RSSI = -256; else { String name = "RSCP: "; int spacing = 15; if (netType.equals("gsm") && (tier == 3 || tier == 4)) { RSCP = rssi; RSSI = 0; } else { RSSI = rssi; RSCP = 0; } LTE_RSSI = 0; } if (netType.equals("cdma") && rssi2G != null && rssi2G < -30 && rssi2G >= -120) CDMA_RSSI = rssi2G; if (tier == 5) { if (lteSnr != null && lteSnr > -101) lteSnr = lteSnr / 10; if (rsrq != null && rsrq > 0) rsrq = -rsrq; LTE_RSRP = simpleValidate(rsrp); LTE_RSRQ = simpleValidate(rsrq); LTE_SNR = simpleValidate(lteSnr); LTE_CQI = simpleValidate(lteCqi); ECIO = simpleValidate(eci0); ECNO = simpleValidate(ecn0); } //nerdview.setValue(0, "RSCP", simpleValidate(rscp, "RSCP", "dBm")); //BER = simpleValidate(ber); SNR = simpleValidate(snr); if (rsrp != null && rsrp <= -10 && rsrp >= -140 && tier == 5) { LTEIdentity = ReportManager.getInstance(context.getApplicationContext()).getNeighbors(); } else { LTEIdentity = null; Neighbors = ReportManager.getInstance(context.getApplicationContext()).getNeighbors(); } } location = ReportManager.getInstance(context.getApplicationContext()).getLastKnownLocation(); try { JSONObject serviceMode = PhoneState.getServiceMode(); if (serviceMode != null && serviceMode.getLong("time") + 5000 > System.currentTimeMillis()) { if (serviceMode.has("rrc") && serviceMode.getString("rrc").length() > 1) { RRC = serviceMode.getString("rrc"); } else RRC = null; if (serviceMode.has("band") && serviceMode.getString("band").length() > 0) { Band = Integer.parseInt(serviceMode.getString("band")); } //else if (serviceMode.has("freq") && serviceMode.getString("freq").length() > 0) { Band = Integer.parseInt(serviceMode.getString("freq")); } else Band = 0; if (serviceMode.has("channel") && serviceMode.getString("channel").length() > 0) { Channel = Integer.parseInt(serviceMode.getString("channel")); } else Channel = 0; } else { RRC = null; Band = 0; Channel = 0; } TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Service.TELEPHONY_SERVICE); String carrier = telephonyManager.getNetworkOperatorName(); String mcc = "0", mnc = "0"; if (telephonyManager.getNetworkOperator() != null && telephonyManager.getNetworkOperator().length() >= 4) { mcc = telephonyManager.getNetworkOperator().substring(0, 3); mnc = telephonyManager.getNetworkOperator().substring(3); } int networkType = telephonyManager.getNetworkType(); int networkTier = PhoneState.getNetworkGeneration(networkType); String nettype = PhoneState.getNetworkName(telephonyManager.getNetworkType()); String data = PhoneState.getNetworkName(telephonyManager.getNetworkType()) + " "; int dataState = telephonyManager.getDataState(); if (dataState == TelephonyManager.DATA_CONNECTED) { String activity = getActivityName(telephonyManager.getDataActivity()); data += activity; } else if (telephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) { String state = getStateName(telephonyManager.getDataState()); data += state; } Data = data; Carrier = carrier; Date date = new Date(System.currentTimeMillis()); final String dateStr = DateFormat.getDateFormat(context).format(date); final String timeStr = dateStr + " " + DateFormat.getTimeFormat(context).format(date); Time = timeStr; MCC = Integer.parseInt(mcc); MNC = Integer.parseInt(mnc); // Tell the service we're watching the signal, so keep it updated Intent intent = new Intent(CommonIntentActionsOld.VIEWING_SIGNAL); context.sendBroadcast(intent); WifiInfo wifiinfo = getWifiInfo(); WifiConfiguration wifiConfig = getWifiConfig(); setWifi(wifiinfo, wifiConfig); // Instantiate only the relevant Network type if (netType.equals("cdma")) connectedNetwork = CDMAInfo = new CDMAInfo(this); else if (netType.equals("gsm") && networkTier < 3) connectedNetwork = GSMInfo = new GSMInfo(this); else if (netType.equals("gsm") && networkTier < 5) connectedNetwork = WCDMAInfo = new WCDMAInfo(this); if (networkTier == 5) // LTE connectedNetwork = LTEInfo = new LTEInfo(this); if (wifiConfig != null) connectedNetwork = WiFiInfo = new WIFIInfo(this); // The most relevant network ends up in NetworkInfo } catch (Exception e) { } } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "updateNerdViewFromDB", "exception querying signal data: " + e.getMessage()); } finally { if (cell_cursor != null) cell_cursor.close(); if (sig_cursor != null) sig_cursor.close(); } }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * @param db//from w w w. j a va 2 s. c om * @param tableId * @param rowId * @return the sync state of the row (see {@link SyncState}), or null if the * row does not exist. Rows are required to have non-null sync states. * @throws IllegalStateException if the row has a null sync state or has * 2+ conflicts or checkpoints and * those do not have matching sync states! */ public SyncState getSyncState(OdkConnectionInterface db, String tableId, String rowId) throws IllegalStateException { Cursor c = null; try { c = db.query(tableId, new String[] { DataTableColumns.SYNC_STATE }, K_DATATABLE_ID_EQUALS_PARAM, new Object[] { rowId }, null, null, null, null); if (c.moveToFirst()) { int syncStateIndex = c.getColumnIndex(DataTableColumns.SYNC_STATE); if (c.isNull(syncStateIndex)) { throw new IllegalStateException(t + ": row had a null sync state!"); } String val = CursorUtils.getIndexAsString(c, syncStateIndex); while (c.moveToNext()) { if (c.isNull(syncStateIndex)) { throw new IllegalStateException(t + ": row had a null sync state!"); } String otherVal = CursorUtils.getIndexAsString(c, syncStateIndex); if (!val.equals(otherVal)) { throw new IllegalStateException(t + ": row with 2+ conflicts or checkpoints does " + "not have matching sync states!"); } } return SyncState.valueOf(val); } return null; } finally { if (c != null && !c.isClosed()) { c.close(); } } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void sortChannels() { ContentResolver cr = getContentResolver(); StringBuilder where = new StringBuilder(TvBrowserContentProvider.CHANNEL_KEY_SELECTION); where.append("=1"); LinearLayout main = (LinearLayout) getLayoutInflater().inflate(R.layout.channel_sort_list, getParentViewGroup(), false); Button sortAlphabetically = (Button) main.findViewById(R.id.channel_sort_alpabetically); final DynamicListView channelSort = (DynamicListView) main.findViewById(R.id.channel_sort); String[] projection = { TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.CHANNEL_KEY_NAME, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER, TvBrowserContentProvider.CHANNEL_KEY_SELECTION, TvBrowserContentProvider.CHANNEL_KEY_LOGO }; Cursor channels = cr.query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, projection, where.toString(), null, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER); final ArrayList<SortInterface> channelSource = new ArrayList<SortInterface>(); if (channels.moveToFirst()) { do {/*w ww . j a va 2s . c o m*/ int key = channels.getInt(0); String name = channels.getString(1); int order = 0; if (!channels.isNull(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER))) { order = channels .getInt(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER)); } Bitmap channelLogo = UiUtils.createBitmapFromByteArray( channels.getBlob(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_LOGO))); if (channelLogo != null) { BitmapDrawable l = new BitmapDrawable(getResources(), channelLogo); ColorDrawable background = new ColorDrawable(SettingConstants.LOGO_BACKGROUND_COLOR); background.setBounds(0, 0, channelLogo.getWidth() + 2, channelLogo.getHeight() + 2); LayerDrawable logoDrawable = new LayerDrawable(new Drawable[] { background, l }); logoDrawable.setBounds(background.getBounds()); l.setBounds(2, 2, channelLogo.getWidth(), channelLogo.getHeight()); channelLogo = UiUtils.drawableToBitmap(logoDrawable); } channelSource.add(new ChannelSort(key, name, order, channelLogo)); } while (channels.moveToNext()); channels.close(); final Comparator<SortInterface> sortComparator = new Comparator<SortInterface>() { @Override public int compare(SortInterface lhs, SortInterface rhs) { if (lhs.getSortNumber() < rhs.getSortNumber()) { return -1; } else if (lhs.getSortNumber() > rhs.getSortNumber()) { return 1; } return 0; } }; Collections.sort(channelSource, sortComparator); // create default logo for channels without logo final Bitmap defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); final StableArrayAdapter<SortInterface> aa = new StableArrayAdapter<SortInterface>(TvBrowser.this, R.layout.channel_sort_row, channelSource) { public View getView(int position, View convertView, ViewGroup parent) { ChannelSort value = (ChannelSort) getItem(position); ViewHolder holder = null; if (convertView == null) { LayoutInflater mInflater = (LayoutInflater) getContext() .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.channel_sort_row, getParentViewGroup(), false); holder.mTextView = (TextView) convertView.findViewById(R.id.row_of_channel_sort_text); holder.mSortNumber = (TextView) convertView.findViewById(R.id.row_of_channel_sort_number); holder.mLogo = (ImageView) convertView.findViewById(R.id.row_of_channel_sort_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.mTextView.setText(value.getName()); String sortNumber = String.valueOf(value.getSortNumber()); if (value.getSortNumber() == 0) { sortNumber = "-"; } sortNumber += "."; holder.mSortNumber.setText(sortNumber); Bitmap logo = value.getLogo(); if (logo != null) { holder.mLogo.setImageBitmap(logo); } else { holder.mLogo.setImageBitmap(defaultLogo); } return convertView; } }; channelSort.setAdapter(aa); channelSort.setArrayList(channelSource); channelSort.setSortDropListener(new SortDropListener() { @Override public void dropped(int originalPosition, int position) { int startIndex = originalPosition; int endIndex = position; int droppedPos = position; if (originalPosition > position) { startIndex = position; endIndex = originalPosition; } int previousNumber = 0; if (startIndex > 0) { previousNumber = aa.getItem(startIndex - 1).getSortNumber(); } int firstVisible = channelSort.getFirstVisiblePosition(); for (int i = startIndex; i <= endIndex; i++) { if (i == droppedPos || aa.getItem(i).getSortNumber() != 0) { aa.getItem(i).setSortNumber(++previousNumber); if (i >= firstVisible) { View line = channelSort.getChildAt(i - firstVisible); if (line != null) { ((TextView) line.findViewById(R.id.row_of_channel_sort_number)) .setText(String.valueOf(previousNumber) + "."); } } } } } }); channelSort.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapterView, final View view, final int position, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); LinearLayout numberSelection = (LinearLayout) getLayoutInflater() .inflate(R.layout.sort_number_selection, getParentViewGroup(), false); mSelectionNumberChanged = false; final NumberPicker number = (NumberPicker) numberSelection.findViewById(R.id.sort_picker); number.setMinValue(1); number.setMaxValue(channelSource.size()); number.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); number.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { mSelectionNumberChanged = true; } }); final EditText numberAlternative = (EditText) numberSelection .findViewById(R.id.sort_entered_number); builder.setView(numberSelection); final ChannelSort selection = (ChannelSort) channelSource.get(position); TextView name = (TextView) numberSelection.findViewById(R.id.sort_picker_channel_name); name.setText(selection.getName()); if (selection.getSortNumber() > 0) { if (selection.getSortNumber() < channelSource.size() + 1) { number.setValue(selection.getSortNumber()); } else { numberAlternative.setText(String.valueOf(selection.getSortNumber())); } } builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String test = numberAlternative.getText().toString().trim(); if (test.length() == 0 || mSelectionNumberChanged) { selection.setSortNumber(number.getValue()); } else { try { selection.setSortNumber(Integer.parseInt(test)); } catch (NumberFormatException e1) { } } Collections.sort(channelSource, sortComparator); aa.notifyDataSetChanged(); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } }); sortAlphabetically.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collections.sort(channelSource, new Comparator<SortInterface>() { @Override public int compare(SortInterface lhs, SortInterface rhs) { return lhs.getName().compareToIgnoreCase(rhs.getName()); } }); for (int i = 0; i < channelSource.size(); i++) { channelSource.get(i).setSortNumber(i + 1); } aa.notifyDataSetChanged(); } }); AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); builder.setTitle(R.string.action_sort_channels); builder.setView(main); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean somethingChanged = false; for (SortInterface selection : channelSource) { if (((ChannelSort) selection).wasChanged()) { somethingChanged = true; ContentValues values = new ContentValues(); values.put(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER, selection.getSortNumber()); getContentResolver().update( ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS, ((ChannelSort) selection).getKey()), values, null, null); } } if (somethingChanged) { updateProgramListChannelBar(); } } }); builder.setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); } }