More wizardry

This commit is contained in:
Dominik Schürmann 2014-06-27 23:01:11 +02:00
parent 8bfba0826f
commit 1d5606a1a3
5 changed files with 206 additions and 108 deletions

View File

@ -18,6 +18,7 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -66,6 +67,8 @@ public class ImportKeysActivity extends ActionBarActivity {
+ "IMPORT_KEY_FROM_KEYSERVER"; + "IMPORT_KEY_FROM_KEYSERVER";
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN = Constants.INTENT_PREFIX public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN"; + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN";
public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_FILE_AND_RETURN";
public static final String ACTION_IMPORT_KEY_FROM_KEYBASE = Constants.INTENT_PREFIX public static final String ACTION_IMPORT_KEY_FROM_KEYBASE = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_KEYBASE"; + "IMPORT_KEY_FROM_KEYBASE";
@ -224,7 +227,8 @@ public class ImportKeysActivity extends ActionBarActivity {
); );
return; return;
} }
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) { } else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)
|| ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(action)) {
// NOTE: this only displays the appropriate fragment, no actions are taken // NOTE: this only displays the appropriate fragment, no actions are taken
mSwitchToTab = TAB_FILE; mSwitchToTab = TAB_FILE;
@ -509,12 +513,13 @@ public class ImportKeysActivity extends ActionBarActivity {
} }
*/ */
/*
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) { if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
ImportKeysActivity.this.setResult(Activity.RESULT_OK, mPendingIntentData); ImportKeysActivity.this.setResult(RESULT_OK, mPendingIntentData);
finish(); ImportKeysActivity.this.finish();
} else if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(getIntent().getAction())) {
ImportKeysActivity.this.setResult(RESULT_OK);
ImportKeysActivity.this.finish();
} }
*/
} }
} }
}; };

View File

