@Override public void onClick(View v) { if (v.getId() == R.id.btnSaveDB) { // they've hit apply. OnChange(); // make sure we've got everything. File fDirectory = new File(MakeParentPath()); if (!fDirectory.exists() && !fDirectory.mkdir()) { Toast.makeText(this, "Couldn't create directory. Not saved", Toast.LENGTH_LONG).show(); } else { File f = new File(MakeFilePath(m_strTargetFilename)); if (f.exists()) { Toast.makeText(this, "File already exists. Not saved", Toast.LENGTH_LONG).show(); } else { SQLiteDatabase db = RaceDatabase.Get(); db.beginTransaction(); String strDBPath = db.getPath(); try { if (CopyFile(new File(strDBPath), f)) { Toast.makeText(this, "DB Saved", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "DB failed to save", Toast.LENGTH_LONG).show(); } } catch (IOException e) { Toast.makeText(this, "Failed to copy DB: " + e.toString(), Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(this, "Unexpected failure: " + e.toString(), Toast.LENGTH_LONG).show(); } db.endTransaction(); } } } }
@Override public void onClick(DialogInterface arg0, int choice) { // only one alert dialog for this sucker at this point if (arg0 == m_dbWarning) { if (choice == AlertDialog.BUTTON_POSITIVE) { try { String strDBPath = RaceDatabase.Get().getPath(); RaceDatabase.Get().close(); if (CopyFile(m_copyThis, new File(strDBPath))) { RaceDatabase.CreateOnPath(getApplicationContext(), strDBPath); Toast.makeText(this, "Successfully imported database", Toast.LENGTH_LONG).show(); } } catch (IOException e) { Toast.makeText(this, "Failed to import database: " + e.toString(), Toast.LENGTH_LONG) .show(); } } m_dbWarning = null; } }