reorder menus, cleanup code, add experimental tab activity

This commit is contained in:
Dominik Schürmann 2014-01-07 22:40:18 +01:00
parent 44117fb191
commit caf3b02042
13 changed files with 314 additions and 402 deletions

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/lists_tabs_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_key_list_public_import"
android:showAsAction="always|withText"
android:title="@string/menu_import"/>
<item
android:id="@+id/menu_key_list_public_export"
android:showAsAction="never"
android:title="@string/menu_export_keys"/>
</menu>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_key_list_secret_create"
android:showAsAction="always|withText"
android:title="@string/menu_create_key"/>
<item
android:id="@+id/menu_key_list_secret_create_expert"
android:showAsAction="never"
android:title="@string/menu_create_key_expert"/>
<item
android:id="@+id/menu_key_list_secret_import"
android:showAsAction="never"
android:title="@string/menu_import"/>
<item
android:id="@+id/menu_key_list_secret_export"
android:showAsAction="never"
android:title="@string/menu_export_keys"/>
</menu>

View File

@ -52,9 +52,6 @@
<item
android:id="@+id/menu_key_view_delete"
android:showAsAction="never"
android:title="@string/menu_delete_key">
<menu>
</menu>
</item>
android:title="@string/menu_delete_key"/>
</menu>

View File

@ -83,6 +83,7 @@
<string name="menu_api_app_settings">Registered Apps</string>
<string name="menu_import_from_file">Import from file</string>
<string name="menu_import_from_qr_code">Import from QR Code</string>
<string name="menu_import">Import</string>
<string name="menu_import_from_nfc">Import from NFC</string>
<string name="menu_export_keys">Export all keys</string>
<string name="menu_export_key">Export to file</string>
@ -101,7 +102,7 @@
<string name="menu_sign_key">Sign key</string>
<string name="menu_beam_preferences">Beam settings</string>
<string name="menu_key_edit_cancel">Cancel</string>
<!-- label -->
<string name="label_sign">Sign</string>
<string name="label_message">Message</string>

View File

@ -325,10 +325,22 @@ public class EditKeyActivity extends KeyActivity {
showExportKeysDialog(mDataUri, Id.type.secret_key, Constants.path.APP_DIR
+ "/secexport.asc");
return true;
case R.id.menu_key_edit_delete:
deleteKey(mDataUri, Id.type.secret_key);
case R.id.menu_key_edit_delete: {
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
setResult(RESULT_CANCELED);
finish();
}
}
};
deleteKey(mDataUri, Id.type.secret_key, returnHandler);
return true;
}
}
return super.onOptionsItemSelected(item);
}

View File

@ -0,0 +1,175 @@
package org.sufficientlysecure.keychain.ui;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
public class EncryptDecryptActivity extends SherlockFragmentActivity {
private FragmentActivity mActivity;
private ActionBar mActionBar;
private ActionBar.Tab mTab1;
private ActionBar.Tab mTab2;
private ActionBar.Tab mTab3;
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// MenuInflater inflater = getSupportMenuInflater();
// inflater.inflate(R.menu.lists_activity, menu);
// return true;
// }
/**
* Menu item to go back home in ActionBar, other menu items are defined in Fragments
*/
@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(mActivity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
// case R.id.menu_import:
// ImportExportHelper.openFileStream(mActivity);
// return true;
//
// case R.id.menu_export:
// ImportExportHelper.exportLists(mActivity);
// return true;
default:
return super.onOptionsItemSelected(item);
}
}
/**
* Set up Tabs on create
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = this;
setContentView(R.layout.lists_activity);
mActionBar = getSupportActionBar();
mActionBar.setDisplayShowTitleEnabled(true);
mActionBar.setDisplayHomeAsUpEnabled(true);
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mTab1 = getSupportActionBar().newTab();
mTab2 = getSupportActionBar().newTab();
mTab3 = getSupportActionBar().newTab();
mTab1.setTabListener(new TabListener<KeyListPublicFragment>(this, "publicList",
KeyListPublicFragment.class));
mTab2.setTabListener(new TabListener<KeyListPublicFragment>(this, "import",
KeyListPublicFragment.class));
setTabTextBasedOnOrientation(getResources().getConfiguration());
mActionBar.addTab(mTab1);
mActionBar.addTab(mTab2);
// mActionBar.addTab(mTab3);
}
private void setTabTextBasedOnOrientation(Configuration config) {
// longer names for landscape mode or tablets
// if (config.orientation == Configuration.ORIENTATION_LANDSCAPE
// || config.screenLayout == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
mTab1.setText(getString(R.string.dashboard_manage_keys));
mTab2.setText(getString(R.string.dashboard_manage_keys));
// } else {
// mTab1.setText(getString(R.string.lists_tab_blacklist_short));
// mTab2.setText(getString(R.string.lists_tab_whitelist_short));
// mTab3.setText(getString(R.string.lists_tab_redirection_list_short));
// }
}
/**
* Change text on orientation change
*/
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setTabTextBasedOnOrientation(newConfig);
}
public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
private Fragment mFragment;
private final Activity mActivity;
private final String mTag;
private final Class<T> mClass;
/**
* Constructor used each time a new tab is created.
*
* @param activity
* The host Activity, used to instantiate the fragment
* @param tag
* The identifier tag for the fragment
* @param clz
* The fragment's Class, used to instantiate the fragment
*/
public TabListener(Activity activity, String tag, Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
/**
* Open Fragment based on selected Tab
*/
@Override
public void onTabSelected(Tab tab, FragmentTransaction ignoredFt) {
// bug in compatibility lib:
// http://stackoverflow.com/questions/8645549/null-fragmenttransaction-being-passed-to-tablistener-ontabselected
FragmentManager fragMgr = ((FragmentActivity) mActivity).getSupportFragmentManager();
FragmentTransaction ft = fragMgr.beginTransaction();
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.replace(R.id.lists_tabs_container, mFragment, mTag);
ft.commit();
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ignoredFt) {
FragmentManager fragMgr = ((FragmentActivity) mActivity).getSupportFragmentManager();
FragmentTransaction ft = fragMgr.beginTransaction();
if (mFragment != null) {
// Remove the fragment
ft.remove(mFragment);
}
ft.commit();
}
}
}

