List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:com.google.android.apps.muzei.SourceSubscriberService.java
@Override protected void onHandleIntent(Intent intent) { if (intent == null || intent.getAction() == null) { return;/* w w w . j ava 2s. c o m*/ } String action = intent.getAction(); if (!ACTION_PUBLISH_STATE.equals(action)) { return; } // Handle API call from source String token = intent.getStringExtra(EXTRA_TOKEN); ComponentName selectedSource = SourceManager.getSelectedSource(this); if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) { Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for " + selectedSource); return; } SourceState state = null; if (intent.hasExtra(EXTRA_STATE)) { Bundle bundle = intent.getBundleExtra(EXTRA_STATE); if (bundle != null) { state = SourceState.fromBundle(bundle); } } if (state == null) { // If there is no state, there is nothing to change return; } ContentValues values = new ContentValues(); values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString()); values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true); values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription()); values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable()); JSONArray commandsSerialized = new JSONArray(); int numSourceActions = state.getNumUserCommands(); boolean supportsNextArtwork = false; for (int i = 0; i < numSourceActions; i++) { UserCommand command = state.getUserCommandAt(i); if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) { supportsNextArtwork = true; } else { commandsSerialized.put(command.serialize()); } } values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork); values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString()); ContentResolver contentResolver = getContentResolver(); Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { selectedSource.flattenToShortString() }, null, null); if (existingSource != null && existingSource.moveToFirst()) { Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, existingSource.getLong(0)); contentResolver.update(sourceUri, values, null, null); } else { contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values); } if (existingSource != null) { existingSource.close(); } Artwork artwork = state.getCurrentArtwork(); if (artwork != null) { artwork.setComponentName(selectedSource); contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues()); // Download the artwork contained from the newly published SourceState startService(TaskQueueService.getDownloadCurrentArtworkIntent(this)); } }
From source file:com.openerp.base.res.Res_PartnerSyncHelper.java
public void syncContacts(Context context, Account account) { HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>(); mContentResolver = context.getContentResolver(); int company_id = Integer.parseInt(OpenERPAccountManager.currentUser(context).getCompany_id()); RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .build();//from w ww . j a v a 2s.c o m // Load the local contacts Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(); Cursor cursor = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, SYNC1_PARTNER_ID }, null, null, null); while (cursor.moveToNext()) { SyncEntry entry = new SyncEntry(); entry.partner_id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); localContacts.put(cursor.getString(1), entry); } cursor.close(); try { Res_PartnerDBHelper dbHelper = new Res_PartnerDBHelper(context); HashMap<String, Object> res = dbHelper.search(dbHelper, new String[] { "phone != ? ", "OR", "mobile != ? ", "OR", "email != ?" }, new String[] { "false", "false", "false" }); // checking if records exist? int total = Integer.parseInt(res.get("total").toString()); if (total > 0) { @SuppressWarnings("unchecked") List<HashMap<String, Object>> rows = (List<HashMap<String, Object>>) res.get("records"); for (HashMap<String, Object> row_data : rows) { if (!(row_data.get("company_id").toString()).equalsIgnoreCase("false")) { JSONArray db_company_id = new JSONArray(row_data.get("company_id").toString()); String com_id = db_company_id.getJSONArray(0).getString(0).toString(); if (com_id.equalsIgnoreCase(String.valueOf(company_id))) { String partnerID = row_data.get("id").toString(); String name = (row_data.get("name").toString()).replaceAll("[^\\w\\s]", ""); String mail = row_data.get("email").toString(); String number = row_data.get("phone").toString(); String mobile = row_data.get("mobile").toString(); String website = row_data.get("website").toString(); String street = row_data.get("street").toString(); String street2 = row_data.get("street2").toString(); String city = row_data.get("city").toString(); String zip = row_data.get("zip").toString(); String company = "OpenERP"; String image = row_data.get("image_small").toString(); if (localContacts.get(row_data.get("id").toString()) == null) { addContact(context, account, partnerID, name, mail, number, mobile, website, street, street2, city, zip, company, image); } } } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java
/** * Returns a new instance of {@link Author} with the data of the touple * currently pointed at by the {@link Cursor} passed as argument. The * data of the cursor is expected to appear as in {@link BookAuthorQuery}. * * @param cursor the {@link Cursor} from which the data of the * {@link Author} will be retrieved. * @return a new instance of {@link Author} with the data of the touple * currently pointed at by the {@link Cursor} passed as argument. *//*from ww w .j ava 2 s.c o m*/ private Author newAuthor(Cursor cursor) { if (cursor == null) { return null; } Author author = new Author(); author.setId(cursor.getLong(BookAuthorQuery.COL_ID)); author.setName(cursor.getString(BookAuthorQuery.COL_NAME)); return author; }
From source file:alberthsu.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from w w w .jav a2s. co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java
void showMenuForObj(int position) { //this first cursor is the internal one Cursor cursor = (Cursor) mObjects.getItem(position); long objId = cursor.getLong(0); DbObj obj = mMusubi.objForId(objId); FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev);/* ww w. jav a 2 s .com*/ } ft.addToBackStack(null); // Create and show the dialog. DialogFragment newFragment = new ObjMenuDialogFragment(obj); newFragment.show(ft, "dialog"); }
From source file:com.example.danstormont.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from w w w . j a va2 s . co m * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java
/** * Returns a new instance of {@link Category} with the data of the touple * currently pointed at by the {@link Cursor} passed as argument. The * data of the cursor is expected to appear as in {@link BookCategoryQuery}. * * @param cursor the {@link Cursor} from which the data of the * {@link Category} will be retrieved. * @return a new instance of {@link Category} with the data of the touple * currently pointed at by the {@link Cursor} passed as argument. *///from w ww . j a v a2 s. c o m private Category newCategory(Cursor cursor) { if (cursor == null) { return null; } Category author = new Category(); author.setId(cursor.getLong(BookCategoryQuery.COL_ID)); author.setName(cursor.getString(BookCategoryQuery.COL_NAME)); return author; }
From source file:com.moez.QKSMS.mmssms.Transaction.java
public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts, String subject) throws MmsException { final SendReq sendRequest = new SendReq(); // create send request addresses for (int i = 0; i < recipients.length; i++) { final EncodedStringValue[] phoneNumbers = EncodedStringValue.extract(recipients[i]); if (phoneNumbers != null && phoneNumbers.length > 0) { sendRequest.addTo(phoneNumbers[0]); }// w w w. ja v a2s .co m } if (subject != null) { sendRequest.setSubject(new EncodedStringValue(subject)); } sendRequest.setDate(Calendar.getInstance().getTimeInMillis() / 1000L); try { sendRequest.setFrom(new EncodedStringValue(Utils.getMyPhoneNumber(context))); } catch (Exception e) { // my number is nothing } final PduBody pduBody = new PduBody(); // assign parts to the pdu body which contains sending data if (parts != null) { for (int i = 0; i < parts.length; i++) { MMSPart part = parts[i]; if (part != null) { try { PduPart partPdu = new PduPart(); partPdu.setName(part.Name.getBytes()); partPdu.setContentType(part.MimeType.getBytes()); if (part.MimeType.startsWith("text")) { partPdu.setCharset(CharacterSets.UTF_8); } partPdu.setData(part.Data); pduBody.addPart(partPdu); } catch (Exception e) { } } } } ByteArrayOutputStream out = new ByteArrayOutputStream(); SmilXmlSerializer.serialize(SmilHelper.createSmilDocument(pduBody), out); PduPart smilPart = new PduPart(); smilPart.setContentId("smil".getBytes()); smilPart.setContentLocation("smil.xml".getBytes()); smilPart.setContentType(ContentType.APP_SMIL.getBytes()); smilPart.setData(out.toByteArray()); pduBody.addPart(0, smilPart); sendRequest.setBody(pduBody); // create byte array which will actually be sent final PduComposer composer = new PduComposer(context, sendRequest); final byte[] bytesToSend; try { bytesToSend = composer.make(); } catch (OutOfMemoryError e) { throw new MmsException("Out of memory!"); } MessageInfo info = new MessageInfo(); info.bytes = bytesToSend; if (saveMessage) { try { PduPersister persister = PduPersister.getPduPersister(context); info.location = persister.persist(sendRequest, Uri.parse("content://mms/outbox"), true, settings.getGroup(), null); } catch (Exception e) { if (LOCAL_LOGV) Log.v(TAG, "error saving mms message"); Log.e(TAG, "exception thrown", e); // use the old way if something goes wrong with the persister insert(context, recipients, parts, subject); } } try { Cursor query = context.getContentResolver().query(info.location, new String[] { "thread_id" }, null, null, null); if (query != null && query.moveToFirst()) { info.token = query.getLong(query.getColumnIndex("thread_id")); } else { // just default sending token for what I had before info.token = 4444L; } } catch (Exception e) { Log.e(TAG, "exception thrown", e); info.token = 4444L; } return info; }
From source file:com.HskPackage.HskNamespace.HSK1ProjectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from www. j a v a 2 s . com final TextView codice = (TextView) findViewById(R.id.codice); final Button carattere = (Button) findViewById(R.id.carattere); final TextView fonetica = (TextView) findViewById(R.id.fonetica); final TextView significato = (TextView) findViewById(R.id.significato); /*********** CREATE A DATABASE ******************************************************/ final String DB_PATH = "/data/data/com.HskPackage.HskNamespace/"; final String DB_NAME = "chineseX.db"; SQLiteDatabase db = null; boolean exists = (new File(DB_PATH + DB_NAME)).exists(); AssetManager assetManager = getAssets(); if (!exists) { try { InputStream in = assetManager.open(DB_NAME); OutputStream out = new FileOutputStream(DB_PATH + DB_NAME); copyFile(in, out); in.close(); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } File dbFile = new File(DB_PATH + DB_NAME); db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); } else { File dbFile = new File(DB_PATH + DB_NAME); db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); } final Integer valore = 1; //String query = "SELECT * FROM chineseX"; String query = "SELECT * FROM chineseX where _id = ? "; String[] selectionArgs = { valore.toString() }; Cursor cursor = null; cursor = db.rawQuery(query, selectionArgs); //cursor = db.rawQuery(query, null); int count = cursor.getCount(); System.out.println("il numero di dati contenuti nel database " + count); while (cursor.moveToNext()) { long id = cursor.getLong(0); System.out.println("Questo l'ID ====>" + id); scodice = cursor.getString(1); codice.setText(scodice); System.out.println("Questo il codice ====>" + codice); scarattere = cursor.getString(2); carattere.setText(scarattere); System.out.println("Questo il carattere ====>" + carattere); sfonetica = cursor.getString(3); fonetica.setText(sfonetica); System.out.println("Questo il fonet ====>" + fonetica); ssignificato = cursor.getString(4); significato.setText("?? - Visualizza Significato"); System.out.println("Questo il carattere ====>" + ssignificato); } //fine db.close(); //set up sound button final MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.hangout_ringtone); //final MediaPlayer chword001 = MediaPlayer.create(this, R.raw.ayi001); /* // set up change Images miaImmagine = (ImageView) findViewById(R.id.Image); // dichiaro l'oggetto image view miaImmagine.setImageResource(R.drawable.uno1); // associo l'immagine alla figura uno // setto un evento di cattura del click sull'immagine miaImmagine.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { //chword001.start(); } }) ; */ final Intent first = new Intent(this, Activity2.class); final Intent immagine = new Intent(this, Activity3.class); /* * Un intent definito nella javadoc della classe android.content.Intent come una * "descrizione astratta dell'operazione da eseguire". * E un intent ESPLICITO perch cosciamo il destinatario. * Passiamo come parametri il context attuale ed la classe che identifica l'activity di destinazione. * E' importante che la classe sia registrata nell'AndroidManifest.xml * */ Button b = (Button) this.findViewById(R.id.button1); Button b2 = (Button) this.findViewById(R.id.button2); Button b3 = (Button) this.findViewById(R.id.carattere); b.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 1; valore = valore + 1; if (valore >= 153) { valore = 1; } System.out.println("AVANTI" + valore); first.putExtra("AVANTI", valore); startActivity(first); finish(); mpButtonClick.start(); } }); b2.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 153; System.out.println("AVANTI == >" + valore); first.putExtra("AVANTI", valore); startActivity(first); finish(); mpButtonClick.start(); } }); b3.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 1; System.out.println("AVANTI" + valore); immagine.putExtra("AVANTI", valore); startActivity(immagine); finish(); mpButtonClick.start(); } }); }
From source file:com.example.riteden.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from w w w . j a v a2 s .c om * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db //WeatherProvider.query() Cursor cur = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cur.moveToFirst()) { return cur.getLong(cur.getColumnIndex(WeatherContract.LocationEntry._ID)); } ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri return_rowID = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI return ContentUris.parseId(return_rowID); }