Example usage for android.database.sqlite SQLiteDatabase close

List of usage examples for android.database.sqlite SQLiteDatabase close

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase close.

Prototype

public void close() 

Source Link

Document

Releases a reference to the object, closing the object if the last reference was released.

Usage

From source file:com.yammy.meter.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.isvo_activity_main);
    lat = (TextView) this.findViewById(R.id.main_lat);
    longi = (TextView) this.findViewById(R.id.main_long);
    nopol = (TextView) this.findViewById(R.id.main_nopol);
    jarak = (TextView) this.findViewById(R.id.main_jarak);
    start = (Button) this.findViewById(R.id.buttonStartRec);
    stop = (Button) this.findViewById(R.id.buttonStopRec);
    reset = (Button) this.findViewById(R.id.buttonClrMapMain);
    stop.setEnabled(false);//from ww w  .  j a va 2s.co m
    reset.setEnabled(false);
    Location location = null;

    getVehVal();

    int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (result != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(result, MainActivity.this, 1).show();
    } else {
        /**
         * try to get current location via GPS
         * pending : path recording using Polyline & get length
         */

        locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (!enabledGPS) {
            requestGPS();
            finish();
        }

        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_main)).getMap();
        GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getBaseContext());

        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.setIndoorEnabled(false);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this);
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        try {
            user_pos = new LatLng(location.getLatitude(), location.getLongitude());
            if (location != null
                    && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
                Toast.makeText(getApplicationContext(),
                        "Current Location : " + location.getLatitude() + "," + location.getLongitude(),
                        Toast.LENGTH_LONG).show();
                drawMarker(location);
            } else {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
                drawMarker(location);
            }
        } catch (NullPointerException e) {
            //requestGPS();
        }
    }

    start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            recording = true;
            Toast.makeText(getBaseContext(), "Mulai merekam perjalanan", Toast.LENGTH_SHORT).show();
            stop.setEnabled(true);
            start.setEnabled(false);
            reset.setEnabled(false);
            jarakTotal = 0.0;
        }
    });
    stop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            recording = false;
            Toast.makeText(getBaseContext(), "Selesai merekam perjalanan", Toast.LENGTH_SHORT).show();
            Toast.makeText(getBaseContext(), "Perjalanan terakhir " + jarakTotal + " m", Toast.LENGTH_SHORT)
                    .show();
            /**
             * then save to database
             */
            try {
                dbHelper = new MySQLHelper(getApplicationContext());
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                ContentValues simpan = new ContentValues();
                simpan.put("id_kendaraan", idkendaraan);
                simpan.put("jarak", jarakTotal);
                db.insert("perjalanan", null, simpan);
                Toast.makeText(getBaseContext(), "Perjalanan tersimpan", Toast.LENGTH_SHORT).show();
                db.close();
            } catch (Exception e) {
                Toast.makeText(getBaseContext(), "Tidak bisa menyimpan perjalanan", Toast.LENGTH_SHORT).show();
            }

            //partial reset
            stop.setEnabled(false);
            start.setEnabled(true);
            reset.setEnabled(true);
            jarakTotal = 0.0;

            checkJarak();
        }
    });
    reset.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            map.clear();
            jarakTotal = 0.0;
            jarak.setText(null);
        }
    });
    checkJarak();
}

From source file:net.olejon.mdapp.ClinicalTrialsCardsActivity.java

