diff options
Diffstat (limited to 'org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java')
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java | 108 |
1 files changed, 33 insertions, 75 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java index 2ac059038..2bf02d8bf 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java @@ -1,20 +1,32 @@ +/* + * 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 org.thialfihar.android.apg.helper.PGPHelper; import org.thialfihar.android.apg.helper.PGPMain; import org.thialfihar.android.apg.service.PassphraseCacheService; import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment; -import org.thialfihar.android.apg.ui.widget.KeyListAdapter; import org.thialfihar.android.apg.util.Log; -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; -import com.google.zxing.integration.android.IntentIntegrator; import android.content.Intent; import android.os.Bundle; @@ -25,7 +37,6 @@ import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.ExpandableListView; -import android.widget.ExpandableListView.ExpandableListContextMenuInfo; public class KeyListSecretActivity extends KeyListActivity { @@ -33,23 +44,20 @@ public class KeyListSecretActivity extends KeyListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mKeyType = Id.type.secret_key; + setContentView(R.layout.key_list_secret_activity); mExportFilename = Constants.path.APP_DIR + "/secexport.asc"; - mKeyType = Id.type.secret_key; + // mList.setOnChildClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { - menu.add(3, Id.menu.option.search, 0, R.string.menu_search) - .setIcon(R.drawable.ic_menu_search).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + super.onCreateOptionsMenu(menu); menu.add(1, Id.menu.option.create, 1, R.string.menu_createKey).setShowAsAction( MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); - menu.add(0, Id.menu.option.import_keys, 2, R.string.menu_importKeys).setShowAsAction( - MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT); - menu.add(0, Id.menu.option.export_keys, 3, R.string.menu_exportKeys).setShowAsAction( - MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; } @@ -68,70 +76,21 @@ public class KeyListSecretActivity extends KeyListActivity { } } - @Override - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); - ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; - int type = ExpandableListView.getPackedPositionType(info.packedPosition); - - if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { - // TODO: user id? menu.setHeaderTitle("Key"); - menu.add(0, Id.menu.edit, 0, R.string.menu_editKey); - menu.add(0, Id.menu.export, 1, R.string.menu_exportKey); - menu.add(0, Id.menu.delete, 2, R.string.menu_deleteKey); - menu.add(0, Id.menu.share_qr_code, 2, R.string.menu_share); - } - } - - @Override - public boolean onContextItemSelected(android.view.MenuItem menuItem) { - ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo(); - int type = ExpandableListView.getPackedPositionType(info.packedPosition); - int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition); - - if (type != ExpandableListView.PACKED_POSITION_TYPE_GROUP) { - return super.onContextItemSelected(menuItem); - } - - switch (menuItem.getItemId()) { - case Id.menu.edit: { - mSelectedItem = groupPosition; - checkPassPhraseAndEdit(); - return true; - } - - case Id.menu.share_qr_code: { - mSelectedItem = groupPosition; - - long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()) - .getGroupId(mSelectedItem); - // String msg = keyId + "," + PGPHelper.getFingerPrint(keyId); - String msg = PGPHelper.getPubkeyAsArmoredString(this, keyId); - - new IntentIntegrator(this).shareText(msg); - } - - default: { - return super.onContextItemSelected(menuItem); - } - } - } - - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, - int childPosition, long id) { - mSelectedItem = groupPosition; - checkPassPhraseAndEdit(); - return true; - } - - public void checkPassPhraseAndEdit() { - long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem); + // + // public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, + // int childPosition, long id) { + // mSelectedItem = groupPosition; + // checkPassPhraseAndEdit(); + // return true; + // } + // + public void checkPassPhraseAndEdit(long keyId) { String passPhrase = PassphraseCacheService.getCachedPassphrase(this, keyId); if (passPhrase == null) { showPassphraseDialog(keyId); } else { PGPMain.setEditPassPhrase(passPhrase); - editKey(); + editKey(keyId); } } @@ -144,7 +103,7 @@ public class KeyListSecretActivity extends KeyListActivity { String passPhrase = PassphraseCacheService.getCachedPassphrase( KeyListSecretActivity.this, secretKeyId); PGPMain.setEditPassPhrase(passPhrase); - editKey(); + editKey(secretKeyId); } } }; @@ -170,8 +129,7 @@ public class KeyListSecretActivity extends KeyListActivity { startActivityForResult(intent, Id.message.create_key); } - private void editKey() { - long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem); + private void editKey(long keyId) { Intent intent = new Intent(EditKeyActivity.ACTION_EDIT_KEY); intent.putExtra(EditKeyActivity.EXTRA_KEY_ID, keyId); startActivityForResult(intent, Id.message.edit_key); |