View File

@ -40,6 +40,8 @@ import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
/**
* This implements export key method and delete key method. Used in lists and key view and key edit.
*
* TODO: get key type by looking at dataUri!
*
*/
@ -48,22 +50,11 @@ public class KeyActivity extends SherlockFragmentActivity {
protected FileDialogFragment mFileDialog;
protected String mExportFilename;
protected void deleteKey(Uri dataUri, final int keyType) {
protected void deleteKey(Uri dataUri, final int keyType, Handler deleteHandler) {
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
setResult(RESULT_CANCELED);
finish();
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(returnHandler);
Messenger messenger = new Messenger(deleteHandler);
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
new long[] { keyRingRowId }, keyType);
@ -77,11 +68,8 @@ public class KeyActivity extends SherlockFragmentActivity {
* @param keyRingMasterKeyId
* if -1 export all keys
*/
public void showExportKeysDialog(Uri dataUri, final int keyType, final String exportFilename) {
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
// TODO?
final long keyRingMasterKeyId = ProviderHelper.getSecretMasterKeyId(this, keyRingRowId);
public void showExportKeysDialog(final Uri dataUri, final int keyType,
final String exportFilename) {
mExportFilename = exportFilename;
// Message is received after file is selected
@ -92,6 +80,12 @@ public class KeyActivity extends SherlockFragmentActivity {
Bundle data = message.getData();
mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
// TODO?
long keyRingMasterKeyId = ProviderHelper.getSecretMasterKeyId(KeyActivity.this,
keyRingRowId);
exportKeys(keyRingMasterKeyId, keyType);
}
}
@ -103,7 +97,7 @@ public class KeyActivity extends SherlockFragmentActivity {
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
public void run() {
String title = null;
if (keyRingMasterKeyId != -1) {
if (dataUri != null) {
// single key export
title = getString(R.string.title_export_key);
} else {

View File

@ -1,314 +0,0 @@
/*
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.R;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
public class KeyListActivity extends SherlockFragmentActivity {
protected String mExportFilename = Constants.path.APP_DIR + "/";
protected String mImportData;
protected boolean mDeleteAfterImport = false;
protected int mKeyType;
FileDialogFragment mFileDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
handleActions(getIntent());
}
// TODO: needed?
// @Override
// protected void onNewIntent(Intent intent) {
// super.onNewIntent(intent);
// handleActions(intent);
// }
protected void handleActions(Intent intent) {
String action = intent.getAction();
Bundle extras = intent.getExtras();
if (extras == null) {
extras = new Bundle();
}
/**
* Android Standard Actions
*/
String searchString = null;
if (Intent.ACTION_SEARCH.equals(action)) {
searchString = extras.getString(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 KeyListAdapter(this, searchString);
// mList.setAdapter(mListAdapter);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case Id.request.filename: {
if (resultCode == RESULT_OK && data != null) {
try {
String path = data.getData().getPath();
Log.d(Constants.TAG, "path=" + path);
// set filename used in export/import dialogs
mFileDialog.setFilename(path);
} catch (NullPointerException e) {
Log.e(Constants.TAG, "Nullpointer while retrieving path!", e);
}
}
return;
}
default: {
break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// TODO: reimplement!
// menu.add(3, Id.menu.option.search, 0, R.string.menu_search)
// .setIcon(R.drawable.ic_menu_search).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, Id.menu.option.import_from_file, 5, R.string.menu_import_from_file)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add(0, Id.menu.option.export_keys, 6, R.string.menu_export_keys).setShowAsAction(
MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@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;
case Id.menu.option.import_from_file: {
Intent intentImportFromFile = new Intent(this, ImportKeysActivity.class);
intentImportFromFile.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE);
startActivityForResult(intentImportFromFile, 0);
return true;
}
case Id.menu.option.export_keys: {
showExportKeysDialog(-1);
return true;
}
// case Id.menu.option.search:
// startSearch("", false, null, false);
// return true;
default: {
return super.onOptionsItemSelected(item);
}
}
}
/**
* Show dialog where to export keys
*
* @param keyRingMasterKeyId
* if -1 export all keys
*/
public void showExportKeysDialog(final long keyRingMasterKeyId) {
// Message is received after file is selected
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == FileDialogFragment.MESSAGE_OKAY) {
Bundle data = message.getData();
mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
exportKeys(keyRingMasterKeyId);
}
}
};
// Create a new Messenger for the communication back
final Messenger messenger = new Messenger(returnHandler);
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
public void run() {
String title = null;
if (keyRingMasterKeyId != -1) {
// single key export
title = getString(R.string.title_export_key);
} else {
title = getString(R.string.title_export_keys);
}
String message = null;
if (mKeyType == Id.type.public_key) {
message = getString(R.string.specify_file_to_export_to);
} else {
message = getString(R.string.specify_file_to_export_secret_keys_to);
}
mFileDialog = FileDialogFragment.newInstance(messenger, title, message,
mExportFilename, null, Id.request.filename);
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
}
});
}
/**
* Show dialog to delete key
*
* @param keyRingIds
*/
public void showDeleteKeyDialog(long[] keyRingIds) {
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
// no further actions needed
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(returnHandler);
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
keyRingIds, mKeyType);
deleteKeyDialog.show(getSupportFragmentManager(), "deleteKeyDialog");
}
/**
* Export keys
*
* @param keyRingMasterKeyId
* if -1 export all keys
*/
public void exportKeys(long keyRingMasterKeyId) {
Log.d(Constants.TAG, "exportKeys started");
// Send all information needed to service to export key in other thread
Intent intent = new Intent(this, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING);
// fill values for this action
Bundle data = new Bundle();
data.putString(KeychainIntentService.EXPORT_FILENAME, mExportFilename);
data.putInt(KeychainIntentService.EXPORT_KEY_TYPE, mKeyType);
if (keyRingMasterKeyId == -1) {
data.putBoolean(KeychainIntentService.EXPORT_ALL, true);
} else {
data.putLong(KeychainIntentService.EXPORT_KEY_RING_MASTER_KEY_ID, keyRingMasterKeyId);
}
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// Message is received after exporting is done in ApgService
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(this,
R.string.progress_exporting, ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
int exported = returnData.getInt(KeychainIntentService.RESULT_EXPORT);
String toastMessage;
if (exported == 1) {
toastMessage = getString(R.string.key_exported);
} else if (exported > 0) {
toastMessage = getString(R.string.keys_exported, exported);
} else {
toastMessage = getString(R.string.no_keys_exported);
}
Toast.makeText(KeyListActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
}
};
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(exportHandler);
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
exportHandler.showProgressDialog(this);
// start service with intent
startService(intent);
}
}