private void search(final String string, boolean cache) {
    try {//from w  ww.j  a  v  a 2  s  .  c  om
        RequestQueue requestQueue = Volley.newRequestQueue(mContext);

        String apiUri = getString(R.string.project_website_uri) + "api/1/clinicaltrials/?search="
                + URLEncoder.encode(string.toLowerCase(), "utf-8");

        if (!cache)
            requestQueue.getCache().remove(apiUri);

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(apiUri, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                mProgressBar.setVisibility(View.GONE);
                mSwipeRefreshLayout.setRefreshing(false);

                if (response.length() == 0) {
                    mSwipeRefreshLayout.setVisibility(View.GONE);
                    mNoClinicalTrialsLayout.setVisibility(View.VISIBLE);
                } else {
                    if (mTools.isTablet()) {
                        int spanCount = (response.length() == 1) ? 1 : 2;

                        mRecyclerView.setLayoutManager(
                                new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
                    }

                    mRecyclerView.setAdapter(new ClinicalTrialsCardsAdapter(mContext, response));

                    ContentValues contentValues = new ContentValues();
                    contentValues.put(ClinicalTrialsSQLiteHelper.COLUMN_STRING, string);

                    SQLiteDatabase sqLiteDatabase = new ClinicalTrialsSQLiteHelper(mContext)
                            .getWritableDatabase();

                    sqLiteDatabase.delete(ClinicalTrialsSQLiteHelper.TABLE,
                            ClinicalTrialsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(string)
                                    + " COLLATE NOCASE",
                            null);
                    sqLiteDatabase.insert(ClinicalTrialsSQLiteHelper.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.clinicaltrials_cards_something_went_wrong), 1);

                finish();

                Log.e("ClinicalTrialsCards", error.toString());
            }
        });

        jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        requestQueue.add(jsonArrayRequest);
    } catch (Exception e) {
        Log.e("ClinicalTrialsCards", Log.getStackTraceString(e));
    }
}

From source file:net.olejon.mdapp.NotesEditActivity.java

private void saveNote() {
    String title = mTitleEditText.getText().toString().trim();
    String text = mTextEditText.getText().toString().trim();
    String patientId = mPatientIdEditText.getText().toString().trim();
    String patientName = mPatientNameEditText.getText().toString().trim();
    String patientDoctor = mPatientDoctorEditText.getText().toString().trim();
    String patientDepartment = mPatientDepartmentEditText.getText().toString().trim();
    String patientRoom = mPatientRoomEditText.getText().toString().trim();

    if (title.equals("") || text.equals("")) {
        mTools.showToast(getString(R.string.notes_edit_invalid_values), 1);
    } else {/*from   www .  j a va 2s.co m*/
        ContentValues contentValues = new ContentValues();

        contentValues.put(NotesSQLiteHelper.COLUMN_TITLE, title);
        contentValues.put(NotesSQLiteHelper.COLUMN_TEXT, text);
        contentValues.put(NotesSQLiteHelper.COLUMN_DATA, "");
        contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_ID, patientId);
        contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_NAME, patientName);
        contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_DOCTOR, patientDoctor);
        contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_DEPARTMENT, patientDepartment);
        contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_ROOM, patientRoom);

        if (mPatientMedicationsJsonArray.length() == 0) {
            contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_MEDICATIONS, "");
        } else {
            contentValues.put(NotesSQLiteHelper.COLUMN_PATIENT_MEDICATIONS,
                    mPatientMedicationsJsonArray.toString());
        }

        SQLiteDatabase sqLiteDatabase = new NotesSQLiteHelper(mContext).getWritableDatabase();

        if (noteId == 0) {
            sqLiteDatabase.insert(NotesSQLiteHelper.TABLE, null, contentValues);
        } else {
            sqLiteDatabase.update(NotesSQLiteHelper.TABLE, contentValues,
                    NotesSQLiteHelper.COLUMN_ID + " = " + noteId, null);
        }

        sqLiteDatabase.close();

        mTools.showToast(getString(R.string.notes_edit_saved), 1);

        finish();
    }
}

From source file:com.raspi.chatapp.util.storage.MessageHistory.java

public boolean renameChat(String buddyId, String newName) {
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(MessageHistoryContract.ChatEntry.COLUMN_NAME_NAME, newName);
    String where = MessageHistoryContract.ChatEntry.COLUMN_NAME_BUDDY_ID + "=?";

    int res = db.update(MessageHistoryContract.ChatEntry.TABLE_NAME_ALL_CHATS, cv, where,
            new String[] { buddyId });
    db.close();
    return (res > 0);
}

