mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 03:02:15 -05:00
Add additional email addresses in create key
This commit is contained in:
parent
e3547b4979
commit
bce0fe6221
@ -40,6 +40,7 @@ python copy OpenKeychain communication grey vpn_key 24
|
|||||||
python copy OpenKeychain navigation grey chevron_left 24
|
python copy OpenKeychain navigation grey chevron_left 24
|
||||||
python copy OpenKeychain navigation grey chevron_right 24
|
python copy OpenKeychain navigation grey chevron_right 24
|
||||||
python copy OpenKeychain social grey person 48
|
python copy OpenKeychain social grey person 48
|
||||||
|
python copy OpenKeychain communication grey email 24
|
||||||
|
|
||||||
# navigation drawer sections
|
# navigation drawer sections
|
||||||
python copy OpenKeychain communication black vpn_key 24
|
python copy OpenKeychain communication black vpn_key 24
|
||||||
|
@ -20,17 +20,30 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.widget.DefaultItemAnimator;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.AddEmailDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.EmailEditText;
|
import org.sufficientlysecure.keychain.ui.widget.EmailEditText;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CreateKeyEmailFragment extends Fragment {
|
public class CreateKeyEmailFragment extends Fragment {
|
||||||
|
|
||||||
public static final String ARG_NAME = "name";
|
public static final String ARG_NAME = "name";
|
||||||
@ -38,10 +51,14 @@ public class CreateKeyEmailFragment extends Fragment {
|
|||||||
|
|
||||||
CreateKeyActivity mCreateKeyActivity;
|
CreateKeyActivity mCreateKeyActivity;
|
||||||
EmailEditText mEmailEdit;
|
EmailEditText mEmailEdit;
|
||||||
|
RecyclerView mEmailsRecyclerView;
|
||||||
View mBackButton;
|
View mBackButton;
|
||||||
View mNextButton;
|
View mNextButton;
|
||||||
|
|
||||||
String mName;
|
String mName;
|
||||||
|
ArrayList<EmailAdapter.ViewModel> mAdditionalEmailModels;
|
||||||
|
|
||||||
|
EmailAdapter mEmailAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
@ -86,6 +103,7 @@ public class CreateKeyEmailFragment extends Fragment {
|
|||||||
mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email);
|
mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email);
|
||||||
mBackButton = view.findViewById(R.id.create_key_back_button);
|
mBackButton = view.findViewById(R.id.create_key_back_button);
|
||||||
mNextButton = view.findViewById(R.id.create_key_next_button);
|
mNextButton = view.findViewById(R.id.create_key_next_button);
|
||||||
|
mEmailsRecyclerView = (RecyclerView) view.findViewById(R.id.create_key_emails);
|
||||||
|
|
||||||
// initial values
|
// initial values
|
||||||
mName = getArguments().getString(ARG_NAME);
|
mName = getArguments().getString(ARG_NAME);
|
||||||
@ -108,10 +126,45 @@ public class CreateKeyEmailFragment extends Fragment {
|
|||||||
createKeyCheck();
|
createKeyCheck();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mEmailsRecyclerView.setHasFixedSize(true);
|
||||||
|
mEmailsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
|
mEmailsRecyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||||
|
|
||||||
|
mAdditionalEmailModels = new ArrayList<>();
|
||||||
|
mEmailAdapter = new EmailAdapter(mAdditionalEmailModels, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
addEmail();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mEmailsRecyclerView.setAdapter(mEmailAdapter);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addEmail() {
|
||||||
|
Handler returnHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) {
|
||||||
|
Bundle data = message.getData();
|
||||||
|
|
||||||
|
// add new user id
|
||||||
|
mEmailAdapter.add(
|
||||||
|
data.getString(AddEmailDialogFragment.MESSAGE_DATA_EMAIL)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
|
AddEmailDialogFragment addEmailDialog = AddEmailDialogFragment.newInstance(messenger);
|
||||||
|
|
||||||
|
addEmailDialog.show(getActivity().getSupportFragmentManager(), "addEmailDialog");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
@ -121,14 +174,137 @@ public class CreateKeyEmailFragment extends Fragment {
|
|||||||
private void createKeyCheck() {
|
private void createKeyCheck() {
|
||||||
if (isEditTextNotEmpty(getActivity(), mEmailEdit)) {
|
if (isEditTextNotEmpty(getActivity(), mEmailEdit)) {
|
||||||
|
|
||||||
|
ArrayList<String> emails = new ArrayList<>();
|
||||||
|
for (EmailAdapter.ViewModel holder : mAdditionalEmailModels) {
|
||||||
|
emails.add(holder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
CreateKeyPassphraseFragment frag =
|
CreateKeyPassphraseFragment frag =
|
||||||
CreateKeyPassphraseFragment.newInstance(
|
CreateKeyPassphraseFragment.newInstance(
|
||||||
mName,
|
mName,
|
||||||
mEmailEdit.getText().toString()
|
mEmailEdit.getText().toString(),
|
||||||
|
emails
|
||||||
);
|
);
|
||||||
|
|
||||||
mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT);
|
mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class EmailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private List<ViewModel> mDataset;
|
||||||
|
private View.OnClickListener mFooterOnClickListener;
|
||||||
|
private static final int TYPE_FOOTER = 0;
|
||||||
|
private static final int TYPE_ITEM = 1;
|
||||||
|
|
||||||
|
public static class ViewModel {
|
||||||
|
String email;
|
||||||
|
|
||||||
|
ViewModel(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provide a reference to the views for each data item
|
||||||
|
// Complex data items may need more than one view per item, and
|
||||||
|
// you provide access to all the views for a data item in a view holder
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
// each data item is just a string in this case
|
||||||
|
public TextView mTextView;
|
||||||
|
public ImageButton mDeleteButton;
|
||||||
|
|
||||||
|
public ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
mTextView = (TextView) itemView.findViewById(R.id.create_key_email_item_email);
|
||||||
|
mDeleteButton = (ImageButton) itemView.findViewById(R.id.create_key_email_item_delete_button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooterHolder extends RecyclerView.ViewHolder {
|
||||||
|
public Button mAddButton;
|
||||||
|
|
||||||
|
public FooterHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
mAddButton = (Button) itemView.findViewById(R.id.create_key_add_email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provide a suitable constructor (depends on the kind of dataset)
|
||||||
|
public EmailAdapter(List<ViewModel> myDataset, View.OnClickListener onFooterClickListener) {
|
||||||
|
mDataset = myDataset;
|
||||||
|
mFooterOnClickListener = onFooterClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new views (invoked by the layout manager)
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
if (viewType == TYPE_FOOTER) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.create_key_email_list_footer, parent, false);
|
||||||
|
return new FooterHolder(v);
|
||||||
|
} else {
|
||||||
|
//inflate your layout and pass it to view holder
|
||||||
|
View v = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.create_key_email_list_item, parent, false);
|
||||||
|
return new ViewHolder(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the contents of a view (invoked by the layout manager)
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||||
|
if (holder instanceof ViewHolder) {
|
||||||
|
ViewHolder thisHolder = (ViewHolder) holder;
|
||||||
|
// - get element from your dataset at this position
|
||||||
|
// - replace the contents of the view with that element
|
||||||
|
final ViewModel model = mDataset.get(position);
|
||||||
|
|
||||||
|
thisHolder.mTextView.setText(model.email);
|
||||||
|
thisHolder.mDeleteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
remove(model);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (holder instanceof FooterHolder) {
|
||||||
|
FooterHolder thisHolder = (FooterHolder) holder;
|
||||||
|
thisHolder.mAddButton.setOnClickListener(mFooterOnClickListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the size of your dataset (invoked by the layout manager)
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDataset.size() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
if (isPositionFooter(position)) {
|
||||||
|
return TYPE_FOOTER;
|
||||||
|
} else {
|
||||||
|
return TYPE_ITEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPositionFooter(int position) {
|
||||||
|
return position == mDataset.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String email) {
|
||||||
|
mDataset.add(new ViewModel(email));
|
||||||
|
notifyItemInserted(mDataset.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(ViewModel model) {
|
||||||
|
int position = mDataset.indexOf(model);
|
||||||
|
mDataset.remove(position);
|
||||||
|
notifyItemRemoved(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,9 @@ import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
|||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class CreateKeyFinalFragment extends Fragment {
|
public class CreateKeyFinalFragment extends Fragment {
|
||||||
|
|
||||||
public static final int REQUEST_EDIT_KEY = 0x00008007;
|
public static final int REQUEST_EDIT_KEY = 0x00008007;
|
||||||
@ -63,10 +66,12 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
|
|
||||||
public static final String ARG_NAME = "name";
|
public static final String ARG_NAME = "name";
|
||||||
public static final String ARG_EMAIL = "email";
|
public static final String ARG_EMAIL = "email";
|
||||||
|
public static final String ARG_ADDITIONAL_EMAILS = "emails";
|
||||||
public static final String ARG_PASSPHRASE = "passphrase";
|
public static final String ARG_PASSPHRASE = "passphrase";
|
||||||
|
|
||||||
String mName;
|
String mName;
|
||||||
String mEmail;
|
String mEmail;
|
||||||
|
ArrayList<String> mAdditionalEmails;
|
||||||
String mPassphrase;
|
String mPassphrase;
|
||||||
|
|
||||||
SaveKeyringParcel mSaveKeyringParcel;
|
SaveKeyringParcel mSaveKeyringParcel;
|
||||||
@ -74,12 +79,15 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*/
|
*/
|
||||||
public static CreateKeyFinalFragment newInstance(String name, String email, String passphrase) {
|
public static CreateKeyFinalFragment newInstance(String name, String email,
|
||||||
|
ArrayList<String> additionalEmails,
|
||||||
|
String passphrase) {
|
||||||
CreateKeyFinalFragment frag = new CreateKeyFinalFragment();
|
CreateKeyFinalFragment frag = new CreateKeyFinalFragment();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_NAME, name);
|
args.putString(ARG_NAME, name);
|
||||||
args.putString(ARG_EMAIL, email);
|
args.putString(ARG_EMAIL, email);
|
||||||
|
args.putStringArrayList(ARG_ADDITIONAL_EMAILS, additionalEmails);
|
||||||
args.putString(ARG_PASSPHRASE, passphrase);
|
args.putString(ARG_PASSPHRASE, passphrase);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
@ -102,11 +110,25 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
// get args
|
// get args
|
||||||
mName = getArguments().getString(ARG_NAME);
|
mName = getArguments().getString(ARG_NAME);
|
||||||
mEmail = getArguments().getString(ARG_EMAIL);
|
mEmail = getArguments().getString(ARG_EMAIL);
|
||||||
|
mAdditionalEmails = getArguments().getStringArrayList(ARG_ADDITIONAL_EMAILS);
|
||||||
mPassphrase = getArguments().getString(ARG_PASSPHRASE);
|
mPassphrase = getArguments().getString(ARG_PASSPHRASE);
|
||||||
|
|
||||||
// set values
|
// set values
|
||||||
mNameEdit.setText(mName);
|
mNameEdit.setText(mName);
|
||||||
|
if (mAdditionalEmails != null && mAdditionalEmails.size() > 0) {
|
||||||
|
String emailText = mEmail + ", ";
|
||||||
|
Iterator<?> it = mAdditionalEmails.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Object next = it.next();
|
||||||
|
emailText += next;
|
||||||
|
if (it.hasNext()) {
|
||||||
|
emailText += ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mEmailEdit.setText(emailText);
|
||||||
|
} else {
|
||||||
mEmailEdit.setText(mEmail);
|
mEmailEdit.setText(mEmail);
|
||||||
|
}
|
||||||
|
|
||||||
mCreateButton.setOnClickListener(new View.OnClickListener() {
|
mCreateButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -167,12 +189,19 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
String userId = KeyRing.createUserId(mName, mEmail, null);
|
String userId = KeyRing.createUserId(mName, mEmail, null);
|
||||||
mSaveKeyringParcel.mAddUserIds.add(userId);
|
mSaveKeyringParcel.mAddUserIds.add(userId);
|
||||||
mSaveKeyringParcel.mChangePrimaryUserId = userId;
|
mSaveKeyringParcel.mChangePrimaryUserId = userId;
|
||||||
|
if (mAdditionalEmails != null && mAdditionalEmails.size() > 0) {
|
||||||
|
for (String email : mAdditionalEmails) {
|
||||||
|
String thisUserId = KeyRing.createUserId(mName, email, null);
|
||||||
|
mSaveKeyringParcel.mAddUserIds.add(thisUserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
mSaveKeyringParcel.mNewUnlock = mPassphrase != null
|
mSaveKeyringParcel.mNewUnlock = mPassphrase != null
|
||||||
? new ChangeUnlockParcel(mPassphrase, null)
|
? new ChangeUnlockParcel(mPassphrase, null)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createKey() {
|
private void createKey() {
|
||||||
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
||||||
intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING);
|
intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING);
|
||||||
|
@ -35,14 +35,18 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
|
import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class CreateKeyPassphraseFragment extends Fragment {
|
public class CreateKeyPassphraseFragment extends Fragment {
|
||||||
|
|
||||||
public static final String ARG_NAME = "name";
|
public static final String ARG_NAME = "name";
|
||||||
public static final String ARG_EMAIL = "email";
|
public static final String ARG_EMAIL = "email";
|
||||||
|
public static final String ARG_ADDITIONAL_EMAILS = "emails";
|
||||||
|
|
||||||
// model
|
// model
|
||||||
String mName;
|
String mName;
|
||||||
String mEmail;
|
String mEmail;
|
||||||
|
ArrayList<String> mAdditionalEmails;
|
||||||
|
|
||||||
// view
|
// view
|
||||||
CreateKeyActivity mCreateKeyActivity;
|
CreateKeyActivity mCreateKeyActivity;
|
||||||
@ -55,12 +59,14 @@ public class CreateKeyPassphraseFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*/
|
*/
|
||||||
public static CreateKeyPassphraseFragment newInstance(String name, String email) {
|
public static CreateKeyPassphraseFragment newInstance(String name, String email,
|
||||||
|
ArrayList<String> additionalEmails) {
|
||||||
CreateKeyPassphraseFragment frag = new CreateKeyPassphraseFragment();
|
CreateKeyPassphraseFragment frag = new CreateKeyPassphraseFragment();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_NAME, name);
|
args.putString(ARG_NAME, name);
|
||||||
args.putString(ARG_EMAIL, email);
|
args.putString(ARG_EMAIL, email);
|
||||||
|
args.putStringArrayList(ARG_ADDITIONAL_EMAILS, additionalEmails);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
|
|
||||||
@ -114,6 +120,7 @@ public class CreateKeyPassphraseFragment extends Fragment {
|
|||||||
// initial values
|
// initial values
|
||||||
mName = getArguments().getString(ARG_NAME);
|
mName = getArguments().getString(ARG_NAME);
|
||||||
mEmail = getArguments().getString(ARG_EMAIL);
|
mEmail = getArguments().getString(ARG_EMAIL);
|
||||||
|
mAdditionalEmails = getArguments().getStringArrayList(ARG_ADDITIONAL_EMAILS);
|
||||||
mPassphraseEdit.requestFocus();
|
mPassphraseEdit.requestFocus();
|
||||||
mBackButton.setOnClickListener(new View.OnClickListener() {
|
mBackButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -163,6 +170,7 @@ public class CreateKeyPassphraseFragment extends Fragment {
|
|||||||
CreateKeyFinalFragment.newInstance(
|
CreateKeyFinalFragment.newInstance(
|
||||||
mName,
|
mName,
|
||||||
mEmail,
|
mEmail,
|
||||||
|
mAdditionalEmails,
|
||||||
mPassphraseEdit.getText().toString()
|
mPassphraseEdit.getText().toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -528,7 +528,6 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addUserId() {
|
private void addUserId() {
|
||||||
// Message is received after passphrase is cached
|
|
||||||
Handler returnHandler = new Handler() {
|
Handler returnHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
|
@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 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.dialog;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.EmailEditText;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
public class AddEmailDialogFragment extends DialogFragment implements OnEditorActionListener {
|
||||||
|
private static final String ARG_MESSENGER = "messenger";
|
||||||
|
|
||||||
|
public static final int MESSAGE_OKAY = 1;
|
||||||
|
public static final int MESSAGE_CANCEL = 2;
|
||||||
|
|
||||||
|
public static final String MESSAGE_DATA_EMAIL = "email";
|
||||||
|
|
||||||
|
private Messenger mMessenger;
|
||||||
|
private EmailEditText mEmail;
|
||||||
|
|
||||||
|
public static AddEmailDialogFragment newInstance(Messenger messenger) {
|
||||||
|
|
||||||
|
AddEmailDialogFragment frag = new AddEmailDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable(ARG_MESSENGER, messenger);
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates dialog
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final Activity activity = getActivity();
|
||||||
|
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||||
|
|
||||||
|
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
|
||||||
|
|
||||||
|
alert.setTitle(R.string.create_key_add_email);
|
||||||
|
|
||||||
|
LayoutInflater inflater = activity.getLayoutInflater();
|
||||||
|
View view = inflater.inflate(R.layout.add_email_dialog, null);
|
||||||
|
alert.setView(view);
|
||||||
|
|
||||||
|
mEmail = (EmailEditText) view.findViewById(R.id.add_email_address);
|
||||||
|
|
||||||
|
alert.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dismiss();
|
||||||
|
|
||||||
|
// return new user id back to activity
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
String email = mEmail.getText().toString();
|
||||||
|
data.putString(MESSAGE_DATA_EMAIL, email);
|
||||||
|
sendMessageToHandler(MESSAGE_OKAY, data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.setNegativeButton(android.R.string.cancel, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Hack to open keyboard.
|
||||||
|
// This is the only method that I found to work across all Android versions
|
||||||
|
// http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
|
||||||
|
// Notes: * onCreateView can't be used because we want to add buttons to the dialog
|
||||||
|
// * opening in onActivityCreated does not work on Android 4.4
|
||||||
|
mEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
|
mEmail.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
InputMethodManager imm = (InputMethodManager) getActivity()
|
||||||
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
imm.showSoftInput(mEmail, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mEmail.requestFocus();
|
||||||
|
|
||||||
|
mEmail.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
|
||||||
|
mEmail.setOnEditorActionListener(this);
|
||||||
|
|
||||||
|
return alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
super.onCancel(dialog);
|
||||||
|
|
||||||
|
dismiss();
|
||||||
|
sendMessageToHandler(MESSAGE_CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
super.onDismiss(dialog);
|
||||||
|
|
||||||
|
// hide keyboard on dismiss
|
||||||
|
hideKeyboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideKeyboard() {
|
||||||
|
if (getActivity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InputMethodManager inputManager = (InputMethodManager) getActivity()
|
||||||
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
|
// check if no view has focus:
|
||||||
|
View v = getActivity().getCurrentFocus();
|
||||||
|
if (v == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associate the "done" button on the soft keyboard with the okay button in the view
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if (EditorInfo.IME_ACTION_DONE == actionId) {
|
||||||
|
AlertDialog dialog = ((AlertDialog) getDialog());
|
||||||
|
Button bt = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
|
||||||
|
bt.performClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message back to handler which is initialized in a activity
|
||||||
|
*
|
||||||
|
* @param what Message integer you want to send
|
||||||
|
*/
|
||||||
|
private void sendMessageToHandler(Integer what) {
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = what;
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMessenger.send(msg);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.w(Constants.TAG, "Messenger is null!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message back to handler which is initialized in a activity
|
||||||
|
*
|
||||||
|
* @param what Message integer you want to send
|
||||||
|
*/
|
||||||
|
private void sendMessageToHandler(Integer what, Bundle data) {
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = what;
|
||||||
|
if (data != null) {
|
||||||
|
msg.setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMessenger.send(msg);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.w(Constants.TAG, "Messenger is null!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
BIN
OpenKeychain/src/main/res/drawable-hdpi/ic_email_grey_24dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-hdpi/ic_email_grey_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 372 B |
BIN
OpenKeychain/src/main/res/drawable-mdpi/ic_email_grey_24dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-mdpi/ic_email_grey_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 307 B |
BIN
OpenKeychain/src/main/res/drawable-xhdpi/ic_email_grey_24dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-xhdpi/ic_email_grey_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 439 B |
BIN
OpenKeychain/src/main/res/drawable-xxhdpi/ic_email_grey_24dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-xxhdpi/ic_email_grey_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 563 B |
Binary file not shown.
After Width: | Height: | Size: 805 B |
26
OpenKeychain/src/main/res/layout/add_email_dialog.xml
Normal file
26
OpenKeychain/src/main/res/layout/add_email_dialog.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?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="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingLeft="24dp"
|
||||||
|
android:paddingRight="24dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/create_key_add_email_text"
|
||||||
|
android:textAppearance="?android:textAppearanceMedium" />
|
||||||
|
|
||||||
|
<org.sufficientlysecure.keychain.ui.widget.EmailEditText
|
||||||
|
android:id="@+id/add_email_address"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:hint="@string/label_email"
|
||||||
|
android:imeOptions="actionNext"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -4,6 +4,7 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:fillViewport="true"
|
android:fillViewport="true"
|
||||||
@ -34,6 +35,12 @@
|
|||||||
android:hint="@string/label_email"
|
android:hint="@string/label_email"
|
||||||
android:ems="10" />
|
android:ems="10" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/create_key_emails"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
<?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="wrap_content"
|
||||||
|
android:minHeight="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:singleLine="true">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/create_key_add_email"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:text="@string/btn_add_email"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:drawableLeft="@drawable/ic_email_grey_24dp"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:gravity="left|center_vertical" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,28 @@
|
|||||||
|
<?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="wrap_content"
|
||||||
|
android:minHeight="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:singleLine="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/create_key_email_item_email"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="alice@example.com"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:paddingLeft="8dp" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/create_key_email_item_delete_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:src="@drawable/ic_close_grey_24dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
style="@style/SelectableItem" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -98,6 +98,7 @@
|
|||||||
<string name="btn_decrypt_files">"Decrypt files"</string>
|
<string name="btn_decrypt_files">"Decrypt files"</string>
|
||||||
<string name="btn_encrypt_files">"Encrypt files"</string>
|
<string name="btn_encrypt_files">"Encrypt files"</string>
|
||||||
<string name="btn_encrypt_text">"Encrypt text"</string>
|
<string name="btn_encrypt_text">"Encrypt text"</string>
|
||||||
|
<string name="btn_add_email">"Add additional email address"</string>
|
||||||
|
|
||||||
<!-- menu -->
|
<!-- menu -->
|
||||||
<string name="menu_preferences">"Settings"</string>
|
<string name="menu_preferences">"Settings"</string>
|
||||||
@ -628,10 +629,12 @@
|
|||||||
<string name="create_key_rsa">"(3 subkeys, RSA, 4096 bit)"</string>
|
<string name="create_key_rsa">"(3 subkeys, RSA, 4096 bit)"</string>
|
||||||
<string name="create_key_custom">"(custom key configuration)"</string>
|
<string name="create_key_custom">"(custom key configuration)"</string>
|
||||||
<string name="create_key_name_text">"Choose a name associated with this key. This can be a full name, e.g., 'John Doe', or a nickname, e.g., 'Johnny'."</string>
|
<string name="create_key_name_text">"Choose a name associated with this key. This can be a full name, e.g., 'John Doe', or a nickname, e.g., 'Johnny'."</string>
|
||||||
<string name="create_key_email_text">"Choose the email address used for encrypted communication."</string>
|
<string name="create_key_email_text">"Enter your main email address used for secure communication."</string>
|
||||||
<string name="create_key_passphrase_text">"Choose a strong passphrase. It protects your key when your device gets stolen."</string>
|
<string name="create_key_passphrase_text">"Choose a strong passphrase. It protects your key when your device gets stolen."</string>
|
||||||
<string name="create_key_hint_full_name">"Full Name or Nickname"</string>
|
<string name="create_key_hint_full_name">"Full Name or Nickname"</string>
|
||||||
<string name="create_key_edit">"Change key configuration"</string>
|
<string name="create_key_edit">"Change key configuration"</string>
|
||||||
|
<string name="create_key_add_email">"Add email address"</string>
|
||||||
|
<string name="create_key_add_email_text">"Additional email addresses are also associated to this key and can be used for secure communication."</string>
|
||||||
|
|
||||||
<!-- View key -->
|
<!-- View key -->
|
||||||
<string name="view_key_revoked">"Revoked: Key must not be used anymore!"</string>
|
<string name="view_key_revoked">"Revoked: Key must not be used anymore!"</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user