List of usage examples for android.database.sqlite SQLiteDatabase insert
public long insert(String table, String nullColumnHack, ContentValues values)
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testUpdateToken() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); assertTrue(mGroupAuthAccessDbController.updateToken(1, "fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.")); Cursor cursor = db.query(GroupAccess.TABLE_NAME, GroupAccess.COLUMN.ALL_COLUMNS, GroupAccess.COLUMN.GROUP_ID + " = ? ", new String[] { String.valueOf(1) }, null, null, null); int count = cursor.getCount(); if (count == 0) cursor.close();/*from w ww . ja v a2 s . co m*/ assertTrue(cursor.moveToFirst()); int groupId = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.GROUP_ID)); boolean synchronize = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.SYNCHRONIZE)) == 1; boolean interrupted = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.INTERRUPTED)) == 1; Date lastTokenRequestDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_TOKEN_REQUEST)), new ParsePosition(0)); Date lastUpdateDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER)), new ParsePosition(0)); String token = cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.TOKEN)); cursor.close(); assertEquals(1, groupId); assertEquals(true, synchronize); assertEquals(false, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.", token); }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testGetGroupAuthAccessesBySynchronize() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); Date otherDate = new Date(); cv.put(GroupAccess.COLUMN.GROUP_ID, 2); cv.put(GroupAccess.COLUMN.INTERRUPTED, true); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, false); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); List<GroupAccess> groupAccessList = mGroupAuthAccessDbController.getGroupAuthAccesses(true); assertNotNull(groupAccessList);/*from w ww. j a va2 s . co m*/ assertEquals(1, groupAccessList.size()); for (GroupAccess groupAccess : groupAccessList) { assertNotNull(groupAccess); switch (groupAccess.getGroupId()) { case 1: assertEquals(1, groupAccess.getGroupId()); assertEquals(false, groupAccess.wasInterrupted()); assertEquals(true, groupAccess.isSynchronize()); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(groupAccess.getLastUpdateFromServer())); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(groupAccess.getLastTokenRequest())); assertEquals("fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds.", groupAccess.getToken()); break; default: assertTrue(false); } } }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testGetGroupAuthAccessesSinceDate() throws Exception { Date currentDate = new Date(1230); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); Date otherDate = new Date(); cv.put(GroupAccess.COLUMN.GROUP_ID, 2); cv.put(GroupAccess.COLUMN.INTERRUPTED, true); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, false); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); List<GroupAccess> groupAccessList = mGroupAuthAccessDbController .getGroupAuthAccesses(ISO8601Utils.format(otherDate)); assertNotNull(groupAccessList);//from w ww.ja va2s.com assertEquals(1, groupAccessList.size()); for (GroupAccess groupAccess : groupAccessList) { assertNotNull(groupAccess); switch (groupAccess.getGroupId()) { case 2: assertEquals(2, groupAccess.getGroupId()); assertEquals(true, groupAccess.wasInterrupted()); assertEquals(false, groupAccess.isSynchronize()); assertEquals(ISO8601Utils.format(otherDate), ISO8601Utils.format(groupAccess.getLastUpdateFromServer())); assertEquals(ISO8601Utils.format(otherDate), ISO8601Utils.format(groupAccess.getLastTokenRequest())); assertEquals("fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds.", groupAccess.getToken()); break; default: assertTrue(false); } } }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testUpdate() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); GroupAccess groupAccess = new GroupAccess(1, "fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds."); groupAccess.setLastTokenRequest(currentDate); groupAccess.setLastUpdateFromServer(currentDate); groupAccess.setSynchronize(true);/* w w w .ja va2s . co m*/ groupAccess.setInterrupted(true); assertTrue(mGroupAuthAccessDbController.update(groupAccess)); Cursor cursor = db.query(GroupAccess.TABLE_NAME, GroupAccess.COLUMN.ALL_COLUMNS, GroupAccess.COLUMN.GROUP_ID + " = ? ", new String[] { String.valueOf(1) }, null, null, null); int count = cursor.getCount(); if (count == 0) cursor.close(); assertTrue(cursor.moveToFirst()); int groupId = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.GROUP_ID)); boolean synchronize = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.SYNCHRONIZE)) == 1; boolean interrupted = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.INTERRUPTED)) == 1; Date lastTokenRequestDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_TOKEN_REQUEST)), new ParsePosition(0)); Date lastUpdateDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER)), new ParsePosition(0)); String token = cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.TOKEN)); cursor.close(); assertEquals(1, groupId); assertEquals(true, synchronize); assertEquals(true, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.", token); }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testGetGroupAuthAccesses() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); Date otherDate = new Date(); cv.put(GroupAccess.COLUMN.GROUP_ID, 2); cv.put(GroupAccess.COLUMN.INTERRUPTED, true); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); List<GroupAccess> groupAccessList = mGroupAuthAccessDbController.getGroupAuthAccesses(); assertNotNull(groupAccessList);//from ww w . j a va2 s.c om assertEquals(2, groupAccessList.size()); for (GroupAccess groupAccess : groupAccessList) { assertNotNull(groupAccess); switch (groupAccess.getGroupId()) { case 1: assertEquals(1, groupAccess.getGroupId()); assertEquals(false, groupAccess.wasInterrupted()); assertEquals(true, groupAccess.isSynchronize()); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(groupAccess.getLastUpdateFromServer())); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(groupAccess.getLastTokenRequest())); assertEquals("fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds.", groupAccess.getToken()); break; case 2: assertEquals(2, groupAccess.getGroupId()); assertEquals(true, groupAccess.wasInterrupted()); assertEquals(true, groupAccess.isSynchronize()); assertEquals(ISO8601Utils.format(otherDate), ISO8601Utils.format(groupAccess.getLastUpdateFromServer())); assertEquals(ISO8601Utils.format(otherDate), ISO8601Utils.format(groupAccess.getLastTokenRequest())); assertEquals("fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds.", groupAccess.getToken()); break; default: assertTrue(false); } } }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public void addCategories(WallpaperJson categories) { SQLiteDatabase db = this.getWritableDatabase(); for (int i = 0; i < categories.getCategories.size(); i++) { ContentValues values = new ContentValues(); values.put(KEY_NAME, categories.getCategories.get(i).name); values.put(KEY_THUMB_URL, categories.getCategories.get(i).thumbUrl); db.insert(TABLE_CATEGORIES, null, values); }//from ww w.ja v a 2 s.c o m db.close(); }
From source file:net.olejon.mdapp.InteractionsCardsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();//from www. ja va 2 s . co m return; } // Intent final Intent intent = getIntent(); searchString = intent.getStringExtra("search"); // Layout setContentView(R.layout.activity_interactions_cards); // Toolbar mToolbar = (Toolbar) findViewById(R.id.interactions_cards_toolbar); mToolbar.setTitle(getString(R.string.interactions_cards_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.interactions_cards_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.interactions_cards_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.interactions_cards_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new InteractionsCardsAdapter(mContext, mProgressBar, new JSONArray())); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // No interactions mNoInteractionsLayout = (LinearLayout) findViewById(R.id.interactions_cards_no_interactions); Button noInteractionsButton = (Button) findViewById(R.id.interactions_cards_no_interactions_button); noInteractionsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.interactions_cards_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "http://interaksjoner.no/analyser.asp?PreparatNavn=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8") + "&submit1=Sjekk"); mContext.startActivity(intent); } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } } }); // Search search(searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put(InteractionsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new InteractionsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(InteractionsSQLiteHelper.TABLE, InteractionsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(InteractionsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle(getString(R.string.interactions_cards_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); mNoInteractionsLayout.setVisibility(View.GONE); mSwipeRefreshLayout.setVisibility(View.VISIBLE); search(correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("InteractionsCards", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } }
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
private void fillCategory(SQLiteDatabase db, ContentValues values, JSONObject category, String categoryId) throws JSONException { values.clear();/*w w w . j a v a 2 s . c om*/ values.put(CategoryTable.COLUMN_ID, categoryId); values.put(CategoryTable.COLUMN_NAME, category.getString(JsonAttributes.NAME)); values.put(CategoryTable.COLUMN_THEME, category.getString(JsonAttributes.THEME)); values.put(CategoryTable.COLUMN_SOLVED, category.getString(JsonAttributes.SOLVED)); values.put(CategoryTable.COLUMN_SCORES, category.getString(JsonAttributes.SCORES)); db.insert(CategoryTable.NAME, null, values); }
From source file:net.olejon.mdapp.DiseasesAndTreatmentsSearchActivity.java
private void search(final String language, final String string, final boolean cache) { mFirstPubMedPosition = 0;/* www.ja v a 2s.c o m*/ mFirstWebOfSciencePosition = 0; mFirstMedlinePlusPosition = 0; mFirstWikipediaPosition = 0; mFirstUpToDatePosition = 0; mFirstBmjPosition = 0; mFirstNhiPosition = 0; mFirstSmlPosition = 0; mFirstForskningPosition = 0; mFirstHelsebiblioteketPosition = 0; mFirstTidsskriftetPosition = 0; mFirstOncolexPosition = 0; mFirstBrukerhandbokenPosition = 0; mFirstHelsenorgePosition = 0; try { RequestQueue requestQueue = Volley.newRequestQueue(mContext); String apiUri = getString(R.string.project_website_uri) + "api/1/diseases-and-treatments/" + language + "/?search=" + URLEncoder.encode(string, "utf-8"); if (!cache) requestQueue.getCache().remove(apiUri); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(apiUri, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { for (int i = 0; i < response.length(); i++) { try { JSONObject jsonObject = response.getJSONObject(i); String type = jsonObject.getString("type"); if (mFirstPubMedPosition == 0 && type.equals("pubmed")) mFirstPubMedPosition = i; if (mFirstWebOfSciencePosition == 0 && type.equals("webofscience")) mFirstWebOfSciencePosition = i; if (mFirstMedlinePlusPosition == 0 && type.equals("medlineplus")) mFirstMedlinePlusPosition = i; if (mFirstWikipediaPosition == 0 && type.equals("wikipedia")) mFirstWikipediaPosition = i; if (mFirstUpToDatePosition == 0 && type.equals("uptodate")) mFirstUpToDatePosition = i; if (mFirstBmjPosition == 0 && type.equals("bmj")) mFirstBmjPosition = i; if (mFirstNhiPosition == 0 && type.equals("nhi")) mFirstNhiPosition = i; if (mFirstSmlPosition == 0 && type.equals("sml")) mFirstSmlPosition = i; if (mFirstForskningPosition == 0 && type.equals("forskning")) mFirstForskningPosition = i; if (mFirstHelsebiblioteketPosition == 0 && type.equals("helsebiblioteket")) mFirstHelsebiblioteketPosition = i; if (mFirstTidsskriftetPosition == 0 && type.equals("tidsskriftet")) mFirstTidsskriftetPosition = i; if (mFirstOncolexPosition == 0 && type.equals("oncolex")) mFirstOncolexPosition = i; if (mFirstBrukerhandbokenPosition == 0 && type.equals("brukerhandboken")) mFirstBrukerhandbokenPosition = i; if (mFirstHelsenorgePosition == 0 && type.equals("helsenorge")) mFirstHelsenorgePosition = i; } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } } mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); if (mTools.isTablet()) mRecyclerView.setLayoutManager( new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); mRecyclerView.setAdapter(new DiseasesAndTreatmentsSearchAdapter(mContext, response, string)); ContentValues contentValues = new ContentValues(); contentValues.put(DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING, string); SQLiteDatabase sqLiteDatabase = new DiseasesAndTreatmentsSQLiteHelper(mContext) .getWritableDatabase(); sqLiteDatabase.delete(DiseasesAndTreatmentsSQLiteHelper.TABLE, DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(string) + " COLLATE NOCASE", null); sqLiteDatabase.insert(DiseasesAndTreatmentsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); mTools.showToast(getString(R.string.diseases_and_treatments_search_could_not_search), 1); Log.e("DiseasesAndTreatments", error.toString()); finish(); } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonArrayRequest); } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } }
From source file:net.olejon.mdapp.ClinicalTrialsCardsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();/*from ww w. j a va 2 s. c o m*/ return; } // Intent final Intent intent = getIntent(); searchString = intent.getStringExtra("search"); // Layout setContentView(R.layout.activity_clinicaltrials_cards); // Toolbar mToolbar = (Toolbar) findViewById(R.id.clinicaltrials_cards_toolbar); mToolbar.setTitle(getString(R.string.clinicaltrials_cards_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.clinicaltrials_cards_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.clinicaltrials_cards_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.clinicaltrials_cards_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new ClinicalTrialsCardsAdapter(mContext, new JSONArray())); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // No clinical trials mNoClinicalTrialsLayout = (LinearLayout) findViewById(R.id.clinicaltrials_cards_no_clinicaltrials); Button noClinicalTrialsButton = (Button) findViewById(R.id.clinicaltrials_cards_no_results_button); noClinicalTrialsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.clinicaltrials_cards_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "https://clinicaltrials.gov/ct2/results?term=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8") + "&no_unk=Y"); mContext.startActivity(intent); } catch (Exception e) { Log.e("ClinicalTrialsCards", Log.getStackTraceString(e)); } } }); // Search search(searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put(ClinicalTrialsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new ClinicalTrialsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(ClinicalTrialsSQLiteHelper.TABLE, ClinicalTrialsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(ClinicalTrialsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle( getString(R.string.clinicaltrials_cards_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); mNoClinicalTrialsLayout.setVisibility(View.GONE); mSwipeRefreshLayout.setVisibility(View.VISIBLE); search(correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("ClinicalTrialsCards", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("ClinicalTrialsCards", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("ClinicalTrialsCards", Log.getStackTraceString(e)); } }