From bc43797c32542aa48a34f44d486645d24fca06ba Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Mon, 9 Mar 2015 00:37:14 +0530 Subject: added card --- .../keychain/ui/ViewKeyFragment.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java index 628970b27..389b39c82 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java @@ -18,6 +18,7 @@ package org.sufficientlysecure.keychain.ui; +import android.content.DialogInterface; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -44,6 +45,7 @@ public class ViewKeyFragment extends LoaderFragment implements public static final String ARG_DATA_URI = "uri"; private ListView mUserIds; + private ListView mLinkedSystemContact; boolean mIsSecret = false; @@ -81,6 +83,15 @@ public class ViewKeyFragment extends LoaderFragment implements } }); + mLinkedSystemContact = (ListView) view.findViewById(R.id.view_key_linked_system_contact); + + mLinkedSystemContact.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + showSystemContact(position); + } + }); + return root; } @@ -100,6 +111,10 @@ public class ViewKeyFragment extends LoaderFragment implements } } + private void showSystemContact(final int position) { + + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -148,6 +163,7 @@ public class ViewKeyFragment extends LoaderFragment implements getLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this); } + @Override public Loader onCreateLoader(int id, Bundle args) { setContentShown(false); @@ -164,6 +180,7 @@ public class ViewKeyFragment extends LoaderFragment implements } } + @Override public void onLoadFinished(Loader loader, Cursor data) { /* TODO better error handling? May cause problems when a key is deleted, * because the notification triggers faster than the activity closes. @@ -202,6 +219,7 @@ public class ViewKeyFragment extends LoaderFragment implements * This is called when the last Cursor provided to onLoadFinished() above is about to be closed. * We need to make sure we are no longer using it. */ + @Override public void onLoaderReset(Loader loader) { switch (loader.getId()) { case LOADER_ID_USER_IDS: { -- cgit v1.2.3 From f8a6f814dd4f4e015707085c297b91abf237ed14 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 10 Mar 2015 01:05:40 +0530 Subject: added contact linking --- .../keychain/ui/ViewKeyFragment.java | 61 ++++++++++++++++++---- .../keychain/util/ContactHelper.java | 28 ++++++++++ 2 files changed, 80 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java index 389b39c82..f4cbe88a9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java @@ -18,25 +18,31 @@ package org.sufficientlysecure.keychain.ui; +import android.content.ContentResolver; +import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.database.Cursor; +import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.provider.ContactsContract; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListView; +import android.widget.*; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; +import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment; +import org.sufficientlysecure.keychain.util.ContactHelper; import org.sufficientlysecure.keychain.util.Log; public class ViewKeyFragment extends LoaderFragment implements @@ -45,12 +51,18 @@ public class ViewKeyFragment extends LoaderFragment implements public static final String ARG_DATA_URI = "uri"; private ListView mUserIds; - private ListView mLinkedSystemContact; + //private ListView mLinkedSystemContact; boolean mIsSecret = false; + private String mName; + + LinearLayout mSystemContactLayout; + ImageView mSystemContactPicture; + TextView mSystemContactName; private static final int LOADER_ID_UNIFIED = 0; private static final int LOADER_ID_USER_IDS = 1; + private static final int LOADER_ID_SYSTEM_CONTACT = 2; private UserIdsAdapter mUserIdsAdapter; @@ -83,15 +95,17 @@ public class ViewKeyFragment extends LoaderFragment implements } }); - mLinkedSystemContact = (ListView) view.findViewById(R.id.view_key_linked_system_contact); + mSystemContactLayout = (LinearLayout) view.findViewById(R.id.system_contact_layout); + mSystemContactName = (TextView) view.findViewById(R.id.system_contact_name); + mSystemContactPicture = (ImageView) view.findViewById(R.id.system_contact_picture); + // mLinkedSystemContact = (ListView) view.findViewById(R.id.view_key_linked_system_contact); - mLinkedSystemContact.setOnItemClickListener(new AdapterView.OnItemClickListener() { + /* mLinkedSystemContact.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { showSystemContact(position); } - }); - + });*/ return root; } @@ -111,8 +125,32 @@ public class ViewKeyFragment extends LoaderFragment implements } } - private void showSystemContact(final int position) { + private void loadLinkedSystemContact(String name, final long masterKeyId) { + final Context context = mSystemContactName.getContext(); + final ContentResolver resolver = context.getContentResolver(); + + final long contactId = ContactHelper.findContactId(resolver, masterKeyId); + + if (contactId != -1) {//contact exists for given master key + mSystemContactName.setText(name); + + Bitmap picture = ContactHelper.loadPhotoByMasterKeyId(resolver, masterKeyId, true); + if (picture != null) mSystemContactPicture.setImageBitmap(picture); + mSystemContactLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + launchContactActivity(contactId, context); + } + }); + } + } + + private void launchContactActivity(final long contactId, Context context) { + Intent intent = new Intent(Intent.ACTION_VIEW); + Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId)); + intent.setData(uri); + context.startActivity(intent); } @Override @@ -196,7 +234,12 @@ public class ViewKeyFragment extends LoaderFragment implements if (data.moveToFirst()) { mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0; - + if (mName == null) {//to ensure we load the linked system contact only once + String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); + mName = mainUserId[0]; + long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); + loadLinkedSystemContact(mName, masterKeyId); + } // load user ids after we know if it's a secret key mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, !mIsSecret, null); mUserIds.setAdapter(mUserIdsAdapter); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 08c7c02fb..f1ed36a8d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -267,6 +267,34 @@ public class ContactHelper { return null; } + /** + * returns the CONTACT_ID of the raw contact to which a masterKeyId is associated, if the + * raw contact has not been marked for deletion + * @param resolver + * @param masterKeyId + * @return CONTACT_ID (id of aggregated contact) linked to masterKeyId + */ + public static long findContactId(ContentResolver resolver, long masterKeyId) { + long contactId = -1; + Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI, + new String[]{ + ContactsContract.RawContacts.CONTACT_ID + }, + ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + + ContactsContract.RawContacts.SOURCE_ID + "=? AND " + + ContactsContract.RawContacts.DELETED + "=?", + new String[]{//"0" for "not deleted" + Constants.ACCOUNT_TYPE, Long.toString(masterKeyId), "0" + }, null); + if (raw != null) { + if (raw.moveToNext()) { + contactId = raw.getLong(0); + } + raw.close(); + } + return contactId; + } + public static Bitmap getCachedPhotoByMasterKeyId(ContentResolver contentResolver, long masterKeyId) { if (masterKeyId == -1) { return null; -- cgit v1.2.3 From 012b7e4830e9a52b896c17c98af68db5ade2e333 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 10 Mar 2015 01:27:33 +0530 Subject: cleaned up code, added comments optimised imports --- .../keychain/ui/ViewKeyFragment.java | 24 ++++++++++++++-------- .../keychain/util/ContactHelper.java | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java index f4cbe88a9..bb3df2541 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui; import android.content.ContentResolver; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; @@ -62,7 +61,6 @@ public class ViewKeyFragment extends LoaderFragment implements private static final int LOADER_ID_UNIFIED = 0; private static final int LOADER_ID_USER_IDS = 1; - private static final int LOADER_ID_SYSTEM_CONTACT = 2; private UserIdsAdapter mUserIdsAdapter; @@ -98,14 +96,7 @@ public class ViewKeyFragment extends LoaderFragment implements mSystemContactLayout = (LinearLayout) view.findViewById(R.id.system_contact_layout); mSystemContactName = (TextView) view.findViewById(R.id.system_contact_name); mSystemContactPicture = (ImageView) view.findViewById(R.id.system_contact_picture); - // mLinkedSystemContact = (ListView) view.findViewById(R.id.view_key_linked_system_contact); - /* mLinkedSystemContact.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - showSystemContact(position); - } - });*/ return root; } @@ -125,6 +116,13 @@ public class ViewKeyFragment extends LoaderFragment implements } } + /** + * Checks if a system contact exists for given masterKeyId, and if it does, sets name, picture + * and onClickListener for the linked system contact's layout + * + * @param name + * @param masterKeyId + */ private void loadLinkedSystemContact(String name, final long masterKeyId) { final Context context = mSystemContactName.getContext(); final ContentResolver resolver = context.getContentResolver(); @@ -146,6 +144,14 @@ public class ViewKeyFragment extends LoaderFragment implements } } + /** + * launches the default android Contacts app to view a contact with the passed + * contactId (CONTACT_ID column from ContactsContract.RawContact table which is _ID column in + * ContactsContract.Contact table) + * + * @param contactId _ID for row in ContactsContract.Contacts table + * @param context + */ private void launchContactActivity(final long contactId, Context context) { Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index f1ed36a8d..a7b5c2983 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -270,6 +270,7 @@ public class ContactHelper { /** * returns the CONTACT_ID of the raw contact to which a masterKeyId is associated, if the * raw contact has not been marked for deletion + * * @param resolver * @param masterKeyId * @return CONTACT_ID (id of aggregated contact) linked to masterKeyId -- cgit v1.2.3 From 7d2e2e3eec85193f41554605483506b1233e7f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 9 Mar 2015 22:00:44 +0100 Subject: Make create key wizard step-by-step --- .../keychain/ui/CreateKeyActivity.java | 4 +- .../keychain/ui/CreateKeyEmailFragment.java | 134 ++++++++++++++++ .../keychain/ui/CreateKeyFinalFragment.java | 2 +- .../keychain/ui/CreateKeyInputFragment.java | 167 -------------------- .../keychain/ui/CreateKeyNameFragment.java | 140 +++++++++++++++++ .../keychain/ui/CreateKeyPassphraseFragment.java | 170 +++++++++++++++++++++ 6 files changed, 447 insertions(+), 170 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyNameFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index 60cc404b6..2da5511b8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -39,8 +39,8 @@ public class CreateKeyActivity extends BaseActivity { super.onCreate(savedInstanceState); // pass extras into fragment - CreateKeyInputFragment frag = - CreateKeyInputFragment.newInstance( + CreateKeyNameFragment frag = + CreateKeyNameFragment.newInstance( getIntent().getStringExtra(EXTRA_NAME), getIntent().getStringExtra(EXTRA_EMAIL) ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java new file mode 100644 index 000000000..d9f391149 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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 . + */ + +package org.sufficientlysecure.keychain.ui; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; +import org.sufficientlysecure.keychain.ui.widget.EmailEditText; + +public class CreateKeyEmailFragment extends Fragment { + + public static final String ARG_NAME = "name"; + public static final String ARG_EMAIL = "email"; + + CreateKeyActivity mCreateKeyActivity; + EmailEditText mEmailEdit; + View mBackButton; + View mNextButton; + + String mName; + + /** + * Creates new instance of this fragment + */ + public static CreateKeyEmailFragment newInstance(String name, String email) { + CreateKeyEmailFragment frag = new CreateKeyEmailFragment(); + + Bundle args = new Bundle(); + args.putString(ARG_NAME, name); + args.putString(ARG_EMAIL, email); + + frag.setArguments(args); + + return frag; + } + + /** + * 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(context.getString(R.string.create_key_empty)); + editText.requestFocus(); + output = false; + } else { + editText.setError(null); + } + + return output; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.create_key_email_fragment, container, false); + + mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email); + mBackButton = view.findViewById(R.id.create_key_back_button); + mNextButton = view.findViewById(R.id.create_key_next_button); + + // initial values + mName = getArguments().getString(ARG_NAME); + String email = getArguments().getString(ARG_EMAIL); + mEmailEdit.setText(email); + + // focus empty edit fields + if (email == null) { + mEmailEdit.requestFocus(); + } + mBackButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mCreateKeyActivity.loadFragment(null, null, FragAction.TO_LEFT); + } + }); + mNextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + createKeyCheck(); + } + }); + + return view; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mCreateKeyActivity = (CreateKeyActivity) getActivity(); + } + + private void createKeyCheck() { + if (isEditTextNotEmpty(getActivity(), mEmailEdit)) { + + CreateKeyPassphraseFragment frag = + CreateKeyPassphraseFragment.newInstance( + mName, + mEmailEdit.getText().toString() + ); + + mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT); + } + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 920488e3e..dc9f3d4ad 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -95,7 +95,7 @@ public class CreateKeyFinalFragment extends Fragment { mEmailEdit = (TextView) view.findViewById(R.id.email); mUploadCheckbox = (CheckBox) view.findViewById(R.id.create_key_upload); mBackButton = view.findViewById(R.id.create_key_back_button); - mCreateButton = view.findViewById(R.id.create_key_create_button); + mCreateButton = view.findViewById(R.id.create_key_next_button); mEditText = (TextView) view.findViewById(R.id.create_key_edit_text); mEditButton = view.findViewById(R.id.create_key_edit_button); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java deleted file mode 100644 index 05408e21e..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * 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 . - */ - -package org.sufficientlysecure.keychain.ui; - -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; -import org.sufficientlysecure.keychain.ui.widget.EmailEditText; -import org.sufficientlysecure.keychain.ui.widget.NameEditText; -import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText; - -public class CreateKeyInputFragment extends Fragment { - - public static final String ARG_NAME = "name"; - public static final String ARG_EMAIL = "email"; - CreateKeyActivity mCreateKeyActivity; - NameEditText mNameEdit; - EmailEditText mEmailEdit; - PassphraseEditText mPassphraseEdit; - EditText mPassphraseEditAgain; - View mCreateButton; - - /** - * Creates new instance of this fragment - */ - public static CreateKeyInputFragment newInstance(String name, String email) { - CreateKeyInputFragment frag = new CreateKeyInputFragment(); - - Bundle args = new Bundle(); - args.putString(ARG_NAME, name); - args.putString(ARG_EMAIL, email); - - frag.setArguments(args); - - return frag; - } - - /** - * 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(context.getString(R.string.create_key_empty)); - editText.requestFocus(); - output = false; - } else { - editText.setError(null); - } - - return output; - } - - private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) { - boolean output = true; - if (!editText1.getText().toString().equals(editText2.getText().toString())) { - editText2.setError(context.getString(R.string.create_key_passphrases_not_equal)); - editText2.requestFocus(); - output = false; - } else { - editText2.setError(null); - } - - return output; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.create_key_input_fragment, container, false); - - mNameEdit = (NameEditText) view.findViewById(R.id.create_key_name); - mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase); - mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email); - mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again); - mCreateButton = view.findViewById(R.id.create_key_button); - - // initial values - String name = getArguments().getString(ARG_NAME); - String email = getArguments().getString(ARG_EMAIL); - mNameEdit.setText(name); - mEmailEdit.setText(email); - - // focus non-empty edit fields - if (name != null && email != null) { - mPassphraseEdit.requestFocus(); - } else if (name != null) { - mEmailEdit.requestFocus(); - } - mCreateButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - createKeyCheck(); - } - }); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mCreateKeyActivity = (CreateKeyActivity) getActivity(); - } - - private void createKeyCheck() { - if (isEditTextNotEmpty(getActivity(), mNameEdit) - && isEditTextNotEmpty(getActivity(), mEmailEdit) - && isEditTextNotEmpty(getActivity(), mPassphraseEdit) - && areEditTextsEqual(getActivity(), mPassphraseEdit, mPassphraseEditAgain)) { - - CreateKeyFinalFragment frag = - CreateKeyFinalFragment.newInstance( - mNameEdit.getText().toString(), - mEmailEdit.getText().toString(), - mPassphraseEdit.getText().toString() - ); - - hideKeyboard(); - mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT); - } - } - - 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); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyNameFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyNameFragment.java new file mode 100644 index 000000000..50a3bd655 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyNameFragment.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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 . + */ + +package org.sufficientlysecure.keychain.ui; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; +import org.sufficientlysecure.keychain.ui.widget.EmailEditText; +import org.sufficientlysecure.keychain.ui.widget.NameEditText; + +public class CreateKeyNameFragment extends Fragment { + + public static final String ARG_NAME = "name"; + public static final String ARG_EMAIL = "email"; + + CreateKeyActivity mCreateKeyActivity; + NameEditText mNameEdit; + View mNextButton; + + String mEmail; + + /** + * Creates new instance of this fragment + */ + public static CreateKeyNameFragment newInstance(String name, String email) { + CreateKeyNameFragment frag = new CreateKeyNameFragment(); + + Bundle args = new Bundle(); + args.putString(ARG_NAME, name); + args.putString(ARG_EMAIL, email); + + frag.setArguments(args); + + return frag; + } + + /** + * 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(context.getString(R.string.create_key_empty)); + editText.requestFocus(); + output = false; + } else { + editText.setError(null); + } + + return output; + } + + private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) { + boolean output = true; + if (!editText1.getText().toString().equals(editText2.getText().toString())) { + editText2.setError(context.getString(R.string.create_key_passphrases_not_equal)); + editText2.requestFocus(); + output = false; + } else { + editText2.setError(null); + } + + return output; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.create_key_name_fragment, container, false); + + mNameEdit = (NameEditText) view.findViewById(R.id.create_key_name); + mNextButton = view.findViewById(R.id.create_key_next_button); + + // initial values + String name = getArguments().getString(ARG_NAME); + mEmail = getArguments().getString(ARG_EMAIL); + mNameEdit.setText(name); + + // focus empty edit fields + if (name == null) { + mNameEdit.requestFocus(); + } + mNextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + createKeyCheck(); + } + }); + + return view; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mCreateKeyActivity = (CreateKeyActivity) getActivity(); + } + + private void createKeyCheck() { + if (isEditTextNotEmpty(getActivity(), mNameEdit)) { + + CreateKeyEmailFragment frag = + CreateKeyEmailFragment.newInstance( + mNameEdit.getText().toString(), + mEmail + ); + + mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT); + } + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java new file mode 100644 index 000000000..be77d5042 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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 . + */ + +package org.sufficientlysecure.keychain.ui; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; +import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText; + +public class CreateKeyPassphraseFragment extends Fragment { + + public static final String ARG_NAME = "name"; + public static final String ARG_EMAIL = "email"; + + // model + String mName; + String mEmail; + + // view + CreateKeyActivity mCreateKeyActivity; + PassphraseEditText mPassphraseEdit; + EditText mPassphraseEditAgain; + View mBackButton; + View mNextButton; + + /** + * Creates new instance of this fragment + */ + public static CreateKeyPassphraseFragment newInstance(String name, String email) { + CreateKeyPassphraseFragment frag = new CreateKeyPassphraseFragment(); + + Bundle args = new Bundle(); + args.putString(ARG_NAME, name); + args.putString(ARG_EMAIL, email); + + frag.setArguments(args); + + return frag; + } + + /** + * 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(context.getString(R.string.create_key_empty)); + editText.requestFocus(); + output = false; + } else { + editText.setError(null); + } + + return output; + } + + private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) { + boolean output = true; + if (!editText1.getText().toString().equals(editText2.getText().toString())) { + editText2.setError(context.getString(R.string.create_key_passphrases_not_equal)); + editText2.requestFocus(); + output = false; + } else { + editText2.setError(null); + } + + return output; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.create_key_passphrase_fragment, container, false); + + mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase); + mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again); + mBackButton = view.findViewById(R.id.create_key_back_button); + mNextButton = view.findViewById(R.id.create_key_next_button); + + // initial values + mName = getArguments().getString(ARG_NAME); + mEmail = getArguments().getString(ARG_EMAIL); + mPassphraseEdit.requestFocus(); + mBackButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + back(); + } + }); + mNextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + createKeyCheck(); + } + }); + + return view; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mCreateKeyActivity = (CreateKeyActivity) getActivity(); + } + + private void back() { + hideKeyboard(); + mCreateKeyActivity.loadFragment(null, null, FragAction.TO_LEFT); + } + + private void createKeyCheck() { + if (isEditTextNotEmpty(getActivity(), mPassphraseEdit) + && areEditTextsEqual(getActivity(), mPassphraseEdit, mPassphraseEditAgain)) { + + CreateKeyFinalFragment frag = + CreateKeyFinalFragment.newInstance( + mName, + mEmail, + mPassphraseEdit.getText().toString() + ); + + hideKeyboard(); + mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT); + } + } + + 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); + } + +} -- cgit v1.2.3 From 224f243c7988d2e21606d3461ae0712ceb0f1207 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 10 Mar 2015 03:28:12 +0530 Subject: added CALLER_IS_SYNCADAPTER parameter to delete queries --- .../keychain/util/ContactHelper.java | 50 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 08c7c02fb..07144e264 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -267,6 +267,35 @@ public class ContactHelper { return null; } + /** + * returns the CONTACT_ID of the raw contact to which a masterKeyId is associated, if the + * raw contact has not been marked for deletion + * + * @param resolver + * @param masterKeyId + * @return CONTACT_ID (id of aggregated contact) linked to masterKeyId + */ + public static long findContactId(ContentResolver resolver, long masterKeyId) { + long contactId = -1; + Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI, + new String[]{ + ContactsContract.RawContacts.CONTACT_ID + }, + ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + + ContactsContract.RawContacts.SOURCE_ID + "=? AND " + + ContactsContract.RawContacts.DELETED + "=?", + new String[]{//"0" for "not deleted" + Constants.ACCOUNT_TYPE, Long.toString(masterKeyId), "0" + }, null); + if (raw != null) { + if (raw.moveToNext()) { + contactId = raw.getLong(0); + } + raw.close(); + } + return contactId; + } + public static Bitmap getCachedPhotoByMasterKeyId(ContentResolver contentResolver, long masterKeyId) { if (masterKeyId == -1) { return null; @@ -398,8 +427,13 @@ public class ContactHelper { * TODO: Does this work? */ private static int debugDeleteRawContacts(ContentResolver resolver) { + //allows us to actually wipe the RawContact from the device, otherwise would be just flagged + //for deletion + Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon(). + appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(); + Log.d(Constants.TAG, "Deleting all raw contacts associated to OK..."); - return resolver.delete(ContactsContract.RawContacts.CONTENT_URI, + return resolver.delete(deleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=?", new String[]{ Constants.ACCOUNT_TYPE @@ -407,7 +441,12 @@ public class ContactHelper { } private static int deleteRawContactById(ContentResolver resolver, long rawContactId) { - return resolver.delete(ContactsContract.RawContacts.CONTENT_URI, + //allows us to actually wipe the RawContact from the device, otherwise would be just flagged + //for deletion + Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon(). + appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(); + + return resolver.delete(deleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + ContactsContract.RawContacts._ID + "=?", new String[]{ Constants.ACCOUNT_TYPE, Long.toString(rawContactId) @@ -415,7 +454,12 @@ public class ContactHelper { } private static int deleteRawContactByMasterKeyId(ContentResolver resolver, long masterKeyId) { - return resolver.delete(ContactsContract.RawContacts.CONTENT_URI, + //allows us to actually wipe the RawContact from the device, otherwise would be just flagged + //for deletion + Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon(). + appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(); + + return resolver.delete(deleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + ContactsContract.RawContacts.SOURCE_ID + "=?", new String[]{ Constants.ACCOUNT_TYPE, Long.toString(masterKeyId) -- cgit v1.2.3 From 301200197926cc4b951b08aec79f632774d764ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 9 Mar 2015 22:09:48 +0100 Subject: Show passphrase checkbox in create key --- .../keychain/ui/CreateKeyPassphraseFragment.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java index be77d5042..00ac00ff4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java @@ -21,10 +21,14 @@ import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.text.method.HideReturnsTransformationMethod; +import android.text.method.PasswordTransformationMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.EditText; import org.sufficientlysecure.keychain.R; @@ -44,6 +48,7 @@ public class CreateKeyPassphraseFragment extends Fragment { CreateKeyActivity mCreateKeyActivity; PassphraseEditText mPassphraseEdit; EditText mPassphraseEditAgain; + CheckBox mShowPassphrase; View mBackButton; View mNextButton; @@ -102,6 +107,7 @@ public class CreateKeyPassphraseFragment extends Fragment { mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase); mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again); + mShowPassphrase = (CheckBox) view.findViewById(R.id.create_key_show_passphrase); mBackButton = view.findViewById(R.id.create_key_back_button); mNextButton = view.findViewById(R.id.create_key_next_button); @@ -121,6 +127,19 @@ public class CreateKeyPassphraseFragment extends Fragment { createKeyCheck(); } }); + mShowPassphrase.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + mPassphraseEdit.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); + mPassphraseEditAgain.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); + } else { + mPassphraseEdit.setTransformationMethod(PasswordTransformationMethod.getInstance()); + mPassphraseEditAgain.setTransformationMethod(PasswordTransformationMethod.getInstance()); + } + } + }); + return view; } -- cgit v1.2.3 From bce0fe62217e1f174559354b1a0dc06fd9663385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 10 Mar 2015 01:44:07 +0100 Subject: Add additional email addresses in create key --- .../keychain/ui/CreateKeyEmailFragment.java | 180 ++++++++++++++++- .../keychain/ui/CreateKeyFinalFragment.java | 33 +++- .../keychain/ui/CreateKeyPassphraseFragment.java | 10 +- .../keychain/ui/EditKeyFragment.java | 1 - .../keychain/ui/dialog/AddEmailDialogFragment.java | 215 +++++++++++++++++++++ 5 files changed, 433 insertions(+), 6 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEmailDialogFragment.java (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java index d9f391149..66424e012 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyEmailFragment.java @@ -20,17 +20,30 @@ package org.sufficientlysecure.keychain.ui; import android.app.Activity; import android.content.Context; 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.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.inputmethod.InputMethodManager; +import android.widget.Button; import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.TextView; import org.sufficientlysecure.keychain.R; 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 java.util.ArrayList; +import java.util.List; + public class CreateKeyEmailFragment extends Fragment { public static final String ARG_NAME = "name"; @@ -38,10 +51,14 @@ public class CreateKeyEmailFragment extends Fragment { CreateKeyActivity mCreateKeyActivity; EmailEditText mEmailEdit; + RecyclerView mEmailsRecyclerView; View mBackButton; View mNextButton; String mName; + ArrayList mAdditionalEmailModels; + + EmailAdapter mEmailAdapter; /** * Creates new instance of this fragment @@ -86,6 +103,7 @@ public class CreateKeyEmailFragment extends Fragment { mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email); mBackButton = view.findViewById(R.id.create_key_back_button); mNextButton = view.findViewById(R.id.create_key_next_button); + mEmailsRecyclerView = (RecyclerView) view.findViewById(R.id.create_key_emails); // initial values mName = getArguments().getString(ARG_NAME); @@ -108,10 +126,45 @@ public class CreateKeyEmailFragment extends Fragment { 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; } + 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 public void onAttach(Activity activity) { super.onAttach(activity); @@ -121,14 +174,137 @@ public class CreateKeyEmailFragment extends Fragment { private void createKeyCheck() { if (isEditTextNotEmpty(getActivity(), mEmailEdit)) { + ArrayList emails = new ArrayList<>(); + for (EmailAdapter.ViewModel holder : mAdditionalEmailModels) { + emails.add(holder.toString()); + } + CreateKeyPassphraseFragment frag = CreateKeyPassphraseFragment.newInstance( mName, - mEmailEdit.getText().toString() + mEmailEdit.getText().toString(), + emails ); mCreateKeyActivity.loadFragment(null, frag, FragAction.TO_RIGHT); } } + public static class EmailAdapter extends RecyclerView.Adapter { + private List 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 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); + } + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index dc9f3d4ad..4853c61c5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -47,6 +47,9 @@ import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; +import java.util.ArrayList; +import java.util.Iterator; + public class CreateKeyFinalFragment extends Fragment { 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_EMAIL = "email"; + public static final String ARG_ADDITIONAL_EMAILS = "emails"; public static final String ARG_PASSPHRASE = "passphrase"; String mName; String mEmail; + ArrayList mAdditionalEmails; String mPassphrase; SaveKeyringParcel mSaveKeyringParcel; @@ -74,12 +79,15 @@ public class CreateKeyFinalFragment extends 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 additionalEmails, + String passphrase) { CreateKeyFinalFragment frag = new CreateKeyFinalFragment(); Bundle args = new Bundle(); args.putString(ARG_NAME, name); args.putString(ARG_EMAIL, email); + args.putStringArrayList(ARG_ADDITIONAL_EMAILS, additionalEmails); args.putString(ARG_PASSPHRASE, passphrase); frag.setArguments(args); @@ -102,11 +110,25 @@ public class CreateKeyFinalFragment extends Fragment { // get args mName = getArguments().getString(ARG_NAME); mEmail = getArguments().getString(ARG_EMAIL); + mAdditionalEmails = getArguments().getStringArrayList(ARG_ADDITIONAL_EMAILS); mPassphrase = getArguments().getString(ARG_PASSPHRASE); // set values mNameEdit.setText(mName); - mEmailEdit.setText(mEmail); + 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); + } mCreateButton.setOnClickListener(new View.OnClickListener() { @Override @@ -167,12 +189,19 @@ public class CreateKeyFinalFragment extends Fragment { String userId = KeyRing.createUserId(mName, mEmail, null); mSaveKeyringParcel.mAddUserIds.add(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 ? new ChangeUnlockParcel(mPassphrase, null) : null; } } + private void createKey() { Intent intent = new Intent(getActivity(), KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java index 00ac00ff4..055ea608b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyPassphraseFragment.java @@ -35,14 +35,18 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText; +import java.util.ArrayList; + public class CreateKeyPassphraseFragment extends Fragment { public static final String ARG_NAME = "name"; public static final String ARG_EMAIL = "email"; + public static final String ARG_ADDITIONAL_EMAILS = "emails"; // model String mName; String mEmail; + ArrayList mAdditionalEmails; // view CreateKeyActivity mCreateKeyActivity; @@ -55,12 +59,14 @@ public class CreateKeyPassphraseFragment extends Fragment { /** * Creates new instance of this fragment */ - public static CreateKeyPassphraseFragment newInstance(String name, String email) { + public static CreateKeyPassphraseFragment newInstance(String name, String email, + ArrayList additionalEmails) { CreateKeyPassphraseFragment frag = new CreateKeyPassphraseFragment(); Bundle args = new Bundle(); args.putString(ARG_NAME, name); args.putString(ARG_EMAIL, email); + args.putStringArrayList(ARG_ADDITIONAL_EMAILS, additionalEmails); frag.setArguments(args); @@ -114,6 +120,7 @@ public class CreateKeyPassphraseFragment extends Fragment { // initial values mName = getArguments().getString(ARG_NAME); mEmail = getArguments().getString(ARG_EMAIL); + mAdditionalEmails = getArguments().getStringArrayList(ARG_ADDITIONAL_EMAILS); mPassphraseEdit.requestFocus(); mBackButton.setOnClickListener(new View.OnClickListener() { @Override @@ -163,6 +170,7 @@ public class CreateKeyPassphraseFragment extends Fragment { CreateKeyFinalFragment.newInstance( mName, mEmail, + mAdditionalEmails, mPassphraseEdit.getText().toString() ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 25ca6e8fd..1e9a90fc8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -528,7 +528,6 @@ public class EditKeyFragment extends LoaderFragment implements } private void addUserId() { - // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEmailDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEmailDialogFragment.java new file mode 100644 index 000000000..5d5ca533e --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEmailDialogFragment.java @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2015 Dominik Schürmann + * + * 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 . + */ + +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); + } + } + +} -- cgit v1.2.3 From b3257e0ffa53f93d550d71c1a5ffcecb4f4df0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 10 Mar 2015 02:13:36 +0100 Subject: Ripple --- .../main/java/org/sufficientlysecure/keychain/util/ContactHelper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 07144e264..1413273e8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -386,7 +386,7 @@ public class ContactHelper { // Do not store expired or revoked keys in contact db - and remove them if they already exist if (isExpired || isRevoked) { - Log.d(Constants.TAG, "Expired or revoked: Deleting " + rawContactId); + Log.d(Constants.TAG, "Expired or revoked: Deleting rawContactId " + rawContactId); if (rawContactId != -1) { deleteRawContactById(resolver, rawContactId); } @@ -423,8 +423,6 @@ public class ContactHelper { /** * Delete all raw contacts associated to OpenKeychain. - *

- * TODO: Does this work? */ private static int debugDeleteRawContacts(ContentResolver resolver) { //allows us to actually wipe the RawContact from the device, otherwise would be just flagged -- cgit v1.2.3