List of usage examples for android.content ContentValues clear
public void clear()
From source file:org.jsharkey.sky.webservice.WebserviceHelper.java
/** * Perform a webservice query to retrieve and store the forecast for the * given widget. This call blocks until request is finished and * {@link Forecasts#CONTENT_URI} has been updated. */// ww w . ja v a 2 s. c om public static void updateForecasts(Context context, Uri appWidgetUri, int days) throws ParseException { if (sUserAgent == null) { prepareUserAgent(context); } Uri appWidgetForecasts = Uri.withAppendedPath(appWidgetUri, AppWidgets.TWIG_FORECASTS); ContentResolver resolver = context.getContentResolver(); Cursor cursor = null; double lat = Double.NaN; double lon = Double.NaN; String countryCode = null; // Pull exact forecast location from database try { cursor = resolver.query(appWidgetUri, PROJECTION_APPWIDGET, null, null, null); if (cursor != null && cursor.moveToFirst()) { lat = cursor.getDouble(COL_LAT); lon = cursor.getDouble(COL_LON); countryCode = cursor.getString(COL_COUNTRY_CODE); } } finally { if (cursor != null) { cursor.close(); } } Log.d(TAG, "using country code=" + countryCode); // Query webservice for this location List<Forecast> forecasts = null; if (COUNTRY_US.equals(countryCode)) { forecasts = new NoaaSource().getForecasts(lat, lon, days); } else { forecasts = new MetarSource().getForecasts(lat, lon, days); } if (forecasts == null || forecasts.size() == 0) { throw new ParseException("No forecasts found from webservice query"); } // Purge existing forecasts covered by incoming data, and anything // before today long lastMidnight = ForecastUtils.getLastMidnight(); long earliest = Long.MAX_VALUE; for (Forecast forecast : forecasts) { earliest = Math.min(earliest, forecast.validStart); } resolver.delete(appWidgetForecasts, ForecastsColumns.VALID_START + " >= " + earliest + " OR " + ForecastsColumns.VALID_START + " <= " + lastMidnight, null); // Insert any new forecasts found ContentValues values = new ContentValues(); for (Forecast forecast : forecasts) { Log.d(TAG, "inserting forecast with validStart=" + forecast.validStart); values.clear(); values.put(ForecastsColumns.VALID_START, forecast.validStart); values.put(ForecastsColumns.TEMP_HIGH, forecast.tempHigh); values.put(ForecastsColumns.TEMP_LOW, forecast.tempLow); values.put(ForecastsColumns.CONDITIONS, forecast.conditions); values.put(ForecastsColumns.URL, forecast.url); if (forecast.alert) { values.put(ForecastsColumns.ALERT, ForecastsColumns.ALERT_TRUE); } resolver.insert(appWidgetForecasts, values); } // Mark widget cache as being updated values.clear(); values.put(AppWidgetsColumns.LAST_UPDATED, System.currentTimeMillis()); resolver.update(appWidgetUri, values, null, null); }
From source file:org.jsharkey.sky.WebserviceHelper.java
/** * Perform a webservice query to retrieve and store the forecast for the * given widget. This call blocks until request is finished and * {@link Forecasts#CONTENT_URI} has been updated. *///from w w w . j a v a 2s . c om public static void updateForecasts(Context context, Uri appWidgetUri, int days) throws ForecastParseException { Uri appWidgetForecasts = Uri.withAppendedPath(appWidgetUri, AppWidgets.TWIG_FORECASTS); ContentResolver resolver = context.getContentResolver(); Cursor cursor = null; double lat = Double.NaN; double lon = Double.NaN; // Pull exact forecast location from database try { cursor = resolver.query(appWidgetUri, PROJECTION_APPWIDGET, null, null, null); if (cursor != null && cursor.moveToFirst()) { lat = cursor.getDouble(COL_LAT); lon = cursor.getDouble(COL_LON); } } finally { if (cursor != null) { cursor.close(); } } // Query webservice for this location List<Forecast> forecasts = queryLocation(lat, lon, days); if (forecasts == null || forecasts.size() == 0) { throw new ForecastParseException("No forecasts found from webservice query"); } // Purge existing forecasts covered by incoming data, and anything // before today long lastMidnight = ForecastUtils.getLastMidnight(); long earliest = Long.MAX_VALUE; for (Forecast forecast : forecasts) { earliest = Math.min(earliest, forecast.validStart); } resolver.delete(appWidgetForecasts, ForecastsColumns.VALID_START + " >= " + earliest + " OR " + ForecastsColumns.VALID_START + " <= " + lastMidnight, null); // Insert any new forecasts found ContentValues values = new ContentValues(); for (Forecast forecast : forecasts) { Log.d(TAG, "inserting forecast with validStart=" + forecast.validStart); values.clear(); values.put(ForecastsColumns.VALID_START, forecast.validStart); values.put(ForecastsColumns.TEMP_HIGH, forecast.tempHigh); values.put(ForecastsColumns.TEMP_LOW, forecast.tempLow); values.put(ForecastsColumns.CONDITIONS, forecast.conditions); values.put(ForecastsColumns.URL, forecast.url); if (forecast.alert) { values.put(ForecastsColumns.ALERT, ForecastsColumns.ALERT_TRUE); } resolver.insert(appWidgetForecasts, values); } // Mark widget cache as being updated values.clear(); values.put(AppWidgetsColumns.LAST_UPDATED, System.currentTimeMillis()); resolver.update(appWidgetUri, values, null, null); }
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
/** * Updates a list of given quizzes./*from w ww . ja v a 2s . c o m*/ * * @param writableDatabase The database to write the quizzes to. * @param quizzes The quizzes to write. */ private static void updateQuizzes(SQLiteDatabase writableDatabase, List<Quiz> quizzes) { Quiz quiz; ContentValues quizValues = new ContentValues(); String[] quizArgs = new String[1]; for (int i = 0; i < quizzes.size(); i++) { quiz = quizzes.get(i); quizValues.clear(); quizValues.put(QuizTable.COLUMN_SOLVED, quiz.isSolved()); quizArgs[0] = quiz.getQuestion(); writableDatabase.update(QuizTable.NAME, quizValues, QuizTable.COLUMN_QUESTION + "=?", quizArgs); } }
From source file:org.sensapp.android.sensappdroid.api.SensAppHelper.java
public static boolean renameSensor(Context context, String name, String newName) { ContentValues values = new ContentValues(); values.put(SensAppContract.Sensor.NAME, newName); context.getContentResolver().update(Uri.parse(SensAppContract.Sensor.CONTENT_URI + "/" + name), values, null, null);//w ww .jav a 2s . c o m values.clear(); values.put(SensAppContract.Measure.SENSOR, newName); context.getContentResolver().update(Uri.parse(SensAppContract.Measure.CONTENT_URI + "/" + name), values, null, null); return true; }
From source file:com.tct.email.LegacyConversions.java
/** * Add a single attachment part to the message * * This will skip adding attachments if they are already found in the attachments table. * The heuristic for this will fail (false-positive) if two identical attachments are * included in a single POP3 message./* ww w .j ava 2 s. c om*/ * TODO: Fix that, by (elsewhere) simulating an mLocation value based on the attachments * position within the list of multipart/mixed elements. This would make every POP3 attachment * unique, and might also simplify the code (since we could just look at the positions, and * ignore the filename, etc.) * * TODO: Take a closer look at encoding and deal with it if necessary. * * @param context a context for file operations * @param localMessage the attachments will be built against this message * @param part a single attachment part from POP or IMAP * @param index add for pop re-download attachment * @param protocol add to judge if it's pop3,it can be used later * @param isInline add to judge if it's isInline attachment */ public static void addOneAttachment(final Context context, final EmailContent.Message localMessage, final Part part, int index, String protocol, boolean isInline) throws MessagingException, IOException { Attachment localAttachment = mimePartToAttachment(context, part, index, protocol, isInline); // TS: Gantao 2015-06-04 EMAIL BUGFIX_1009030 MOD_E localAttachment.mMessageKey = localMessage.mId; localAttachment.mAccountKey = localMessage.mAccountKey; if (DEBUG_ATTACHMENTS) { LogUtils.d(Logging.LOG_TAG, "Add attachment " + localAttachment); } // To prevent duplication - do we already have a matching attachment? // The fields we'll check for equality are: // mFileName, mMimeType, mContentId, mMessageKey, mLocation // NOTE: This will false-positive if you attach the exact same file, twice, to a POP3 // message. We can live with that - you'll get one of the copies. final Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId); final Cursor cursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); boolean attachmentFoundInDb = false; try { while (cursor.moveToNext()) { final Attachment dbAttachment = new Attachment(); dbAttachment.restore(cursor); // We test each of the fields here (instead of in SQL) because they may be // null, or may be strings. if (!TextUtils.equals(dbAttachment.mFileName, localAttachment.mFileName) || !TextUtils.equals(dbAttachment.mMimeType, localAttachment.mMimeType) || !TextUtils.equals(dbAttachment.mContentId, localAttachment.mContentId) || !TextUtils.equals(dbAttachment.mLocation, localAttachment.mLocation)) { continue; } // We found a match, so use the existing attachment id, and stop looking/looping attachmentFoundInDb = true; localAttachment.mId = dbAttachment.mId; if (DEBUG_ATTACHMENTS) { LogUtils.d(Logging.LOG_TAG, "Skipped, found db attachment " + dbAttachment); } break; } } finally { cursor.close(); } //TS: Gantao 2015-07-16 EMAIL BUGFIX_1045624 MOD_S // Save the attachment (so far) in order to obtain an id if (!attachmentFoundInDb) { localAttachment.save(context); } // If an attachment body was actually provided, we need to write the file now saveAttachmentBody(context, part, localAttachment, localMessage.mAccountKey); //TS: Gantao 2015-07-16 EMAIL BUGFIX_1045624 MOD_E if (localMessage.mAttachments == null) { localMessage.mAttachments = new ArrayList<Attachment>(); } //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_S Body body = Body.restoreBodyWithMessageId(context, localAttachment.mMessageKey); ContentValues cv = new ContentValues(); if (body != null && body.mHtmlContent != null && localAttachment.mContentId != null && localAttachment.getContentUri() != null) { cv.clear(); String html = body.mHtmlContent; String contentIdRe = "\\s+(?i)src=\"cid(?-i):\\Q" + localAttachment.mContentId + "\\E\""; //TS: zhaotianyong 2015-03-23 EMAIL BUGFIX_899799 MOD_S //TS: zhaotianyong 2015-04-01 EMAIL BUGFIX_962560 MOD_S String srcContentUri = " src=\"" + localAttachment.getContentUri() + "\""; //TS: zhaotianyong 2015-04-01 EMAIL BUGFIX_962560 MOD_E //TS: zhaotianyong 2015-03-23 EMAIL BUGFIX_899799 MOD_E //TS: zhaotianyong 2015-04-15 EMAIL BUGFIX_976967 MOD_S try { html = html.replaceAll(contentIdRe, srcContentUri); } catch (PatternSyntaxException e) { LogUtils.w(Logging.LOG_TAG, "Unrecognized backslash escape sequence in pattern"); } //TS: zhaotianyong 2015-04-15 EMAIL BUGFIX_976967 MOD_E cv.put(BodyColumns.HTML_CONTENT, html); Body.updateBodyWithMessageId(context, localAttachment.mMessageKey, cv); Body.restoreBodyHtmlWithMessageId(context, localAttachment.mMessageKey); } //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_E localMessage.mAttachments.add(localAttachment); //TS: Gantao 2015-09-28 EMAIL FEATURE_526529 MOD_S //We do not think the inline images is an attachment from now. if (!isInline) { localMessage.mFlagAttachment = true; } //TS: Gantao 2015-09-28 EMAIL FEATURE_526529 MOD_E }
From source file:com.example.myexamplecursorloader.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // ??/*from w ww. ja v a 2s. co m*/ getContentResolver().delete(PlaceManager.Place.CONTENT_URI, null, null); // ?(??DB????????????) List<Place> places = new ArrayList<Place>(); Place place = new Place("1", "?", "http://www.pref.hokkaido.lg.jp/"); places.add(place); place = new Place("2", "", "http://www.pref.gunma.jp/"); places.add(place); place = new Place("3", "", "http://www.pref.okayama.jp/"); places.add(place); place = new Place("4", "", "http://www.pref.hiroshima.lg.jp/"); places.add(place); place = new Place("5", "?", "http://www.pref.kagawa.lg.jp/"); places.add(place); ContentValues values = new ContentValues(); for (Place p : places) { values.clear(); values.put(PlaceManager.Place.KEY_PLACE_ID, p.getPlaceID()); values.put(PlaceManager.Place.KEY_PLACE, p.getPlace()); values.put(PlaceManager.Place.KEY_URL, p.getUrl()); getContentResolver().insert(PlaceManager.Place.CONTENT_URI, values); } // ??? Intent intent = new Intent(getApplicationContext(), PlaceListActivity.class); startActivity(intent); }
From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_list_bus.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); DbOpenHelper dbOpenHelper = new DbOpenHelper(getActivity()); SQLiteDatabase db;/*from ww w . j a v a2 s .c o m*/ db = dbOpenHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.clear(); String st; st = "SELECT Name FROM bus_path_table WHERE bus_path_table.Type_transport_id='" + typeTransport + "'" + "ORDER BY Number"; Cursor c = db.rawQuery(st, null); while (c.moveToNext()) { String st2 = ""; st2 = c.getString(0); results.add(st2); } // ?? gridView = (GridView) getView().findViewById(R.id.gridview); //? ClickListener ? listview gridView.setOnItemClickListener((android.widget.AdapterView.OnItemClickListener) this); dataList = new ArrayList<Map<String, Object>>(); dataList = getData(); //? ClickListener ? gridView simpleAdapter = new SimpleAdapter(getActivity(), dataList, R.layout.gridview_item, new String[] { "image", "text" }, new int[] { R.id.image, R.id.text }); // listview gridView.setAdapter(simpleAdapter); }
From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_list_bus_stop.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Context context = getActivity(); DbOpenHelper dbOpenHelper = new DbOpenHelper(context); SQLiteDatabase db;// ww w .j a va 2 s. co m db = dbOpenHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.clear(); String st; st = ""; st = "SELECT bus_stop_table.Name FROM bus_stop_path_table INNER JOIN bus_stop_table ON bus_stop_path_table.Bus_stop_id=bus_stop_table.id "; st = st + "INNER JOIN bus_path_table ON bus_stop_path_table.Bus_path_id=bus_path_table.id "; st = st + " WHERE bus_stop_path_table.Bus_path_id='" + busPathId + "'"; st = st + " AND bus_stop_path_table.Type_day_id='" + typeDay + "'"; Cursor c = db.rawQuery(st, null); while (c.moveToNext()) { String st2 = ""; st2 = c.getString(0); results.add(st2); } // ?? ListView lvMain = (ListView) getView().findViewById(R.id.listView1); lvMain.setDivider(null);// ? ListView //?? ? String[] values = results.toArray(new String[results.size()]); // custom adapter ? listview //? ClickListener ? listview lvMain.setOnItemClickListener(new AdapterView.OnItemClickListener() { // ? public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //? ? String busStop = (String) parent.getItemAtPosition(position); String busStopId = ""; Context context = getActivity(); DbOpenHelper dbOpenHelper = new DbOpenHelper(context); SQLiteDatabase db; db = dbOpenHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.clear(); String st = ""; st = "SELECT bus_stop_table.id FROM bus_stop_table "; st = st + " WHERE bus_stop_table.Name='" + busStop + "'"; Cursor c = db.rawQuery(st, null); while (c.moveToNext()) { busStopId = c.getString(0); } Intent intent = new Intent(getActivity(), List_bus_time.class); intent.putExtra("busPathId", busPathId); intent.putExtra("busStopId", busStopId); intent.putExtra("typeDay", typeDay); //? ? ? startActivity(intent); // // overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);**/ } }); ListviewArrayAdapter adapter = new ListviewArrayAdapter(getActivity(), values, values.length - 1); // listview lvMain.setAdapter(adapter); }
From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_list_bus.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (type.equals("listBus")) { //? intent ? ? ? Intent intent = new Intent(getActivity(), List_bus_stop.class); String numberBus = simpleAdapter.getItem(position).toString(); numberBus = numberBus.substring(32, numberBus.length() - 1); numberBus = numberBus.replaceAll(" ", ""); Context context = getActivity(); DbOpenHelper dbOpenHelper = new DbOpenHelper(context); SQLiteDatabase db;//from ww w . j a v a 2 s . c o m db = dbOpenHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.clear(); String st = ""; st = "SELECT bus_path_table.id FROM bus_path_table "; st = st + " WHERE bus_path_table.Name='" + numberBus + "'"; st = st + " AND bus_path_table.Type_transport_id='" + typeTransport + "'"; Cursor c = db.rawQuery(st, null); String busPathId = null; while (c.moveToNext()) { busPathId = c.getString(0); } intent.putExtra("busPathId", busPathId); //? ? ? startActivity(intent); } else { //? ? //? intent ? ? ? Intent intent = new Intent(getActivity(), Scheme.class); String numberBus = simpleAdapter.getItem(position).toString(); numberBus = numberBus.substring(32, numberBus.length() - 1); numberBus = numberBus.replaceAll(" ", ""); intent.putExtra("numberBus", numberBus); intent.putExtra("typeTransport", typeTransport); startActivity(intent); } }
From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_time.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Context context = getActivity(); DbOpenHelper dbOpenHelper = new DbOpenHelper(context); SQLiteDatabase db;//from w ww . j ava2 s. c o m db = dbOpenHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.clear(); String busStopPathId = ""; String st = ""; st = "SELECT bus_stop_path_table.id FROM bus_stop_path_table "; st = st + " WHERE bus_stop_path_table.Bus_path_id='" + busPathId + "'"; st = st + " AND bus_stop_path_table.Bus_stop_id='" + busStopId + "'"; st = st + " AND bus_stop_path_table.Type_day_id='" + typeDay + "'"; Cursor c = db.rawQuery(st, null); while (c.moveToNext()) { busStopPathId = c.getString(0); } st = ""; st = "SELECT bus_time_table.Time FROM bus_time_table "; st = st + " WHERE bus_time_table.Bus_path_stop_id='" + busStopPathId + "'"; st = st + " AND bus_time_table.Type_day_id='" + typeDay + "'"; c = db.rawQuery(st, null); ArrayList<String> busTimeArray = new ArrayList<String>(); while (c.moveToNext()) { String str = c.getString(0).replaceAll(" ", ""); if (str.equals("-")) { } else { busTimeArray.add(c.getString(0)); } } String st3; String hour; for (int i = 0; i < busTimeArray.size(); i++) { st3 = busTimeArray.get(i); hour = st3.substring(0, st3.indexOf(':')); int k = 0; int number = 0; for (int j = 0; j < allTime.size(); j++) { if (hour.equals(allTime.get(j).Get_hour())) { k = 1; number = j; } } if (k == 0) { Time myTime = new Time(); myTime.Set_hour(hour); myTime.Add_minutes(st3.substring(st3.indexOf(':') + 1, st3.length())); allTime.add(myTime); } else { allTime.get(number).Add_minutes(st3.substring(st3.indexOf(':') + 1, st3.length())); } } ArrayList<String> hours = new ArrayList<String>(); for (int i = 0; i < allTime.size(); i++) { hours.add(allTime.get(i).Get_hour()); } String[] resultsHours = hours.toArray(new String[hours.size()]); ListView listView = (ListView) getView().findViewById(R.id.lv); listView.setOnItemClickListener((android.widget.AdapterView.OnItemClickListener) this); ListviewArrayAdapterBusTime caa; caa = new ListviewArrayAdapterBusTime(getActivity(), resultsHours, allTime); listView.setAdapter(caa); }