diff --git a/.classpath b/.classpath
index def5917bf..7c492fceb 100644
--- a/.classpath
+++ b/.classpath
@@ -1,6 +1,6 @@
-
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 765bd8c3b..01c96c824 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -13,4 +13,7 @@
+
+
+
\ No newline at end of file
diff --git a/src/com/android/keepass/Database.java b/src/com/android/keepass/Database.java
new file mode 100644
index 000000000..922f94730
--- /dev/null
+++ b/src/com/android/keepass/Database.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2009 Brian Pellin.
+ *
+ * This file is part of KeePassDroid.
+ *
+ * KeePassDroid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KeePassDroid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with KeePassDroid. If not, see .
+ *
+ */package com.android.keepass;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.UUID;
+import java.util.Vector;
+
+import org.bouncycastle1.crypto.InvalidCipherTextException;
+import org.phoneid.keepassj2me.ImporterV3;
+import org.phoneid.keepassj2me.PwEntry;
+import org.phoneid.keepassj2me.PwGroup;
+import org.phoneid.keepassj2me.PwManager;
+
+public class Database {
+ public static HashMap> gGroups = new HashMap>();
+ public static HashMap> gEntries = new HashMap>();
+ public static PwGroup gRoot;
+ private static PwManager mPM;
+
+ public static int LoadData(String filename, String password) {
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(filename);
+ } catch (FileNotFoundException e) {
+ return R.string.FileNotFound;
+ }
+
+ ImporterV3 Importer = new ImporterV3();
+
+ try {
+ mPM = Importer.openDatabase(fis, password);
+ if ( mPM != null ) {
+ mPM.constructTree(null);
+ populateGlobals(null);
+ }
+ } catch (InvalidCipherTextException e) {
+ return R.string.InvalidPassword;
+ } catch (IOException e) {
+ return -1;
+ }
+
+ return 0;
+
+ }
+
+ private static void populateGlobals(PwGroup currentGroup) {
+ if (currentGroup == null) {
+ Vector rootChildGroups = mPM.getGrpRoots();
+ for (int i = 0; i < rootChildGroups.size(); i++ ){
+ PwGroup cur = (PwGroup) rootChildGroups.elementAt(i);
+ gRoot = cur.parent;
+ gGroups.put(cur.groupId, new WeakReference(cur));
+ populateGlobals(cur);
+ return;
+ }
+ }
+
+ Vector childGroups = currentGroup.childGroups;
+ Vector childEntries = currentGroup.childEntries;
+
+ for (int i = 0; i < childEntries.size(); i++ ) {
+ PwEntry cur = (PwEntry) childEntries.elementAt(i);
+ gEntries.put(UUID.nameUUIDFromBytes(cur.uuid), new WeakReference(cur));
+ }
+
+ for (int i = 0; i < childGroups.size(); i++ ) {
+ PwGroup cur = (PwGroup) childGroups.elementAt(i);
+ gGroups.put(cur.groupId, new WeakReference(cur));
+ populateGlobals(cur);
+ }
+ }
+
+
+
+}
diff --git a/src/com/android/keepass/EntryActivity.java b/src/com/android/keepass/EntryActivity.java
index f6ba3a32f..863c2a2bd 100644
--- a/src/com/android/keepass/EntryActivity.java
+++ b/src/com/android/keepass/EntryActivity.java
@@ -19,6 +19,8 @@
*/
package com.android.keepass;
+import java.util.UUID;
+
import org.phoneid.keepassj2me.PwEntry;
import android.app.Activity;
@@ -41,9 +43,7 @@ public class EntryActivity extends Activity {
public static void Launch(Activity act, PwEntry pw) {
Intent i = new Intent(act, EntryActivity.class);
- KeePass.gPwEntry.put(KeePass.gNumPwEntry, pw);
- i.putExtra(KEY_ENTRY, KeePass.gNumPwEntry);
- KeePass.gNumPwEntry++;
+ i.putExtra(KEY_ENTRY, pw.uuid);
act.startActivity(i);
}
@@ -58,11 +58,11 @@ public class EntryActivity extends Activity {
setContentView(R.layout.entry_view);
Intent i = getIntent();
- mId = i.getIntExtra(KEY_ENTRY, -1);
- assert(mId < 0);
-
- mEntry = KeePass.gPwEntry.get(mId);
+ UUID uuid = UUID.nameUUIDFromBytes(i.getByteArrayExtra(KEY_ENTRY));
+ assert(uuid != null);
+ mEntry = Database.gEntries.get(uuid).get();
+
fillData();
}
diff --git a/src/com/android/keepass/GroupActivity.java b/src/com/android/keepass/GroupActivity.java
index b7c8ef7d0..22642a548 100644
--- a/src/com/android/keepass/GroupActivity.java
+++ b/src/com/android/keepass/GroupActivity.java
@@ -35,18 +35,15 @@ public class GroupActivity extends ListActivity {
public static final String KEY_ENTRY = "entry";
- private Vector mGroups;
- private Vector mEntries;
+ private PwGroup mGroup;
- public static void Launch(Activity act, Vector groups, Vector entries) {
+ public static void Launch(Activity act, PwGroup group) {
Intent i = new Intent(act, GroupActivity.class);
- KeePass.gGroups.put(KeePass.gNumEntries, groups);
- KeePass.gEntries.put(KeePass.gNumEntries, entries);
+ if ( group != null ) {
+ i.putExtra(KEY_ENTRY, group.groupId);
+ }
- i.putExtra(KEY_ENTRY, KeePass.gNumEntries);
-
- KeePass.gNumEntries++;
act.startActivity(i);
}
@@ -55,15 +52,14 @@ public class GroupActivity extends ListActivity {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
- // TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
- int size = mGroups.size();
+ int size = mGroup.childGroups.size();
PwItemView iv;
if (position < size ) {
- PwGroup group = (PwGroup) mGroups.elementAt(position);
+ PwGroup group = (PwGroup) mGroup.childGroups.elementAt(position);
iv = new PwGroupView(this, group);
} else {
- PwEntry entry = (PwEntry) mEntries.elementAt(position - size);
+ PwEntry entry = (PwEntry) mGroup.childEntries.elementAt(position - size);
iv = new PwEntryView(this, entry);
}
iv.onClick();
@@ -74,26 +70,20 @@ public class GroupActivity extends ListActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
- mId = getIntent().getIntExtra(KEY_ENTRY, -1);
+ int id = getIntent().getIntExtra(KEY_ENTRY, -1);
assert(mId >= 0);
- mGroups = KeePass.gGroups.get(mId);
- assert(mGroups != null);
- mEntries = KeePass.gEntries.get(mId);
- assert(mEntries != null);
+ if ( id == -1 ) {
+ mGroup = Database.gRoot;
+ } else {
+ mGroup = Database.gGroups.get(id).get();
+ }
+ assert(mGroup != null);
- setListAdapter(new PwListAdapter(this, mGroups, mEntries));
+ setListAdapter(new PwListAdapter(this, mGroup));
getListView().setTextFilterEnabled(true);
}
- @Override
- protected void onDestroy() {
- super.onDestroy();
-
- KeePass.gGroups.remove(mId);
- KeePass.gEntries.remove(mId);
- }
-
}
diff --git a/src/com/android/keepass/KeePass.java b/src/com/android/keepass/KeePass.java
index 3da205ff4..42341f2d2 100644
--- a/src/com/android/keepass/KeePass.java
+++ b/src/com/android/keepass/KeePass.java
@@ -22,6 +22,7 @@ package com.android.keepass;
import org.bouncycastle1.crypto.InvalidCipherTextException;
import org.phoneid.keepassj2me.ImporterV3;
import org.phoneid.keepassj2me.PwEntry;
+import org.phoneid.keepassj2me.PwGroup;
import org.phoneid.keepassj2me.PwManager;
import android.app.Activity;
@@ -34,19 +35,14 @@ import android.widget.EditText;
import android.widget.Toast;
import java.io.*;
+import java.lang.ref.WeakReference;
import java.util.HashMap;
+import java.util.UUID;
import java.util.Vector;
public class KeePass extends Activity {
- private PwManager mPM;
- public static HashMap gGroups = new HashMap();
- public static HashMap gEntries = new HashMap();
- public static Integer gNumEntries = new Integer(0);
-
- public static HashMap gPwEntry = new HashMap();
- public static Integer gNumPwEntry = new Integer(0);
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -58,8 +54,6 @@ public class KeePass extends Activity {
loadDefaultPrefs();
- //setEditText(R.id.pass_password, "12345");
-
}
@Override
@@ -94,33 +88,6 @@ public class KeePass extends Activity {
editor.commit();
}
- private boolean fillData(String filename, String password) {
- FileInputStream fis;
- try {
- fis = new FileInputStream(filename);
- } catch (FileNotFoundException e) {
- errorMessage(R.string.FileNotFound);
- return false;
- }
-
- ImporterV3 Importer = new ImporterV3();
-
- try {
- mPM = Importer.openDatabase(fis, password);
- if ( mPM != null ) {
- mPM.constructTree(null);
- }
- } catch (InvalidCipherTextException e) {
- errorMessage(R.string.InvalidPassword);
- return false;
- } catch (IOException e) {
- errorMessage("IO Error");
- return false;
- }
-
- return true;
-
- }
private void errorMessage(CharSequence text)
{
@@ -132,14 +99,6 @@ public class KeePass extends Activity {
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
}
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
- gGroups.remove(requestCode);
- gEntries.remove(requestCode);
- }
-
private class ClickHandler implements View.OnClickListener {
private Activity mAct;
@@ -148,8 +107,18 @@ public class KeePass extends Activity {
}
public void onClick(View view) {
- if ( fillData(getEditText(R.id.pass_filename),getEditText(R.id.pass_password)) ) {
- GroupActivity.Launch(mAct, mPM.getGrpRoots(), new Vector());
+ int result = Database.LoadData(getEditText(R.id.pass_filename),getEditText(R.id.pass_password));
+
+ switch (result) {
+ case 0:
+ GroupActivity.Launch(mAct, null);
+ break;
+ case -1:
+ errorMessage("Unknown error.");
+ break;
+ default:
+ errorMessage(result);
+ break;
}
}
diff --git a/src/com/android/keepass/PwGroupView.java b/src/com/android/keepass/PwGroupView.java
index f15e7d017..a780b4d58 100644
--- a/src/com/android/keepass/PwGroupView.java
+++ b/src/com/android/keepass/PwGroupView.java
@@ -43,7 +43,7 @@ public class PwGroupView extends PwItemView {
@Override
void onClick() {
- GroupActivity.Launch(mAct, mPw.childGroups, mPw.childEntries);
+ GroupActivity.Launch(mAct, mPw);
}
diff --git a/src/com/android/keepass/PwItemView.java b/src/com/android/keepass/PwItemView.java
index e401aa201..59ef7f233 100644
--- a/src/com/android/keepass/PwItemView.java
+++ b/src/com/android/keepass/PwItemView.java
@@ -20,6 +20,7 @@
package com.android.keepass;
import android.content.Context;
+import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -31,6 +32,7 @@ abstract public class PwItemView extends LinearLayout {
mTitle = new TextView(context);
mTitle.setText(title);
+ mTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
addView(mTitle, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
diff --git a/src/com/android/keepass/PwListAdapter.java b/src/com/android/keepass/PwListAdapter.java
index 0fb1835e9..351a55007 100644
--- a/src/com/android/keepass/PwListAdapter.java
+++ b/src/com/android/keepass/PwListAdapter.java
@@ -32,20 +32,18 @@ import org.phoneid.keepassj2me.PwGroup;
public class PwListAdapter extends BaseAdapter {
private Activity mAct;
- private Vector mGroupList;
- private Vector mEntryList;
+ private PwGroup mGroup;
- PwListAdapter(Activity act, Vector gl, Vector el) {
+ PwListAdapter(Activity act, PwGroup group) {
mAct = act;
- mGroupList = gl;
- mEntryList = el;
+ mGroup = group;
}
@Override
public int getCount() {
- return mGroupList.size() + mEntryList.size();
+ return mGroup.childGroups.size() + mGroup.childEntries.size();
}
@Override
@@ -60,7 +58,7 @@ public class PwListAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- int size = mGroupList.size();
+ int size = mGroup.childGroups.size();
if ( position < size ) {
return createGroupView(position, convertView);
@@ -72,11 +70,11 @@ public class PwListAdapter extends BaseAdapter {
private PwGroupView createGroupView(int position, View convertView) {
PwGroupView gv;
if (convertView == null || ! (convertView instanceof PwGroupView)) {
- PwGroup group = (PwGroup) mGroupList.elementAt(position);
+ PwGroup group = (PwGroup) mGroup.childGroups.elementAt(position);
gv = new PwGroupView(mAct, group);
} else {
gv = (PwGroupView) convertView;
- gv.setGroup((PwGroup) mGroupList.elementAt(position));
+ gv.setGroup((PwGroup) mGroup.childGroups.elementAt(position));
}
return gv;
}
@@ -84,10 +82,10 @@ public class PwListAdapter extends BaseAdapter {
private PwEntryView createEntryView(int position, View convertView) {
PwEntryView ev;
if (convertView == null || ! (convertView instanceof PwEntryView) ) {
- ev = new PwEntryView(mAct, (PwEntry) mEntryList.elementAt(position));
+ ev = new PwEntryView(mAct, (PwEntry) mGroup.childEntries.elementAt(position));
} else {
ev = (PwEntryView) convertView;
- ev.setEntry((PwEntry) mEntryList.elementAt(position));
+ ev.setEntry((PwEntry) mGroup.childEntries.elementAt(position));
}
return ev;
}