]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
Updated backup/restore to use OISafe for naming.
authorrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Mon, 19 Jan 2009 19:45:37 +0000 (19:45 +0000)
committerrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Mon, 19 Jan 2009 19:45:37 +0000 (19:45 +0000)
Updated filenames to use OISafe.

git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1785 72b678ce-9140-0410-bee8-679b907dd61a

res/values/strings.xml
src/org/openintents/safe/Backup.java
src/org/openintents/safe/CategoryList.java
src/org/openintents/safe/RestoreHandler.java

index 534d2bc09275e992290f84c2b3131d273cff3695..ab4d471fb3c43501dc8170ed3a60d98d0a1dbc0d 100644 (file)
@@ -52,7 +52,8 @@
        <string name="cannot_decrypt_password">Cannot decrypt password</string>
        <string name="error_export">Error exporting database</string>\r
        <string name="export_database">Export Database</string>
-       <string name="export_success">Export to 'passwordsafe.csv' successful.   Warning!   The file is not encrypted.</string>
+       <string name="export_success">Export to '</string>\r
+       <string name="export_success2">' successful.   Warning!   The file is not encrypted.</string>
        <string name="export_file_error">Unable to create export file 'passwordsafe.csv' on SDCARD.  You might try disconnecting USB from computer.</string>
        <string name="import_database">Import Database</string>\r
        <string name="import_file_missing">Import file is missing:</string>\r
        <string name="dialog_title_external_access">OI Safe: Another application requests access.</string>\r
        <string name="dialog_summary_external_access">Allow other applications to secure your data with OI Safe.</string>\r
        <string name="dialog_comment_external_access">This can also be set in OI Safe\'s Menu / Preferences.</string>\r
-       <string name="pref_title_lock_timeout">Lock timeout</string>\r
+       <string name="pref_title_lock_timeout">Auto lock timeout</string>\r
        <string name="pref_summary_lock_timeout">Minutes before timeout occurs and safe is locked.</string>\r
-       <string name="pref_dialog_title_lock_timeout">Lock timeout</string>\r
+       <string name="pref_dialog_title_lock_timeout">Auto lock timeout</string>\r
        <string name="intent_decrypt">Decrypt (OI Safe)</string>\r
        <string name="intent_encrypt">Encrypt (OI Safe)</string>\r
        <string name="intent_get_password">Get password (OI Safe)</string>\r
