Skip to content

Commit

Permalink
Link UbuntuOne login to the wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
matburt committed May 5, 2012
1 parent 09ffc82 commit 507e0ac
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 21 deletions.
69 changes: 69 additions & 0 deletions res/layout/wizard_ubuntuone.xml
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:id="@+id/wizard_ubuntuone">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/log_in_to_ubuntuone"
android:textSize="20dp"
android:textStyle="bold"
android:paddingBottom="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email"
android:textSize="20dp"/>
<EditText
android:id="@+id/wizard_ubuntu_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:inputType="textEmailAddress"
android:hint="@string/wizard_ubuntu_email_hint"
android:singleLine="true"/>
<TextView
android:paddingTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password"
android:textSize="20dp"/>
<EditText
android:id="@+id/wizard_ubuntu_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:inputType="textPassword"
android:password="true"
android:singleLine="true"/>
<Button
android:layout_marginTop="10dp"
android:id="@+id/wizard_ubuntu_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login"
android:textSize="20dp"/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1.0"
/>
<include layout="@layout/wizard_navbar"/>
</LinearLayout>
</ScrollView>
6 changes: 6 additions & 0 deletions res/values/strings.xml
Expand Up @@ -96,11 +96,13 @@
<string name="wizard_ssh">an SSH server</string>
<string name="wizard_null">nothing (capture only)</string>
<string name="log_in_to_dropbox">Log in to Dropbox</string>
<string name="log_in_to_ubuntuone">Log in to Ubuntu One</string>
<string name="log_in_to_webdav">Log in to your WebDAV server</string>
<string name="log_in_to_ssh">Log in to your SSH server</string>
<string name="null_sync_description">This is a capture only synchronizer. It will not attempt to synchronize to any source.</string>
<string name="url">URL</string>
<string name="wizard_dropbox_email_hint">uri@frankandrobot.com</string>
<string name="wizard_ubuntu_email_hint">username</string>

<!-- preference strings -->
<string name="title_capture_with_timestamp">Capture with Timestamp</string>
Expand Down Expand Up @@ -134,6 +136,10 @@
<string name="preference_dropbox_login_summary">Login to retrieve an OAuth token</string>
<string name="preference_dropbox_path">Path</string>
<string name="preference_dropbox_path_summary">Dropbox path to index.org file</string>
<string name="preference_ubuntuone_login">Login</string>
<string name="preference_ubuntuone_path">Path</string>
<string name="preference_ubuntuone_login_summary">Login to retrieve an OAuth token</string>
<string name="preference_ubuntuone_path_summary">UbuntuOne path to index.org file</string>
<string name="preference_clear_db_dialog_title">Clear DB?</string>
<string name="preference_clear_db_dialog_message">Are you sure want to clear DB?</string>
<string name="preference_combine_block_agenda_summary">Combines block agendas into one node, with separators. Needs resync of agenda file to take effect</string>
Expand Down
@@ -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;
}
}
35 changes: 34 additions & 1 deletion src/com/matburt/mobileorg/Settings/WizardActivity.java
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
58 changes: 39 additions & 19 deletions src/com/matburt/mobileorg/Synchronizers/UbuntuOneSynchronizer.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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() {
Expand Down Expand Up @@ -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),
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
// }
}
}

0 comments on commit 507e0ac

Please sign in to comment.