@ -207,7 +207,9 @@ public class ImportKeysListFragment extends ListFragment implements
if (getLoaderManager().getLoader(LOADER_ID_KEYBASE) != null) { if (getLoaderManager().getLoader(LOADER_ID_KEYBASE) != null) {
getLoaderManager().destroyLoader(LOADER_ID_KEYBASE); getLoaderManager().destroyLoader(LOADER_ID_KEYBASE);
} }
setListShown(true); if (getView() != null) {
setListShown(true);
}
} }
private void restartLoaders() { private void restartLoaders() {

View File

@ -17,7 +17,11 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -41,8 +45,11 @@ import android.widget.ProgressBar;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.htmltextview.HtmlTextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ContactHelper; import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -53,15 +60,22 @@ public class WizardActivity extends ActionBarActivity {
// values for mCurrentScreen // values for mCurrentScreen
private enum State { private enum State {
START, CREATE_KEY, NFC, FINISH START, CREATE_KEY, IMPORT_KEY, K9
} }
public static final int REQUEST_CODE_IMPORT = 0x00007703;
Button mBackButton; Button mBackButton;
Button mNextButton; Button mNextButton;
StartFragment mStartFragment; StartFragment mStartFragment;
CreateKeyFragment mCreateKeyFragment; CreateKeyFragment mCreateKeyFragment;
GenericFragment mNFCFragment; K9Fragment mK9Fragment;
GenericFragment mFinishFragment;
private static final String K9_PACKAGE = "com.fsck.k9";
// private static final String K9_MARKET_INTENT_URI_BASE = "market://details?id=%s";
// private static final Intent K9_MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse(
// String.format(K9_MARKET_INTENT_URI_BASE, K9_PACKAGE)));
private static final Intent K9_MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/k9mail/k-9/releases/tag/4.904"));
LinearLayout mProgressLayout; LinearLayout mProgressLayout;
View mProgressLine; View mProgressLine;
@ -121,7 +135,7 @@ public class WizardActivity extends ActionBarActivity {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.wizard_create_key_fragment, View view = inflater.inflate(R.layout.wizard_create_key_fragment,
container, false); container, false);
final AutoCompleteTextView emailView = (AutoCompleteTextView) view.findViewById(R.id.email); final AutoCompleteTextView emailView = (AutoCompleteTextView) view.findViewById(R.id.email);
@ -157,21 +171,17 @@ public class WizardActivity extends ActionBarActivity {
// remove drawable if email is empty // remove drawable if email is empty
emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); emailView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
} }
// if (mEditorListener != null) {
// mEditorListener.onEdited();
// }
} }
}); });
return view; return view;
} }
} }
public static class GenericFragment extends Fragment { public static class K9Fragment extends Fragment {
public static GenericFragment newInstance(String text) { public static K9Fragment newInstance() {
GenericFragment myFragment = new GenericFragment(); K9Fragment myFragment = new K9Fragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("text", text);
myFragment.setArguments(args); myFragment.setArguments(args);
return myFragment; return myFragment;
@ -180,12 +190,12 @@ public class WizardActivity extends ActionBarActivity {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.wizard_generic_fragment, View v = inflater.inflate(R.layout.wizard_k9_fragment,
container, false); container, false);
TextView text = (TextView) v HtmlTextView text = (HtmlTextView) v
.findViewById(R.id.fragment_vehicle_reg_generic_text); .findViewById(R.id.wizard_k9_text);
text.setText(getArguments().getString("text")); text.setHtmlFromString("Install K9. It's good for you! Here is a screenhot how to enable OK in K9: (TODO)", true);
return v; return v;
} }
@ -221,12 +231,10 @@ public class WizardActivity extends ActionBarActivity {
mProgressLayout = (LinearLayout) findViewById(R.id.wizard_progress); mProgressLayout = (LinearLayout) findViewById(R.id.wizard_progress);
mProgressLine = findViewById(R.id.wizard_progress_line); mProgressLine = findViewById(R.id.wizard_progress_line);
mProgressBar = (ProgressBar) findViewById(R.id.wizard_progress_progressbar); mProgressBar = (ProgressBar) findViewById(R.id.wizard_progress_progressbar);
mProgressImage = (ImageView) findViewById(R.id.wizard_progress_image); mProgressImage = (ImageView) findViewById(R.id.wizard_progress_image);
mProgressText = (TextView) findViewById(R.id.wizard_progress_text); mProgressText = (TextView) findViewById(R.id.wizard_progress_text);
mStartFragment = StartFragment.newInstance(); changeToState(State.START);
loadFragment(mStartFragment);
mCurrentState = State.START;
} }
private enum ProgressState { private enum ProgressState {
@ -281,115 +289,170 @@ public class WizardActivity extends ActionBarActivity {
} }
switch (mCurrentState) { switch (mCurrentState) {
case START: { case START: {
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.wizard_start_radio_group); RadioGroup radioGroup = (RadioGroup) findViewById(R.id.wizard_start_radio_group);
int selectedId = radioGroup.getCheckedRadioButtonId(); int selectedId = radioGroup.getCheckedRadioButtonId();
switch (selectedId) { switch (selectedId) {
case R.id.wizard_start_new_key: { case R.id.wizard_start_new_key: {
mCurrentState = State.CREATE_KEY; changeToState(State.CREATE_KEY);
mCreateKeyFragment = CreateKeyFragment.newInstance(); break;
loadFragment(mCreateKeyFragment); }
case R.id.wizard_start_import: {
changeToState(State.IMPORT_KEY);
break;
}
case R.id.wizard_start_skip: {
finish();
break; break;
} }
} }
mBackButton.setText(R.string.btn_back); mBackButton.setText(R.string.btn_back);
// if (isEditTextNotEmpty(this, asd)) {
// mLicensePlate = asd.getText().toString();
//
// showProgress(ProgressState.WORKING,
// "doing something";
// }
break; break;
} }
case CREATE_KEY: case CREATE_KEY:
EditText nameEdit = (EditText) findViewById(R.id.name);
EditText emailEdit = (EditText) findViewById(R.id.email);
EditText passphraseEdit = (EditText) findViewById(R.id.passphrase);
AsyncTask<String, Boolean, Boolean> generateTask = new AsyncTask<String, Boolean, Boolean>() { if (isEditTextNotEmpty(this, nameEdit)
&& isEditTextNotEmpty(this, emailEdit)
&& isEditTextNotEmpty(this, passphraseEdit)) {
@Override // SaveKeyringParcel newKey = new SaveKeyringParcel();
protected void onPreExecute() { // newKey.addUserIds.add(nameEdit.getText().toString() + " <"
super.onPreExecute(); // + emailEdit.getText().toString() + ">");
showProgress(ProgressState.WORKING, "generating key...");
}
@Override AsyncTask<String, Boolean, Boolean> generateTask = new AsyncTask<String, Boolean, Boolean>() {
protected Boolean doInBackground(String... params) {
return false;
}
@Override @Override
protected void onPostExecute(Boolean result) { protected void onPreExecute() {
super.onPostExecute(result); super.onPreExecute();
// if (result) { showProgress(ProgressState.WORKING, "generating key...");
// showProgress( }
// ProgressState.WORKING,
// "asd");
//
// } else {
// showProgress(
// ProgressState.ERROR, "asd");
// }
}
}; @Override
protected Boolean doInBackground(String... params) {
return true;
}
generateTask.execute(""); @Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
showProgress(ProgressState.ENABLED, "key generated successfully!");
changeToState(State.K9);
} else {
showProgress(ProgressState.ERROR, "error in key gen");
}
}
};
generateTask.execute("");
}
break; break;
case NFC: case K9: {
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.wizard_k9_radio_group);
int selectedId = radioGroup.getCheckedRadioButtonId();
switch (selectedId) {
case R.id.wizard_k9_install: {
try {
startActivity(K9_MARKET_INTENT);
} catch (ActivityNotFoundException e) {
Log.e(Constants.TAG, "Activity not found for: " + K9_MARKET_INTENT);
}
break;
}
case R.id.wizard_k9_skip: {
finish();
break;
}
}
mCurrentState = State.FINISH;
hideProgress();
mFinishFragment = GenericFragment
.newInstance("asd");
loadFragment(mFinishFragment);
mNextButton.setText("finish");
break;
case FINISH:
finish(); finish();
break; break;
}
default: default:
break; break;
} }
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_IMPORT: {
if (resultCode == Activity.RESULT_OK) {
// imported now...
changeToState(State.K9);
} else {
// back to start
changeToState(State.START);
}
break;
}
default: {
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
}
public void backOnClick(View view) { public void backOnClick(View view) {
switch (mCurrentState) { switch (mCurrentState) {
case START: case START:
finish(); finish();
break; break;
case CREATE_KEY: case CREATE_KEY:
loadFragment(mStartFragment); changeToState(State.START);
mCurrentState = State.START;
mBackButton.setText(android.R.string.cancel);
mNextButton.setText(R.string.btn_next);
break; break;
case NFC: case IMPORT_KEY:
loadFragment(mCreateKeyFragment); changeToState(State.START);
mCurrentState = State.CREATE_KEY;
mBackButton.setText(R.string.btn_back);
mNextButton.setText(R.string.btn_next);
break; break;
case FINISH:
loadFragment(mNFCFragment);
mCurrentState = State.NFC;
mBackButton.setText(R.string.btn_back);
mNextButton.setText(R.string.btn_next);
break;
default: default:
loadFragment(mStartFragment); changeToState(State.START);
mCurrentState = State.START;
mBackButton.setText(android.R.string.cancel);
mNextButton.setText(R.string.btn_next);
break; break;
} }
} }
private void changeToState(State state) {
switch (state) {
case START: {
mCurrentState = State.START;
mStartFragment = StartFragment.newInstance();
loadFragment(mStartFragment);
mBackButton.setText(android.R.string.cancel);
mNextButton.setText(R.string.btn_next);
break;
}
case CREATE_KEY: {
mCurrentState = State.CREATE_KEY;
mCreateKeyFragment = CreateKeyFragment.newInstance();
loadFragment(mCreateKeyFragment);
break;
}
case IMPORT_KEY: {
mCurrentState = State.IMPORT_KEY;
Intent intent = new Intent(this, ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
startActivityForResult(intent, REQUEST_CODE_IMPORT);
break;
}
case K9: {
mCurrentState = State.K9;
mBackButton.setEnabled(false); // don't go back to import/create key
mK9Fragment = K9Fragment.newInstance();
loadFragment(mK9Fragment);
break;
}
}
}
} }

View File

@ -1,15 +0,0 @@
<?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,43 @@
<?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" >
<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="@+id/wizard_k9_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:text="Text..."
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="@+id/wizard_k9_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="install K9"
android:id="@+id/wizard_k9_install" />
<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 install"
android:id="@+id/wizard_k9_skip" />
</RadioGroup>
</LinearLayout>