diff --git a/res/layout/wizard_ubuntuone.xml b/res/layout/wizard_ubuntuone.xml
new file mode 100644
index 00000000..cd72936c
--- /dev/null
+++ b/res/layout/wizard_ubuntuone.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 89465fda..3d772110 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -96,11 +96,13 @@
an SSH server
nothing (capture only)
Log in to Dropbox
+ Log in to Ubuntu One
Log in to your WebDAV server
Log in to your SSH server
This is a capture only synchronizer. It will not attempt to synchronize to any source.
URL
uri@frankandrobot.com
+ username
Capture with Timestamp
@@ -134,6 +136,10 @@
Login to retrieve an OAuth token
Path
Dropbox path to index.org file
+ Login
+ Path
+ Login to retrieve an OAuth token
+ UbuntuOne path to index.org file
Clear DB?
Are you sure want to clear DB?
Combines block agendas into one node, with separators. Needs resync of agenda file to take effect
diff --git a/src/com/matburt/mobileorg/Settings/UbuntuOneSettingsActivity.java b/src/com/matburt/mobileorg/Settings/UbuntuOneSettingsActivity.java
index 3c4fc4df..a01488b5 100644
--- a/src/com/matburt/mobileorg/Settings/UbuntuOneSettingsActivity.java
+++ b/src/com/matburt/mobileorg/Settings/UbuntuOneSettingsActivity.java
@@ -1,15 +1,21 @@
package com.matburt.mobileorg.Settings;
import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import com.matburt.mobileorg.R;
-public class UbuntuOneSettingsActivity
+public class UbuntuOneSettingsActivity extends PreferenceActivity implements OnPreferenceClickListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.ubuntuone_preferences);
}
+
+ public boolean onPreferenceClick(Preference p) {
+ return true;
+ }
}
\ No newline at end of file
diff --git a/src/com/matburt/mobileorg/Settings/WizardActivity.java b/src/com/matburt/mobileorg/Settings/WizardActivity.java
index aac8462c..02af1b60 100644
--- a/src/com/matburt/mobileorg/Settings/WizardActivity.java
+++ b/src/com/matburt/mobileorg/Settings/WizardActivity.java
@@ -38,6 +38,7 @@
import com.matburt.mobileorg.Views.PageFlipView;
import com.matburt.mobileorg.Synchronizers.WebDAVSynchronizer;
import com.matburt.mobileorg.Synchronizers.SSHSynchronizer;
+import com.matburt.mobileorg.Synchronizers.UbuntuOneSynchronizer;
import com.matburt.mobileorg.Parsing.MobileOrgApplication;
public class WizardActivity extends Activity {
@@ -302,7 +303,32 @@ public void onClick(View v) {
}
void createUbuntuLogin() {
-
+ wizard.removePagesAfter( 1 );
+ //add login page to wizard
+ wizard.addPage( R.layout.wizard_ubuntuone );
+ //enable nav buttons on that page
+ wizard.setNavButtonStateOnPage(1, true, PageFlipView.MIDDLE_PAGE);
+ wizard.disableAllNextActions( 1 );
+ //get references to login forms
+ ubuntuoneEmail = (EditText) wizard
+ .findViewById(R.id.wizard_ubuntu_email);
+ ubuntuonePass = (EditText) wizard
+ .findViewById(R.id.wizard_ubuntu_password);
+ //setup listener for buttons
+ loginButton = (Button) wizard
+ .findViewById(R.id.wizard_ubuntu_login_button);
+ loginButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (isLoggedIn) {
+ // We're going to log out
+ //dropbox.deauthenticate();
+ } else {
+ // Try to log in
+ loginUbuntuOne();
+ }
+ }
+ });
}
void loginSSH() {
@@ -397,6 +423,13 @@ void loginDropbox() {
dropbox.login(dropboxListener, email, password);
}
}
+
+ void loginUbuntuOne() {
+ UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer((Context)this, (MobileOrgApplication)getApplication());
+ uos.username = ubuntuoneEmail.getText().toString();
+ uos.password = ubuntuonePass.getText().toString();
+ uos.login();
+ }
//convience function
void showToast(String msg) {
diff --git a/src/com/matburt/mobileorg/Synchronizers/UbuntuOneSynchronizer.java b/src/com/matburt/mobileorg/Synchronizers/UbuntuOneSynchronizer.java
index 04f34f8b..8732f45d 100644
--- a/src/com/matburt/mobileorg/Synchronizers/UbuntuOneSynchronizer.java
+++ b/src/com/matburt/mobileorg/Synchronizers/UbuntuOneSynchronizer.java
@@ -8,6 +8,7 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
+import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
@@ -65,15 +66,15 @@ public class UbuntuOneSynchronizer extends Synchronizer {
private static final String PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/";
private static final String UTF8 = "UTF-8";
- private String remoteIndexPath;
- private String remotePath;
- private String username;
- private String password;
+ public String remoteIndexPath;
+ public String remotePath;
+ public String username;
+ public String password;
- private String consumer_key;
- private String consumer_secret;
- private String access_token;
- private String token_secret;
+ public String consumer_key;
+ public String consumer_secret;
+ public String access_token;
+ public String token_secret;
private CommonsHttpOAuthConsumer consumer;
@@ -86,6 +87,11 @@ public UbuntuOneSynchronizer(Context parentContext, MobileOrgApplication appInst
this.username = sharedPreferences.getString("webUser", "");
this.password = sharedPreferences.getString("webPass", "");
+
+ consumer_key = sharedPreferences.getString("ubuntuConsumerKey", "");
+ consumer_secret = sharedPreferences.getString("ubuntuConsumerSecret", "");
+ access_token = sharedPreferences.getString("ubuntuAccessToken", "");
+ token_secret = sharedPreferences.getString("ubuntuTokenSecret", "");
}
public void invalidate() {
@@ -135,9 +141,10 @@ protected BufferedReader getRemoteFile(String filename) {
protected void postSynchronize() {
}
- private void login() {
+ public void login() {
invalidate();
try {
+ Log.i("MobileOrg", "Logging into Ubuntu One");
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(LOGIN_HOST, LOGIN_PORT),
@@ -150,14 +157,24 @@ private void login() {
consumer_secret = loginData.getString(CONSUMER_SECRET);
access_token = loginData.getString(ACCESS_TOKEN);
token_secret = loginData.getString(TOKEN_SECRET);
+
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ Editor edit = sharedPreferences.edit();
+ edit.putString("ubuntuConsumerKey", consumer_key);
+ edit.putString("ubuntuConsumerSecret", consumer_secret);
+ edit.putString("ubuntuAccessToken", access_token);
+ edit.putString("ubuntuTokenSecret", token_secret);
+ Log.i("MobileOrg", "Logged in to Ubuntu One: " + consumer_key);
+ edit.commit();
+
buildConsumer();
ping_u1_url(this.username);
} catch (ClientProtocolException e) {
- e.printStackTrace();
+ Log.e("MobileOrg", "Protocol Exception: " + e.toString());
} catch (IOException e) {
- e.printStackTrace();
+ Log.e("MobileOrg", "IO Exception: " + e.toString());
} catch (JSONException e) {
- e.printStackTrace();
+ Log.e("MobileOrg", "JSONException: " + e.toString());
// } catch (InterruptedException e) {
// e.printStackTrace();
}
@@ -256,13 +273,16 @@ private void ping_u1_url(String username) {
return;
}
}
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ } catch (Exception e) {
+ Log.e("MobileOrg", "Exception in Ubuntu One Ping: " + e.toString());
+ }
+ // } catch (UnsupportedEncodingException e) {
+ // e.printStackTrace();
+ // } catch (ClientProtocolException e) {
+ // e.printStackTrace();
+ // } catch (IOException e) {
+ // e.printStackTrace();
+ // }
}
}