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:net.olejon.mdapp.NotesEditActivity.java

private void deleteNote(boolean delete) {
    if (delete) {
        SQLiteDatabase sqLiteDatabase = new NotesSQLiteHelper(mContext).getWritableDatabase();
        sqLiteDatabase.delete(NotesSQLiteHelper.TABLE, NotesSQLiteHelper.COLUMN_ID + " = " + noteId, null);
        sqLiteDatabase.close();

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

        finish();/* w w w .jav a 2 s. c o m*/
    } else {
        new MaterialDialog.Builder(mContext).title(getString(R.string.notes_edit_delete_dialog_title))
                .content(getString(R.string.notes_edit_delete_dialog_message))
                .positiveText(getString(R.string.notes_edit_delete_dialog_positive_button))
                .neutralText(getString(R.string.notes_edit_delete_dialog_neutral_button))
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        deleteNote(true);
                    }
                }).contentColorRes(R.color.black).positiveColorRes(R.color.red)
                .neutralColorRes(R.color.dark_blue).show();
    }
}

From source file:it.sasabz.android.sasabus.fragments.OnlineShowFragment.java

/** Called with the activity is first created. */
@Override//  ww w . j a  va2  s  .c  o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!XMLRequest.haveNetworkConnection()) {
        Toast.makeText(getContext(), R.string.no_network_connection, Toast.LENGTH_LONG).show();
        getFragmentManager().popBackStack();
        return null;
    }
    result = inflater.inflate(R.layout.connection_listview_layout, container, false);

    if (list == null && request == null) {
        progress = new ProgressDialog(getContext());
        progress.setMessage(getResources().getText(R.string.waiting));
        progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progress.setCancelable(false);
        progress.show();

        request = new XMLConnectionRequestList(from, to, datetime, this);
        request.execute();
    } else {
        progress = null;
        fillData(list);
    }
    listview = (ListView) result.findViewById(android.R.id.list);
    listview.setOnItemClickListener(this);
    Button later = (Button) result.findViewById(R.id.later);
    Button earlier = (Button) result.findViewById(R.id.earlier);

    later.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            progress = new ProgressDialog(getContext());
            progress.setMessage(getResources().getText(R.string.waiting));
            progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progress.setCancelable(false);
            progress.show();
            isLater = true;
            XMLForwardScroll forward = new XMLForwardScroll(list, getThis());
            forward.execute();

        }
    });

    earlier.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            progress = new ProgressDialog(getContext());
            progress.setMessage(getResources().getText(R.string.waiting));
            progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progress.setCancelable(false);
            progress.show();
            isEarlier = true;
            XMLBackwardScroll backward = new XMLBackwardScroll(list, getThis());
            backward.execute();

        }
    });

    Button favorites = (Button) result.findViewById(R.id.favorite);
    favorites.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            SQLiteDatabase favdb = new FavoritenDB(getActivity()).getReadableDatabase();
            Favorit favorit = new Favorit(from.getName(), to.getName());
            if (favorit.insert(favdb)) {
                Toast.makeText(getActivity(), R.string.favorit_add, Toast.LENGTH_LONG).show();
            }
            favdb.close();

        }
    });

    return result;
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public void updateNote(int row_id) {

    try {//  w ww  .ja  v  a 2  s. c o m
        JSONArray tagID = db.getSelectedTagId(selectedTags);
        long stage_id = Long.parseLong(stages.get(noteStages.getSelectedItem().toString()));
        ContentValues values = new ContentValues();
        JSONObject vals = new JSONObject();

        // If Pad Installed Over Server
        if (padAdded) {
            JSONArray url = new JSONArray();
            url.put(originalMemo);
            JSONObject obj = oe_obj.call_kw("pad.common", "pad_get_content", url);

            // HTMLHelper helper = new HTMLHelper();
            String link = HTMLHelper.htmlToString(obj.getString("result"));
            values.put("stage_id", stage_id);
            vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString()));

            values.put("name", db.generateName(link));
            vals.put("name", values.get("name").toString());

            values.put("memo", obj.getString("result"));
            vals.put("memo", values.get("memo").toString());

            values.put("note_pad_url", originalMemo);
            vals.put("note_pad_url", values.get("note_pad_url").toString());
        } // If Pad Not Installed Over Server
        else {
            values.put("stage_id", stage_id);
            vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString()));

            values.put("name", db.generateName(noteMemo.getText().toString()));
            vals.put("name", values.get("name").toString());

            values.put("memo", Html.toHtml(noteMemo.getText()));
            vals.put("memo", values.get("memo").toString());
        }

        JSONArray tag_ids = new JSONArray();
        tag_ids.put(6);
        tag_ids.put(false);
        JSONArray c_ids = new JSONArray(tagID.toString());
        tag_ids.put(c_ids);
        vals.put("tag_ids", new JSONArray("[" + tag_ids.toString() + "]"));

        // This will update Notes over Server And Local database
        db = new NoteDBHelper(scope.context());
        if (oe_obj.updateValues(db.getModelName(), vals, row_id)) {
            db.write(db, values, row_id, true);
            db.executeSQL("delete from note_note_note_tag_rel where note_note_id = ? and oea_name = ?",
                    new String[] { row_id + "", scope.User().getAndroidName() });
            for (int i = 0; i < tagID.length(); i++) {
                ContentValues rel_vals = new ContentValues();
                rel_vals.put("note_note_id", row_id);
                rel_vals.put("note_tag_id", tagID.getInt(i));
                rel_vals.put("oea_name", scope.User().getAndroidName());
                SQLiteDatabase insertDb = db.getWritableDatabase();
                insertDb.insert("note_note_note_tag_rel", null, rel_vals);
                insertDb.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

public int getCategoryCount(String category) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_WALLPAPERS, null, "LOWER(" + KEY_CATEGORY + ") LIKE ?",
            new String[] { "%" + category.toLowerCase(Locale.getDefault()) + "%" }, null, null, null);
    int count = cursor.getCount();
    cursor.close();//from w w w  . j a v a 2s  . c  om
    db.close();
    return count;
}

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

