mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-19 20:31:52 -05:00
Merge pull request #305 from hav3n/branch-dialog-fragment
Partial fix for #304
This commit is contained in:
commit
152790a194
@ -17,22 +17,9 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.nfc.NdefMessage;
|
import android.nfc.NdefMessage;
|
||||||
@ -51,6 +38,18 @@ import android.widget.ArrayAdapter;
|
|||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
import com.devspark.appmsg.AppMsg;
|
import com.devspark.appmsg.AppMsg;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.BadImportKeyDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNavigationListener {
|
public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNavigationListener {
|
||||||
public static final String ACTION_IMPORT_KEY = Constants.INTENT_PREFIX + "IMPORT_KEY";
|
public static final String ACTION_IMPORT_KEY = Constants.INTENT_PREFIX + "IMPORT_KEY";
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_QR_CODE = Constants.INTENT_PREFIX
|
public static final String ACTION_IMPORT_KEY_FROM_QR_CODE = Constants.INTENT_PREFIX
|
||||||
@ -236,10 +235,10 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
|
|||||||
* inside your Activity."
|
* inside your Activity."
|
||||||
* <p/>
|
* <p/>
|
||||||
* from http://stackoverflow.com/questions/10983396/fragment-oncreateview-and-onactivitycreated-called-twice/14295474#14295474
|
* from http://stackoverflow.com/questions/10983396/fragment-oncreateview-and-onactivitycreated-called-twice/14295474#14295474
|
||||||
*
|
* <p/>
|
||||||
* In our case, if we start ImportKeysActivity with parameters to directly search using a fingerprint,
|
* In our case, if we start ImportKeysActivity with parameters to directly search using a fingerprint,
|
||||||
* the fragment would be loaded twice resulting in the query being empty after the second load.
|
* the fragment would be loaded twice resulting in the query being empty after the second load.
|
||||||
*
|
* <p/>
|
||||||
* Our solution:
|
* Our solution:
|
||||||
* To prevent that a fragment will be loaded again even if it was already loaded loadNavFragment
|
* To prevent that a fragment will be loaded again even if it was already loaded loadNavFragment
|
||||||
* checks against mCurrentNavPostition.
|
* checks against mCurrentNavPostition.
|
||||||
@ -395,23 +394,8 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
|
|||||||
AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO)
|
AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO)
|
||||||
.show();
|
.show();
|
||||||
if (bad > 0) {
|
if (bad > 0) {
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(
|
BadImportKeyDialogFragment badImportKeyDialogFragment = BadImportKeyDialogFragment.newInstance(bad);
|
||||||
ImportKeysActivity.this);
|
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
|
||||||
|
|
||||||
alert.setIcon(android.R.drawable.ic_dialog_alert);
|
|
||||||
alert.setTitle(R.string.warning);
|
|
||||||
|
|
||||||
alert.setMessage(ImportKeysActivity.this.getResources()
|
|
||||||
.getQuantityString(R.plurals.bad_keys_encountered, bad, bad));
|
|
||||||
|
|
||||||
alert.setPositiveButton(android.R.string.ok,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
dialog.cancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alert.setCancelable(true);
|
|
||||||
alert.create().show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
package org.sufficientlysecure.keychain.ui.dialog;
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012-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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
|
||||||
|
public class BadImportKeyDialogFragment extends DialogFragment {
|
||||||
|
private static final String ARG_BAD_IMPORT = "bad_import";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of this Bad Import Key DialogFragment
|
||||||
|
* @param bad
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static BadImportKeyDialogFragment newInstance(int bad) {
|
||||||
|
BadImportKeyDialogFragment frag = new BadImportKeyDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
|
||||||
|
args.putInt(ARG_BAD_IMPORT, bad);
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
final FragmentActivity activity = getActivity();
|
||||||
|
|
||||||
|
final int badImport = getArguments().getInt(ARG_BAD_IMPORT);
|
||||||
|
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
|
||||||
|
|
||||||
|
alert.setIcon(R.drawable.ic_dialog_alert_holo_light);
|
||||||
|
alert.setTitle(R.string.warning);
|
||||||
|
|
||||||
|
alert.setMessage(activity.getResources()
|
||||||
|
.getQuantityString(R.plurals.bad_keys_encountered, badImport, badImport));
|
||||||
|
|
||||||
|
alert.setPositiveButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alert.setCancelable(true);
|
||||||
|
|
||||||
|
|
||||||
|
return alert.create();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,156 @@
|
|||||||
|
package org.sufficientlysecure.keychain.ui.dialog;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012-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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Id;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.util.Choice;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
public class CreateKeyDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
public interface OnAlgorithmSelectedListener {
|
||||||
|
public void onAlgorithmSelected(Choice algorithmChoice, int keySize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String ARG_EDITOR_CHILD_COUNT = "child_count";
|
||||||
|
|
||||||
|
private int mNewKeySize;
|
||||||
|
private Choice mNewKeyAlgorithmChoice;
|
||||||
|
private OnAlgorithmSelectedListener mAlgorithmSelectedListener;
|
||||||
|
|
||||||
|
public void setOnAlgorithmSelectedListener(OnAlgorithmSelectedListener listener) {
|
||||||
|
mAlgorithmSelectedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateKeyDialogFragment newInstance(int mEditorChildCount) {
|
||||||
|
CreateKeyDialogFragment frag = new CreateKeyDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
|
||||||
|
args.putInt(ARG_EDITOR_CHILD_COUNT, mEditorChildCount);
|
||||||
|
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
return frag;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
final FragmentActivity context = getActivity();
|
||||||
|
final LayoutInflater mInflater;
|
||||||
|
|
||||||
|
final int childCount = getArguments().getInt(ARG_EDITOR_CHILD_COUNT);
|
||||||
|
mInflater = context.getLayoutInflater();
|
||||||
|
|
||||||
|
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||||
|
|
||||||
|
View view = mInflater.inflate(R.layout.create_key_dialog, null);
|
||||||
|
dialog.setView(view);
|
||||||
|
dialog.setTitle(R.string.title_create_key);
|
||||||
|
|
||||||
|
boolean wouldBeMasterKey = (childCount == 0);
|
||||||
|
|
||||||
|
final Spinner algorithm = (Spinner) view.findViewById(R.id.create_key_algorithm);
|
||||||
|
Vector<Choice> choices = new Vector<Choice>();
|
||||||
|
choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString(
|
||||||
|
R.string.dsa)));
|
||||||
|
if (!wouldBeMasterKey) {
|
||||||
|
choices.add(new Choice(Id.choice.algorithm.elgamal, getResources().getString(
|
||||||
|
R.string.elgamal)));
|
||||||
|
}
|
||||||
|
|
||||||
|
choices.add(new Choice(Id.choice.algorithm.rsa, getResources().getString(
|
||||||
|
R.string.rsa)));
|
||||||
|
|
||||||
|
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(context,
|
||||||
|
android.R.layout.simple_spinner_item, choices);
|
||||||
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
algorithm.setAdapter(adapter);
|
||||||
|
// make RSA the default
|
||||||
|
for (int i = 0; i < choices.size(); ++i) {
|
||||||
|
if (choices.get(i).getId() == Id.choice.algorithm.rsa) {
|
||||||
|
algorithm.setSelection(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size);
|
||||||
|
ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(
|
||||||
|
context, R.array.key_size_spinner_values,
|
||||||
|
android.R.layout.simple_spinner_item);
|
||||||
|
keySizeAdapter
|
||||||
|
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
keySize.setAdapter(keySizeAdapter);
|
||||||
|
keySize.setSelection(3); // Default to 4096 for the key length
|
||||||
|
dialog.setPositiveButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface di, int id) {
|
||||||
|
di.dismiss();
|
||||||
|
try {
|
||||||
|
int nKeyIndex = keySize.getSelectedItemPosition();
|
||||||
|
switch (nKeyIndex) {
|
||||||
|
case 0:
|
||||||
|
mNewKeySize = 512;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
mNewKeySize = 1024;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mNewKeySize = 2048;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
mNewKeySize = 4096;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
mNewKeySize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mNewKeyAlgorithmChoice = (Choice) algorithm.getSelectedItem();
|
||||||
|
mAlgorithmSelectedListener.onAlgorithmSelected(mNewKeyAlgorithmChoice, mNewKeySize);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.setCancelable(true);
|
||||||
|
dialog.setNegativeButton(android.R.string.cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface di, int id) {
|
||||||
|
di.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return dialog.create();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,23 +16,8 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.widget;
|
package org.sufficientlysecure.keychain.ui.widget;
|
||||||
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
|
||||||
import org.sufficientlysecure.keychain.Id;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
|
||||||
import org.sufficientlysecure.keychain.util.Choice;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -43,13 +28,25 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
|
|
||||||
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
|
import org.sufficientlysecure.keychain.Id;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.CreateKeyDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
||||||
|
import org.sufficientlysecure.keychain.util.Choice;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
public class SectionView extends LinearLayout implements OnClickListener, EditorListener {
|
public class SectionView extends LinearLayout implements OnClickListener, EditorListener {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private BootstrapButton mPlusButton;
|
private BootstrapButton mPlusButton;
|
||||||
@ -149,84 +146,16 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Id.type.key: {
|
case Id.type.key: {
|
||||||
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
|
CreateKeyDialogFragment mCreateKeyDialogFragment = CreateKeyDialogFragment.newInstance(mEditors.getChildCount());
|
||||||
|
mCreateKeyDialogFragment.setOnAlgorithmSelectedListener(new CreateKeyDialogFragment.OnAlgorithmSelectedListener() {
|
||||||
View view = mInflater.inflate(R.layout.create_key_dialog, null);
|
@Override
|
||||||
dialog.setView(view);
|
public void onAlgorithmSelected(Choice algorithmChoice, int keySize) {
|
||||||
dialog.setTitle(R.string.title_create_key);
|
mNewKeyAlgorithmChoice = algorithmChoice;
|
||||||
|
mNewKeySize = keySize;
|
||||||
boolean wouldBeMasterKey = (mEditors.getChildCount() == 0);
|
createKey();
|
||||||
|
|
||||||
final Spinner algorithm = (Spinner) view.findViewById(R.id.create_key_algorithm);
|
|
||||||
Vector<Choice> choices = new Vector<Choice>();
|
|
||||||
choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString(
|
|
||||||
R.string.dsa)));
|
|
||||||
if (!wouldBeMasterKey) {
|
|
||||||
choices.add(new Choice(Id.choice.algorithm.elgamal, getResources().getString(
|
|
||||||
R.string.elgamal)));
|
|
||||||
}
|
|
||||||
|
|
||||||
choices.add(new Choice(Id.choice.algorithm.rsa, getResources().getString(
|
|
||||||
R.string.rsa)));
|
|
||||||
|
|
||||||
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
|
|
||||||
android.R.layout.simple_spinner_item, choices);
|
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
algorithm.setAdapter(adapter);
|
|
||||||
// make RSA the default
|
|
||||||
for (int i = 0; i < choices.size(); ++i) {
|
|
||||||
if (choices.get(i).getId() == Id.choice.algorithm.rsa) {
|
|
||||||
algorithm.setSelection(i);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
mCreateKeyDialogFragment.show(mActivity.getSupportFragmentManager(), "createKeyDialog");
|
||||||
final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size);
|
|
||||||
ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(
|
|
||||||
getContext(), R.array.key_size_spinner_values,
|
|
||||||
android.R.layout.simple_spinner_item);
|
|
||||||
keySizeAdapter
|
|
||||||
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
keySize.setAdapter(keySizeAdapter);
|
|
||||||
keySize.setSelection(3); // Default to 4096 for the key length
|
|
||||||
dialog.setPositiveButton(android.R.string.ok,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface di, int id) {
|
|
||||||
di.dismiss();
|
|
||||||
try {
|
|
||||||
int nKeyIndex = keySize.getSelectedItemPosition();
|
|
||||||
switch (nKeyIndex) {
|
|
||||||
case 0:
|
|
||||||
mNewKeySize = 512;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
mNewKeySize = 1024;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
mNewKeySize = 2048;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
mNewKeySize = 4096;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
mNewKeySize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mNewKeyAlgorithmChoice = (Choice) algorithm.getSelectedItem();
|
|
||||||
createKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.setCancelable(true);
|
|
||||||
dialog.setNegativeButton(android.R.string.cancel,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface di, int id) {
|
|
||||||
di.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.create().show();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user