Start work on a first-time wizard

This commit is contained in:
Dominik Schürmann 2014-06-27 21:40:18 +02:00
parent a1bcbe72a3
commit 9fe07478e7
8 changed files with 622 additions and 4 deletions

View File

@ -79,6 +79,11 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".ui.WizardActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/title_wizard"
android:windowSoftInputMode="stateHidden" />
<activity <activity
android:name=".ui.EditKeyActivity" android:name=".ui.EditKeyActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:configChanges="orientation|screenSize|keyboardHidden|keyboard"

View File

@ -113,10 +113,10 @@ public class KeyListActivity extends DrawerActivity {
} }
private void createKey() { private void createKey() {
Intent intent = new Intent(this, EditKeyActivity.class); Intent intent = new Intent(this, WizardActivity.class);
intent.setAction(EditKeyActivity.ACTION_CREATE_KEY); // intent.setAction(EditKeyActivity.ACTION_CREATE_KEY);
intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true); // intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true);
intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view // intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} }

View File

@ -0,0 +1,395 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui;
import android.content.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<String>
(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<String, Boolean, Boolean> generateTask = new AsyncTask<String, Boolean, Boolean>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgress(ProgressState.WORKING, "generating key...");
}
@Override
protected Boolean doInBackground(String... params) {
return 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;
}
}
}

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/wizard_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/wizard_back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="backOnClick"
android:text="cancel"
style="@style/SelectableItem" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="?android:attr/listDivider" />
<Button
android:id="@+id/wizard_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="nextOnClick"
android:text="next"
style="@style/SelectableItem" />
</LinearLayout>
<View
android:id="@+id/wizard_progress_line"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_above="@+id/wizard_buttons"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="?android:attr/listDivider"
android:visibility="gone" />
<LinearLayout
android:id="@+id/wizard_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/wizard_progress_line"
android:visibility="gone">
<ProgressBar
android:id="@+id/wizard_progress_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/wizard_progress_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_light_refresh" />
<TextView
android:id="@+id/wizard_progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="asd"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<View
android:id="@+id/wizard_line2"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_above="@+id/wizard_progress"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="?android:attr/listDivider" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/wizard_line2">
<LinearLayout
android:id="@+id/wizard_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp" />
</ScrollView>
</RelativeLayout>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:text="Enter Full Name, Email and Passphrase!"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name"
android:ems="10"
android:id="@+id/name" />
<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="bla@example.com"
android:layout_weight="1"
android:ems="10"
android:inputType="textEmailAddress" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="passphrase"
android:ems="10"
android:id="@+id/passphrase"
android:layout_gravity="center_horizontal" />
</LinearLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/fragment_vehicle_reg_generic_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:text="Result text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:text="Welcome to OpenKeychain"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
style="@style/SectionHeader"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="14dp"
android:text="What you wanna do today?"
android:layout_weight="1" />
<RadioGroup
android:id="@+id/wizard_start_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:checked="true"
android:textAppearance="?android:attr/textAppearanceMedium"
style="@style/SelectableItem"
android:text="new key"
android:id="@+id/wizard_start_new_key" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceMedium"
style="@style/SelectableItem"
android:text="import existing key"
android:id="@+id/wizard_start_import" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceMedium"
style="@style/SelectableItem"
android:text="skip wizard"
android:id="@+id/wizard_start_skip" />
</RadioGroup>
</LinearLayout>

View File

@ -9,6 +9,7 @@
<string name="title_authentication">Passphrase</string> <string name="title_authentication">Passphrase</string>
<string name="title_create_key">Create Key</string> <string name="title_create_key">Create Key</string>
<string name="title_edit_key">Edit Key</string> <string name="title_edit_key">Edit Key</string>
<string name="title_wizard">Welcome to OpenKeychain</string>
<string name="title_preferences">Preferences</string> <string name="title_preferences">Preferences</string>
<string name="title_api_registered_apps">Apps</string> <string name="title_api_registered_apps">Apps</string>
<string name="title_key_server_preference">Keyserver Preference</string> <string name="title_key_server_preference">Keyserver Preference</string>