Merge remote-tracking branch 'upstream/master'

Conflicts:
	OpenKeychain-Test/src/test/resources/extern/OpenPGP-Haskell
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
This commit is contained in:
Daniel Albert
2014-07-16 18:49:16 +02:00
68 changed files with 3346 additions and 1097 deletions

View File

@@ -0,0 +1,187 @@
/*
* Copyright (C) 2014 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 android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import org.spongycastle.bcpg.sig.KeyFlags;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import java.util.regex.Matcher;
public class CreateKeyActivity extends ActionBarActivity {
AutoCompleteTextView nameEdit;
AutoCompleteTextView emailEdit;
EditText passphraseEdit;
Button createButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_key_activity);
nameEdit = (AutoCompleteTextView) findViewById(R.id.name);
emailEdit = (AutoCompleteTextView) findViewById(R.id.email);
passphraseEdit = (EditText) findViewById(R.id.passphrase);
createButton = (Button) findViewById(R.id.create_key_button);
emailEdit.setThreshold(1); // Start working from first character
emailEdit.setAdapter(
new ArrayAdapter<String>
(this, android.R.layout.simple_spinner_dropdown_item,
ContactHelper.getPossibleUserEmails(this)
)
);
emailEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
String email = editable.toString();
if (email.length() > 0) {
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
if (emailMatcher.matches()) {
emailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.uid_mail_ok, 0);
} else {
emailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.uid_mail_bad, 0);
}
} else {
// remove drawable if email is empty
emailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
});
nameEdit.setThreshold(1); // Start working from first character
nameEdit.setAdapter(
new ArrayAdapter<String>
(this, android.R.layout.simple_spinner_dropdown_item,
ContactHelper.getPossibleUserNames(this)
)
);
createButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createKeyCheck();
}
});
}
private void createKeyCheck() {
if (isEditTextNotEmpty(this, nameEdit)
&& isEditTextNotEmpty(this, emailEdit)
&& isEditTextNotEmpty(this, passphraseEdit)) {
createKey();
}
}
private void createKey() {
Intent intent = new Intent(this, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
// Message is received after importing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
this,
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
CreateKeyActivity.this.finish();
}
}
};
// fill values for this action
Bundle data = new Bundle();
SaveKeyringParcel parcel = new SaveKeyringParcel();
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.CERTIFY_OTHER, null));
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.SIGN_DATA, null));
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, null));
String userId = nameEdit.getText().toString() + " <" + emailEdit.getText().toString() + ">";
parcel.mAddUserIds.add(userId);
parcel.mNewPassphrase = passphraseEdit.getText().toString();
// get selected key entries
data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(this);
startService(intent);
}
/**
* Checks if text of given EditText is not empty. If it is empty an error is
* set and the EditText gets the focus.
*
* @param context
* @param editText
* @return true if EditText is not empty
*/
private static boolean isEditTextNotEmpty(Context context, EditText editText) {
boolean output = true;
if (editText.getText().toString().length() == 0) {
editText.setError("empty!");
editText.requestFocus();
output = false;
} else {
editText.setError(null);
}
return output;
}
}

View File