private void getNotes() {
    if (mIsAuthenticated) {
        GetNotesTask getNotesTask = new GetNotesTask();
        getNotesTask.execute();//  w ww .  j  av a 2 s  .  co m
    } else {
        new MaterialDialog.Builder(mContext).title(getString(R.string.notes_dialog_verify_pin_code_title))
                .customView(R.layout.activity_notes_dialog_verify_pin_code, true)
                .positiveText(getString(R.string.notes_dialog_verify_pin_code_positive_button))
                .negativeText(getString(R.string.notes_dialog_verify_pin_code_negative_button))
                .neutralText(getString(R.string.notes_dialog_verify_pin_code_neutral_button))
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        EditText pinCodeEditText = (EditText) dialog
                                .findViewById(R.id.notes_dialog_verify_pin_code);

                        String pinCode = pinCodeEditText.getText().toString();

                        if (pinCode.equals(mTools.getSharedPreferencesString("NOTES_PIN_CODE"))) {
                            GetNotesTask getNotesTask = new GetNotesTask();
                            getNotesTask.execute();

                            dialog.dismiss();
                        } else {
                            mTools.showToast(getString(R.string.notes_dialog_verify_pin_code_wrong), 1);
                        }
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        dialog.dismiss();

                        finish();
                    }

                    @Override
                    public void onNeutral(MaterialDialog dialog) {
                        dialog.dismiss();

                        new MaterialDialog.Builder(mContext)
                                .title(getString(R.string.notes_dialog_reset_pin_code_title))
                                .content(getString(R.string.notes_dialog_reset_pin_code_message))
                                .positiveText(getString(R.string.notes_dialog_reset_pin_code_positive_button))
                                .neutralText(getString(R.string.notes_dialog_reset_pin_code_neutral_button))
                                .callback(new MaterialDialog.ButtonCallback() {
                                    @Override
                                    public void onPositive(MaterialDialog dialog) {
                                        mTools.setSharedPreferencesString("NOTES_PIN_CODE", "");

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

                                        sqLiteDatabase.delete(NotesSQLiteHelper.TABLE, null, null);

                                        sqLiteDatabase.close();

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

                                        finish();
                                    }

                                    @Override
                                    public void onNeutral(MaterialDialog dialog) {
                                        finish();
                                    }
                                }).cancelListener(new DialogInterface.OnCancelListener() {
                                    @Override
                                    public void onCancel(DialogInterface dialogInterface) {
                                        finish();
                                    }
                                }).contentColorRes(R.color.black).positiveColorRes(R.color.red)
                                .neutralColorRes(R.color.dark_blue).show();
                    }
                }).showListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(DialogInterface dialogInterface) {
                        mInputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
                    }
                }).cancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        dialogInterface.dismiss();

                        finish();
                    }
                }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue)
                .negativeColorRes(R.color.black).neutralColorRes(R.color.dark_blue).autoDismiss(false).show();
    }
}

From source file:heartware.com.heartware_master.DBAdapter.java

