Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored into individual wizard classes.

  • Loading branch information...
commit 58e9f602f7d988b6ac612515821856634355b403 1 parent ca94342
@hdweiss hdweiss authored
View
484 src/com/matburt/mobileorg/Gui/Wizard/WizardActivity.java
@@ -1,101 +1,21 @@
package com.matburt.mobileorg.Gui.Wizard;
import android.app.Activity;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.Message;
-import android.preference.PreferenceManager;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
-import android.widget.TextView;
-import android.widget.Toast;
-import com.dropbox.client2.DropboxAPI;
-import com.dropbox.client2.DropboxAPI.Account;
-import com.dropbox.client2.android.AndroidAuthSession;
-import com.dropbox.client2.exception.DropboxException;
-import com.dropbox.client2.session.AccessTokenPair;
-import com.dropbox.client2.session.AppKeyPair;
-import com.dropbox.client2.session.Session.AccessType;
import com.matburt.mobileorg.R;
-import com.matburt.mobileorg.Synchronizers.SSHSynchronizer;
-import com.matburt.mobileorg.Synchronizers.UbuntuOneSynchronizer;
-import com.matburt.mobileorg.Synchronizers.WebDAVSynchronizer;
+import com.matburt.mobileorg.Gui.Wizard.Wizards.Wizard;
import com.matburt.mobileorg.util.OrgUtils;
public class WizardActivity extends Activity implements RadioGroup.OnCheckedChangeListener {
- private final class UIHandler extends Handler {
- public static final int DISPLAY_UI_TOAST = 0;
-
- public UIHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case DISPLAY_UI_TOAST: {
- Context context = getApplicationContext();
- Toast t = Toast.makeText(context, (String) msg.obj,
- Toast.LENGTH_LONG);
- progress.dismiss();
- t.show();
- }
- default:
- break;
- }
- }
- }
-
- // container
private WizardView wizardView;
- // page 1 variables
- private String syncSource;
- private int syncWebDav, syncDropBox, syncUbuntuOne, syncSdCard, syncNull, syncSSH;
- private RadioGroup syncGroup;
- // page 2 variables
- private Button loginButton;
- private ProgressDialog progress;
- // dropbox variables
- private DropboxAPI<AndroidAuthSession> dropboxApi;
- private TextView dropboxAccountInfo;
- private boolean dropboxLoginAttempted = false;
- private boolean isLoggedIn = false;
- // ubuntuone variables
- private EditText ubuntuoneEmail;
- private EditText ubuntuonePass;
- // sd card variables
- private DirectoryBrowser<?> directory;
- private FolderAdapter directoryAdapter;
- // webdav variables
- private EditText webdavUser;
- private EditText webdavPass;
- private EditText webdavUrl;
- private Button webdavLoginButton;
- // ssh variables
- private EditText sshUser;
- private EditText sshPass;
- private EditText sshPath;
- private EditText sshHost;
- private EditText sshPort;
- // page 3 variables
- private ListView folderList;
+ private Wizard activeWizard;
- private UIHandler uiHandler;
+ private int syncWebDav, syncDropBox, syncUbuntuOne, syncSdCard, syncNull, syncSSH;
- /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
@@ -106,15 +26,12 @@ public void onCreate(Bundle savedInstanceState) {
// when wizard first starts can't go to next page
wizardView.setNavButtonStateOnPage(0, false, WizardView.FIRST_PAGE);
-
-
// setup page 1
// get ids and pointers to sync radio buttons
- syncGroup = (RadioGroup) findViewById(R.id.sync_group);
+ RadioGroup syncGroup = (RadioGroup) findViewById(R.id.sync_group);
syncGroup.clearCheck();
syncGroup.setOnCheckedChangeListener(this);
-
syncWebDav = ((RadioButton) findViewById(R.id.sync_webdav)).getId();
syncDropBox = ((RadioButton) findViewById(R.id.sync_dropbox)).getId();
syncUbuntuOne = ((RadioButton) findViewById(R.id.sync_ubuntuone))
@@ -122,399 +39,44 @@ public void onCreate(Bundle savedInstanceState) {
syncSdCard = ((RadioButton) findViewById(R.id.sync_sdcard)).getId();
syncNull = ((RadioButton) findViewById(R.id.sync_null)).getId();
syncSSH = ((RadioButton) findViewById(R.id.sync_ssh)).getId();
-
- // setup progress dialog
- progress = new ProgressDialog(this);
- progress.setMessage(getString(R.string.please_wait));
- progress.setTitle(getString(R.string.signing_in));
}
-
- @Override
- protected void onResume() {
- super.onResume();
-
- if (dropboxLoginAttempted
- && dropboxApi.getSession().authenticationSuccessful()) {
- dropboxLoginAttempted = false;
- try {
- // MANDATORY call to complete auth.
- // Sets the access token on the session
- dropboxApi.getSession().finishAuthentication();
- AccessTokenPair tokens = dropboxApi.getSession()
- .getAccessTokenPair();
- storeKeys(tokens.key, tokens.secret);
- showToast("Logged in!");
- try {
- Account accountInfo = dropboxApi.accountInfo();
- dropboxAccountInfo.setText("User: "
- + accountInfo.displayName + "; Id: "
- + String.valueOf(accountInfo.uid));
- } catch (DropboxException e) {
- }
- loginButton.setEnabled(false);
- createDropboxList();
- wizardView.enablePage(1);
- } catch (IllegalStateException e) {
- showToast(String.format("Login failed: %s", e.toString()));
- }
- }
- }
-
@Override
protected void onPause() {
super.onPause();
wizardView.saveCurrentPage();
}
+ @Override
+ protected void onResume() {
+ super.onResume();
+ //dropboxWizard.handleDropboxResume(wizardView);
+ }
@Override
public void onCheckedChanged(RadioGroup arg, int checkedId) {
+ this.activeWizard = Wizard.getWizard(getWizardType(checkedId), wizardView,
+ getApplicationContext());
+ // allow scrolling to next page
+ wizardView.enablePage(0);
+ }
+
+ public Wizard.TYPE getWizardType(int checkedId) {
if (checkedId == syncWebDav) {
- syncSource = "webdav";
- createWebDAVConfig();
+ return Wizard.TYPE.WebDAV;
} else if (checkedId == syncDropBox) {
- syncSource = "dropbox";
- createDropboxLogin();
+ return Wizard.TYPE.Dropbox;
} else if (checkedId == syncUbuntuOne) {
- syncSource = "ubuntu";
- createUbuntuLogin();
+ return Wizard.TYPE.Ubuntu;
} else if (checkedId == syncSdCard) {
- syncSource = "sdcard";
- createSDcardFolderSelector();
+ return Wizard.TYPE.SDCard;
} else if (checkedId == syncSSH) {
- syncSource = "scp";
- createSSHConfig();
+ return Wizard.TYPE.SSH;
} else if (checkedId == syncNull) {
- syncSource = "null";
- createNullConfig();
+ return Wizard.TYPE.Null;
}
- // allow scrolling to next page
- wizardView.enablePage(0);
- }
-
- private void setupDoneButton() {
- Button done = (Button) wizardView.findViewById(R.id.wizard_done_button);
- done.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- saveSettings();
- finish();
- }
- });
- }
-
-
- private void createNullConfig() {
- wizardView.removePagesAfter(1);
- wizardView.addPage(R.layout.wizard_null);
- wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
- wizardView.enablePage(1);
- }
-
- private void createSSHConfig() {
- wizardView.removePagesAfter(1);
- wizardView.addPage(R.layout.wizard_ssh);
- sshUser = (EditText) wizardView.findViewById(R.id.wizard_ssh_username);
- sshPass = (EditText) wizardView.findViewById(R.id.wizard_ssh_password);
- sshPath = (EditText) wizardView.findViewById(R.id.wizard_ssh_path);
- sshHost = (EditText) wizardView.findViewById(R.id.wizard_ssh_host);
- sshPort = (EditText) wizardView.findViewById(R.id.wizard_ssh_port);
- webdavLoginButton = (Button) wizardView
- .findViewById(R.id.wizard_ssh_login_button);
- webdavLoginButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- loginSSH();
- }
- });
- wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
- wizardView.enablePage(1);
- }
-
- private void createWebDAVConfig() {
- wizardView.removePagesAfter(1);
- wizardView.addPage(R.layout.wizard_webdav);
- webdavUser = (EditText) wizardView
- .findViewById(R.id.wizard_webdav_username);
- webdavPass = (EditText) wizardView
- .findViewById(R.id.wizard_webdav_password);
- webdavUrl = (EditText) wizardView.findViewById(R.id.wizard_webdav_url);
- webdavLoginButton = (Button) wizardView
- .findViewById(R.id.wizard_webdav_login_button);
- webdavLoginButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- loginWebdav();
- }
- });
- wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
- wizardView.enablePage(1);
- }
-
- private void createSDcardFolderSelector() {
- wizardView.removePagesAfter(1);
- wizardView.addPage(R.layout.wizard_folder_pick_list);
- wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
-
- directory = new LocalDirectoryBrowser(this);
- directoryAdapter = new FolderAdapter(this, R.layout.folder_adapter_row,
- directory.listFiles());
- directoryAdapter
- .setDoneButton((Button) findViewById(R.id.wizard_done_button));
- directoryAdapter.setDirectoryBrowser(directory);
-
- folderList = (ListView) wizardView.findViewById(R.id.wizard_folder_list);
- folderList.setAdapter(directoryAdapter);
- directoryAdapter.notifyDataSetChanged();
- }
-
- private void createDropboxLogin() {
- wizardView.removePagesAfter(1);
- wizardView.addPage(R.layout.wizard_dropbox);
- wizardView.setNavButtonStateOnPage(1, true, WizardView.MIDDLE_PAGE);
- wizardView.disableAllNextActions(1);
- dropboxAccountInfo = (TextView) findViewById(R.id.wizard_dropbox_accountinfo);
-
- AppKeyPair appKeys = new AppKeyPair(
- getString(R.string.dropbox_consumer_key),
- getString(R.string.dropbox_consumer_secret));
- AndroidAuthSession session = new AndroidAuthSession(appKeys,
- AccessType.DROPBOX);
- dropboxApi = new DropboxAPI<AndroidAuthSession>(session);
-
- loginButton = (Button) wizardView
- .findViewById(R.id.wizard_dropbox_login_button);
- loginButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (isLoggedIn) {
- dropboxApi.getSession().unlink();
- // need to clear the keys
- } else {
- dropboxLoginAttempted = true;
- dropboxApi.getSession().startAuthentication(
- WizardActivity.this);
- }
- }
- });
- }
-
- private void createDropboxList() {
- wizardView.addPage(R.layout.wizard_folder_pick_list);
- wizardView.enablePage(1);
- // enable nav buttons on that page
- wizardView.setNavButtonStateOnPage(2, true, WizardView.LAST_PAGE);
-
- // setup directory browser
- directory = new DropboxDirectoryBrowser(this, dropboxApi);
- // setup directory browser adapter
- directoryAdapter = new FolderAdapter(this, R.layout.folder_adapter_row,
- directory.listFiles());
- directoryAdapter
- .setDoneButton((Button) findViewById(R.id.wizard_done_button));
- // bind adapter to browser
- directoryAdapter.setDirectoryBrowser(directory);
- // bind adapter to listview
- folderList = (ListView) wizardView.findViewById(R.id.wizard_folder_list);
- folderList.setAdapter(directoryAdapter);
- directoryAdapter.notifyDataSetChanged();
- // TODO Technically, this should be an async task app may crash
- // when list of root items is very long and network connection
- // is slow
- }
-
-
-
- private void createUbuntuLogin() {
- wizardView.removePagesAfter(1);
- wizardView.addPage(R.layout.wizard_ubuntuone);
- wizardView.setNavButtonStateOnPage(1, true, WizardView.MIDDLE_PAGE);
- wizardView.disableAllNextActions(1);
- ubuntuoneEmail = (EditText) wizardView
- .findViewById(R.id.wizard_ubuntu_email);
- ubuntuonePass = (EditText) wizardView
- .findViewById(R.id.wizard_ubuntu_password);
- loginButton = (Button) wizardView
- .findViewById(R.id.wizard_ubuntu_login_button);
- loginButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (isLoggedIn == false) {
- loginUbuntuOne();
- }
- }
- });
- }
-
-
-
- private void loginSSH() {
- final String pathActual = sshPath.getText().toString();
- final String passActual = sshPass.getText().toString();
- final String userActual = sshUser.getText().toString();
- final String hostActual = sshHost.getText().toString();
- String portNumGiven = sshPort.getText().toString();
- int portNum;
- if (portNumGiven.trim().equals("")) {
- portNum = 22;
- } else {
- portNum = Integer.parseInt(portNumGiven);
- }
- final int portActual = portNum;
-
- final Context ctxt = this;
- progress.show();
-
- Thread uiThread = new HandlerThread("UIHandler");
- uiThread.start();
- uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());
-
- Thread loginThread = new Thread() {
- public void run() {
- SSHSynchronizer sds = new SSHSynchronizer(ctxt);
- String extra = sds.testConnection(pathActual, userActual,
- passActual, hostActual, portActual);
- if (extra != null) {
- showToastRemote("Login failed: " + extra);
- return;
- }
- showToastRemote("Login succeeded");
- }
- };
- loginThread.start();
- }
-
- private void loginWebdav() {
- final String urlActual = webdavUrl.getText().toString();
- final String passActual = webdavPass.getText().toString();
- final String userActual = webdavUser.getText().toString();
- final Context ctxt = this;
- progress.show();
-
- Thread uiThread = new HandlerThread("UIHandler");
- uiThread.start();
- uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());
-
- Thread loginThread = new Thread() {
- public void run() {
- WebDAVSynchronizer wds = new WebDAVSynchronizer(ctxt);
- String extra = wds.testConnection(urlActual, userActual,
- passActual);
- if (extra != null) {
- showToastRemote("Login failed: " + extra);
- return;
- }
- showToastRemote("Login succeeded");
- }
- };
- loginThread.start();
- }
-
- private void loginUbuntuOne() {
- final UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer(
- (Context) this);
- uos.username = ubuntuoneEmail.getText().toString();
- uos.password = ubuntuonePass.getText().toString();
-
- // move this into another thread, so we don't get an ANR if the network
- // is unavailable
- Thread uiThread = new HandlerThread("UIHandler");
- uiThread.start();
- uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());
- showToast("Logging in, please wait");
- if (uos.login()) {
- showToastRemote("Login Successfull");
- loginButton.setEnabled(false);
- wizardView.enablePage(1);
- uos.getBaseUser();
- createUbuntuOneList();
- } else {
- showToastRemote("Login Failed");
- }
- }
-
-
- private void createUbuntuOneList() {
- wizardView.addPage(R.layout.wizard_folder_pick_list);
- wizardView.enablePage(1);
-
- wizardView.setNavButtonStateOnPage(2, true, WizardView.LAST_PAGE);
-
- UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer((Context) this);
- uos.getBaseUser();
- directory = new UbuntuOneDirectoryBrowser(this, uos);
-
- directoryAdapter = new FolderAdapter(this, R.layout.folder_adapter_row,
- directory.listFiles());
- directoryAdapter
- .setDoneButton((Button) findViewById(R.id.wizard_done_button));
-
- directoryAdapter.setDirectoryBrowser(directory);
-
- folderList = (ListView) wizardView.findViewById(R.id.wizard_folder_list);
- folderList.setAdapter(directoryAdapter);
- directoryAdapter.notifyDataSetChanged();
- // debug
- // TODO Technically, this should be an async task app may crash
- // when list of root items is very long and network connection
- // is slow
- }
-
-
- private void showToast(String msg) {
- Toast error = Toast.makeText(this, msg, Toast.LENGTH_LONG);
- error.show();
- }
-
- private void showToastRemote(String message) {
- Message msg = uiHandler.obtainMessage(UIHandler.DISPLAY_UI_TOAST);
- msg.obj = message;
- uiHandler.sendMessage(msg);
- }
-
-
- private void storeKeys(String key, String secret) {
- // Save the access key for later
- SharedPreferences prefs = PreferenceManager
- .getDefaultSharedPreferences(getBaseContext());
- Editor edit = prefs.edit();
- edit.putString("dbPrivKey", key);
- edit.putString("dbPrivSecret", secret);
- edit.commit();
- }
-
- private void saveSettings() {
- SharedPreferences appSettings = PreferenceManager
- .getDefaultSharedPreferences(getBaseContext());
- SharedPreferences.Editor editor = appSettings.edit();
- editor.putString("syncSource", syncSource);
- if (syncSource.equals("webdav")) {
- editor.putString("webUrl", webdavUrl.getText().toString());
- editor.putString("webPass", webdavPass.getText().toString());
- editor.putString("webUser", webdavUser.getText().toString());
- } else if (syncSource.equals("scp")) {
- editor.putString("scpPath", sshPath.getText().toString());
- editor.putString("scpUser", sshUser.getText().toString());
- editor.putString("scpPass", sshPass.getText().toString());
- editor.putString("scpHost", sshHost.getText().toString());
- if (sshPort.getText().toString().trim().equals("")) {
- editor.putString("scpPort", "22");
- } else {
- editor.putString("scpPort", sshPort.getText().toString());
- }
- } else if (syncSource.equals("dropbox"))
- editor.putString("dropboxPath",
- directoryAdapter.getCheckedDirectory() + "/");
- else if (syncSource.equals("ubuntu"))
- editor.putString("ubuntuOnePath",
- directoryAdapter.getCheckedDirectory() + "/");
- else if (syncSource.equals("sdcard"))
- editor.putString("indexFilePath",
- directoryAdapter.getCheckedDirectory());
- editor.putString("storageMode", "sdcard");
- editor.commit();
+ return Wizard.TYPE.Null;
}
}
View
5 src/com/matburt/mobileorg/Gui/Wizard/WizardUtils.java
@@ -1,5 +0,0 @@
-package com.matburt.mobileorg.Gui.Wizard;
-
-public class WizardUtils {
-
-}
View
4 src/com/matburt/mobileorg/Gui/Wizard/WizardView.java
@@ -181,6 +181,10 @@ public void addPage(int resId) {
View v = LayoutInflater.from(getContext()).inflate(resId, null);
container.addView(v);
}
+
+ public void addPage(View view) {
+ container.addView(view);
+ }
// delete all pages after and including given page
public void removePagesAfter(int page) {
View
3  ...mobileorg/Gui/Wizard/DropboxDirectoryBrowser.java → ...g/Gui/Wizard/Wizards/DropboxDirectoryBrowser.java
@@ -1,4 +1,4 @@
-package com.matburt.mobileorg.Gui.Wizard;
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
import java.io.File;
@@ -9,6 +9,7 @@
import com.dropbox.client2.DropboxAPI.Entry;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.exception.DropboxException;
+import com.matburt.mobileorg.Gui.Wizard.DirectoryBrowser;
public class DropboxDirectoryBrowser extends DirectoryBrowser<String> {
View
159 src/com/matburt/mobileorg/Gui/Wizard/Wizards/DropboxWizard.java
@@ -0,0 +1,159 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.dropbox.client2.DropboxAPI;
+import com.dropbox.client2.DropboxAPI.Account;
+import com.dropbox.client2.android.AndroidAuthSession;
+import com.dropbox.client2.exception.DropboxException;
+import com.dropbox.client2.session.AccessTokenPair;
+import com.dropbox.client2.session.AppKeyPair;
+import com.dropbox.client2.session.Session.AccessType;
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.FolderAdapter;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+
+public class DropboxWizard extends Wizard {
+
+ private TextView dropboxAccountInfo;
+ private DropboxAPI<AndroidAuthSession> dropboxApi;
+
+ private boolean isLoggedIn = false;
+ private boolean dropboxLoginAttempted = false;
+ private Button loginButton;
+
+ public DropboxWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createDropboxLogin();
+ }
+
+ public View createDropboxLogin() {
+ wizardView.removePagesAfter(1);
+
+ View view = LayoutInflater.from(context).inflate(R.layout.wizard_dropbox, null);
+
+ dropboxAccountInfo = (TextView) view.findViewById(R.id.wizard_dropbox_accountinfo);
+
+ AppKeyPair appKeys = new AppKeyPair(
+ context.getString(R.string.dropbox_consumer_key),
+ context.getString(R.string.dropbox_consumer_secret));
+ AndroidAuthSession session = new AndroidAuthSession(appKeys,
+ AccessType.DROPBOX);
+
+ dropboxApi = new DropboxAPI<AndroidAuthSession>(session);
+
+ loginButton = (Button) view
+ .findViewById(R.id.wizard_dropbox_login_button);
+ loginButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (isLoggedIn) {
+ dropboxApi.getSession().unlink();
+ // need to clear the keys
+ } else {
+ dropboxLoginAttempted = true;
+ dropboxApi.getSession().startAuthentication(context);
@matburt Owner
matburt added a note

This also seems to have broken the Dropbox wizard... I think we are getting the oauth error from the dropbox api because it can't figure out what activity to redirect back to... 'context' in this case must be incorrect, it needs to point back to the main wizard view. Ref issue #344

@matburt Owner
matburt added a note

Testing authentication when the dropbox app isn't installed seems to work fine... but if you have the dropbox app installed the dropbox api will try to use it for authentication... that seems to be where the problem comes in.

@matburt Owner
matburt added a note

hmm, maybe it's not an issue now... I've rebuilt it and everything seems fine, although it does seem like my dropbox login session on my android device was reset... we may want to keep that in mind if someone comes along and has similar troubles after 0.9.8. All good, sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+ }
+ });
+
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.MIDDLE_PAGE);
+ wizardView.disableAllNextActions(1);
+ return view;
+ }
+
+ public View createDropboxList() {
+ View view = LayoutInflater.from(context).inflate(R.layout.wizard_folder_pick_list, null);
+
+ // setup directory browser
+ DropboxDirectoryBrowser directory = new DropboxDirectoryBrowser(context, dropboxApi);
+ // setup directory browser adapter
+ FolderAdapter directoryAdapter = new FolderAdapter(context, R.layout.folder_adapter_row,
+ directory.listFiles());
+ directoryAdapter
+ .setDoneButton((Button) view.findViewById(R.id.wizard_done_button));
+ // bind adapter to browser
+ directoryAdapter.setDirectoryBrowser(directory);
+ // bind adapter to listview
+ ListView folderList = (ListView) view.findViewById(R.id.wizard_folder_list);
+ folderList.setAdapter(directoryAdapter);
+ directoryAdapter.notifyDataSetChanged();
+
+
+ wizardView.addPage(view);
+ wizardView.enablePage(1);
+ // enable nav buttons on that page
+ wizardView.setNavButtonStateOnPage(2, true, WizardView.LAST_PAGE);
+
+ return view;
+ }
+
+ public void handleDropboxResume() {
+ if (dropboxLoginAttempted
+ && dropboxApi.getSession().authenticationSuccessful()) {
+ dropboxLoginAttempted = false;
+ try {
+ // MANDATORY call to complete auth.
+ // Sets the access token on the session
+ dropboxApi.getSession().finishAuthentication();
+ AccessTokenPair tokens = dropboxApi.getSession()
+ .getAccessTokenPair();
+ storeKeys(tokens.key, tokens.secret);
+ Toast.makeText(context, "Logged in!", Toast.LENGTH_SHORT)
+ .show();
+ try {
+ Account accountInfo = dropboxApi.accountInfo();
+ dropboxAccountInfo.setText("User: "
+ + accountInfo.displayName + "; Id: "
+ + String.valueOf(accountInfo.uid));
+ } catch (DropboxException e) {
+ }
+ loginButton.setEnabled(false);
+ createDropboxList();
+ wizardView.enablePage(1);
+ } catch (IllegalStateException e) {
+ Toast.makeText(context,
+ String.format("Login failed: %s", e.toString()),
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+
+
+ private void storeKeys(String key, String secret) {
+ // Save the access key for later
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ Editor edit = prefs.edit();
+
+ edit.putString("dbPrivKey", key);
+ edit.putString("dbPrivSecret", secret);
+ edit.commit();
+ }
+
+ @Override
+ public void saveSettings() {
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ Editor editor = prefs.edit();
+
+ editor.putString("syncSource", "dropbox");
+ editor.commit();
+ }
+}
View
36 src/com/matburt/mobileorg/Gui/Wizard/Wizards/NullWizard.java
@@ -0,0 +1,36 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+
+public class NullWizard extends Wizard {
+
+ public NullWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createNullConfig();
+ }
+
+ public void createNullConfig() {
+ wizardView.removePagesAfter(1);
+
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_null, null);
+
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
+ wizardView.enablePage(1);
+ }
+
+ @Override
+ public void saveSettings() {
+ }
+}
View
63 src/com/matburt/mobileorg/Gui/Wizard/Wizards/SDCardWizard.java
@@ -0,0 +1,63 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ListView;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.FolderAdapter;
+import com.matburt.mobileorg.Gui.Wizard.LocalDirectoryBrowser;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+
+public class SDCardWizard extends Wizard {
+
+ private FolderAdapter directoryAdapter;
+
+ public SDCardWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createSDcardFolderSelector();
+ }
+
+ public View createSDcardFolderSelector() {
+ wizardView.removePagesAfter(1);
+
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_folder_pick_list, null);
+
+ LocalDirectoryBrowser directory = new LocalDirectoryBrowser(context);
+ directoryAdapter = new FolderAdapter(context, R.layout.folder_adapter_row,
+ directory.listFiles());
+ directoryAdapter
+ .setDoneButton((Button) view.findViewById(R.id.wizard_done_button));
+ directoryAdapter.setDirectoryBrowser(directory);
+
+ ListView folderList = (ListView) view.findViewById(R.id.wizard_folder_list);
+ folderList.setAdapter(directoryAdapter);
+ directoryAdapter.notifyDataSetChanged();
+
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
+ return view;
+ }
+
+ public void saveSettings() {
+ SharedPreferences appSettings = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = appSettings.edit();
+
+ editor.putString("syncSource", "sdcard");
+ editor.putString("indexFilePath",
+ directoryAdapter.getCheckedDirectory());
+
+ editor.commit();
+ }
+}
View
117 src/com/matburt/mobileorg/Gui/Wizard/Wizards/SSHWizard.java
@@ -0,0 +1,117 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.HandlerThread;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+import com.matburt.mobileorg.Synchronizers.SSHSynchronizer;
+
+public class SSHWizard extends Wizard {
+
+ private EditText sshUser;
+ private EditText sshPass;
+ private EditText sshPath;
+ private EditText sshHost;
+ private EditText sshPort;
+
+ public SSHWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createSSHConfig();
+ }
+
+ public View createSSHConfig() {
+ wizardView.removePagesAfter(1);
+
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_ssh, null);
+
+ sshUser = (EditText) view.findViewById(R.id.wizard_ssh_username);
+ sshPass = (EditText) view.findViewById(R.id.wizard_ssh_password);
+ sshPath = (EditText) view.findViewById(R.id.wizard_ssh_path);
+ sshHost = (EditText) view.findViewById(R.id.wizard_ssh_host);
+ sshPort = (EditText) view.findViewById(R.id.wizard_ssh_port);
+
+ Button webdavLoginButton = (Button) view
+ .findViewById(R.id.wizard_ssh_login_button);
+ webdavLoginButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ loginSSH();
+ }
+ });
+
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
+ wizardView.enablePage(1);
+ return view;
+ }
+
+
+ private void loginSSH() {
+ final String pathActual = sshPath.getText().toString();
+ final String passActual = sshPass.getText().toString();
+ final String userActual = sshUser.getText().toString();
+ final String hostActual = sshHost.getText().toString();
+ String portNumGiven = sshPort.getText().toString();
+ int portNum;
+ if (portNumGiven.trim().equals("")) {
+ portNum = 22;
+ } else {
+ portNum = Integer.parseInt(portNumGiven);
+ }
+ final int portActual = portNum;
+
+ progress.show();
+
+ Thread uiThread = new HandlerThread("UIHandler");
+ uiThread.start();
+ uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());
+
+ Thread loginThread = new Thread() {
+ public void run() {
+ SSHSynchronizer sds = new SSHSynchronizer(context);
+ String extra = sds.testConnection(pathActual, userActual,
+ passActual, hostActual, portActual);
+ if (extra != null) {
+ showToastRemote("Login failed: " + extra);
+ return;
+ }
+ showToastRemote("Login succeeded");
+ }
+ };
+ loginThread.start();
+ }
+
+ public void saveSettings() {
+ SharedPreferences appSettings = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = appSettings.edit();
+
+ editor.putString("syncSource", "scp");
+
+ editor.putString("scpPath", sshPath.getText().toString());
+ editor.putString("scpUser", sshUser.getText().toString());
+ editor.putString("scpPass", sshPass.getText().toString());
+ editor.putString("scpHost", sshHost.getText().toString());
+ if (sshPort.getText().toString().trim().equals("")) {
+ editor.putString("scpPort", "22");
+ } else {
+ editor.putString("scpPort", sshPort.getText().toString());
+ }
+
+ editor.commit();
+ }
+}
View
3  ...bileorg/Gui/Wizard/UbuntuOneDirectoryBrowser.java → ...Gui/Wizard/Wizards/UbuntuOneDirectoryBrowser.java
@@ -1,10 +1,11 @@
-package com.matburt.mobileorg.Gui.Wizard;
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
import java.io.File;
import android.content.Context;
import android.util.Log;
+import com.matburt.mobileorg.Gui.Wizard.DirectoryBrowser;
import com.matburt.mobileorg.Synchronizers.UbuntuOneSynchronizer;
public class UbuntuOneDirectoryBrowser extends DirectoryBrowser<String> {
View
133 src/com/matburt/mobileorg/Gui/Wizard/Wizards/UbuntuOneWizard.java
@@ -0,0 +1,133 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.HandlerThread;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.FolderAdapter;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+import com.matburt.mobileorg.Synchronizers.UbuntuOneSynchronizer;
+
+public class UbuntuOneWizard extends Wizard {
+
+ private EditText ubuntuoneEmail;
+ private EditText ubuntuonePass;
+ private Button loginButton;
+
+ private boolean isLoggedIn = false;
+
+ private FolderAdapter directoryAdapter;
+
+ public UbuntuOneWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createUbuntuLogin();
+ }
+
+ private View createUbuntuLogin() {
+ wizardView.removePagesAfter(1);
+
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_ubuntuone, null);
+
+ ubuntuoneEmail = (EditText) view.findViewById(R.id.wizard_ubuntu_email);
+ ubuntuonePass = (EditText) view
+ .findViewById(R.id.wizard_ubuntu_password);
+ loginButton = (Button) view
+ .findViewById(R.id.wizard_ubuntu_login_button);
+ loginButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (isLoggedIn == false) {
+ loginUbuntuOne();
+ }
+ }
+ });
+
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.MIDDLE_PAGE);
+ wizardView.disableAllNextActions(1);
+ return view;
+ }
+
+
+ private void loginUbuntuOne() {
+ final UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer(
+ (Context) context);
+ uos.username = ubuntuoneEmail.getText().toString();
+ uos.password = ubuntuonePass.getText().toString();
+
+ // move this into another thread, so we don't get an ANR if the network
+ // is unavailable
+ Thread uiThread = new HandlerThread("UIHandler");
+ uiThread.start();
+ uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());
+ Toast.makeText(context, "Logging in, please wait", Toast.LENGTH_SHORT).show();
+ if (uos.login()) {
+ showToastRemote("Login Successfull");
+ loginButton.setEnabled(false);
+ wizardView.enablePage(1);
+ uos.getBaseUser();
+ createUbuntuOneList();
+ } else {
+ showToastRemote("Login Failed");
+ }
+ }
+
+
+ private View createUbuntuOneList() {
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_folder_pick_list, null);
+
+ UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer(context);
+ uos.getBaseUser();
+ UbuntuOneDirectoryBrowser directory = new UbuntuOneDirectoryBrowser(context, uos);
+
+ directoryAdapter = new FolderAdapter(context, R.layout.folder_adapter_row,
+ directory.listFiles());
+ directoryAdapter
+ .setDoneButton((Button) view.findViewById(R.id.wizard_done_button));
+
+ directoryAdapter.setDirectoryBrowser(directory);
+
+ ListView folderList = (ListView) wizardView.findViewById(R.id.wizard_folder_list);
+ folderList.setAdapter(directoryAdapter);
+ directoryAdapter.notifyDataSetChanged();
+ // debug
+ // TODO Technically, this should be an async task app may crash
+ // when list of root items is very long and network connection
+ // is slow
+
+ wizardView.addPage(view);
+ wizardView.enablePage(1);
+ wizardView.setNavButtonStateOnPage(2, true, WizardView.LAST_PAGE);
+ return view;
+ }
+
+ public void saveSettings() {
+ SharedPreferences appSettings = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = appSettings.edit();
+
+
+ editor.putString("syncSource", "ubuntu");
+
+ editor.putString("ubuntuOnePath",
+ directoryAdapter.getCheckedDirectory() + "/");
+
+ editor.commit();
+ }
+}
View
99 src/com/matburt/mobileorg/Gui/Wizard/Wizards/WebDAVWizard.java
@@ -0,0 +1,99 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.HandlerThread;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+import com.matburt.mobileorg.Synchronizers.WebDAVSynchronizer;
+
+public class WebDAVWizard extends Wizard {
+
+ private EditText webdavUser;
+ private EditText webdavPass;
+ private EditText webdavUrl;
+
+ public WebDAVWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createWebDAVConfig();
+ }
+
+ public View createWebDAVConfig() {
+ wizardView.removePagesAfter(1);
+
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_webdav, null);
+
+ webdavUser = (EditText) view
+ .findViewById(R.id.wizard_webdav_username);
+ webdavPass = (EditText) view
+ .findViewById(R.id.wizard_webdav_password);
+ webdavUrl = (EditText) view.findViewById(R.id.wizard_webdav_url);
+ Button webdavLoginButton = (Button) view
+ .findViewById(R.id.wizard_webdav_login_button);
+ webdavLoginButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ loginWebdav();
+ }
+ });
+
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
+ wizardView.enablePage(1);
+ return view;
+ }
+
+
+
+ public void loginWebdav() {
+ final String urlActual = webdavUrl.getText().toString();
+ final String passActual = webdavPass.getText().toString();
+ final String userActual = webdavUser.getText().toString();
+ progress.show();
+
+ Thread uiThread = new HandlerThread("UIHandler");
+ uiThread.start();
+ uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());
+
+ Thread loginThread = new Thread() {
+ public void run() {
+ WebDAVSynchronizer wds = new WebDAVSynchronizer(context);
+ String extra = wds.testConnection(urlActual, userActual,
+ passActual);
+ if (extra != null) {
+ showToastRemote("Login failed: " + extra);
+ return;
+ }
+ showToastRemote("Login succeeded");
+ }
+ };
+ loginThread.start();
+ }
+
+ public void saveSettings() {
+ SharedPreferences appSettings = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = appSettings.edit();
+
+ editor.putString("syncSource", "webdav");
+
+ editor.putString("webUrl", webdavUrl.getText().toString());
+ editor.putString("webPass", webdavPass.getText().toString());
+ editor.putString("webUser", webdavUser.getText().toString());
+
+ editor.commit();
+ }
+}
View
104 src/com/matburt/mobileorg/Gui/Wizard/Wizards/Wizard.java
@@ -0,0 +1,104 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.widget.Toast;
+
+public abstract class Wizard {
+
+ protected Context context;
+ protected WizardView wizardView;
+
+ protected UIHandler uiHandler;
+ protected ProgressDialog progress;
+
+ public Wizard(WizardView wizardView, Context context) {
+ this.context = context;
+ this.wizardView = wizardView;
+
+ progress = new ProgressDialog(context);
+ progress.setMessage(context.getString(R.string.please_wait));
+ progress.setTitle(context.getString(R.string.signing_in));
+
+ setupFirstPage();
+ }
+
+ public abstract void setupFirstPage();
+
+ public final class UIHandler extends Handler {
+ public static final int DISPLAY_UI_TOAST = 0;
+
+ public UIHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case DISPLAY_UI_TOAST: {
+ Toast t = Toast.makeText(context, (String) msg.obj,
+ Toast.LENGTH_LONG);
+ progress.dismiss();
+ t.show();
+ }
+ default:
+ break;
+ }
+ }
+ }
+
+ public void showToastRemote(String message) {
+ Message msg = uiHandler.obtainMessage(UIHandler.DISPLAY_UI_TOAST);
+ msg.obj = message;
+ uiHandler.sendMessage(msg);
+ }
+
+ public abstract void saveSettings();
+
+ public enum TYPE {
+ WebDAV, Dropbox, Ubuntu, SDCard, SSH, Null
+ };
+
+ public static Wizard getWizard(TYPE type, WizardView wizardView,
+ Context context) {
+ Wizard wizard;
+
+ switch (type) {
+ case WebDAV:
+ wizard = new WebDAVWizard(wizardView, context);
+ break;
+
+ case Dropbox:
+ wizard = new DropboxWizard(wizardView, context);
+ break;
+
+ case Ubuntu:
+ wizard = new UbuntuOneWizard(wizardView, context);
+ break;
+
+ case SDCard:
+ wizard = new SDCardWizard(wizardView, context);
+ break;
+
+ case SSH:
+ wizard = new SSHWizard(wizardView, context);
+ break;
+
+ case Null:
+ wizard = new NullWizard(wizardView, context);
+ break;
+
+ default:
+ wizard = new NullWizard(wizardView, context);
+ break;
+ }
+
+ return wizard;
+ }
+}
@matburt

This also seems to have broken the Dropbox wizard... I think we are getting the oauth error from the dropbox api because it can't figure out what activity to redirect back to... 'context' in this case must be incorrect, it needs to point back to the main wizard view. Ref issue #344

@matburt

Testing authentication when the dropbox app isn't installed seems to work fine... but if you have the dropbox app installed the dropbox api will try to use it for authentication... that seems to be where the problem comes in.

@matburt

hmm, maybe it's not an issue now... I've rebuilt it and everything seems fine, although it does seem like my dropbox login session on my android device was reset... we may want to keep that in mind if someone comes along and has similar troubles after 0.9.8. All good, sorry for the noise.

Please sign in to comment.
Something went wrong with that request. Please try again.