index ab3ef95ec7c11ef1c0205ec0375c9bda66567c3d..20d377d8a13fb6c28e0d46616e117d37af422a46 100644 (file)
@@ -30,7 +30,7 @@ public class Backup {
        private static boolean debug = false;
        private static final String TAG = "Backup";
        
-       public static int CURRENT_VERSION = 2;
+       public static int CURRENT_VERSION = 1;
        
        private String result="";
        
@@ -49,7 +49,7 @@ public class Backup {
             serializer.setOutput(str, "utf-8");
             serializer.startDocument(null, Boolean.valueOf(true));
             serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-            serializer.startTag(null, "AndroidPasswordSafe");
+            serializer.startTag(null, "OISafe");
             
             serializer.attribute(null, "version", Integer.toString(CURRENT_VERSION));
             
@@ -114,7 +114,7 @@ public class Backup {
                                serializer.endTag(null, "Category");
                        }
 
-                       serializer.endTag(null, "AndroidPasswordSafe");
+                       serializer.endTag(null, "OISafe");
                        serializer.endDocument();
 
                        dbHelper.close();
index 0cb90a1f91612b2a192dd77684b16ae3bba11ae7..eb2c17a31d6cfead2cb23c8ccbbad306af8bae0e 100644 (file)
@@ -101,8 +101,8 @@ public class CategoryList extends ListActivity {
 
     public static final int MAX_CATEGORIES = 256;
 
-    private static final String EXPORT_FILENAME = "/sdcard/passwordsafe.csv";
-    public static final String BACKUP_FILENAME = "/sdcard/passwordsafe.xml";
+    private static final String EXPORT_FILENAME = "/sdcard/oisafe.csv";
+    public static final String BACKUP_FILENAME = "/sdcard/oisafe.xml";
     
     public static final String KEY_ID = "id";  // Intent keys
 
@@ -113,6 +113,7 @@ public class CategoryList extends ListActivity {
        private int importedEntries=0;
        private Thread importThread=null;
        private boolean importDeletedDatabase=false;
+       private String importedFilename="";
 
        private Thread backupThread=null;
 
@@ -148,24 +149,27 @@ public class CategoryList extends ListActivity {
                                Toast.makeText(CategoryList.this, importMessage,
                                        Toast.LENGTH_LONG).show();
                        }
-                       String deleteMsg=getString(R.string.import_delete_csv) +
-                               " " + EXPORT_FILENAME + "?";
-                               Dialog about = new AlertDialog.Builder(CategoryList.this)
-                                       .setIcon(R.drawable.passicon)
-                                       .setTitle(R.string.import_complete)
-                                       .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
-                                               public void onClick(DialogInterface dialog, int whichButton) {
-                                                       File csvFile=new File(EXPORT_FILENAME);
-                                                       csvFile.delete();
-                                               }
-                                       })
-                                       .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
-                                               public void onClick(DialogInterface dialog, int whichButton) {
-                                               }
-                                       }) 
-                                       .setMessage(deleteMsg)
-                                       .create();
-                               about.show();
+                       if (importedFilename != "") {
+                               String deleteMsg=getString(R.string.import_delete_csv) +
+                                       " " + importedFilename + "?";
+                                       Dialog about = new AlertDialog.Builder(CategoryList.this)
+                                               .setIcon(R.drawable.passicon)
+                                               .setTitle(R.string.import_complete)
+                                               .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
+                                                       public void onClick(DialogInterface dialog, int whichButton) {
+                                                               File csvFile=new File(importedFilename);
+                                                               csvFile.delete();
+                                                               importedFilename="";
+                                                       }
+                                               })
+                                               .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
+                                                       public void onClick(DialogInterface dialog, int whichButton) {
+                                                       }
+                                               }) 
+                                               .setMessage(deleteMsg)
+                                               .create();
+                                       about.show();
+                       }
                                
                        if ((importedEntries!=0) || (importDeletedDatabase))
                        {
@@ -647,8 +651,9 @@ public class CategoryList extends ListActivity {
     }
     
        public boolean exportDatabase(){
+               String filename=EXPORT_FILENAME;
                try {
-                       CSVWriter writer = new CSVWriter(new FileWriter(EXPORT_FILENAME), ',');
+                       CSVWriter writer = new CSVWriter(new FileWriter(filename), ',');
 
                        String[] header = { getString(R.string.category),
                                        getString(R.string.description), 
@@ -726,7 +731,9 @@ public class CategoryList extends ListActivity {
                        Toast.LENGTH_SHORT).show();
                        return false;
                }
-        Toast.makeText(CategoryList.this, R.string.export_success,
+               String msg=getString(R.string.export_success)+filename+
+                       getString(R.string.export_success2);
+        Toast.makeText(CategoryList.this, msg,
                 Toast.LENGTH_LONG).show();
                return true;
        }
@@ -735,7 +742,7 @@ public class CategoryList extends ListActivity {
                dbHelper.deleteDatabase();
        }
 
-       public void deleteDatabase4Import(){
+       public void deleteDatabase4Import(final String filename){
 //             Log.i(TAG,"deleteDatabase4Import");
                Dialog about = new AlertDialog.Builder(this)
                        .setIcon(R.drawable.passicon)
@@ -744,7 +751,7 @@ public class CategoryList extends ListActivity {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                        deleteDatabaseNow();
                                        importDeletedDatabase=true;
-                                       importDatabaseThreadStart();
+                                       importDatabaseThreadStart(filename);
                                }
                        })
                        .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@@ -757,10 +764,11 @@ public class CategoryList extends ListActivity {
        }
                
        public void importDatabase(){
-               File csvFile=new File(EXPORT_FILENAME);
+               final String filename=EXPORT_FILENAME;
+               File csvFile=new File(filename);
                if (!csvFile.exists()) {
                        String msg=getString(R.string.import_file_missing) + " " +
-                               EXPORT_FILENAME;
+                               filename;
                Toast.makeText(CategoryList.this, msg,
                        Toast.LENGTH_LONG).show();
                        return;
@@ -770,13 +778,13 @@ public class CategoryList extends ListActivity {
                        .setTitle(R.string.dialog_import_title)
                        .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
-                                       deleteDatabase4Import();
+                                       deleteDatabase4Import(filename);
                                }
                        })
                        .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                        importDeletedDatabase=false;
-                                       importDatabaseThreadStart();
+                                       importDatabaseThreadStart(filename);
                                }
                        }) 
                        .setMessage(R.string.dialog_import_msg)