@@ -280,7 +280,7 @@ public class EditKeyActivityOld extends ActionBarActivity implements EditorListe
Uri secretUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
WrappedSecretKeyRing keyRing = new ProviderHelper(this).getWrappedSecretKeyRing(secretUri);
mMasterCanSign = keyRing.getSubKey().canCertify();
mMasterCanSign = keyRing.getSecretKey().canCertify();
for (WrappedSecretKey key : keyRing.secretKeyIterator()) {
// Turn into uncached instance
mKeys.add(key.getUncached());
@@ -288,7 +288,7 @@ public class EditKeyActivityOld extends ActionBarActivity implements EditorListe
}
boolean isSet = false;
for (String userId : keyRing.getSubKey().getUserIds()) {
for (String userId : keyRing.getSecretKey().getUserIds()) {
Log.d(Constants.TAG, "Added userId " + userId);
if (!isSet) {
isSet = true;
@@ -556,7 +556,7 @@ public class EditKeyActivityOld extends ActionBarActivity implements EditorListe
saveParams.deletedKeys = mKeysView.getDeletedKeys();
saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView);
saveParams.keysUsages = getKeysUsages(mKeysView);
saveParams.newPassphrase = mNewPassphrase;
saveParams.mNewPassphrase = mNewPassphrase;
saveParams.oldPassphrase = mCurrentPassphrase;
saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray());
saveParams.keys = getKeys(mKeysView);

View File

@@ -228,7 +228,7 @@ public class EditKeyFragment extends LoaderFragment implements
}
});
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSaveKeyringParcel.addSubKeys);
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSaveKeyringParcel.mAddSubKeys);
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
// Prepare the loaders. Either re-connect with an existing ones,
@@ -298,7 +298,7 @@ public class EditKeyFragment extends LoaderFragment implements
Bundle data = message.getData();
// cache new returned passphrase!
mSaveKeyringParcel.newPassphrase = data
mSaveKeyringParcel.mNewPassphrase = data
.getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE);
}
}
@@ -320,19 +320,19 @@ public class EditKeyFragment extends LoaderFragment implements
switch (message.what) {
case EditUserIdDialogFragment.MESSAGE_CHANGE_PRIMARY_USER_ID:
// toggle
if (mSaveKeyringParcel.changePrimaryUserId != null
&& mSaveKeyringParcel.changePrimaryUserId.equals(userId)) {
mSaveKeyringParcel.changePrimaryUserId = null;
if (mSaveKeyringParcel.mChangePrimaryUserId != null
&& mSaveKeyringParcel.mChangePrimaryUserId.equals(userId)) {
mSaveKeyringParcel.mChangePrimaryUserId = null;
} else {
mSaveKeyringParcel.changePrimaryUserId = userId;
mSaveKeyringParcel.mChangePrimaryUserId = userId;
}
break;
case EditUserIdDialogFragment.MESSAGE_REVOKE:
// toggle
if (mSaveKeyringParcel.revokeUserIds.contains(userId)) {
mSaveKeyringParcel.revokeUserIds.remove(userId);
if (mSaveKeyringParcel.mRevokeUserIds.contains(userId)) {
mSaveKeyringParcel.mRevokeUserIds.remove(userId);
} else {
mSaveKeyringParcel.revokeUserIds.add(userId);
mSaveKeyringParcel.mRevokeUserIds.add(userId);
}
break;
}
@@ -363,10 +363,10 @@ public class EditKeyFragment extends LoaderFragment implements
break;
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
// toggle
if (mSaveKeyringParcel.revokeSubKeys.contains(keyId)) {
mSaveKeyringParcel.revokeSubKeys.remove(keyId);
if (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId)) {
mSaveKeyringParcel.mRevokeSubKeys.remove(keyId);
} else {
mSaveKeyringParcel.revokeSubKeys.add(keyId);
mSaveKeyringParcel.mRevokeSubKeys.add(keyId);
}
break;
}
@@ -450,10 +450,11 @@ public class EditKeyFragment extends LoaderFragment implements
}
private void save(String passphrase) {
Log.d(Constants.TAG, "add userids to parcel: " + mUserIdsAddedAdapter.getDataAsStringList());
Log.d(Constants.TAG, "mSaveKeyringParcel.newPassphrase: " + mSaveKeyringParcel.newPassphrase);
mSaveKeyringParcel.mAddUserIds = mUserIdsAddedAdapter.getDataAsStringList();
mSaveKeyringParcel.addUserIds = mUserIdsAddedAdapter.getDataAsStringList();
Log.d(Constants.TAG, "mSaveKeyringParcel.mAddUserIds: " + mSaveKeyringParcel.mAddUserIds);
Log.d(Constants.TAG, "mSaveKeyringParcel.mNewPassphrase: " + mSaveKeyringParcel.mNewPassphrase);
Log.d(Constants.TAG, "mSaveKeyringParcel.mRevokeUserIds: " + mSaveKeyringParcel.mRevokeUserIds);
// Message is received after importing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
@@ -509,4 +510,4 @@ public class EditKeyFragment extends LoaderFragment implements
// start service with intent
getActivity().startService(intent);
}
}
}

View File