public void createProfile(HashMap<String, String> queryValues) {
    SQLiteDatabase database = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(USERNAME, queryValues.get(USERNAME));
    values.put(PASSWORD, queryValues.get(PASSWORD));
    values.put(DIFFICULTY, queryValues.get(DIFFICULTY));
    values.put(DISABILITY, queryValues.get(DISABILITY));
    database.insert(PROFILES_TABLE, null, values);
    database.close();
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

/**
 * Load all Lectures from the DB on the day specified
 *
 * @param context The Android Context/*from   w  w w  .j  a v  a2s .c  o m*/
 * @param day The day to load lectures for (0..), or -1 for all days
 * @return ArrayList of Lecture objects
 */
public static LectureList loadLecturesForDayIndex(Context context, int day) {
    MyApp.LogDebug(LOG_TAG, "load lectures of day " + day);

    SQLiteDatabase lecturedb = null;
    LecturesDBOpenHelper lecturesDB = new LecturesDBOpenHelper(context);
    lecturedb = lecturesDB.getReadableDatabase();

    HighlightDBOpenHelper highlightDB = new HighlightDBOpenHelper(context);
    SQLiteDatabase highlightdb = highlightDB.getReadableDatabase();

    LectureList lectures = new LectureList();
    Cursor cursor, hCursor;
    boolean allDays;

    if (day == ALL_DAYS) {
        allDays = true;
    } else {
        allDays = false;
    }

    try {
        cursor = lecturedb.query(LecturesTable.NAME, LecturesDBOpenHelper.allcolumns,
                allDays ? null : (LecturesTable.Columns.DAY + "=?"),
                allDays ? null : (new String[] { String.format("%d", day) }), null, null,
                LecturesTable.Columns.DATE_UTC);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        highlightdb.close();
        lecturesDB.close();
        return null;
    }
    try {
        hCursor = highlightdb.query(HighlightsTable.NAME, HighlightDBOpenHelper.allcolumns, null, null, null,
                null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        highlightdb.close();
        lecturesDB.close();
        return null;
    }
    MyApp.LogDebug(LOG_TAG, "Got " + cursor.getCount() + " rows.");
    MyApp.LogDebug(LOG_TAG, "Got " + hCursor.getCount() + " highlight rows.");

    if (cursor.getCount() == 0) {
        cursor.close();
        lecturedb.close();
        highlightdb.close();
        lecturesDB.close();
        return null;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Lecture lecture = new Lecture(cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.EVENT_ID)));
        lecture.title = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TITLE));
        lecture.subtitle = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.SUBTITLE));
        lecture.day = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DAY));
        lecture.room = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.ROOM));
        lecture.startTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.START));
        lecture.duration = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DURATION));
        lecture.speakers = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.SPEAKERS));
        lecture.track = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TRACK));
        lecture.type = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TYPE));
        lecture.lang = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.LANG));
        lecture.abstractt = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.ABSTRACT));
        lecture.description = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DESCR));
        lecture.relStartTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.REL_START));
        lecture.date = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DATE));
        lecture.links = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.LINKS));
        lecture.dateUTC = cursor.getLong(cursor.getColumnIndex(LecturesTable.Columns.DATE_UTC));
        lecture.room_index = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.ROOM_IDX));
        lecture.recordingLicense = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.REC_LICENSE));
        lecture.recordingOptOut = cursor.getInt(
                cursor.getColumnIndex(LecturesTable.Columns.REC_OPTOUT)) == LecturesTable.Values.REC_OPTOUT_OFF
                        ? Lecture.RECORDING_OPTOUT_OFF
                        : Lecture.RECORDING_OPTOUT_ON;
        lecture.changedTitle = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TITLE)) != 0;
        lecture.changedSubtitle = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_SUBTITLE)) != 0;
        lecture.changedRoom = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_ROOM)) != 0;
        lecture.changedDay = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_DAY)) != 0;
        lecture.changedSpeakers = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_SPEAKERS)) != 0;
        lecture.changedRecordingOptOut = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_RECORDING_OPTOUT)) != 0;
        lecture.changedLanguage = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_LANGUAGE)) != 0;
        lecture.changedTrack = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TRACK)) != 0;
        lecture.changedIsNew = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_IS_NEW)) != 0;
        lecture.changedTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TIME)) != 0;
        lecture.changedDuration = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_DURATION)) != 0;
        lecture.changedIsCanceled = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_IS_CANCELED)) != 0;

        lectures.add(lecture);
        cursor.moveToNext();
    }
    cursor.close();

    hCursor.moveToFirst();
    while (!hCursor.isAfterLast()) {
        String lecture_id = hCursor.getString(hCursor.getColumnIndex(HighlightsTable.Columns.EVENT_ID));
        int highlightState = hCursor.getInt(hCursor.getColumnIndex(HighlightsTable.Columns.HIGHLIGHT));
        MyApp.LogDebug(LOG_TAG, "lecture " + lecture_id + " is hightlighted:" + highlightState);

        for (Lecture lecture : lectures) {
            if (lecture.lecture_id.equals(lecture_id)) {
                lecture.highlight = (highlightState == HighlightsTable.Values.HIGHLIGHT_STATE_ON ? true
                        : false);
            }
        }
        hCursor.moveToNext();
    }
    hCursor.close();

    highlightdb.close();
    lecturedb.close();
    lecturesDB.close();
    return lectures;
}

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