@@ -789,11 +797,11 @@ public class CategoryList extends ListActivity {
         * the import in a thread it allows the main UI thread to return
         * and permit the updating of the progress dialog.
         */
-       private void importDatabaseThreadStart(){
+       private void importDatabaseThreadStart(final String filename){
                showDialog(IMPORT_PROGRESS_KEY);
                importThread = new Thread(new Runnable() {
                        public void run() {
-                               importDatabaseFromCSV();
+                               importDatabaseFromCSV(filename);
                                dismissDialog(IMPORT_PROGRESS_KEY);
                                
                                Message m = new Message();
@@ -810,13 +818,13 @@ public class CategoryList extends ListActivity {
         * While running inside a thread, read from a CSV and import
         * into the database.
         */
-       private void importDatabaseFromCSV(){
+       private void importDatabaseFromCSV(String filename){
                try {
                        importMessage="";
                        importedEntries=0;
                        
                        final int recordLength=6;
-                       CSVReader reader= new CSVReader(new FileReader(EXPORT_FILENAME));
+                       CSVReader reader= new CSVReader(new FileReader(filename));
                    String [] nextLine;
                    nextLine = reader.readNext();
                    if (nextLine==null) {
@@ -888,7 +896,7 @@ public class CategoryList extends ListActivity {
                    //
                    // read the whole file again to import the actual fields
                    //
-                       reader = new CSVReader(new FileReader(EXPORT_FILENAME));
+                       reader = new CSVReader(new FileReader(filename));
                    nextLine = reader.readNext();
                    int newEntries=0;
                    int lineNumber=0;
@@ -972,6 +980,7 @@ public class CategoryList extends ListActivity {
                    }else{
                        importMessage=getString(R.string.added)+ " "+ newEntries +
                                " "+ getString(R.string.entries);
+                       importedFilename=filename;
                    }
                } catch (IOException e) {
                        e.printStackTrace();
index 91122975ef6a799983b5ff6ded5137b8c523b41b..0dc766c4d6e78186e02ddc3d817275fa7a02f7c2 100644 (file)
@@ -31,7 +31,7 @@ public class RestoreHandler extends DefaultHandler {
     // Fields
     // ===========================================================
     
-    private boolean in_apws = false;
+    private boolean in_oisafe = false;
     private boolean in_masterkey = false;
     private boolean in_category = false;
     private boolean in_entry = false;
@@ -73,8 +73,8 @@ public class RestoreHandler extends DefaultHandler {
        public void startElement(String namespaceURI, String localName,
                String qName, Attributes atts) throws SAXException {
                
-               if (localName.equals("AndroidPasswordSafe")) {
-                       in_apws = true;
+               if (localName.equals("OISafe")) {
+                       in_oisafe = true;
                        String attrValue = atts.getValue("version");
                        int version = Integer.parseInt(attrValue);
 
@@ -83,14 +83,14 @@ public class RestoreHandler extends DefaultHandler {
                        myRestoreDataSet.setVersion(version);
                        myRestoreDataSet.setDate(date);
 
-                       if (debug) Log.d(TAG,"found APWS "+version+" date "+date);
+                       if (debug) Log.d(TAG,"found OISafe "+version+" date "+date);
                        
-               }else if (in_apws && localName.equals("MasterKey")) {
+               }else if (in_oisafe && localName.equals("MasterKey")) {
                        in_masterkey = true;
 
                        if (debug) Log.d(TAG,"found MasterKey");
 
-               }else if (in_apws && localName.equals("Category")) {
+               }else if (in_oisafe && localName.equals("Category")) {
                        in_category = true;
 
                        String name = atts.getValue("name");
@@ -125,11 +125,11 @@ public class RestoreHandler extends DefaultHandler {
        public void endElement(String namespaceURI, String localName, String qName)
                throws SAXException {
        
-               if (localName.equals("AndroidPasswordSafe")) {
-                       in_apws = false;
-               }else if (in_apws && localName.equals("MasterKey")) {
+               if (localName.equals("OISafe")) {
+                       in_oisafe = false;
+               }else if (in_oisafe && localName.equals("MasterKey")) {
                        in_masterkey = false;
-               }else if (in_apws && localName.equals("Category")) {
+               }else if (in_oisafe && localName.equals("Category")) {
                        in_category = false;
                        
                        myRestoreDataSet.storyCategory();