diff options
Diffstat (limited to 'org_apg/src/org/thialfihar/android/apg/ui/widget')
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyCursorAdapter.java | 92 | ||||
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyListAdapterOld.java | 218 |
2 files changed, 40 insertions, 270 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyCursorAdapter.java b/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyCursorAdapter.java index 45b617d68..f3c24ba75 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyCursorAdapter.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyCursorAdapter.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de> + * Copyright (C) 2010 Thialfihar <thi@thialfihar.org> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,60 +20,47 @@ package org.thialfihar.android.apg.ui.widget; import org.thialfihar.android.apg.R; import org.thialfihar.android.apg.helper.OtherHelper; import org.thialfihar.android.apg.helper.PGPHelper; +import org.thialfihar.android.apg.provider.ApgContract.KeyRings; +import org.thialfihar.android.apg.provider.ApgContract.UserIds; +import org.thialfihar.android.apg.ui.SelectPublicKeyFragment; import android.content.Context; import android.database.Cursor; import android.support.v4.widget.CursorAdapter; -import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; +import android.widget.ListView; import android.widget.TextView; public class SelectPublicKeyCursorAdapter extends CursorAdapter { private LayoutInflater mInflater; -// private int mActivityIndex; -// private int mTimeIndex; -// private int mActionIndex; -// private int mAmountIndex; + private ListView mListView; - public SelectPublicKeyCursorAdapter(Context context, Cursor c) { + @SuppressWarnings("deprecation") + public SelectPublicKeyCursorAdapter(Context context, ListView listView, Cursor c) { super(context, c); -// -// mActivityIndex = c.getColumnIndex(Notes.ACTIVITY); -// mTimeIndex = c.getColumnIndex(Notes.TIME); -// mActionIndex = c.getColumnIndex(Notes.ACTION); -// mAmountIndex = c.getColumnIndex(Notes.AMOUNT); mInflater = LayoutInflater.from(context); + mListView = listView; + } + + public String getUserId(int position) { + mCursor.moveToPosition(position); + return mCursor.getString(mCursor.getColumnIndex(UserIds.USER_ID)); + } + + public long getMasterKeyId(int position) { + mCursor.moveToPosition(position); + return mCursor.getLong(mCursor.getColumnIndex(KeyRings.MASTER_KEY_ID)); } @Override public void bindView(View view, Context context, Cursor cursor) { - // TextView activity = (TextView) view.findViewById(android.R.id.text1); - // TextView time = (TextView) view.findViewById(android.R.id.text2); - // TextView actionAndAmount = (TextView) view.findViewById(R.id.text3); - // - // activity.setText(cursor.getString(mActivityIndex)); - // - // long lTime = cursor.getLong(mTimeIndex); - // Calendar cal = Calendar.getInstance(); - // cal.setTimeInMillis(lTime); - // time.setText(cal.get(Calendar.HOUR_OF_DAY) + “:” + String.format(“%02d”, - // cal.get(Calendar.MINUTE))); - // - // String amount = cursor.getString(mAmountIndex); - // if ( amount.length() > 0){ - // actionAndAmount.setText(cursor.getString(mActionIndex) + ” (” + amount + “)”); - // } else { - // actionAndAmount.setText(cursor.getString(mActionIndex)); - // } - -// boolean enabled = isEnabled(position); - - + boolean enabled = cursor.getInt(cursor.getColumnIndex(SelectPublicKeyFragment.ROW_VALID)) > 0; + TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); mainUserId.setText(R.string.unknownUserId); TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); @@ -82,7 +70,7 @@ public class SelectPublicKeyCursorAdapter extends CursorAdapter { TextView status = (TextView) view.findViewById(R.id.status); status.setText(R.string.unknownStatus); - String userId = cursor.getString(2); // USER_ID + String userId = cursor.getString(cursor.getColumnIndex(UserIds.USER_ID)); if (userId != null) { String[] userIdSplit = OtherHelper.splitUserId(userId); @@ -92,45 +80,45 @@ public class SelectPublicKeyCursorAdapter extends CursorAdapter { mainUserId.setText(userIdSplit[0]); } - long masterKeyId = cursor.getLong(1); // MASTER_KEY_ID + long masterKeyId = cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID)); keyId.setText(PGPHelper.getSmallFingerPrint(masterKeyId)); if (mainUserIdRest.getText().length() == 0) { mainUserIdRest.setVisibility(View.GONE); } -// if (enabled) { -// status.setText(R.string.canEncrypt); -// } else { - if (cursor.getInt(3) > 0) { - // has some CAN_ENCRYPT keys, but col(4) = 0, so must be revoked or expired + if (enabled) { + status.setText(R.string.canEncrypt); + } else { + if (cursor.getInt(cursor.getColumnIndex(SelectPublicKeyFragment.ROW_AVAILABLE)) > 0) { + // has some CAN_ENCRYPT keys, but col(ROW_VALID) = 0, so must be revoked or expired status.setText(R.string.expired); } else { status.setText(R.string.noKey); } -// } + } status.setText(status.getText() + " "); CheckBox selected = (CheckBox) view.findViewById(R.id.selected); -// if (!enabled) { -// mParent.setItemChecked(position, false); -// } + if (!enabled) { + mListView.setItemChecked(cursor.getPosition(), false); + } -// selected.setChecked(mParent.isItemChecked(position)); + selected.setChecked(mListView.isItemChecked(cursor.getPosition())); -// view.setEnabled(enabled); -// mainUserId.setEnabled(enabled); -// mainUserIdRest.setEnabled(enabled); -// keyId.setEnabled(enabled); -// selected.setEnabled(enabled); -// status.setEnabled(enabled); + view.setEnabled(enabled); + mainUserId.setEnabled(enabled); + mainUserIdRest.setEnabled(enabled); + keyId.setEnabled(enabled); + selected.setEnabled(enabled); + status.setEnabled(enabled); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - return mInflater.inflate(R.layout.select_public_key, null); + return mInflater.inflate(R.layout.select_public_key_item, null); } }
\ No newline at end of file diff --git a/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyListAdapterOld.java b/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyListAdapterOld.java deleted file mode 100644 index 4324e36c9..000000000 --- a/org_apg/src/org/thialfihar/android/apg/ui/widget/SelectPublicKeyListAdapterOld.java +++ /dev/null @@ -1,218 +0,0 @@ -package org.thialfihar.android.apg.ui.widget; -///* -// * Copyright (C) 2010 Thialfihar <thi@thialfihar.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.thialfihar.android.apg.ui.widget; -// -//import java.util.Date; -// -//import org.thialfihar.android.apg.R; -//import org.thialfihar.android.apg.Id; -//import org.thialfihar.android.apg.helper.PGPHelper; -//import org.thialfihar.android.apg.helper.PGPMain; -//import org.thialfihar.android.apg.provider.KeyRings; -//import org.thialfihar.android.apg.provider.Keys; -//import org.thialfihar.android.apg.provider.UserIds; -// -//import android.app.Activity; -//import android.content.Context; -//import android.database.Cursor; -//import android.database.DatabaseUtils; -//import android.database.sqlite.SQLiteDatabase; -//import android.database.sqlite.SQLiteQueryBuilder; -//import android.view.LayoutInflater; -//import android.view.View; -//import android.view.ViewGroup; -//import android.widget.BaseAdapter; -//import android.widget.CheckBox; -//import android.widget.ListView; -//import android.widget.TextView; -// -//public class SelectPublicKeyListAdapter extends BaseAdapter { -// protected LayoutInflater mInflater; -// protected ListView mParent; -// protected SQLiteDatabase mDatabase; -// protected Cursor mCursor; -// protected String mSearchString; -// protected Activity mActivity; -// -// public SelectPublicKeyListAdapter(Activity activity, ListView parent, String searchString, -// long selectedKeyIds[]) { -// mSearchString = searchString; -// -// mActivity = activity; -// mParent = parent; -// mDatabase = PGPMain.getDatabase().db(); -// mInflater = (LayoutInflater) parent.getContext().getSystemService( -// Context.LAYOUT_INFLATER_SERVICE); -// long now = new Date().getTime() / 1000; -// SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); -// qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " + "(" -// + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "." -// + Keys.KEY_RING_ID + " AND " + Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY -// + " = '1'" + ") " + " INNER JOIN " + UserIds.TABLE_NAME + " ON " + "(" -// + Keys.TABLE_NAME + "." + Keys._ID + " = " + UserIds.TABLE_NAME + "." -// + UserIds.KEY_ID + " AND " + UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0') "); -// -// String inIdList = null; -// -// if (selectedKeyIds != null && selectedKeyIds.length > 0) { -// inIdList = KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID + " IN ("; -// for (int i = 0; i < selectedKeyIds.length; ++i) { -// if (i != 0) { -// inIdList += ", "; -// } -// inIdList += DatabaseUtils.sqlEscapeString("" + selectedKeyIds[i]); -// } -// inIdList += ")"; -// } -// -// if (searchString != null && searchString.trim().length() > 0) { -// String[] chunks = searchString.trim().split(" +"); -// qb.appendWhere("(EXISTS (SELECT tmp." + UserIds._ID + " FROM " + UserIds.TABLE_NAME -// + " AS tmp WHERE " + "tmp." + UserIds.KEY_ID + " = " + Keys.TABLE_NAME + "." -// + Keys._ID); -// for (int i = 0; i < chunks.length; ++i) { -// qb.appendWhere(" AND tmp." + UserIds.USER_ID + " LIKE "); -// qb.appendWhereEscapeString("%" + chunks[i] + "%"); -// } -// qb.appendWhere("))"); -// -// if (inIdList != null) { -// qb.appendWhere(" OR (" + inIdList + ")"); -// } -// } -// -// String orderBy = UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC"; -// if (inIdList != null) { -// orderBy = inIdList + " DESC, " + orderBy; -// } -// -// mCursor = qb.query(mDatabase, new String[] { -// KeyRings.TABLE_NAME + "." + KeyRings._ID, // 0 -// KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID, // 1 -// UserIds.TABLE_NAME + "." + UserIds.USER_ID, // 2 -// "(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " -// + "tmp." + Keys.KEY_RING_ID + " = " + KeyRings.TABLE_NAME + "." -// + KeyRings._ID + " AND " + "tmp." + Keys.IS_REVOKED + " = '0' AND " -// + "tmp." + Keys.CAN_ENCRYPT + " = '1')", // 3 -// "(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " -// + "tmp." + Keys.KEY_RING_ID + " = " + KeyRings.TABLE_NAME + "." -// + KeyRings._ID + " AND " + "tmp." + Keys.IS_REVOKED + " = '0' AND " -// + "tmp." + Keys.CAN_ENCRYPT + " = '1' AND " + "tmp." + Keys.CREATION -// + " <= '" + now + "' AND " + "(tmp." + Keys.EXPIRY + " IS NULL OR " -// + "tmp." + Keys.EXPIRY + " >= '" + now + "'))", // 4 -// }, KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?", new String[] { "" -// + Id.database.type_public }, null, null, orderBy); -// -// activity.startManagingCursor(mCursor); -// } -// -// public void cleanup() { -// if (mCursor != null) { -// mActivity.stopManagingCursor(mCursor); -// mCursor.close(); -// } -// } -// -// @Override -// public boolean isEnabled(int position) { -// mCursor.moveToPosition(position); -// return mCursor.getInt(4) > 0; // valid CAN_ENCRYPT -// } -// -// @Override -// public boolean hasStableIds() { -// return true; -// } -// -// public int getCount() { -// return mCursor.getCount(); -// } -// -// public Object getItem(int position) { -// mCursor.moveToPosition(position); -// return mCursor.getString(2); // USER_ID -// } -// -// public long getItemId(int position) { -// mCursor.moveToPosition(position); -// return mCursor.getLong(1); // MASTER_KEY_ID -// } -// -// public View getView(int position, View convertView, ViewGroup parent) { -// mCursor.moveToPosition(position); -// -// View view = mInflater.inflate(R.layout.select_public_key_item, null); -// boolean enabled = isEnabled(position); -// -// TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); -// mainUserId.setText(R.string.unknownUserId); -// TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); -// mainUserIdRest.setText(""); -// TextView keyId = (TextView) view.findViewById(R.id.keyId); -// keyId.setText(R.string.noKey); -// TextView status = (TextView) view.findViewById(R.id.status); -// status.setText(R.string.unknownStatus); -// -// String userId = mCursor.getString(2); // USER_ID -// if (userId != null) { -// String chunks[] = userId.split(" <", 2); -// userId = chunks[0]; -// if (chunks.length > 1) { -// mainUserIdRest.setText("<" + chunks[1]); -// } -// mainUserId.setText(userId); -// } -// -// long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID -// keyId.setText(PGPHelper.getSmallFingerPrint(masterKeyId)); -// -// if (mainUserIdRest.getText().length() == 0) { -// mainUserIdRest.setVisibility(View.GONE); -// } -// -// if (enabled) { -// status.setText(R.string.canEncrypt); -// } else { -// if (mCursor.getInt(3) > 0) { -// // has some CAN_ENCRYPT keys, but col(4) = 0, so must be revoked or expired -// status.setText(R.string.expired); -// } else { -// status.setText(R.string.noKey); -// } -// } -// -// status.setText(status.getText() + " "); -// -// CheckBox selected = (CheckBox) view.findViewById(R.id.selected); -// -// if (!enabled) { -// mParent.setItemChecked(position, false); -// } -// -// selected.setChecked(mParent.isItemChecked(position)); -// -// view.setEnabled(enabled); -// mainUserId.setEnabled(enabled); -// mainUserIdRest.setEnabled(enabled); -// keyId.setEnabled(enabled); -// selected.setEnabled(enabled); -// status.setEnabled(enabled); -// -// return view; -// } -//} |