From a1bcbe72a3c52d416b3dfe5c0cc96b65739641ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 24 Jun 2014 22:58:28 +0200 Subject: [PATCH 01/15] new edit key: first version to add user ids --- .../keychain/ui/EditKeyActivityNew.java | 25 ---- .../keychain/ui/EditKeyFragment.java | 18 ++- .../keychain/ui/adapter/UserIdsAdapter.java | 3 +- .../ui/adapter/UserIdsArrayAdapter.java | 131 ++++++++++++++++++ .../ui/dialog/AddUserIdDialogFragment.java | 115 +++++++++++---- .../main/res/layout/add_user_id_dialog.xml | 60 ++++++++ .../src/main/res/layout/edit_key_fragment.xml | 10 ++ 7 files changed, 305 insertions(+), 57 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsArrayAdapter.java create mode 100644 OpenKeychain/src/main/res/layout/add_user_id_dialog.xml diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java index f2b5e68eb..b45e8a6bb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java @@ -20,19 +20,13 @@ package org.sufficientlysecure.keychain.ui; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; -import android.view.View; -import android.view.View.OnClickListener; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.ActionBarHelper; -import org.sufficientlysecure.keychain.remote.ui.AccountsListFragment; import org.sufficientlysecure.keychain.util.Log; public class EditKeyActivityNew extends ActionBarActivity { - private Uri mDataUri; - private EditKeyFragment mEditKeyFragment; @Override @@ -41,25 +35,6 @@ public class EditKeyActivityNew extends ActionBarActivity { setContentView(R.layout.edit_key_activity_new); -// // Inflate a "Done"/"Cancel" custom action bar view -// ActionBarHelper.setTwoButtonView(getSupportActionBar(), -// R.string.btn_save, R.drawable.ic_action_save, -// new OnClickListener() { -// @Override -// public void onClick(View v) { -// // Save -// -// } -// }, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel, -// new OnClickListener() { -// @Override -// public void onClick(View v) { -// // Cancel -// -// } -// } -// ); - Uri dataUri = getIntent().getData(); if (dataUri == null) { Log.e(Constants.TAG, "Data missing. Should be Uri of key!"); 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 ac4390eac..3f330ee94 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -27,6 +27,7 @@ import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v7.app.ActionBarActivity; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -45,6 +46,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; +import org.sufficientlysecure.keychain.ui.adapter.UserIdsArrayAdapter; import org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; @@ -68,6 +70,7 @@ public class EditKeyFragment extends LoaderFragment implements private UserIdsAdapter mUserIdsAdapter; private SubkeysAdapter mKeysAdapter; + private UserIdsArrayAdapter mUserIdsAddedAdapter; private Uri mDataUri; @@ -180,6 +183,10 @@ public class EditKeyFragment extends LoaderFragment implements } }); + mUserIdsAddedAdapter = new UserIdsArrayAdapter(getActivity()); + mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter); + mUserIdsAddedAdapter.setData(mSaveKeyringParcel.addUserIds); + mKeysAdapter = new SubkeysAdapter(getActivity(), null, 0); mKeysList.setAdapter(mKeysAdapter); @@ -321,9 +328,17 @@ public class EditKeyFragment extends LoaderFragment implements Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { - if (message.what == AddUserIdDialogFragment.MESSAGE_OK) { + switch (message.what) { + case AddUserIdDialogFragment.MESSAGE_OKAY: + Bundle data = message.getData(); + String userId = data.getString(AddUserIdDialogFragment.MESSAGE_DATA_USER_ID); + if (userId != null) { + mSaveKeyringParcel.addUserIds.add(userId); + mUserIdsAddedAdapter.setData(mSaveKeyringParcel.addUserIds); + } } + getLoaderManager().getLoader(LOADER_ID_USER_IDS).forceLoad(); } }; @@ -345,5 +360,4 @@ public class EditKeyFragment extends LoaderFragment implements // TODO } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java index 7a7acfe89..7fc78dc41 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java @@ -144,7 +144,6 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC vComment.setVisibility(View.GONE); } - // show small star icon for primary user ids boolean isPrimary = cursor.getInt(mIsPrimary) != 0; boolean isRevoked = cursor.getInt(mIsRevoked) > 0; @@ -185,6 +184,8 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC vName.setEnabled(true); vAddress.setEnabled(true); + // verified: has been verified + // isPrimary: show small star icon for primary user ids int verified = cursor.getInt(mVerifiedId); switch (verified) { case Certs.VERIFIED_SECRET: diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsArrayAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsArrayAdapter.java new file mode 100644 index 000000000..e6445c074 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsArrayAdapter.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2013-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.adapter; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.Context; +import android.os.Build; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.ImageView; +import android.widget.TextView; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.KeyRing; + +import java.util.List; + +public class UserIdsArrayAdapter extends ArrayAdapter { + protected LayoutInflater mInflater; + protected Activity mActivity; + + protected List mData; + + static class ViewHolder { + public TextView vName; + public TextView vAddress; + public TextView vComment; + public ImageView vVerified; + public ImageView vHasChanges; + public CheckBox vCheckBox; + } + + public UserIdsArrayAdapter(Activity activity) { + super(activity, -1); + mActivity = activity; + mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public void setData(List data) { + clear(); + if (data != null) { + this.mData = data; + + // add data to extended ArrayAdapter + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + addAll(data); + } else { + for (String entry : data) { + add(entry); + } + } + } + } + + public List getData() { + return mData; + } + + @Override + public boolean hasStableIds() { + return true; + } + + public View getView(int position, View convertView, ViewGroup parent) { + String entry = mData.get(position); + ViewHolder holder; + if (convertView == null) { + holder = new ViewHolder(); + convertView = mInflater.inflate(R.layout.view_key_userids_item, null); + holder.vName = (TextView) convertView.findViewById(R.id.userId); + holder.vAddress = (TextView) convertView.findViewById(R.id.address); + holder.vComment = (TextView) convertView.findViewById(R.id.comment); + holder.vVerified = (ImageView) convertView.findViewById(R.id.certified); + holder.vHasChanges = (ImageView) convertView.findViewById(R.id.has_changes); + holder.vCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + // user id + String[] splitUserId = KeyRing.splitUserId(entry); + if (splitUserId[0] != null) { + holder.vName.setText(splitUserId[0]); + } else { + holder.vName.setText(R.string.user_id_no_name); + } + if (splitUserId[1] != null) { + holder.vAddress.setText(splitUserId[1]); + holder.vAddress.setVisibility(View.VISIBLE); + } else { + holder.vAddress.setVisibility(View.GONE); + } + if (splitUserId[2] != null) { + holder.vComment.setText(splitUserId[2]); + holder.vComment.setVisibility(View.VISIBLE); + } else { + holder.vComment.setVisibility(View.GONE); + } + + holder.vCheckBox.setVisibility(View.GONE); + + holder.vVerified.setImageResource(R.drawable.key_certify_ok_depth0); + + // all items are "new" + holder.vHasChanges.setVisibility(View.VISIBLE); + + return convertView; + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java index db7c38e71..c27266e3f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java @@ -24,17 +24,32 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.support.v4.app.DialogFragment; +import android.text.TextUtils; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.WindowManager; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; -public class AddUserIdDialogFragment extends DialogFragment { +public class AddUserIdDialogFragment extends DialogFragment implements EditText.OnEditorActionListener { private static final String ARG_MESSENGER = "messenger"; - public static final int MESSAGE_OK = 1; + public static final int MESSAGE_OKAY = 1; + + public static final String MESSAGE_DATA_USER_ID = "user_id"; private Messenger mMessenger; + EditText mName; + EditText mAddress; + EditText mComment; + /** * Creates new instance of this dialog fragment */ @@ -55,34 +70,75 @@ public class AddUserIdDialogFragment extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { mMessenger = getArguments().getParcelable(ARG_MESSENGER); - CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(getActivity()); -// CharSequence[] array = {"change to primary user id", "revoke"}; -// -// builder.setTitle("select action!"); -// builder.setItems(array, new DialogInterface.OnClickListener() { -// -// @Override -// public void onClick(DialogInterface dialog, int which) { -// switch (which) { -// case 0: -// sendMessageToHandler(MESSAGE_CHANGE_PRIMARY_USER_ID, null); -// break; -// case 1: -// sendMessageToHandler(MESSAGE_REVOKE, null); -// break; -// default: -// break; -// } -// } -// }); -// builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int id) { -// dismiss(); -// } -// }); + CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(getActivity()); + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.add_user_id_dialog, null); + alert.setView(view); + alert.setTitle("Add Identity"); - return builder.show(); + mName = (EditText) view.findViewById(R.id.name); + mAddress = (EditText) view.findViewById(R.id.address); + mComment = (EditText) view.findViewById(R.id.comment); + + alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int id) { + done(); + } + }); + + alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + + + return alert.show(); + } + + @Override + public void onActivityCreated(Bundle arg0) { + super.onActivityCreated(arg0); + // Show soft keyboard automatically + mName.requestFocus(); + getDialog().getWindow().setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + mComment.setOnEditorActionListener(this); + } + + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (EditorInfo.IME_ACTION_DONE == actionId) { + done(); + return true; + } + return false; + } + + private void done() { + String name = mName.getText().toString(); + String email = mAddress.getText().toString(); + String comment = mComment.getText().toString(); + + String userId = null; + if (!TextUtils.isEmpty(name)) { + userId = name; + if (!TextUtils.isEmpty(comment)) { + userId += " (" + comment + ")"; + } + if (!TextUtils.isEmpty(email)) { + userId += " <" + email + ">"; + } + } + Bundle data = new Bundle(); + data.putString(MESSAGE_DATA_USER_ID, userId); + sendMessageToHandler(MESSAGE_OKAY, data); + + this.dismiss(); } /** @@ -105,4 +161,5 @@ public class AddUserIdDialogFragment extends DialogFragment { Log.w(Constants.TAG, "Messenger is null!", e); } } + } diff --git a/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml b/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml new file mode 100644 index 000000000..502ca1c70 --- /dev/null +++ b/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/edit_key_fragment.xml b/OpenKeychain/src/main/res/layout/edit_key_fragment.xml index f652269e5..7f94cb3cd 100644 --- a/OpenKeychain/src/main/res/layout/edit_key_fragment.xml +++ b/OpenKeychain/src/main/res/layout/edit_key_fragment.xml @@ -45,6 +45,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> + + + + Date: Fri, 27 Jun 2014 21:40:18 +0200 Subject: [PATCH 02/15] Start work on a first-time wizard --- OpenKeychain/src/main/AndroidManifest.xml | 5 + .../keychain/ui/KeyListActivity.java | 8 +- .../keychain/ui/WizardActivity.java | 395 ++++++++++++++++++ .../src/main/res/layout/wizard_activity.xml | 98 +++++ .../res/layout/wizard_create_key_fragment.xml | 41 ++ .../res/layout/wizard_generic_fragment.xml | 15 + .../main/res/layout/wizard_start_fragment.xml | 63 +++ OpenKeychain/src/main/res/values/strings.xml | 1 + 8 files changed, 622 insertions(+), 4 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/WizardActivity.java create mode 100644 OpenKeychain/src/main/res/layout/wizard_activity.xml create mode 100644 OpenKeychain/src/main/res/layout/wizard_create_key_fragment.xml create mode 100644 OpenKeychain/src/main/res/layout/wizard_generic_fragment.xml create mode 100644 OpenKeychain/src/main/res/layout/wizard_start_fragment.xml diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml index c6e528f4d..d5f031ecc 100644 --- a/OpenKeychain/src/main/AndroidManifest.xml +++ b/OpenKeychain/src/main/AndroidManifest.xml @@ -79,6 +79,11 @@ + + * + * 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.AsyncTask; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBarActivity; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Patterns; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.RadioGroup; +import android.widget.TextView; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.ContactHelper; + +import java.util.regex.Matcher; + + +public class WizardActivity extends ActionBarActivity { + + private State mCurrentState; + + // values for mCurrentScreen + private enum State { + START, CREATE_KEY, NFC, FINISH + } + + Button mBackButton; + Button mNextButton; + StartFragment mStartFragment; + CreateKeyFragment mCreateKeyFragment; + GenericFragment mNFCFragment; + GenericFragment mFinishFragment; + + LinearLayout mProgressLayout; + View mProgressLine; + ProgressBar mProgressBar; + ImageView mProgressImage; + TextView mProgressText; + + /** + * Checks if text of given EditText is not empty. If it is empty an error is + * set and the EditText gets the focus. + * + * @param context + * @param editText + * @return true if EditText is not empty + */ + private static boolean isEditTextNotEmpty(Context context, EditText editText) { + boolean output = true; + if (editText.getText().toString().length() == 0) { + editText.setError("empty!"); + editText.requestFocus(); + output = false; + } else { + editText.setError(null); + } + + return output; + } + + public static class StartFragment extends Fragment { + public static StartFragment newInstance() { + StartFragment myFragment = new StartFragment(); + + Bundle args = new Bundle(); + myFragment.setArguments(args); + + return myFragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.wizard_start_fragment, + container, false); + } + } + + public static class CreateKeyFragment extends Fragment { + public static CreateKeyFragment newInstance() { + CreateKeyFragment myFragment = new CreateKeyFragment(); + + Bundle args = new Bundle(); + myFragment.setArguments(args); + + return myFragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.wizard_create_key_fragment, + container, false); + + final AutoCompleteTextView emailView = (AutoCompleteTextView) view.findViewById(R.id.email); + emailView.setThreshold(1); // Start working from first character + emailView.setAdapter( + new ArrayAdapter + (getActivity(), android.R.layout.simple_dropdown_item_1line, + ContactHelper.getMailAccounts(getActivity()) + ) + ); + emailView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void afterTextChanged(Editable editable) { + String email = editable.toString(); + if (email.length() > 0) { + Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email); + if (emailMatcher.matches()) { + emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_ok, 0); + } else { + emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_bad, 0); + } + } else { + // remove drawable if email is empty + emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } +// if (mEditorListener != null) { +// mEditorListener.onEdited(); +// } + } + }); + return view; + } + } + + public static class GenericFragment extends Fragment { + public static GenericFragment newInstance(String text) { + GenericFragment myFragment = new GenericFragment(); + + Bundle args = new Bundle(); + args.putString("text", text); + myFragment.setArguments(args); + + return myFragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.wizard_generic_fragment, + container, false); + + TextView text = (TextView) v + .findViewById(R.id.fragment_vehicle_reg_generic_text); + text.setText(getArguments().getString("text")); + + return v; + } + + } + + /** + * Loads new fragment + * + * @param fragment + */ + private void loadFragment(Fragment fragment) { + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager + .beginTransaction(); + fragmentTransaction.replace(R.id.wizard_container, + fragment); + fragmentTransaction.commit(); + } + + /** + * Instantiate View and initialize fragments for this Activity + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.wizard_activity); + mBackButton = (Button) findViewById(R.id.wizard_back); + mNextButton = (Button) findViewById(R.id.wizard_next); + + // progress layout + mProgressLayout = (LinearLayout) findViewById(R.id.wizard_progress); + mProgressLine = findViewById(R.id.wizard_progress_line); + mProgressBar = (ProgressBar) findViewById(R.id.wizard_progress_progressbar); + mProgressImage = (ImageView) findViewById(R.id.wizard_progress_image); + mProgressText = (TextView) findViewById(R.id.wizard_progress_text); + + mStartFragment = StartFragment.newInstance(); + loadFragment(mStartFragment); + mCurrentState = State.START; + } + + private enum ProgressState { + WORKING, ENABLED, DISABLED, ERROR + } + + private void showProgress(ProgressState state, String text) { + switch (state) { + case WORKING: + mProgressBar.setVisibility(View.VISIBLE); + mProgressImage.setVisibility(View.GONE); + break; + case ENABLED: + mProgressBar.setVisibility(View.GONE); + mProgressImage.setVisibility(View.VISIBLE); +// mProgressImage.setImageDrawable(getResources().getDrawable( +// R.drawable.status_enabled)); + break; + case DISABLED: + mProgressBar.setVisibility(View.GONE); + mProgressImage.setVisibility(View.VISIBLE); +// mProgressImage.setImageDrawable(getResources().getDrawable( +// R.drawable.status_disabled)); + break; + case ERROR: + mProgressBar.setVisibility(View.GONE); + mProgressImage.setVisibility(View.VISIBLE); +// mProgressImage.setImageDrawable(getResources().getDrawable( +// R.drawable.status_fail)); + break; + + default: + break; + } + mProgressText.setText(text); + + mProgressLine.setVisibility(View.VISIBLE); + mProgressLayout.setVisibility(View.VISIBLE); + } + + private void hideProgress() { + mProgressLine.setVisibility(View.GONE); + mProgressLayout.setVisibility(View.GONE); + } + + public void nextOnClick(View view) { + // close keyboard + if (getCurrentFocus() != null) { + InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + inputManager.hideSoftInputFromWindow(getCurrentFocus() + .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + } + + switch (mCurrentState) { + + case START: { + RadioGroup radioGroup = (RadioGroup) findViewById(R.id.wizard_start_radio_group); + int selectedId = radioGroup.getCheckedRadioButtonId(); + switch (selectedId) { + case R.id.wizard_start_new_key: { + mCurrentState = State.CREATE_KEY; + mCreateKeyFragment = CreateKeyFragment.newInstance(); + loadFragment(mCreateKeyFragment); + break; + } + } + + mBackButton.setText(R.string.btn_back); + +// if (isEditTextNotEmpty(this, asd)) { +// mLicensePlate = asd.getText().toString(); +// +// showProgress(ProgressState.WORKING, +// "doing something"; +// } + break; + } + case CREATE_KEY: + + AsyncTask generateTask = new AsyncTask() { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + + showProgress(ProgressState.WORKING, "generating key..."); + } + + @Override + protected Boolean doInBackground(String... params) { + return false; + } + + @Override + protected void onPostExecute(Boolean result) { + super.onPostExecute(result); + +// if (result) { +// showProgress( +// ProgressState.WORKING, +// "asd"); +// +// } else { +// showProgress( +// ProgressState.ERROR, "asd"); +// } + } + + }; + + generateTask.execute(""); + + break; + case NFC: + + mCurrentState = State.FINISH; + hideProgress(); + mFinishFragment = GenericFragment + .newInstance("asd"); + loadFragment(mFinishFragment); + mNextButton.setText("finish"); + + break; + case FINISH: + finish(); + break; + default: + break; + } + } + + public void backOnClick(View view) { + switch (mCurrentState) { + case START: + finish(); + break; + + case CREATE_KEY: + loadFragment(mStartFragment); + mCurrentState = State.START; + mBackButton.setText(android.R.string.cancel); + mNextButton.setText(R.string.btn_next); + break; + case NFC: + loadFragment(mCreateKeyFragment); + mCurrentState = State.CREATE_KEY; + mBackButton.setText(R.string.btn_back); + mNextButton.setText(R.string.btn_next); + break; + case FINISH: + loadFragment(mNFCFragment); + mCurrentState = State.NFC; + mBackButton.setText(R.string.btn_back); + mNextButton.setText(R.string.btn_next); + break; + + default: + loadFragment(mStartFragment); + mCurrentState = State.START; + mBackButton.setText(android.R.string.cancel); + mNextButton.setText(R.string.btn_next); + break; + } + } + +} diff --git a/OpenKeychain/src/main/res/layout/wizard_activity.xml b/OpenKeychain/src/main/res/layout/wizard_activity.xml new file mode 100644 index 000000000..299d07a76 --- /dev/null +++ b/OpenKeychain/src/main/res/layout/wizard_activity.xml @@ -0,0 +1,98 @@ + + + + + +