From source file:com.dm.wallpaper.board.databases.Database.java

public void addCategories(List<WallpaperJson> categories) {
    String query = "INSERT INTO " + TABLE_CATEGORIES + " (" + KEY_NAME + "," + KEY_THUMB_URL
            + ") VALUES (?,?);";
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement statement = db.compileStatement(query);
    db.beginTransaction();/*from   w w w.  ja va2s .c o  m*/

    for (int i = 0; i < categories.size(); i++) {
        statement.clearBindings();
        statement.bindString(1, categories.get(i).name);
        statement.bindString(2, categories.get(i).thumbUrl == null ? "" : categories.get(i).thumbUrl);
        statement.execute();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();
}

From source file:info.staticfree.android.units.UnitUsageDBHelper.java

public int getUnitUsageDbCount() {
    final SQLiteDatabase db = getReadableDatabase();
    final String[] proj = { UsageEntry._ID };
    if (!db.isOpen()) {
        return -1;
    }//ww  w .  j a v  a  2  s.  c  o m
    final Cursor c = db.query(DB_USAGE_TABLE, proj, null, null, null, null, null);
    c.moveToFirst();
    final int count = c.getCount();
    c.close();
    db.close();
    return count;
}

From source file:com.dm.wallpaper.board.databases.Database.java

public List<Wallpaper> getWallpapers() {
    List<Wallpaper> wallpapers = new ArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_WALLPAPERS, null, null, null, null, null, KEY_ADDED_ON + " DESC, " + KEY_ID);
    if (cursor.moveToFirst()) {
        do {/*from  ww  w.j  a v  a  2 s. c  om*/
            Wallpaper wallpaper = new Wallpaper(cursor.getString(1), cursor.getString(2), cursor.getString(3),
                    cursor.getString(4), cursor.getString(5));
            wallpapers.add(wallpaper);
        } while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return wallpapers;
}

From source file:com.openatk.rockapp.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("MainActivity", "onActivityResult");
    switch (requestCode) {
    // Get the result of taking a picture
    case REQUEST_PICTURE:
        if (resultCode == RESULT_OK) {
            Marker marker = markerHandler.getMarkerByRockId(mCurrentRockSelected);
            if (marker != null) {
                Rock rock = (Rock) marker.getData();
                if (rock != null) {
                    // Update the rock model and save it
                    File image = new File(Rock.IMAGE_PATH,
                            String.format(Rock.IMAGE_FILENAME_PATTERN, rock.getId()));
                    rock.setPicture(image.getAbsolutePath());

                    // TODO set changed and changed date to upload the rock photo
                    SQLiteDatabase database = dbHelper.getWritableDatabase();
                    rock.save(database);
                    database.close();
                    dbHelper.close();// w w  w. j a  v  a2s  .  c om
                    slideMenu.editRock(rock);
                }
            }
        }
        break;
    }
}

From source file:cl.gisred.android.RepartoActivity.java

public void deleteData(int id) {
    SQLiteDatabase db = sqlReparto.getWritableDatabase();
    db.delete("repartos", "id=" + id, null);
    db.close();

    if (iContRep > 0) {
        iContRep--;/*from   ww w  .j a  v  a 2  s  .c  om*/
        updDashboard();
    }

}

From source file:com.maxwen.wallpaper.board.databases.Database.java

public void deleteCategories(@NonNull List<Category> categories) {
    SQLiteDatabase db = this.getWritableDatabase();
    for (int i = 0; i < categories.size(); i++) {
        db.delete(TABLE_CATEGORIES, KEY_NAME + " = ?", new String[] { categories.get(i).getName() });
    }/*  w  ww.  j  av  a2  s . c  o  m*/
    db.close();
}