com.eveningoutpost.dexdrip.utils.DatabaseUtil Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.utils.DatabaseUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Home.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_export_database) {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... params) {
                return DatabaseUtil.saveSql(getBaseContext());
            }

            @Override
            protected void onPostExecute(String filename) {
                super.onPostExecute(filename);

                final Context ctx = getApplicationContext();

                Toast.makeText(ctx, "Export stored at " + filename, Toast.LENGTH_SHORT).show();

                final NotificationCompat.Builder n = new NotificationCompat.Builder(ctx);
                n.setContentTitle("Export complete");
                n.setContentText("Ready to be sent.");
                n.setAutoCancel(true);
                n.setSmallIcon(R.drawable.ic_action_communication_invert_colors_on);
                ShareNotification.viewOrShare("application/octet-stream", Uri.fromFile(new File(filename)), n, ctx);

                final NotificationManager manager = (NotificationManager) ctx.getSystemService(Service.NOTIFICATION_SERVICE);
                manager.notify(Notifications.exportCompleteNotificationId, n.build());
            }
        }.execute();

        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #2
Source File: ImportDatabaseActivity.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
protected String doInBackground(Void... args) {
    //Check if db has the correct version:
    try {
        SQLiteDatabase db = SQLiteDatabase.openDatabase(dbFile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);
        int version = db.getVersion();
        db.close();
        if (getDBVersion() != version) {
            statusDialog.dismiss();
            return "Wrong Database version.\n(" + version + " instead of " + getDBVersion() + ")";
        }
    } catch (SQLiteException e){
        statusDialog.dismiss();
        return "Database cannot be opened... aborting.";
    }
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            statusDialog.setMessage("Step 2: exporting current DB");
        }
    });

    String export = DatabaseUtil.saveSql(getBaseContext());


    if (export == null) {
        statusDialog.dismiss();
        return "Exporting database not successfull... aborting.";
    }

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            statusDialog.setMessage("Step 3: importing DB");
        }
    });

    String result = DatabaseUtil.loadSql(getBaseContext(), dbFile.getAbsolutePath());

    statusDialog.dismiss();
    return result;
}