View File

@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
@ -27,72 +28,49 @@ import com.actionbarsherlock.view.MenuItem;
import android.content.Intent;
import android.os.Bundle;
public class KeyListPublicActivity extends KeyListActivity {
public class KeyListPublicActivity extends KeyActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mKeyType = Id.type.public_key;
setContentView(R.layout.key_list_public_activity);
mExportFilename = Constants.path.APP_DIR + "/pubexport.asc";
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(1, Id.menu.option.key_server, 1, R.string.menu_key_server)
.setIcon(R.drawable.ic_menu_search_list)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(1, Id.menu.option.import_from_qr_code, 2, R.string.menu_import_from_qr_code)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add(1, Id.menu.option.import_from_nfc, 3, R.string.menu_import_from_nfc)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
getSupportMenuInflater().inflate(R.menu.key_list_public, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case Id.menu.option.key_server: {
startActivityForResult(new Intent(this, KeyServerQueryActivity.class), 0);
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;
}
case Id.menu.option.import_from_file: {
case R.id.menu_key_list_public_import:
Intent intentImportFromFile = new Intent(this, ImportKeysActivity.class);
intentImportFromFile.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE);
startActivityForResult(intentImportFromFile, 0);
return true;
}
case Id.menu.option.import_from_qr_code: {
Intent intentImportFromFile = new Intent(this, ImportKeysActivity.class);
intentImportFromFile.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_QR_CODE);
intentImportFromFile.setAction(ImportKeysActivity.ACTION_IMPORT_KEY);
startActivityForResult(intentImportFromFile, Id.request.import_from_qr_code);
return true;
}
case Id.menu.option.import_from_nfc: {
Intent intentImportFromFile = new Intent(this, ImportKeysActivity.class);
intentImportFromFile.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_NFC);
startActivityForResult(intentImportFromFile, 0);
case R.id.menu_key_list_public_export:
showExportKeysDialog(null, Id.type.public_key, Constants.path.APP_DIR
+ "/pubexport.asc");
return true;
}
default: {
default:
return super.onOptionsItemSelected(item);
}
}
}
// @Override