public int getMessageAmount(String buddyId) {
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    try {// w w  w  .  ja va2 s .  co  m
        Cursor c = db.rawQuery("SELECT * FROM " + buddyId, null);
        int cnt = c.getCount();
        c.close();
        db.close();
        return cnt;
    } catch (Exception e) {
        return 0;
    }
}

From source file:com.melchor629.musicote.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    // Set the user interface layout for this Activity
    // The layout file is defined in the project res/layout/main.xml file
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  www  .j  a  v  a2s  . c  o m
    appContext = getApplicationContext();

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.mainLayout);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark,
            R.color.colorGrey600);
    final ListView list = (ListView) findViewById(android.R.id.list);
    list.setOnScrollListener(new ListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            boolean enable = false;
            if (list != null && list.getChildCount() > 0) {
                // check if the first item of the list is visible
                boolean firstItemVisible = list.getFirstVisiblePosition() == 0;
                // check if the top of the first item is visible
                boolean topOfFirstItemVisible = list.getChildAt(0).getTop() == 0;
                // enabling or disabling the refresh layout
                enable = firstItemVisible && topOfFirstItemVisible;
            }
            swipeRefreshLayout.setEnabled(enable);
        }
    });
    getActionBar().setIcon(R.drawable.ic_launcher);
    getActionBar().setDisplayUseLogoEnabled(true);

    // La app prueba en busca de la direccin correcta
    WifiManager mw = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = mw.getConnectionInfo();
    String SSID = wi.getSSID();
    Log.i("MainActivity", "Wifi conectado: " + SSID + " " + (SSID != null ? SSID.equals("Madrigal") : ""));
    if (SSID == null) {
        SSID = "";
        Toast.makeText(this, getString(R.string.no_wifi), Toast.LENGTH_LONG).show();
    }
    if (SSID.equals("Madrigal") || SSID.contains("Madrigal")
            || System.getProperty("os.version").equals("3.4.67+")) {
        MainActivity.HOST = "192.168.1.133";
    } else {
        MainActivity.HOST = "reinoslokos.no-ip.org";
    }
    Log.i("MainActivity", "HOST: " + HOST);

    //Deletes the notification if remains (BUG)
    NotificationManager mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Reproductor.a == -1)
        mn.cancel(1);
    mn.cancel(3);

    //Revisa la base de datos
    DB mDbHelper = new DB(getBaseContext());
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    //Actualizacin de la lista
    if (mDbHelper.isNecesaryUpgrade(db) && Utils.HostTest(HOST) == 200)
        async();
    else
        cursordb(db);

    db.close();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

From source file:com.onesignal.NotificationBundleProcessor.java

private static void saveNotification(Context context, Bundle bundle, boolean opened, int notificationId) {
    try {//from   w w  w  . j  a va 2  s  . c  o m
        JSONObject customJSON = new JSONObject(bundle.getString("custom"));

        OneSignalDbHelper dbHelper = new OneSignalDbHelper(context);
        SQLiteDatabase writableDb = dbHelper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(NotificationTable.COLUMN_NAME_NOTIFICATION_ID, customJSON.getString("i"));
        if (bundle.containsKey("grp"))
            values.put(NotificationTable.COLUMN_NAME_GROUP_ID, bundle.getString("grp"));

        values.put(NotificationTable.COLUMN_NAME_OPENED, opened ? 1 : 0);
        if (!opened)
            values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, notificationId);

        if (bundle.containsKey("title"))
            values.put(NotificationTable.COLUMN_NAME_TITLE, bundle.getString("title"));
        values.put(NotificationTable.COLUMN_NAME_MESSAGE, bundle.getString("alert"));

        values.put(NotificationTable.COLUMN_NAME_FULL_DATA, bundleAsJSONObject(bundle).toString());

        writableDb.insert(NotificationTable.TABLE_NAME, null, values);

        // Clean up old records that have been dismissed or opened already after 1 week.
        writableDb.delete(NotificationTable.TABLE_NAME,
                NotificationTable.COLUMN_NAME_CREATED_TIME + " < "
                        + ((System.currentTimeMillis() / 1000) - 604800) + " AND " + "("
                        + NotificationTable.COLUMN_NAME_DISMISSED + " = 1 OR "
                        + NotificationTable.COLUMN_NAME_OPENED + " = 1" + ")",
                null);

        writableDb.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}