From: rmceoin Date: Fri, 13 Nov 2009 01:34:00 +0000 (+0000) Subject: OI Safe: added counts to CategoryList, added supports-screens, X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=8d73147ef716bfbedbe46dea2ece901370b5f377;p=android-vcpass-oisafe OI Safe: added counts to CategoryList, added supports-screens, bumped version to 1.2.3 git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@2380 72b678ce-9140-0410-bee8-679b907dd61a --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6d1fd7d..5cf9383 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,9 +1,10 @@ + android:versionName="1.2.3" android:versionCode="12"> + + + + + \ No newline at end of file diff --git a/src/org/openintents/safe/CategoryEntry.java b/src/org/openintents/safe/CategoryEntry.java index 0202113..c04318b 100644 --- a/src/org/openintents/safe/CategoryEntry.java +++ b/src/org/openintents/safe/CategoryEntry.java @@ -25,4 +25,32 @@ public class CategoryEntry extends Object { public boolean nameNeedsDecrypt; public String plainName; public boolean plainNameNeedsEncrypt=true; + int count=0; + + public String getName() { + return name; + } + + public int getCount() { + return count; + } + + public CategoryEntry () { + name = ""; + } + + public CategoryEntry (String _name) { + name = _name; + } + + public CategoryEntry (String _name, int _count) { + name = _name; + count = _count; + } + + @Override + public String toString() { + return name + " " + count; + } + } diff --git a/src/org/openintents/safe/CategoryList.java b/src/org/openintents/safe/CategoryList.java index faf01b0..dbc7848 100644 --- a/src/org/openintents/safe/CategoryList.java +++ b/src/org/openintents/safe/CategoryList.java @@ -54,7 +54,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ContextMenu.ContextMenuInfo; import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.Toast; @@ -121,6 +120,7 @@ public class CategoryList extends ListActivity { private static String masterKey; private List rows=null; + private CategoryListItemAdapter catAdapter; private Intent restartTimerIntent=null; private int lastPosition=0; @@ -391,15 +391,14 @@ public class CategoryList extends ListActivity { */ private void fillData() { if (debug) Log.d(TAG,"fillData()"); - List categoryNames=Passwords.getCategoryNames(); rows=Passwords.getCategoryEntries(); if (debug) Log.d(TAG,"fillData: rows="+rows.size()); - ArrayAdapter entries = - new ArrayAdapter(this, android.R.layout.simple_list_item_1, - categoryNames); - setListAdapter(entries); + catAdapter = + new CategoryListItemAdapter(this, R.layout.cat_row, + rows); + setListAdapter(catAdapter); } @@ -669,6 +668,10 @@ public class CategoryList extends ListActivity { setSelection(lastPosition); } } + if (requestCode==REQUEST_OPEN_CATEGORY) { + // update in case passwords were added/deleted and caused the counts to update + catAdapter.notifyDataSetChanged(); + } } private void prePopulate() { diff --git a/src/org/openintents/safe/CategoryListItemAdapter.java b/src/org/openintents/safe/CategoryListItemAdapter.java new file mode 100644 index 0000000..a40dd34 --- /dev/null +++ b/src/org/openintents/safe/CategoryListItemAdapter.java @@ -0,0 +1,78 @@ +/* $Id$ + * + * Copyright 2009 OpenIntents.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openintents.safe; + +import java.util.List; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.LinearLayout; +import android.widget.TextView; + +/** + * @author Randy McEoin + * + * Many thanks to Professional Android Application Development by Reto Meier + * from which this adapter is based upon. + */ +public class CategoryListItemAdapter extends ArrayAdapter { + + private static boolean debug = false; + private static final String TAG = "CategoryListItemAdapter"; + + int resource; + + public CategoryListItemAdapter(Context _context, int _resource, + List _items) { + super(_context, _resource, _items); + resource = _resource; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LinearLayout categoryListView; + + CategoryEntry item = getItem(position); + + String name = item.plainName; + int count = item.count; + + if (convertView == null) { + categoryListView = new LinearLayout(getContext()); + String inflater = Context.LAYOUT_INFLATER_SERVICE; + LayoutInflater vi; + vi = (LayoutInflater)getContext().getSystemService(inflater); + vi.inflate(resource, categoryListView, true); + } else { + categoryListView = (LinearLayout) convertView; + } + + TextView nameView = (TextView)categoryListView.findViewById(R.id.rowName); + TextView countView = (TextView)categoryListView.findViewById(R.id.rowCount); + + if (debug) Log.d(TAG, "count="+count); + nameView.setText(name); + countView.setText(Integer.toString(count)); + + return categoryListView; + } +} + diff --git a/src/org/openintents/safe/DBHelper.java b/src/org/openintents/safe/DBHelper.java index 40f575f..b36b5e8 100644 --- a/src/org/openintents/safe/DBHelper.java +++ b/src/org/openintents/safe/DBHelper.java @@ -414,6 +414,23 @@ public class DBHelper { return row; } + public int getCategoryCount(long Id) { + int count = 0; + try { + Cursor c = + db.rawQuery("SELECT count(*) FROM "+TABLE_PASSWORDS+" WHERE category=" + Id, null); + if (c.getCount() > 0) { + c.moveToFirst(); + count = c.getInt(0); + } + c.close(); + } catch (SQLException e) + { + Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage()); + } + return count; + } + /** * * @param Id diff --git a/src/org/openintents/safe/Passwords.java b/src/org/openintents/safe/Passwords.java index 0b8beb6..0f5292d 100644 --- a/src/org/openintents/safe/Passwords.java +++ b/src/org/openintents/safe/Passwords.java @@ -16,10 +16,12 @@ package org.openintents.safe; +import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -234,6 +236,7 @@ public class Passwords { catEntry.nameNeedsDecrypt=false; categoryEntries.put(id, catEntry); } + catEntry.count=dbHelper.getCategoryCount(id); return catEntry; } @@ -256,6 +259,14 @@ public class Passwords { return catEntry.id; } + public static void updateCategoryCount(long id) { + CategoryEntry catEntry=categoryEntries.get(id); + if (catEntry==null) { + return; + } + catEntry.count=dbHelper.getCategoryCount(id); + } + public static void deleteCategoryEntry(long id) { if (debug) Log.d(TAG,"deleteCategoryEntry("+id+")"); dbHelper.deleteCategory(id); @@ -399,8 +410,14 @@ public class Passwords { } passEntry.needsEncrypt=false; } + // Format the current time. + Date date = new Date(); + DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.LONG); + passEntry.lastEdited=df.format(date); + if (passEntry.id==0) { passEntry.id=dbHelper.addPassword(passEntry); + updateCategoryCount(passEntry.category); } else { dbHelper.updatePassword(passEntry.id, passEntry); } @@ -410,8 +427,14 @@ public class Passwords { public static void deletePassEntry(long id) { if (debug) Log.d(TAG,"deletePassEntry("+id+")"); + PassEntry passEntry=getPassEntry(id, false, false); + if (passEntry==null) { + return; + } + long categoryId=passEntry.category; dbHelper.deletePassword(id); passEntries.remove(id); + updateCategoryCount(categoryId); } public static void updatePassCategory(long passId, long categoryId) { diff --git a/src/org/openintents/safe/service/ServiceDispatchImpl.java b/src/org/openintents/safe/service/ServiceDispatchImpl.java index 8acac94..98f20d6 100644 --- a/src/org/openintents/safe/service/ServiceDispatchImpl.java +++ b/src/org/openintents/safe/service/ServiceDispatchImpl.java @@ -36,7 +36,7 @@ import android.util.Log; import android.os.CountDownTimer; public class ServiceDispatchImpl extends Service { - private static boolean debug = true; + private static boolean debug = false; private static String TAG = "ServiceDispatchIMPL"; public static CryptoHelper ch; // TODO Peli: Could clean this up by moving it into a singleton? Or at least a separate static class? private String salt;