List of usage examples for android.content ContentValues clear
public void clear()
From source file:com.pagenews.zhihudaily.service.CacheService.java
/** * //from www . j a va 2 s . co m * @param id ?id */ private void startDoubanCache(final int id) { Cursor cursor = db.query("Douban", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { if ((cursor.getInt(cursor.getColumnIndex("douban_id")) == id) && (cursor.getString(cursor.getColumnIndex("douban_content")).equals(""))) { StringRequest request = new StringRequest(Api.DOUBAN_ARTICLE_DETAIL + id, new Response.Listener<String>() { @Override public void onResponse(String s) { ContentValues values = new ContentValues(); values.put("douban_content", s); db.update("Douban", values, "douban_id = ?", new String[] { String.valueOf(id) }); values.clear(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }); request.setTag(TAG); VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request); } } while (cursor.moveToNext()); } cursor.close(); }
From source file:com.noshufou.android.su.AppDetailsFragment.java
private void doToggle() { ContentResolver cr = getActivity().getContentResolver(); Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex)); ContentValues values = new ContentValues(); values.put(Apps.ALLOW, mAllow == 1 ? 0 : 1); cr.update(uri, values, null, null);/*from w w w.j a va2 s .c o m*/ // Update the log values.clear(); values.put(Logs.DATE, System.currentTimeMillis()); values.put(Logs.TYPE, Logs.LogType.TOGGLE); cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(mShownIndex)), values); Intent intent = new Intent(getActivity(), ResultService.class); intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE); getActivity().startService(intent); }
From source file:org.zywx.wbpalmstar.plugin.uexcontacts.PFConcactMan.java
public static boolean modify(Context context, String inName, String inNum, String inEmail) { int sdkVersion = Build.VERSION.SDK_INT; ContentResolver contentResolver = context.getContentResolver(); boolean isModify = false; if (sdkVersion < 8) { try {/*w ww . j av a 2 s .c om*/ Cursor cusor = null; String[] projection = new String[] { android.provider.Contacts.People._ID, android.provider.Contacts.People.NAME, android.provider.Contacts.People.NUMBER }; cusor = contentResolver.query(android.provider.Contacts.People.CONTENT_URI, projection, null, null, null); cusor.moveToFirst(); while (cusor.moveToNext()) { String name = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People.NAME)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name != null && name.equals(inName)) { String id = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People._ID)); ContentValues values = new ContentValues(); // ??type?????? values.clear(); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_MOBILE); values.put(android.provider.Contacts.Phones.NUMBER, inNum); String numWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; String[] numWhereParams = { id }; contentResolver.update(android.provider.Contacts.Phones.CONTENT_URI, values, numWhere, numWhereParams); // ?type????? values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, inEmail); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); String emailWhere = android.provider.Contacts.ContactMethods.PERSON_ID + "=? "; String[] emailWhereParams = { id }; contentResolver.update(android.provider.Contacts.ContactMethods.CONTENT_URI, values, emailWhere, emailWhereParams); isModify = true; } } if (cusor != null) cusor.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); return false; } } else if (sdkVersion < 14) { try { Cursor cur = contentResolver.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, null, null, null, null); cur.moveToFirst(); while (cur.moveToNext()) { String name = cur .getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)); String id = cur.getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts._ID)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name.equals(inName)) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); String nameWhere = android.provider.ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, id); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; } } if (cur != null) cur.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } } else { try { Cursor cur = contentResolver.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, null, null, null, null); while (cur.moveToNext()) { String name = cur .getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)); String id = cur.getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts._ID)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name.equals(inName)) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.PhoneLookup.NUMBER); String nameWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, id); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; break; } } if (cur != null) cur.close(); Cursor cursor = context.getContentResolver() .query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { String name = cursor.getString( cursor.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)); String id = cursor .getString(cursor.getColumnIndex(android.provider.ContactsContract.Contacts._ID)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name.equals(inName)) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.PhoneLookup.NUMBER); String nameWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, id); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; break; } } if (cursor != null) cursor.close(); try { Cursor cusor = null; String[] projection = new String[] { android.provider.Contacts.People._ID, android.provider.Contacts.People.NAME, android.provider.Contacts.People.NUMBER }; cusor = contentResolver.query(android.provider.Contacts.People.CONTENT_URI, projection, null, null, null); cusor.moveToFirst(); while (cusor.moveToNext()) { String name = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People.NAME)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name != null && name.equals(inName)) { String id = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People._ID)); ContentValues values = new ContentValues(); // ??type?????? values.clear(); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_MOBILE); values.put(android.provider.Contacts.Phones.NUMBER, inNum); String numWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; String[] numWhereParams = { id }; contentResolver.update(android.provider.Contacts.Phones.CONTENT_URI, values, numWhere, numWhereParams); // ?type????? values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, inEmail); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); String emailWhere = android.provider.Contacts.ContactMethods.PERSON_ID + "=? "; String[] emailWhereParams = { id }; contentResolver.update(android.provider.Contacts.ContactMethods.CONTENT_URI, values, emailWhere, emailWhereParams); isModify = true; break; } } if (cusor != null) cusor.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); return false; } } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } } if (isModify) { ToastShow(context, finder.getString(context, "plugin_contact_modify_succeed")); } else { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } return isModify; }
From source file:org.zywx.wbpalmstar.plugin.uexcontacts.PFConcactMan.java
public static boolean add(Context context, String name, String num, String email) { try {//from w ww . ja va 2 s . c o m int sdkVersion = Build.VERSION.SDK_INT; if (sdkVersion < 8) { ContentValues values = new ContentValues(); values.put(android.provider.Contacts.People.NAME, name); Uri uri = context.getContentResolver().insert(android.provider.Contacts.People.CONTENT_URI, values); // ? Uri numberUri = Uri.withAppendedPath(uri, android.provider.Contacts.People.Phones.CONTENT_DIRECTORY); values.clear(); values.put(android.provider.Contacts.Phones.NUMBER, num); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_HOME); numberUri = context.getContentResolver().insert(numberUri, values); // Uri emailUri = Uri.withAppendedPath(uri, android.provider.Contacts.People.ContactMethods.CONTENT_DIRECTORY); values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, email); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); context.getContentResolver().insert(emailUri, values); ToastShow(context, finder.getString(context, "plugin_contact_add_succeed")); } else { ContentValues values = new ContentValues(); Uri rawContactUri = context.getContentResolver() .insert(android.provider.ContactsContract.RawContacts.CONTENT_URI, values); long rawContactId = android.content.ContentUris.parseId(rawContactUri); // ?data???? if (name != "") { values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, rawContactId); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, name); context.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); } // ?data??? if (num != "") { String[] nums = num.split(";"); for (int i = 0; i < nums.length; i++) { values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, rawContactId); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, nums[i]); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); context.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); } } // ?data?Email? if (email != "") { values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, rawContactId); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, email); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); context.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); } } } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_add_fail")); return false; } return true; }
From source file:com.pagenews.zhihudaily.service.CacheService.java
/** * id/* w ww .j a va 2s. c o m*/ * type0body? * type1?share url * @param id ???id */ private void startZhihuCache(final int id) { Cursor cursor = db.query("Zhihu", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { if ((cursor.getInt(cursor.getColumnIndex("zhihu_id")) == id) && (cursor.getString(cursor.getColumnIndex("zhihu_content")).equals(""))) { StringRequest request = new StringRequest(Request.Method.GET, Api.ZHIHU_NEWS + id, new Response.Listener<String>() { @Override public void onResponse(String s) { Gson gson = new Gson(); ZhihuDailyStory story = gson.fromJson(s, ZhihuDailyStory.class); if (story.getType() == 1) { StringRequest request = new StringRequest(Request.Method.GET, story.getShare_url(), new Response.Listener<String>() { @Override public void onResponse(String s) { ContentValues values = new ContentValues(); values.put("zhihu_content", s); db.update("Zhihu", values, "zhihu_id = ?", new String[] { String.valueOf(id) }); values.clear(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }); request.setTag(TAG); VolleySingleton.getVolleySingleton(CacheService.this) .addToRequestQueue(request); } else { ContentValues values = new ContentValues(); values.put("zhihu_content", s); db.update("Zhihu", values, "zhihu_id = ?", new String[] { String.valueOf(id) }); values.clear(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }); request.setTag(TAG); VolleySingleton.getVolleySingleton(CacheService.this).addToRequestQueue(request); } } while (cursor.moveToNext()); } cursor.close(); }
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
private void fillQuizzesForCategory(SQLiteDatabase db, ContentValues values, JSONArray quizzes, String categoryId) throws JSONException { JSONObject quiz;//from ww w. j a va 2 s . c o m for (int i = 0; i < quizzes.length(); i++) { quiz = quizzes.getJSONObject(i); values.clear(); values.put(QuizTable.FK_CATEGORY, categoryId); values.put(QuizTable.COLUMN_TYPE, quiz.getString(JsonAttributes.TYPE)); values.put(QuizTable.COLUMN_QUESTION, quiz.getString(JsonAttributes.QUESTION)); values.put(QuizTable.COLUMN_ANSWER, quiz.getString(JsonAttributes.ANSWER)); putNonEmptyString(values, quiz, JsonAttributes.OPTIONS, QuizTable.COLUMN_OPTIONS); putNonEmptyString(values, quiz, JsonAttributes.MIN, QuizTable.COLUMN_MIN); putNonEmptyString(values, quiz, JsonAttributes.MAX, QuizTable.COLUMN_MAX); putNonEmptyString(values, quiz, JsonAttributes.START, QuizTable.COLUMN_START); putNonEmptyString(values, quiz, JsonAttributes.END, QuizTable.COLUMN_END); putNonEmptyString(values, quiz, JsonAttributes.STEP, QuizTable.COLUMN_STEP); db.insert(QuizTable.NAME, null, values); } }
From source file:at.bitfire.davdroid.ui.setup.AccountDetailsFragment.java
protected long insertService(SQLiteDatabase db, String accountName, String service, DavResourceFinder.Configuration.ServiceInfo info) { ContentValues values = new ContentValues(); // insert service values.put(Services.ACCOUNT_NAME, accountName); values.put(Services.SERVICE, service); if (info.principal != null) values.put(Services.PRINCIPAL, info.principal.toString()); long serviceID = db.insertWithOnConflict(Services._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); // insert home sets for (URI homeSet : info.homeSets) { values.clear(); values.put(HomeSets.SERVICE_ID, serviceID); values.put(HomeSets.URL, homeSet.toString()); db.insertWithOnConflict(HomeSets._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); }/*from ww w. ja v a 2s . co m*/ // insert collections for (CollectionInfo collection : info.collections.values()) { values = collection.toDB(); values.put(Collections.SERVICE_ID, serviceID); db.insertWithOnConflict(Collections._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); } return serviceID; }
From source file:com.pagenews.zhihudaily.homepage.GuokrPresenter.java
@Override public void loadPosts() { view.showLoading();//from w w w.j a v a 2s. c om if (NetworkState.networkConnected(context)) { model.load(Api.GUOKR_ARTICLES, new OnStringListener() { @Override public void onSuccess(String result) { // api // ???? list.clear(); try { GuokrHandpickNews question = gson.fromJson(result, GuokrHandpickNews.class); for (GuokrHandpickNews.result re : question.getResult()) { list.add(re); if (!queryIfIDExists(re.getId())) { try { db.beginTransaction(); ContentValues values = new ContentValues(); values.put("guokr_id", re.getId()); values.put("guokr_news", gson.toJson(re)); values.put("guokr_content", ""); values.put("guokr_time", (long) re.getDate_picked()); db.insert("Guokr", null, values); values.clear(); db.setTransactionSuccessful(); } catch (Exception e) { e.printStackTrace(); } finally { db.endTransaction(); } } Intent intent = new Intent("com.marktony.zhihudaily.LOCAL_BROADCAST"); intent.putExtra("type", CacheService.TYPE_GUOKR); intent.putExtra("id", re.getId()); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } view.showResults(list); } catch (JsonSyntaxException e) { view.showError(); } view.stopLoading(); } @Override public void onError(VolleyError error) { view.stopLoading(); view.showError(); } }); } else { Cursor cursor = db.query("Guokr", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { GuokrHandpickNews.result result = gson.fromJson( cursor.getString(cursor.getColumnIndex("guokr_news")), GuokrHandpickNews.result.class); list.add(result); } while (cursor.moveToNext()); } cursor.close(); view.stopLoading(); view.showResults(list); // // if (list.isEmpty()) { view.showError(); } } }
From source file:fr.shywim.antoinedaniel.sync.AppState.java
/** * Load AppState from a JSONObject.//from w ww . j a v a 2 s. co m * * @param data json to import. */ void importFromJSON(JSONObject data, Context context, GoogleApiClient apiClient) { Gson gson = new Gson(); try { ContentValues cv = new ContentValues(); Set<String> widgetSounds = gson.fromJson(data.getJSONArray(WIDGET_SOUNDS).toString(), this.widgetSounds.getClass()); for (String soundName : widgetSounds) { synchronized (LOCK) { this.widgetSounds.add(soundName); } Uri uri = Uri.withAppendedPath(ProviderConstants.SOUND_NAME_URI, soundName); cv.clear(); cv.put(ProviderContract.SoundEntry.COLUMN_WIDGET, 1); context.getContentResolver().update(uri, cv, null, null); } Set<String> favSounds = gson.fromJson(data.getJSONArray(FAVORITES_SOUNDS).toString(), this.favSounds.getClass()); for (String soundName : favSounds) { synchronized (LOCK) { this.favSounds.add(soundName); } Uri uri = Uri.withAppendedPath(ProviderConstants.SOUND_NAME_URI, soundName); cv.clear(); cv.put(ProviderContract.SoundEntry.COLUMN_FAVORITE, 1); context.getContentResolver().update(uri, cv, null, null); } Map<String, String> bestScores = gson.fromJson(data.getJSONObject(BEST_SCORES).toString(), this.bestScores.getClass()); for (Map.Entry<String, String> entry : bestScores.entrySet()) { long newLong = Long.parseLong(entry.getValue()); synchronized (LOCK) { if (this.bestScores.containsKey(entry.getKey()) && Long.parseLong(this.bestScores.get(entry.getKey())) <= newLong) this.bestScores.put(entry.getKey(), entry.getValue()); } if (apiClient != null) { Games.Leaderboards.submitScore(apiClient, entry.getKey(), newLong); } } } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.runnerup.gpstracker.GpsTracker.java
public long createActivity(int sport) { assert (state == State.INIT); /**// w ww. j a v a 2 s .c om * Create an Activity instance */ ContentValues tmp = new ContentValues(); tmp.put(DB.ACTIVITY.SPORT, sport); mActivityId = mDB.insert(DB.ACTIVITY.TABLE, "nullColumnHack", tmp); tmp.clear(); tmp.put(DB.LOCATION.ACTIVITY, mActivityId); tmp.put(DB.LOCATION.LAP, 0); // always start with lap 0 mDBWriter = new PersistentGpsLoggerListener(mDB, DB.LOCATION.TABLE, tmp); return mActivityId; }