View File

@ -56,7 +56,7 @@ import android.widget.ListView;
public class KeyListPublicFragment extends Fragment implements AdapterView.OnItemClickListener,
LoaderManager.LoaderCallbacks<Cursor> {
private KeyListPublicActivity mKeyListPublicActivity;
// private KeyListPublicActivity mKeyListPublicActivity;
private KeyListPublicAdapter mAdapter;
private StickyListHeadersListView mStickyList;
@ -77,7 +77,7 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
// mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
mStickyList.setOnItemClickListener(this);
@ -164,7 +164,7 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
// setListShown(false);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key,
mAdapter = new KeyListPublicAdapter(getActivity(), null, Id.type.public_key,
USER_ID_INDEX);
mStickyList.setAdapter(mAdapter);
@ -222,7 +222,7 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
*/
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent detailsIntent = new Intent(mKeyListPublicActivity, KeyViewActivity.class);
Intent detailsIntent = new Intent(getActivity(), KeyViewActivity.class);
detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id)));
startActivity(detailsIntent);
}

View File

@ -27,47 +27,57 @@ import android.os.Bundle;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
public class KeyListSecretActivity extends KeyListActivity {
public class KeyListSecretActivity extends KeyActivity {
@Override
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";
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(1, Id.menu.option.create, 1, R.string.menu_create_key).setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add(1, Id.menu.option.createExpert, 2, R.string.menu_create_key_expert)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
getSupportMenuInflater().inflate(R.menu.key_list_secret, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case Id.menu.option.create: {
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;
case R.id.menu_key_list_secret_create:
createKey();
return true;
}
case Id.menu.option.createExpert: {
return true;
case R.id.menu_key_list_secret_create_expert:
createKeyExpert();
return true;
}
default: {
return true;
case R.id.menu_key_list_secret_export:
showExportKeysDialog(null, Id.type.secret_key, Constants.path.APP_DIR
+ "/secexport.asc");
return true;
case R.id.menu_key_list_secret_import:
Intent intentImportFromFile = new Intent(this, ImportKeysActivity.class);
intentImportFromFile.setAction(ImportKeysActivity.ACTION_IMPORT_KEY);
startActivityForResult(intentImportFromFile, Id.request.import_from_qr_code);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
private void createKey() {

View File

@ -31,6 +31,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
@ -134,10 +135,21 @@ public class KeyViewActivity extends KeyActivity implements CreateNdefMessageCal
case R.id.menu_key_view_share_clipboard:
copyToClipboard(mDataUri);
return true;
case R.id.menu_key_view_delete:
deleteKey(mDataUri, Id.type.public_key);
case R.id.menu_key_view_delete: {
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
setResult(RESULT_CANCELED);
finish();
}
}
};
deleteKey(mDataUri, Id.type.public_key, returnHandler);
return true;
}
}
return super.onOptionsItemSelected(item);
}