select secret key refactored

This commit is contained in:
Dominik
2012-11-01 22:16:41 +01:00
parent f50d71559d
commit 8749569e80
15 changed files with 350 additions and 671 deletions

View File

@@ -1003,7 +1003,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
}
private void selectSecretKey() {
Intent intent = new Intent(this, SelectSecretKeyListActivityOld.class);
Intent intent = new Intent(this, SelectSecretKeyActivity.class);
startActivityForResult(intent, Id.request.secret_keys);
}
@@ -1051,7 +1051,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
setSecretKeyId(bundle.getLong(SelectSecretKeyListActivityOld.RESULT_EXTRA_KEY_ID));
setSecretKeyId(bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID));
} else {
setSecretKeyId(Id.key.none);
}

View File

@@ -20,8 +20,6 @@ package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.util.Log;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
@@ -89,8 +87,7 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
// }
// }
OtherHelper.logDebugBundle(intent.getExtras(), "intent extras");
// preselected master keys
selectedKeyIds = intent.getLongArrayExtra(RESULT_EXTRA_MASTER_KEY_IDS);
// if (searchString == null) {
@@ -99,13 +96,6 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
// mFilterLayout.setVisibility(View.VISIBLE);
// mFilterInfo.setText(getString(R.string.filterInfo, searchString));
// }
//
// if (mListAdapter != null) {
// mListAdapter.cleanup();
// }
//
// mListAdapter = new SelectPublicKeyListAdapter(this, mList, searchString, selectedKeyIds);
// mList.setAdapter(mListAdapter);
}
/**
@@ -126,14 +116,6 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
Intent data = new Intent();
data.putExtra(RESULT_EXTRA_MASTER_KEY_IDS, mSelectFragment.getSelectedMasterKeyIds());
data.putExtra(RESULT_EXTRA_USER_IDS, mSelectFragment.getSelectedUserIds());
long[] keys = mSelectFragment.getSelectedMasterKeyIds();
for (int i = 0; i < keys.length; i++) {
Log.d(Constants.TAG, "" + i + ": " + keys[i]);
}
OtherHelper.logDebugBundle(data.getExtras(), "result extras");
setResult(RESULT_OK, data);
finish();
}

View File

@@ -20,12 +20,13 @@ package org.thialfihar.android.apg.ui;
import java.util.Date;
import java.util.Vector;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
import org.thialfihar.android.apg.provider.ApgContract.Keys;
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
import org.thialfihar.android.apg.provider.ApgDatabase.Tables;
import org.thialfihar.android.apg.ui.widget.SelectPublicKeyCursorAdapter;
import org.thialfihar.android.apg.ui.widget.SelectKeyCursorAdapter;
import com.actionbarsherlock.app.SherlockListFragment;
@@ -42,13 +43,13 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
private SelectPublicKeyActivity mActivity;
private SelectPublicKeyCursorAdapter mAdapter;
private SelectKeyCursorAdapter mAdapter;
private ListView mListView;
private long mSelectedMasterKeyIds[];
public final static String ROW_AVAILABLE = "available";
public final static String ROW_VALID = "valid";
public final static String PROJECTION_ROW_AVAILABLE = "available";
public final static String PROJECTION_ROW_VALID = "valid";
/**
* Define Adapter and Loader on create of Activity
@@ -65,17 +66,11 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
// register long press context menu
registerForContextMenu(mListView);
// Give some text to display if there is no data. In a real
// application this would come from a resource.
setEmptyText(getString(R.string.listEmpty));
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
mAdapter = new SelectPublicKeyCursorAdapter(mActivity, mListView, null);
mAdapter = new SelectKeyCursorAdapter(mActivity, mListView, null, Id.type.public_key);
setListAdapter(mAdapter);
@@ -87,6 +82,11 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements
getLoaderManager().initLoader(0, null, this);
}
/**
* Selects items based on master key ids in list view
*
* @param masterKeyIds
*/
private void preselectMasterKeyIds(long[] masterKeyIds) {
if (masterKeyIds != null) {
for (int i = 0; i < mListView.getCount(); ++i) {
@@ -102,12 +102,13 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements
}
/**
* returns all selected key ids
* Returns all selected master key ids
*
* @return
*/
public long[] getSelectedMasterKeyIds() {
// mListView.getCheckedItemIds() would give the row ids of the KeyRings not the master keys!
// mListView.getCheckedItemIds() would give the row ids of the KeyRings not the master key
// ids!
Vector<Long> vector = new Vector<Long>();
for (int i = 0; i < mListView.getCount(); ++i) {
if (mListView.isItemChecked(i)) {
@@ -125,7 +126,7 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements
}
/**
* returns all selected user ids
* Returns all selected user ids
*
* @return
*/
@@ -156,11 +157,12 @@ public class SelectPublicKeyFragment extends SherlockListFragment implements
UserIds.USER_ID,
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Tables.KEYS + " AS tmp WHERE tmp."
+ Keys.IS_REVOKED + " = '0' AND tmp." + Keys.CAN_ENCRYPT + " = '1') AS "
+ ROW_AVAILABLE,
+ PROJECTION_ROW_AVAILABLE,
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Tables.KEYS + " AS tmp WHERE tmp."
+ Keys.IS_REVOKED + " = '0' AND " + Keys.CAN_ENCRYPT + " = '1' AND tmp."
+ Keys.CREATION + " <= '" + now + "' AND " + "(tmp." + Keys.EXPIRY
+ " IS NULL OR tmp." + Keys.EXPIRY + " >= '" + now + "')) AS " + ROW_VALID, };
+ " IS NULL OR tmp." + Keys.EXPIRY + " >= '" + now + "')) AS "
+ PROJECTION_ROW_VALID, };
String inMasterKeyList = null;
if (mSelectedMasterKeyIds != null && mSelectedMasterKeyIds.length > 0) {

View File

@@ -1,198 +0,0 @@
///*
// * 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;
//
//import java.util.Vector;
//
//import org.thialfihar.android.apg.Constants;
//import org.thialfihar.android.apg.R;
//import org.thialfihar.android.apg.Id;
//import org.thialfihar.android.apg.ui.widget.SelectPublicKeyListAdapter;
//
//import com.actionbarsherlock.app.ActionBar;
//import com.actionbarsherlock.app.SherlockFragmentActivity;
//import com.actionbarsherlock.view.Menu;
//import com.actionbarsherlock.view.MenuItem;
//
//import android.app.SearchManager;
//import android.content.Intent;
//import android.os.Bundle;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
//import android.widget.ListView;
//import android.widget.TextView;
//
//public class SelectPublicKeyListActivityOld extends SherlockFragmentActivity {
//
// // Not used in sourcode, but listed in AndroidManifest!
// public static final String ACTION_SELECT_PUBLIC_KEYS = Constants.INTENT_PREFIX
// + "SELECT_PUBLIC_KEYS";
//
// public static final String RESULT_EXTRA_SELECTION = "selection";
// public static final String RESULT_EXTRA_USER_IDS = "userIds";
//
// protected ListView mList;
// protected SelectPublicKeyListAdapter mListAdapter;
// protected View mFilterLayout;
// protected Button mClearFilterButton;
// protected TextView mFilterInfo;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
//
// final ActionBar actionBar = getSupportActionBar();
// actionBar.setDisplayShowTitleEnabled(true);
// actionBar.setDisplayHomeAsUpEnabled(false);
// actionBar.setHomeButtonEnabled(false);
//
// setContentView(R.layout.select_public_key);
//
// setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
//
// mList = (ListView) findViewById(R.id.list);
// // needed in Android 1.5, where the XML attribute gets ignored
// mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
//
// mFilterLayout = findViewById(R.id.layout_filter);
// mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
// mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
//
// mClearFilterButton.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// handleIntent(new Intent());
// }
// });
//
// handleIntent(getIntent());
// }
//
// @Override
// protected void onNewIntent(Intent intent) {
// super.onNewIntent(intent);
// handleIntent(intent);
// }
//
// private void handleIntent(Intent intent) {
// String searchString = null;
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
// searchString = intent.getStringExtra(SearchManager.QUERY);
// if (searchString != null && searchString.trim().length() == 0) {
// searchString = null;
// }
// }
//
// long selectedKeyIds[] = null;
// selectedKeyIds = intent.getLongArrayExtra(RESULT_EXTRA_SELECTION);
//
// if (selectedKeyIds == null) {
// Vector<Long> vector = new Vector<Long>();
// for (int i = 0; i < mList.getCount(); ++i) {
// if (mList.isItemChecked(i)) {
// vector.add(mList.getItemIdAtPosition(i));
// }
// }
// selectedKeyIds = new long[vector.size()];
// for (int i = 0; i < vector.size(); ++i) {
// selectedKeyIds[i] = vector.get(i);
// }
// }
//
// if (searchString == null) {
// mFilterLayout.setVisibility(View.GONE);
// } else {
// mFilterLayout.setVisibility(View.VISIBLE);
// mFilterInfo.setText(getString(R.string.filterInfo, searchString));
// }
//
// if (mListAdapter != null) {
// mListAdapter.cleanup();
// }
//
// mListAdapter = new SelectPublicKeyListAdapter(this, mList, searchString, selectedKeyIds);
// mList.setAdapter(mListAdapter);
//
// if (selectedKeyIds != null) {
// for (int i = 0; i < mListAdapter.getCount(); ++i) {
// long keyId = mListAdapter.getItemId(i);
// for (int j = 0; j < selectedKeyIds.length; ++j) {
// if (keyId == selectedKeyIds[j]) {
// mList.setItemChecked(i, true);
// break;
// }
// }
// }
// }
// }
//
// private void cancelClicked() {
// setResult(RESULT_CANCELED, null);
// finish();
// }
//
// private void okClicked() {
// Intent data = new Intent();
// Vector<Long> keys = new Vector<Long>();
// Vector<String> userIds = new Vector<String>();
// for (int i = 0; i < mList.getCount(); ++i) {
// if (mList.isItemChecked(i)) {
// keys.add(mList.getItemIdAtPosition(i));
// userIds.add((String) mList.getItemAtPosition(i));
// }
// }
// long selectedKeyIds[] = new long[keys.size()];
// for (int i = 0; i < keys.size(); ++i) {
// selectedKeyIds[i] = keys.get(i);
// }
// String userIdArray[] = new String[0];
// data.putExtra(RESULT_EXTRA_SELECTION, selectedKeyIds);
// data.putExtra(RESULT_EXTRA_USER_IDS, userIds.toArray(userIdArray));
// setResult(RESULT_OK, data);
// finish();
// }
//
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// menu.add(0, Id.menu.option.search, 0, R.string.menu_search).setIcon(
// android.R.drawable.ic_menu_search);
// menu.add(1, Id.menu.option.cancel, 0, R.string.btn_doNotSave).setShowAsAction(
// MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
// menu.add(1, Id.menu.option.okay, 1, R.string.btn_okay).setShowAsAction(
// MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
// return true;
// }
//
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
//
// case Id.menu.option.okay:
// okClicked();
// return true;
//
// case Id.menu.option.cancel:
// cancelClicked();
// return true;
//
// default:
// break;
//
// }
// return false;
// }
//}

View File

@@ -0,0 +1,128 @@
/*
* 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.
* 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;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.content.Intent;
import android.os.Bundle;
public class SelectSecretKeyActivity extends SherlockFragmentActivity {
// Not used in sourcode, but listed in AndroidManifest!
public static final String ACTION_SELECT_SECRET_KEY = Constants.INTENT_PREFIX
+ "SELECT_SECRET_KEY";
public static final String RESULT_EXTRA_MASTER_KEY_ID = "masterKeyId";
public static final String RESULT_EXTRA_USER_ID = "userId";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_secret_key_activity);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
// mFilterLayout = findViewById(R.id.layout_filter);
// mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
// mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
//
// mClearFilterButton.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// handleIntent(new Intent());
// }
// });
handleIntent(getIntent());
}
/**
* This is executed by SelectSecretKeyFragment after clicking on an item
*
* @param masterKeyId
* @param userId
*/
public void afterListSelection(long masterKeyId, String userId) {
Intent data = new Intent();
data.putExtra(RESULT_EXTRA_MASTER_KEY_ID, masterKeyId);
data.putExtra(RESULT_EXTRA_USER_ID, (String) userId);
setResult(RESULT_OK, data);
finish();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
// String searchString = null;
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
// searchString = intent.getStringExtra(SearchManager.QUERY);
// if (searchString != null && searchString.trim().length() == 0) {
// searchString = null;
// }
// }
// if (searchString == null) {
// mFilterLayout.setVisibility(View.GONE);
// } else {
// mFilterLayout.setVisibility(View.VISIBLE);
// mFilterInfo.setText(getString(R.string.filterInfo, searchString));
// }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, Id.menu.option.search, 0, R.string.menu_search).setIcon(
android.R.drawable.ic_menu_search);
return true;
}
/**
* Menu Options
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in Action Bar clicked; go home
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -0,0 +1,151 @@
/*
* 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.
* 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;
import java.util.Date;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
import org.thialfihar.android.apg.provider.ApgContract.Keys;
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
import org.thialfihar.android.apg.provider.ApgDatabase.Tables;
import org.thialfihar.android.apg.ui.widget.SelectKeyCursorAdapter;
import com.actionbarsherlock.app.SherlockListFragment;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.app.LoaderManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class SelectSecretKeyFragment extends SherlockListFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
private SelectSecretKeyActivity mActivity;
private SelectKeyCursorAdapter mAdapter;
private ListView mListView;
public final static String PROJECTION_ROW_AVAILABLE = "available";
public final static String PROJECTION_ROW_VALID = "valid";
/**
* Define Adapter and Loader on create of Activity
*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mActivity = (SelectSecretKeyActivity) getSherlockActivity();
mListView = getListView();
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
long masterKeyId = mAdapter.getMasterKeyId(position);
String userId = mAdapter.getUserId(position);
// return data to activity, which results in finishing it
mActivity.afterListSelection(masterKeyId, userId);
}
});
// Give some text to display if there is no data. In a real
// application this would come from a resource.
setEmptyText(getString(R.string.listEmpty));
mAdapter = new SelectKeyCursorAdapter(mActivity, mListView, null, Id.type.secret_key);
setListAdapter(mAdapter);
// Start out with a progress indicator.
setListShown(false);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// This is called when a new Loader needs to be created. This
// sample only has one Loader, so we don't care about the ID.
Uri baseUri = KeyRings.buildPublicKeyRingsUri();
// These are the rows that we will retrieve.
long now = new Date().getTime() / 1000;
String[] projection = new String[] {
KeyRings._ID,
KeyRings.MASTER_KEY_ID,
UserIds.USER_ID,
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Tables.KEYS + " AS tmp WHERE tmp."
+ Keys.IS_REVOKED + " = '0' AND tmp." + Keys.CAN_SIGN + " = '1') AS "
+ PROJECTION_ROW_AVAILABLE,
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Tables.KEYS + " AS tmp WHERE tmp."
+ Keys.IS_REVOKED + " = '0' AND " + Keys.CAN_SIGN + " = '1' AND tmp."
+ Keys.CREATION + " <= '" + now + "' AND " + "(tmp." + Keys.EXPIRY
+ " IS NULL OR tmp." + Keys.EXPIRY + " >= '" + now + "')) AS "
+ PROJECTION_ROW_VALID, };
// 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(")");
// }
String orderBy = UserIds.USER_ID + " ASC";
// Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed.
return new CursorLoader(getActivity(), baseUri, projection, null, null, orderBy);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// Swap the new cursor in. (The framework will take care of closing the
// old cursor once we return.)
mAdapter.swapCursor(data);
// The list should now be shown.
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
// This is called when the last Cursor provided to onLoadFinished()
// above is about to be closed. We need to make sure we are no
// longer using it.
mAdapter.swapCursor(null);
}
}

View File

@@ -1,130 +0,0 @@
/*
* 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;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.ui.widget.SelectSecretKeyListAdapterOld;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class SelectSecretKeyListActivityOld extends SherlockFragmentActivity {
// Not used in sourcode, but listed in AndroidManifest!
public static final String ACTION_SELECT_SECRET_KEY = Constants.INTENT_PREFIX
+ "SELECT_SECRET_KEY";
public static final String RESULT_EXTRA_USER_ID = "userId";
public static final String RESULT_EXTRA_KEY_ID = "keyId";
protected ListView mList;
protected SelectSecretKeyListAdapterOld mListAdapter;
protected View mFilterLayout;
protected Button mClearFilterButton;
protected TextView mFilterInfo;
protected long mSelectedKeyId = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
setContentView(R.layout.select_secret_key);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
mList = (ListView) findViewById(R.id.list);
mList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent data = new Intent();
data.putExtra(RESULT_EXTRA_KEY_ID, id);
data.putExtra(RESULT_EXTRA_USER_ID, (String) mList.getItemAtPosition(position));
setResult(RESULT_OK, data);
finish();
}
});
mFilterLayout = findViewById(R.id.layout_filter);
mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
mClearFilterButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
handleIntent(new Intent());
}
});
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
String searchString = null;
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
searchString = intent.getStringExtra(SearchManager.QUERY);
if (searchString != null && searchString.trim().length() == 0) {
searchString = null;
}
}
if (searchString == null) {
mFilterLayout.setVisibility(View.GONE);
} else {
mFilterLayout.setVisibility(View.VISIBLE);
mFilterInfo.setText(getString(R.string.filterInfo, searchString));
}
// if (mListAdapter != null) {
// mListAdapter.cleanup();
// }
//
// mListAdapter = new SelectSecretKeyListAdapter(this, mList, searchString);
// mList.setAdapter(mListAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, Id.menu.option.search, 0, R.string.menu_search).setIcon(
android.R.drawable.ic_menu_search);
return true;
}
}

View File

@@ -120,7 +120,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
} else {
// kick off the SecretKey selection activity so the user chooses which key to sign with
// first
Intent intent = new Intent(this, SelectSecretKeyListActivityOld.class);
Intent intent = new Intent(this, SelectSecretKeyActivity.class);
startActivityForResult(intent, Id.request.secret_keys);
}
}

View File

@@ -17,6 +17,7 @@
package org.thialfihar.android.apg.ui.widget;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.helper.PGPHelper;
@@ -34,17 +35,20 @@ import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
public class SelectPublicKeyCursorAdapter extends CursorAdapter {
public class SelectKeyCursorAdapter extends CursorAdapter {
protected int mKeyType;
private LayoutInflater mInflater;
private ListView mListView;
@SuppressWarnings("deprecation")
public SelectPublicKeyCursorAdapter(Context context, ListView listView, Cursor c) {
public SelectKeyCursorAdapter(Context context, ListView listView, Cursor c, int keyType) {
super(context, c);
mInflater = LayoutInflater.from(context);
mListView = listView;
mKeyType = keyType;
}
public String getUserId(int position) {
@@ -59,7 +63,8 @@ public class SelectPublicKeyCursorAdapter extends CursorAdapter {
@Override
public void bindView(View view, Context context, Cursor cursor) {
boolean enabled = cursor.getInt(cursor.getColumnIndex(SelectPublicKeyFragment.ROW_VALID)) > 0;
boolean valid = cursor.getInt(cursor
.getColumnIndex(SelectPublicKeyFragment.PROJECTION_ROW_VALID)) > 0;
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
mainUserId.setText(R.string.unknownUserId);
@@ -87,38 +92,49 @@ public class SelectPublicKeyCursorAdapter extends CursorAdapter {
mainUserIdRest.setVisibility(View.GONE);
}
if (enabled) {
status.setText(R.string.canEncrypt);
if (valid) {
if (mKeyType == Id.type.public_key) {
status.setText(R.string.canEncrypt);
} else {
status.setText(R.string.canSign);
}
} 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
if (cursor.getInt(cursor
.getColumnIndex(SelectPublicKeyFragment.PROJECTION_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 (mKeyType == Id.type.public_key) {
selected.setVisibility(View.VISIBLE);
if (!enabled) {
mListView.setItemChecked(cursor.getPosition(), false);
if (!valid) {
mListView.setItemChecked(cursor.getPosition(), false);
}
selected.setChecked(mListView.isItemChecked(cursor.getPosition()));
selected.setEnabled(valid);
} else {
selected.setVisibility(View.GONE);
}
selected.setChecked(mListView.isItemChecked(cursor.getPosition()));
status.setText(status.getText() + " ");
view.setEnabled(enabled);
mainUserId.setEnabled(enabled);
mainUserIdRest.setEnabled(enabled);
keyId.setEnabled(enabled);
selected.setEnabled(enabled);
status.setEnabled(enabled);
view.setEnabled(valid);
mainUserId.setEnabled(valid);
mainUserIdRest.setEnabled(valid);
keyId.setEnabled(valid);
status.setEnabled(valid);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return mInflater.inflate(R.layout.select_public_key_item, null);
return mInflater.inflate(R.layout.select_key_item, null);
}
}

View File

@@ -1,179 +0,0 @@
/*
* 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 android.app.Activity;
import android.content.Context;
import android.database.Cursor;
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.ListView;
import android.widget.TextView;
public class SelectSecretKeyListAdapterOld { //extends BaseAdapter {
// protected LayoutInflater mInflater;
// protected ListView mParent;
// protected SQLiteDatabase mDatabase;
// protected Cursor mCursor;
// protected String mSearchString;
// protected Activity mActivity;
//
// public SelectSecretKeyListAdapter(Activity activity, ListView parent, String searchString) {
// 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') ");
//
// 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(")");
// }
//
// 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_SIGN + " = '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_SIGN + " = '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_secret }, null, null, UserIds.TABLE_NAME + "." + UserIds.USER_ID
// + " ASC");
//
// 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_SIGN
// }
//
// @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_secret_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.canSign);
// } else {
// if (mCursor.getInt(3) > 0) {
// // has some CAN_SIGN 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() + " ");
//
// view.setEnabled(enabled);
// mainUserId.setEnabled(enabled);
// mainUserIdRest.setEnabled(enabled);
// keyId.setEnabled(enabled);
// status.setEnabled(enabled);
//
// return view;
// }
}