List of usage examples for android.database.sqlite SQLiteDatabase close
public void 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 w ww . j av a2 s.c om 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:org.akop.crosswords.Storage.java
public Crossword getPuzzle(long puzzleId) { long started = SystemClock.uptimeMillis(); Crossword crossword = mPuzzleCache.get((int) puzzleId); if (crossword == null) { StorageHelper helper = getHelper(); SQLiteDatabase db = helper.getReadableDatabase(); try {//from ww w. j a va2 s . com Cursor cursor = db.query(Puzzle.TABLE, new String[] { Puzzle.CLASS, Puzzle.OBJECT, }, Puzzle._ID + " = " + puzzleId, null, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { crossword = mGson.fromJson(cursor.getString(1), Crossword.class); mPuzzleCache.put((int) puzzleId, crossword); } } finally { cursor.close(); } } } finally { db.close(); } } if (crossword != null) { Crosswords.logv("Loaded crossword %s (%dms)", crossword.getHash(), SystemClock.uptimeMillis() - started); } return crossword; }
From source file:com.snt.bt.recon.database.DBHandler.java
public void addTrip(Trip trip) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_SESSION_ID, trip.getSessionId().toString()); values.put(KEY_IMEI, trip.getImei()); values.put(KEY_TRANSPORT, trip.getTransport()); values.put(KEY_TIMESTAMP_START, trip.getTimestampStart()); values.put(KEY_TIMESTAMP_END, trip.getTimestampEnd()); values.put(KEY_APP_VERSION, trip.getAppVersion()); values.put(KEY_UPLOAD_STATUS, trip.getUploadStatus()); // Inserting Row db.insertOrThrow(TABLE_TRIPS, null, values); db.close(); // Closing database connection }
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();/*w w w . jav a 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)); } }
From source file:net.potterpcs.recipebook.RecipeData.java
public int insertRecipe(ContentValues values) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int ret = -1; try {/* w w w. j a v a2 s . c o m*/ ret = (int) db.insert(RECIPES_TABLE, null, values); } finally { db.close(); } return ret; } }
From source file:net.potterpcs.recipebook.RecipeData.java
public void insertTags(ContentValues values) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); try {/* www . ja v a 2 s . c o m*/ db.insertWithOnConflict(TAGS_TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE); } finally { db.close(); } } }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public int favoritesForName(String name) { int ret = 0;//from w w w. j av a2 s . co m SQLiteDatabase db = getReadableDatabase(); if (db != null) { String[] columns = { KEY_NAME }; Cursor cursor = db.query(TABLE_FAVORITES, columns, KEY_NAME + " = ? ", new String[] { "" + name }, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { ret = cursor.getCount(); } if (cursor != null) cursor.close(); db.close(); } return ret; }
From source file:com.ericsender.android_nanodegree.popmovie.com.ericsender.android_nanodegree.popmovie.data.TestProvider.java
public void testBasicFavoriteQueries() { //first insert movies: Map<Long, ContentValues> listContentValues = TestUtilities.createSortedMovieValues(getContext(), "popular"); Map<Long, Long> locationRowIds = TestUtilities.insertMovieRow(mContext, listContentValues); // Insert random favorites SQLiteDatabase db = new MovieDbHelper(getContext()).getWritableDatabase(); Set<Long> insertedMoviedIds = new HashSet<>(); try {//from w ww .j av a 2s . co m db.beginTransaction(); while (insertedMoviedIds.isEmpty()) for (Map.Entry<Long, ContentValues> e : listContentValues.entrySet()) insertedMoviedIds.add(TestUtilities.generateRandomFavoritesAndInsert(db, e.getValue())); insertedMoviedIds.remove(null); db.setTransactionSuccessful(); } finally { db.endTransaction(); db.close(); } // Test the basic content provider query Cursor favCursor = mContext.getContentResolver().query(MovieContract.FavoriteEntry.CONTENT_URI, null, null, null, null); // Make sure we get the correct cursor out of the database TestUtilities.validateFavoritesCursor(favCursor, listContentValues, insertedMoviedIds); // Has the NotificationUri been set correctly? --- we can only test this easily against API // level 19 or greater because getNotificationUri was added in API level 19. if (Build.VERSION.SDK_INT >= 19) { assertEquals("Error: Favoriate Query did not properly set NotificationUri", favCursor.getNotificationUri(), MovieContract.FavoriteEntry.buildUri()); } }
From source file:net.potterpcs.recipebook.RecipeData.java
public void insertDirections(ContentValues values) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); try {/*from w ww. j a va 2s . c o m*/ db.insertWithOnConflict(DIRECTIONS_TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE); } finally { db.close(); } } }
From source file:net.potterpcs.recipebook.RecipeData.java
public void insertIngredients(ContentValues values) { synchronized (DB_LOCK) { SQLiteDatabase db = dbHelper.getWritableDatabase(); try {/* www.j a v a 2 s. com*/ db.insertWithOnConflict(INGREDIENTS_TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE); } finally { db.close(); } } }