@@ -198,7 +198,7 @@ public class EncryptAsymmetricFragment extends Fragment {
String[] userId;
try {
userId = mProviderHelper.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingUri(mSecretKeyId)).getSplitPrimaryUserId();
KeyRings.buildUnifiedKeyRingUri(mSecretKeyId)).getSplitPrimaryUserIdWithFallback();
} catch (PgpGeneralException e) {
userId = null;
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2014 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 android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import org.sufficientlysecure.keychain.R;
public class FirstTimeActivity extends ActionBarActivity {
Button mCreateKey;
Button mImportKey;
Button mSkipSetup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.first_time_activity);
mCreateKey = (Button) findViewById(R.id.first_time_create_key);
mImportKey = (Button) findViewById(R.id.first_time_import_key);
mSkipSetup = (Button) findViewById(R.id.first_time_cancel);
mSkipSetup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FirstTimeActivity.this, KeyListActivity.class);
startActivity(intent);
finish();
}
});
mImportKey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FirstTimeActivity.this, ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
startActivity(intent);
finish();
}
});
mCreateKey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FirstTimeActivity.this, CreateKeyActivity.class);
startActivity(intent);
finish();
}
});
}
}

View File

@@ -32,8 +32,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Constants.choice.algorithm;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
@@ -43,7 +42,6 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd;
import org.sufficientlysecure.keychain.util.Log;
import java.io.IOException;
import java.util.ArrayList;
public class KeyListActivity extends DrawerActivity {
@@ -53,6 +51,15 @@ public class KeyListActivity extends DrawerActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Preferences prefs = Preferences.getPreferences(this);
if (prefs.getFirstTime()) {
prefs.setFirstTime(false);
Intent intent = new Intent(this, FirstTimeActivity.class);
startActivity(intent);
finish();
return;
}
mExportHelper = new ExportHelper(this);
setContentView(R.layout.key_list_activity);
@@ -66,9 +73,10 @@ public class KeyListActivity extends DrawerActivity {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.key_list, menu);
if(Constants.DEBUG) {
if (Constants.DEBUG) {
menu.findItem(R.id.menu_key_list_debug_read).setVisible(true);
menu.findItem(R.id.menu_key_list_debug_write).setVisible(true);
menu.findItem(R.id.menu_key_list_debug_first_time).setVisible(true);
}
return true;
@@ -85,10 +93,6 @@ public class KeyListActivity extends DrawerActivity {
createKey();
return true;
case R.id.menu_key_list_create_expert:
createKeyExpert();
return true;
case R.id.menu_key_list_export:
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
return true;
@@ -98,7 +102,7 @@ public class KeyListActivity extends DrawerActivity {
KeychainDatabase.debugRead(this);
AppMsg.makeText(this, "Restored from backup", AppMsg.STYLE_CONFIRM).show();
getContentResolver().notifyChange(KeychainContract.KeyRings.CONTENT_URI, null);
} catch(IOException e) {
} catch (IOException e) {
Log.e(Constants.TAG, "IO Error", e);
AppMsg.makeText(this, "IO Error: " + e.getMessage(), AppMsg.STYLE_ALERT).show();
}
@@ -108,12 +112,18 @@ public class KeyListActivity extends DrawerActivity {
try {
KeychainDatabase.debugWrite(this);
AppMsg.makeText(this, "Backup successful", AppMsg.STYLE_CONFIRM).show();
} catch(IOException e) {
} catch (IOException e) {
Log.e(Constants.TAG, "IO Error", e);
AppMsg.makeText(this, "IO Error: " + e.getMessage(), AppMsg.STYLE_ALERT).show();
}
return true;
case R.id.menu_key_list_debug_first_time:
Intent intent = new Intent(this, FirstTimeActivity.class);
startActivity(intent);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
@@ -125,50 +135,8 @@ public class KeyListActivity extends DrawerActivity {
}
private void createKey() {
Intent intent = new Intent(this, WizardActivity.class);
// intent.setAction(EditKeyActivity.ACTION_CREATE_KEY);
// intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true);
// intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view
startActivityForResult(intent, 0);
Intent intent = new Intent(this, CreateKeyActivity.class);
startActivity(intent);
}
private void createKeyExpert() {
Intent intent = new Intent(this, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
// Message is received after importing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
this,
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
Bundle data = message.getData();
// OtherHelper.logDebugBundle(data, "message reply");
}
};
// fill values for this action
Bundle data = new Bundle();
SaveKeyringParcel parcel = new SaveKeyringParcel();
parcel.addSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null));
parcel.addSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
parcel.addUserIds.add("swagerinho");
parcel.newPassphrase = "swag";
// get selected key entries
data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(this);
startService(intent);
}
}

View File

@@ -149,8 +149,8 @@ public class ViewCertActivity extends ActionBarActivity
providerHelper.getWrappedPublicKeyRing(sig.getKeyId());
try {
sig.init(signerRing.getSubkey());
if (sig.verifySignature(signeeRing.getSubkey(), signeeUid)) {
sig.init(signerRing.getPublicKey());
if (sig.verifySignature(signeeRing.getPublicKey(), signeeUid)) {
mStatus.setText(R.string.cert_verify_ok);
mStatus.setTextColor(getResources().getColor(R.color.result_green));
} else {

View File

@@ -1,466 +0,0 @@
/*
* Copyright (C) 2014 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 android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.TextView;
import org.sufficientlysecure.htmltextview.HtmlTextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
import java.util.regex.Matcher;
public class WizardActivity extends ActionBarActivity {
private State mCurrentState;
// values for mCurrentScreen
private enum State {
START, CREATE_KEY, IMPORT_KEY, K9
}
public static final int REQUEST_CODE_IMPORT = 0x00007703;
Button mBackButton;
Button mNextButton;
StartFragment mStartFragment;
CreateKeyFragment mCreateKeyFragment;
K9Fragment mK9Fragment;
private static final String K9_PACKAGE = "com.fsck.k9";
// private static final String K9_MARKET_INTENT_URI_BASE = "market://details?id=%s";
// private static final Intent K9_MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse(
// String.format(K9_MARKET_INTENT_URI_BASE, K9_PACKAGE)));
private static final Intent K9_MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/k9mail/k-9/releases/tag/4.904"));
LinearLayout mProgressLayout;
View mProgressLine;
ProgressBar mProgressBar;
ImageView mProgressImage;
TextView mProgressText;
/**
* Checks if text of given EditText is not empty. If it is empty an error is
* set and the EditText gets the focus.
*
* @param context
* @param editText
* @return true if EditText is not empty
*/
private static boolean isEditTextNotEmpty(Context context, EditText editText) {
boolean output = true;
if (editText.getText().toString().length() == 0) {
editText.setError("empty!");
editText.requestFocus();
output = false;
} else {
editText.setError(null);
}
return output;
}
public static class StartFragment extends Fragment {
public static StartFragment newInstance() {
StartFragment myFragment = new StartFragment();
Bundle args = new Bundle();
myFragment.setArguments(args);
return myFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.wizard_start_fragment,
container, false);
}
}
public static class CreateKeyFragment extends Fragment {
public static CreateKeyFragment newInstance() {
CreateKeyFragment myFragment = new CreateKeyFragment();
Bundle args = new Bundle();
myFragment.setArguments(args);
return myFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.wizard_create_key_fragment,
container, false);
final AutoCompleteTextView emailView = (AutoCompleteTextView) view.findViewById(R.id.email);
emailView.setThreshold(1); // Start working from first character
emailView.setAdapter(
new ArrayAdapter<String>
(getActivity(), android.R.layout.simple_spinner_dropdown_item,
ContactHelper.getPossibleUserEmails(getActivity())
)
);
emailView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
String email = editable.toString();
if (email.length() > 0) {
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
if (emailMatcher.matches()) {
emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.uid_mail_ok, 0);
} else {
emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.uid_mail_bad, 0);
}
} else {
// remove drawable if email is empty
emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
});
final AutoCompleteTextView nameView = (AutoCompleteTextView) view.findViewById(R.id.name);
nameView.setThreshold(1); // Start working from first character
nameView.setAdapter(
new ArrayAdapter<String>
(getActivity(), android.R.layout.simple_spinner_dropdown_item,
ContactHelper.getPossibleUserNames(getActivity())
)
);
return view;
}
}
public static class K9Fragment extends Fragment {
public static K9Fragment newInstance() {
K9Fragment myFragment = new K9Fragment();
Bundle args = new Bundle();
myFragment.setArguments(args);
return myFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.wizard_k9_fragment,
container, false);
HtmlTextView text = (HtmlTextView) v
.findViewById(R.id.wizard_k9_text);
text.setHtmlFromString("Install K9. It's good for you! Here is a screenhot how to enable OK in K9: (TODO)", true);
return v;
}
}
/**
* Loads new fragment
*
* @param fragment
*/
private void loadFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.wizard_container,
fragment);
fragmentTransaction.commit();
}
/**
* Instantiate View and initialize fragments for this Activity
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wizard_activity);
mBackButton = (Button) findViewById(R.id.wizard_back);
mNextButton = (Button) findViewById(R.id.wizard_next);
// progress layout
mProgressLayout = (LinearLayout) findViewById(R.id.wizard_progress);
mProgressLine = findViewById(R.id.wizard_progress_line);
mProgressBar = (ProgressBar) findViewById(R.id.wizard_progress_progressbar);
mProgressImage = (ImageView) findViewById(R.id.wizard_progress_image);
mProgressText = (TextView) findViewById(R.id.wizard_progress_text);
changeToState(State.START);
}
private enum ProgressState {
WORKING, ENABLED, DISABLED, ERROR
}
private void showProgress(ProgressState state, String text) {
switch (state) {
case WORKING:
mProgressBar.setVisibility(View.VISIBLE);
mProgressImage.setVisibility(View.GONE);
break;
case ENABLED:
mProgressBar.setVisibility(View.GONE);
mProgressImage.setVisibility(View.VISIBLE);
// mProgressImage.setImageDrawable(getResources().getDrawable(
// R.drawable.status_enabled));
break;
case DISABLED:
mProgressBar.setVisibility(View.GONE);
mProgressImage.setVisibility(View.VISIBLE);
// mProgressImage.setImageDrawable(getResources().getDrawable(
// R.drawable.status_disabled));
break;
case ERROR:
mProgressBar.setVisibility(View.GONE);
mProgressImage.setVisibility(View.VISIBLE);
// mProgressImage.setImageDrawable(getResources().getDrawable(
// R.drawable.status_fail));
break;
default:
break;
}
mProgressText.setText(text);
mProgressLine.setVisibility(View.VISIBLE);
mProgressLayout.setVisibility(View.VISIBLE);
}
private void hideProgress() {
mProgressLine.setVisibility(View.GONE);
mProgressLayout.setVisibility(View.GONE);
}
public void nextOnClick(View view) {
// close keyboard
if (getCurrentFocus() != null) {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus()
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
switch (mCurrentState) {
case START: {
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.wizard_start_radio_group);
int selectedId = radioGroup.getCheckedRadioButtonId();
switch (selectedId) {
case R.id.wizard_start_new_key: {
changeToState(State.CREATE_KEY);
break;
}
case R.id.wizard_start_import: {
changeToState(State.IMPORT_KEY);
break;
}
case R.id.wizard_start_skip: {
finish();
break;
}
}
mBackButton.setText(R.string.btn_back);
break;
}
case CREATE_KEY:
EditText nameEdit = (EditText) findViewById(R.id.name);
EditText emailEdit = (EditText) findViewById(R.id.email);
EditText passphraseEdit = (EditText) findViewById(R.id.passphrase);
if (isEditTextNotEmpty(this, nameEdit)
&& isEditTextNotEmpty(this, emailEdit)
&& isEditTextNotEmpty(this, passphraseEdit)) {
// SaveKeyringParcel newKey = new SaveKeyringParcel();
// newKey.addUserIds.add(nameEdit.getText().toString() + " <"
// + emailEdit.getText().toString() + ">");
AsyncTask<String, Boolean, Boolean> generateTask = new AsyncTask<String, Boolean, Boolean>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgress(ProgressState.WORKING, "generating key...");
}
@Override
protected Boolean doInBackground(String... params) {
return true;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
showProgress(ProgressState.ENABLED, "key generated successfully!");
changeToState(State.K9);
} else {
showProgress(ProgressState.ERROR, "error in key gen");
}
}
};
generateTask.execute("");
}
break;
case K9: {
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.wizard_k9_radio_group);
int selectedId = radioGroup.getCheckedRadioButtonId();
switch (selectedId) {
case R.id.wizard_k9_install: {
try {
startActivity(K9_MARKET_INTENT);
} catch (ActivityNotFoundException e) {
Log.e(Constants.TAG, "Activity not found for: " + K9_MARKET_INTENT);
}
break;
}
case R.id.wizard_k9_skip: {
finish();
break;
}
}
finish();
break;
}
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_IMPORT: {
if (resultCode == Activity.RESULT_OK) {
// imported now...
changeToState(State.K9);
} else {
// back to start
changeToState(State.START);
}
break;
}
default: {
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
}
public void backOnClick(View view) {
switch (mCurrentState) {
case START:
finish();
break;
case CREATE_KEY:
changeToState(State.START);
break;
case IMPORT_KEY:
changeToState(State.START);
break;
default:
changeToState(State.START);
break;
}
}
private void changeToState(State state) {
switch (state) {
case START: {
mCurrentState = State.START;
mStartFragment = StartFragment.newInstance();
loadFragment(mStartFragment);
mBackButton.setText(android.R.string.cancel);
mNextButton.setText(R.string.btn_next);
break;
}
case CREATE_KEY: {
mCurrentState = State.CREATE_KEY;
mCreateKeyFragment = CreateKeyFragment.newInstance();
loadFragment(mCreateKeyFragment);
break;
}
case IMPORT_KEY: {
mCurrentState = State.IMPORT_KEY;
Intent intent = new Intent(this, ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
startActivityForResult(intent, REQUEST_CODE_IMPORT);
break;
}
case K9: {
mCurrentState = State.K9;
mBackButton.setEnabled(false); // don't go back to import/create key
mK9Fragment = K9Fragment.newInstance();
loadFragment(mK9Fragment);
break;
}
}
}
}

View File

@@ -143,7 +143,7 @@ public class SubkeysAdapter extends CursorAdapter {
// for edit key
if (mSaveKeyringParcel != null) {
boolean revokeThisSubkey = (mSaveKeyringParcel.revokeSubKeys.contains(keyId));
boolean revokeThisSubkey = (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId));
if (revokeThisSubkey) {
if (!isRevoked) {

View File

@@ -131,10 +131,10 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
// for edit key
if (mSaveKeyringParcel != null) {
boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.changePrimaryUserId != null);
boolean changeThisPrimaryUserId = (mSaveKeyringParcel.changePrimaryUserId != null
&& mSaveKeyringParcel.changePrimaryUserId.equals(userId));
boolean revokeThisUserId = (mSaveKeyringParcel.revokeUserIds.contains(userId));
boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null);
boolean changeThisPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null
&& mSaveKeyringParcel.mChangePrimaryUserId.equals(userId));
boolean revokeThisUserId = (mSaveKeyringParcel.mRevokeUserIds.contains(userId));
// only if primary user id will be changed
// (this is not triggered if the user id is currently the primary one)

View File

@@ -152,7 +152,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
// above can't be statically verified to have been set in all cases because
// the catch clause doesn't return.
try {
userId = secretRing.getPrimaryUserId();
userId = secretRing.getPrimaryUserIdWithFallback();
} catch (PgpGeneralException e) {
userId = null;
}
@@ -232,7 +232,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
try {
PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase,
secretRing.getPrimaryUserId());
secretRing.getPrimaryUserIdWithFallback());
} catch(PgpGeneralException e) {
Log.e(Constants.TAG, "adding of a passhrase failed", e);
}
@@ -240,7 +240,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
if (unlockedSecretKey.getKeyId() != masterKeyId) {
PassphraseCacheService.addCachedPassphrase(
activity, unlockedSecretKey.getKeyId(), passphrase,
unlockedSecretKey.getPrimaryUserId());
unlockedSecretKey.getPrimaryUserIdWithFallback());
}
// also return passphrase back to activity