Skip to content
Browse files

Merge pull request #328 from matburt/wizard_cleanup

Wizard cleanup
  • Loading branch information...
2 parents 8ef0f88 + 0577cdb commit bbf91559c16103e60db14ce1f435b7eca9e37a95 @matburt committed Dec 9, 2012
Showing with 1,621 additions and 1,293 deletions.
  1. +27 −15 AndroidManifest.xml
  2. +39 −35 res/layout/wizard.xml
  3. +4 −3 res/xml/preferences.xml
  4. +1 −1 src/com/matburt/mobileorg/Gui/Outline/OutlineActivity.java
  5. +53 −0 src/com/matburt/mobileorg/Gui/Wizard/DirectoryBrowser.java
  6. +95 −0 src/com/matburt/mobileorg/Gui/Wizard/FolderAdapter.java
  7. +46 −0 src/com/matburt/mobileorg/Gui/Wizard/LocalDirectoryBrowser.java
  8. +40 −0 src/com/matburt/mobileorg/Gui/Wizard/WideLinearLayout.java
  9. +97 −0 src/com/matburt/mobileorg/Gui/Wizard/WizardActivity.java
  10. +312 −0 src/com/matburt/mobileorg/Gui/Wizard/WizardView.java
  11. +65 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/DropboxDirectoryBrowser.java
  12. +164 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/DropboxWizard.java
  13. +43 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/NullWizard.java
  14. +62 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/SDCardWizard.java
  15. +144 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/SSHWizard.java
  16. +56 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/UbuntuOneDirectoryBrowser.java
  17. +130 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/UbuntuOneWizard.java
  18. +100 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/WebDAVWizard.java
  19. +123 −0 src/com/matburt/mobileorg/Gui/Wizard/Wizards/Wizard.java
  20. +4 −0 src/com/matburt/mobileorg/Services/CalendarSyncService.java
  21. +1 −1 src/com/matburt/mobileorg/Settings/SettingsActivity.java
  22. +0 −678 src/com/matburt/mobileorg/Settings/WizardActivity.java
  23. +0 −57 src/com/matburt/mobileorg/Settings/WizardPreferences.java
  24. +15 −15 src/com/matburt/mobileorg/Synchronizers/DropboxSynchronizer.java
  25. +0 −328 src/com/matburt/mobileorg/Views/PageFlipView.java
  26. +0 −120 src/com/matburt/mobileorg/Views/PageView.java
  27. +0 −40 src/com/matburt/mobileorg/Views/WideLinearLayout.java
View
42 AndroidManifest.xml
@@ -120,8 +120,13 @@
android:label="MobileOrg Settings" >
</activity>
<activity
- android:name=".Settings.WizardActivity"
+ android:name=".Gui.Wizard.WizardActivity"
android:label="MobileOrg Wizard" >
+ <intent-filter>
+ <action android:name="com.matburt.mobileorg.Settings.SETUP_WIZARD" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
</activity>
<activity
android:name=".Gui.CertificateConflictActivity"
@@ -161,21 +166,28 @@
android:name=".Services.TimeclockDialog"
android:theme="@android:style/Theme.Dialog" >
</activity>
- <activity android:name=".Gui.Agenda.AgendaSettings"></activity>
- <activity android:name=".Gui.Agenda.AgendaEntrySetting"></activity>
+ <activity android:name=".Gui.Agenda.AgendaSettings" >
+ </activity>
+ <activity android:name=".Gui.Agenda.AgendaEntrySetting" >
+ </activity>
<activity
android:name="com.dropbox.client2.android.AuthActivity"
- android:launchMode="singleTask"
- android:configChanges="orientation|keyboard">
- <intent-filter>
- <!-- Change this to be db- followed by your app key -->
- <data android:scheme="db-et6v9bbqd4pu0ak" />
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.BROWSABLE"/>
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
- <service android:name=".Services.CalendarSyncService"></service>
+ android:configChanges="orientation|keyboard"
+ android:launchMode="singleTask" >
+ <intent-filter>
+
+ <!-- Change this to be db- followed by your app key -->
+ <data android:scheme="db-2y6mph4a6httm78" />
+
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.BROWSABLE" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ <service android:name=".Services.CalendarSyncService" >
+ </service>
</application>
-</manifest>
+</manifest>
View
74 res/layout/wizard.xml
@@ -1,37 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
-<com.matburt.mobileorg.Views.PageFlipView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/wizard_parent"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:fillViewport="true"
- android:layout_alignParentTop="true">
- <com.matburt.mobileorg.Views.WideLinearLayout
- android:id="@+id/wizard_container"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:orientation="horizontal">
- <!-- page 1 -->
- <ScrollView
- android:id="@+id/wizard_page1_container"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:fillViewport="true">
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <include
- android:layout_marginTop="10dp"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1.0"
- android:id="@+id/wizard_page1"
- layout="@layout/wizard_page1" />
- <include
- layout="@layout/wizard_navbar_first" />
- </LinearLayout>
- </ScrollView>
- </com.matburt.mobileorg.Views.WideLinearLayout>
-</com.matburt.mobileorg.Views.PageFlipView>
+<com.matburt.mobileorg.Gui.Wizard.WizardView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/wizard_parent"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_alignParentTop="true"
+ android:fillViewport="true" >
+ <com.matburt.mobileorg.Gui.Wizard.WideLinearLayout
+ android:id="@+id/wizard_container"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal" >
+
+ <!-- page 1 -->
+
+ <ScrollView
+ android:id="@+id/wizard_page1_container"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:fillViewport="true" >
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <include
+ android:id="@+id/wizard_page1"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dp"
+ android:layout_weight="1.0"
+ layout="@layout/wizard_page1" />
+
+ <include layout="@layout/wizard_navbar_first" />
+ </LinearLayout>
+ </ScrollView>
+ </com.matburt.mobileorg.Gui.Wizard.WideLinearLayout>
+
+</com.matburt.mobileorg.Gui.Wizard.WizardView>
View
7 res/xml/preferences.xml
@@ -2,9 +2,10 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/preference_synchronization" >
- <com.matburt.mobileorg.Settings.WizardPreferences
- android:key="wizardPref"
- android:title="Wizard Preference" />
+ <Preference
+ android:title="@string/rerun_setup_wizard" >
+ <intent android:action="com.matburt.mobileorg.Settings.SETUP_WIZARD" />
+ </Preference>
<ListPreference
android:defaultValue="webdav"
View
2 src/com/matburt/mobileorg/Gui/Outline/OutlineActivity.java
@@ -17,10 +17,10 @@
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardActivity;
import com.matburt.mobileorg.OrgData.OrgProviderUtils;
import com.matburt.mobileorg.Services.SyncService;
import com.matburt.mobileorg.Settings.SettingsActivity;
-import com.matburt.mobileorg.Settings.WizardActivity;
import com.matburt.mobileorg.Synchronizers.Synchronizer;
import com.matburt.mobileorg.util.OrgUtils;
View
53 src/com/matburt/mobileorg/Gui/Wizard/DirectoryBrowser.java
@@ -0,0 +1,53 @@
+package com.matburt.mobileorg.Gui.Wizard;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import android.content.Context;
+
+import com.matburt.mobileorg.R;
+
+public abstract class DirectoryBrowser<T> {
+
+ protected Context context;
+
+ protected T currentDirectory;
+ protected ArrayList<T> directoryListing = new ArrayList<T>();
+ protected ArrayList<String> directoryNames = new ArrayList<String>();
+
+ protected String upOneLevel;
+
+ public abstract void browseTo(int position);
+ protected abstract void browseTo(String directory);
+ public abstract boolean isCurrentDirectoryRoot();
+
+ public DirectoryBrowser(Context context) {
+ this.context = context;
+ this.upOneLevel = context.getString(R.string.up_one_level);
+ }
+
+
+ public ArrayList<String> listFiles() {
+ return directoryNames;
+ }
+
+ public String getDirectoryName(int position) {
+ return directoryNames.get(position);
+ }
+
+ protected T getDir(int position) {
+ return directoryListing.get(position);
+ }
+
+ public String getAbsolutePath(int position) {
+ T directory = directoryListing.get(position);
+
+ if (directory instanceof String)
+ return (String) directory;
+
+ if (directory instanceof File)
+ return ((File) directory).getAbsolutePath();
+
+ return "";
+ }
+}
View
95 src/com/matburt/mobileorg/Gui/Wizard/FolderAdapter.java
@@ -0,0 +1,95 @@
+package com.matburt.mobileorg.Gui.Wizard;
+
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.TextView;
+
+import com.matburt.mobileorg.R;
+
+public class FolderAdapter extends ArrayAdapter<String> {
+ private int currentChecked = -1;
+ private DirectoryBrowser<?> directory;
+ private Button doneButton;
+
+ public FolderAdapter(Context context, int resource, ArrayList<String> list) {
+ super(context, resource, list);
+ }
+
+ public void setDirectoryBrowser(DirectoryBrowser<?> d) {
+ directory = d;
+ }
+
+ public String getCheckedDirectory() {
+ if (currentChecked == -1)
+ return "";
+ // (Toast.makeText(context, directory.getAbsolutePath(currentChecked),
+ // Toast.LENGTH_LONG)).show();
+ return directory.getAbsolutePath(currentChecked);
+ }
+
+ public void setDoneButton(Button b) {
+ doneButton = b;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View row = convertView;
+ TextView folder = null;
+ CheckBox check = null;
+ if (row == null) {
+ LayoutInflater inflater = LayoutInflater.from(getContext());
+ row = inflater.inflate(R.layout.folder_adapter_row, parent, false);
+ folder = (TextView) row.findViewById(R.id.folder);
+ folder.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View folder) {
+ int position = (Integer) folder.getTag();
+ // FolderAdapter.this.clear();
+ directory.browseTo(position);
+ currentChecked = -1;
+ FolderAdapter.this.notifyDataSetChanged();
+ doneButton.setEnabled(false);
+ }
+ });
+ check = (CheckBox) row.findViewById(R.id.checkbox);
+ check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+
+ public void onCheckedChanged(CompoundButton buttonView,
+ boolean isChecked) {
+ // update last checked position
+ int position = (Integer) buttonView.getTag();
+ if (isChecked)
+ currentChecked = position;
+ else if (currentChecked == position)
+ currentChecked = -1;
+ FolderAdapter.this.notifyDataSetChanged();
+ if (isChecked)
+ doneButton.setEnabled(true);
+ }
+ });
+ }
+ folder = (TextView) row.findViewById(R.id.folder);
+ folder.setText(directory.getDirectoryName(position));
+ folder.setTag(Integer.valueOf(position));
+ check = (CheckBox) row.findViewById(R.id.checkbox);
+ // disable the "Up one level" checkbox; otherwise make sure its enabled
+ if (position == 0 && !directory.isCurrentDirectoryRoot())
+ check.setEnabled(false);
+ else
+ check.setEnabled(true);
+ check.setTag(Integer.valueOf(position));
+ // set check state. only one can be checked
+ boolean status = (currentChecked == position) ? true : false;
+ check.setChecked(status);
+ return (row);
+ }
+}
View
46 src/com/matburt/mobileorg/Gui/Wizard/LocalDirectoryBrowser.java
@@ -0,0 +1,46 @@
+package com.matburt.mobileorg.Gui.Wizard;
+
+import java.io.File;
+import java.util.Arrays;
+
+import android.content.Context;
+
+public class LocalDirectoryBrowser extends DirectoryBrowser<File> {
+
+ public LocalDirectoryBrowser(Context context) {
+ super(context);
+
+ browseTo(File.separator);
+ }
+
+ @Override
+ public boolean isCurrentDirectoryRoot() {
+ return currentDirectory.getParent() == null;
+ }
+
+ @Override
+ public void browseTo(int position) {
+ File newdir = getDir(position);
+ browseTo(newdir.getAbsolutePath());
+ }
+
+ @Override
+ public void browseTo(String directory) {
+ currentDirectory = new File(directory);
+ directoryNames.clear();
+ directoryListing.clear();
+ if (currentDirectory.getParent() != null) {
+ directoryNames.add(upOneLevel);
+ directoryListing.add(currentDirectory.getParentFile());
+ }
+ File[] tmpListing = currentDirectory.listFiles();
+ // default list order doesn't seem to be alpha
+ Arrays.sort(tmpListing);
+ for (File dir : tmpListing) {
+ if (dir.isDirectory() && dir.canWrite()) {
+ directoryNames.add(dir.getName());
+ directoryListing.add(dir);
+ }
+ }
+ }
+}
View
40 src/com/matburt/mobileorg/Gui/Wizard/WideLinearLayout.java
@@ -0,0 +1,40 @@
+package com.matburt.mobileorg.Gui.Wizard;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+public class WideLinearLayout extends LinearLayout {
+
+ private int screenWidth;
+
+ public WideLinearLayout(Context context) {
+ super(context);
+ }
+
+ public WideLinearLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setWidth(int w) {
+ screenWidth = w;
+ }
+
+ @Override
+ protected void onMeasure(int w, int h) {
+ // int width = MeasureSpec.getSize(screenWidth);
+ int height = MeasureSpec.getSize(h);
+ // and its children
+ for (int i = 0; i < getChildCount(); i++) {
+ View page = (View) getChildAt(i);
+ // page.measure(screenWidth,hs);
+ ViewGroup.LayoutParams lp = page.getLayoutParams();
+ lp.width = screenWidth;
+ lp.height = height;
+ }
+ // setMeasuredDimension(width,height);
+ super.onMeasure(w, h);
+ }
+}
View
97 src/com/matburt/mobileorg/Gui/Wizard/WizardActivity.java
@@ -0,0 +1,97 @@
+package com.matburt.mobileorg.Gui.Wizard;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.Wizards.SSHWizard;
+import com.matburt.mobileorg.Gui.Wizard.Wizards.Wizard;
+import com.matburt.mobileorg.util.OrgUtils;
+
+public class WizardActivity extends Activity implements RadioGroup.OnCheckedChangeListener {
+
+ private WizardView wizardView;
+ private Wizard activeWizard;
+
+ private int syncWebDav, syncDropBox, syncUbuntuOne, syncSdCard, syncNull, syncSSH;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ OrgUtils.setTheme(this);
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.wizard);
+
+ wizardView = (WizardView) findViewById(R.id.wizard_parent);
+ // when wizard first starts can't go to next page
+ wizardView.setNavButtonStateOnPage(0, false, WizardView.FIRST_PAGE);
+
+ 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))
+ .getId();
+ syncSdCard = ((RadioButton) findViewById(R.id.sync_sdcard)).getId();
+ syncNull = ((RadioButton) findViewById(R.id.sync_null)).getId();
+ syncSSH = ((RadioButton) findViewById(R.id.sync_ssh)).getId();
+ }
+
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ wizardView.saveCurrentPage();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ if(activeWizard != null)
+ activeWizard.refresh();
+ }
+
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == SSHWizard.SSH_CHOOSE_PUB) {
+ if (resultCode == RESULT_OK) {
+ String filePath = data.getData().getPath();
+
+ if (activeWizard instanceof SSHWizard)
+ ((SSHWizard) activeWizard).setPubFile(filePath);
+ }
+ }
+ }
+
+ @Override
+ public void onCheckedChanged(RadioGroup arg, int checkedId) {
+ this.activeWizard = Wizard.getWizard(getWizardType(checkedId), wizardView,
+ this);
+ // allow scrolling to next page
+ wizardView.enablePage(0);
+ }
+
+ public Wizard.TYPE getWizardType(int checkedId) {
+ if (checkedId == syncWebDav) {
+ return Wizard.TYPE.WebDAV;
+ } else if (checkedId == syncDropBox) {
+ return Wizard.TYPE.Dropbox;
+ } else if (checkedId == syncUbuntuOne) {
+ return Wizard.TYPE.Ubuntu;
+ } else if (checkedId == syncSdCard) {
+ return Wizard.TYPE.SDCard;
+ } else if (checkedId == syncSSH) {
+ return Wizard.TYPE.SSH;
+ } else if (checkedId == syncNull) {
+ return Wizard.TYPE.Null;
+ }
+
+ return Wizard.TYPE.Null;
+ }
+}
View
312 src/com/matburt/mobileorg/Gui/Wizard/WizardView.java
@@ -0,0 +1,312 @@
+package com.matburt.mobileorg.Gui.Wizard;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.GestureDetector;
+import android.view.GestureDetector.SimpleOnGestureListener;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.HorizontalScrollView;
+
+import com.matburt.mobileorg.R;
+
+public class WizardView extends HorizontalScrollView implements
+ View.OnTouchListener {
+ private static final String TAG = "PageFlipView";
+ private static final int SWIPE_THRESHOLD_VELOCITY = 50;
+
+ public static final int FIRST_PAGE = 0;
+ public static final int MIDDLE_PAGE = 1;
+ public static final int LAST_PAGE = 2;
+
+ private GestureDetector mGestureDetector;
+ private WideLinearLayout container;
+ private NextPageButtonListener nextPageButtonListener;
+ private PreviousPageButtonListener previousPageButtonListener;
+
+ private int maxScrollX;
+ private int maxEnabledPage = -1;
+ private int currentPage = 0;
+
+ public WizardView(Context context) {
+ super(context);
+ }
+
+ public WizardView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ nextPageButtonListener = new NextPageButtonListener();
+ previousPageButtonListener = new PreviousPageButtonListener();
+ // see
+ // http://blog.velir.com/index.php/2010/11/17/android-snapping-horizontal-scroll/
+ // setup page swiping
+ mGestureDetector = new GestureDetector(getContext(),
+ new PageSwipeDetector());
+ setOnTouchListener(this);
+ }
+
+ // Make the child views the same size as the screen
+ @Override
+ protected void onMeasure(int w, int h) {
+ int width = MeasureSpec.getSize(w);
+ // Tell screen width to our only child
+ container.setWidth(width);
+ // default to w and h given in XML
+ super.onMeasure(w, h);
+ }
+
+
+ @Override
+ public void onFinishInflate() {
+ container = (WideLinearLayout) findViewById(R.id.wizard_container);
+ }
+
+ private static void setButtonState(Button b, boolean state,
+ View.OnClickListener e) {
+ b.setOnClickListener(e);
+ b.setEnabled(state);
+ }
+
+ public void enableNextButton(Button b) {
+ b.setOnClickListener(nextPageButtonListener);
+ b.setEnabled(true);
+ }
+
+ // starting from given page, disable all next buttons, and disable
+ // swiping to the right.
+ public void disableAllNextActions(int page) {
+ // first disable next buttons
+ if (container != null)
+ for (int i = page; i < container.getChildCount(); i++) {
+ // get the pageview container
+ View pageContainer = (View) container.getChildAt(i);
+ // last page doesn't have a next button
+ View nextButton = pageContainer
+ .findViewById(R.id.wizard_next_button);
+ if (nextButton != null)
+ nextButton.setEnabled(false);
+ }
+ // user can't scroll past current page
+ maxScrollX = page * getMeasuredWidth();
+ }
+
+ // disable/enable all buttons for given page
+ public void setNavButtonStateOnPage(int page, boolean state, int page_type) {
+ // get the pageview container
+ View pageContainer = (View) container.getChildAt(page);
+ Button prevButton = (Button) pageContainer
+ .findViewById(R.id.wizard_previous_button);
+ Button nextButton = (Button) pageContainer
+ .findViewById(R.id.wizard_next_button);
+ switch (page_type) {
+ case FIRST_PAGE:
+ setButtonState(nextButton, state, nextPageButtonListener);
+ break;
+ case MIDDLE_PAGE:
+ setButtonState(prevButton, state, previousPageButtonListener);
+ setButtonState(nextButton, state, nextPageButtonListener);
+ break;
+ case LAST_PAGE:
+ setButtonState(prevButton, state, previousPageButtonListener);
+ // Button done=(Button)
+ // pageContainer.findViewById(R.id.wizard_done_button);
+ // done.setEnabled(false);
+ break;
+ }
+ }
+
+ // enable prev/next buttons for give page and allow scrolling
+ // to next page
+ public void enablePage(int page) {
+ if (page == -1) {
+ maxScrollX = 0;
+ maxEnabledPage = -1;
+ return;
+ }
+ // figure out page type
+ int page_type = MIDDLE_PAGE;
+ if (page == getNumberOfPages() - 1)
+ page_type = LAST_PAGE;
+ else if (page == 0)
+ page_type = 0;
+ setNavButtonStateOnPage(page, true, page_type);
+ maxScrollX = (page + 1) * getMeasuredWidth();
+ maxEnabledPage = (page > maxEnabledPage) ? page : maxEnabledPage;
+ }
+
+ public int getNumberOfPages() {
+ return container.getChildCount();
+ }
+
+ public int getCurrentPage() {
+ return currentPage;
+ }
+
+ public void setCurrentPage(int i) {
+ currentPage = i;
+ }
+
+ // used for orientation change
+ public void restoreLastPage() {
+ SharedPreferences prefs = ((Activity) getContext()).getPreferences(0);
+ currentPage = prefs.getInt("currentPage", 0);
+ maxEnabledPage = prefs.getInt("maxEnabledPage", -1);
+ // scroll to last loaded page
+ post(new Runnable() {
+ @Override
+ public void run() {
+ enablePage(maxEnabledPage);
+ scrollTo(currentPage * getMeasuredWidth(), 0);
+ }
+ });
+ }
+
+ // ditto
+ public void saveCurrentPage() {
+ SharedPreferences prefs = ((Activity) getContext()).getPreferences(0);
+ SharedPreferences.Editor editor = prefs.edit();
+ // save current page
+ editor.putInt("currentPage", getCurrentPage());
+ editor.putInt("maxEnabledPage", maxEnabledPage);
+ editor.commit();
+ }
+
+ // adds a new page with the given resource id
+ 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) {
+ for (int i = container.getChildCount() - 1; i >= page; i--)
+ container.removeViewAt(i);
+ }
+
+ // START OF CODE TO HANDLE SWIPING/SCROLLING
+
+ // if scroll more than %25 of screen width, then automagically
+ // scroll to next page
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ boolean actionUp = false;
+ // If the user swipes
+ if (mGestureDetector.onTouchEvent(event))
+ return true;
+ // else
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_POINTER_UP:
+ case MotionEvent.ACTION_CANCEL:
+ int scrollX = getScrollX();
+ int featureWidth = getMeasuredWidth();
+ // if scroll more than %25 of width, then go to next page
+ currentPage = ((scrollX + (featureWidth / 4 * 3)) / featureWidth);
+ Log.d(TAG, "scrollX: " + scrollX + " featureWidth: "
+ + (featureWidth / 4 * 3) + " page: " + currentPage);
+ int scrollTo = currentPage * featureWidth;
+ smoothScrollTo(scrollTo, 0);
+ // if you don't return true, a child view will interfere
+ // with the scrolling
+ actionUp = true;
+ break;
+ default:
+ break;
+ }
+ return actionUp;
+ }
+
+ // Basically, keep HorizontalScrollView from scrolling past current
+ // page, until it's OK to do so (ex: user puts password)
+ @Override
+ public void onScrollChanged(int l, int t, int oldl, int oldt) {
+ // Log.d(TAG,"scroll: "+l+", "+oldl+" maxscroll: "+maxScrollX);
+ if (l > maxScrollX) {
+ // if trying to scroll past maximum allowed, then snap back
+ scrollTo(oldl, 0);
+ // recalculate current page if necessary
+ currentPage = (currentPage * getMeasuredWidth() == maxScrollX) ? --currentPage
+ : currentPage;
+ } else
+ super.onScrollChanged(l, t, oldl, oldt);
+ }
+
+ class NextPageButtonListener implements View.OnClickListener {
+ @Override
+ public void onClick(View v) {
+ scrollRight();
+ }
+ }
+
+ class PreviousPageButtonListener implements View.OnClickListener {
+ @Override
+ public void onClick(View v) {
+ scrollLeft();
+ }
+ }
+
+ // hide keyboard if showing
+ private void hideKeyboard() {
+ InputMethodManager imm = (InputMethodManager) ((Activity) getContext())
+ .getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(getWindowToken(), 0);
+ }
+
+ private void scrollRight() {
+ hideKeyboard();
+ // unfocus login boxes
+ View selectedBox = findFocus();
+ if (selectedBox != null)
+ selectedBox.clearFocus();
+ // scroll
+ int featureWidth = getMeasuredWidth();
+ currentPage = (currentPage < (container.getChildCount() - 1)) ? currentPage + 1
+ : container.getChildCount() - 1;
+ smoothScrollTo(currentPage * featureWidth, 0);
+
+ }
+
+ private void scrollLeft() {
+ hideKeyboard();
+ // unfocus login boxes
+ View selectedBox = findFocus();
+ if (selectedBox != null)
+ selectedBox.clearFocus();
+ // scroll
+ int featureWidth = getMeasuredWidth();
+ currentPage = (currentPage > 0) ? currentPage - 1 : 0;
+ smoothScrollTo(currentPage * featureWidth, 0);
+ }
+
+ private class PageSwipeDetector extends SimpleOnGestureListener {
+ @Override
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
+ float velocityY) {
+ if (velocityX < 0 && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
+ scrollRight();
+ return true;
+ }
+ // left to right
+ else if (velocityX > 0
+ && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
+ scrollLeft();
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onDown(MotionEvent e) {
+ return true;
+ }
+ }
+}
View
65 src/com/matburt/mobileorg/Gui/Wizard/Wizards/DropboxDirectoryBrowser.java
@@ -0,0 +1,65 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import java.io.File;
+
+import android.content.Context;
+import android.util.Log;
+
+import com.dropbox.client2.DropboxAPI;
+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> {
+
+ private DropboxAPI<AndroidAuthSession> dropbox;
+
+ DropboxDirectoryBrowser(Context context,
+ DropboxAPI<AndroidAuthSession> dropboxApi) {
+ super(context);
+ this.dropbox = dropboxApi;
+
+ browseTo(File.separator);
+ }
+
+ @Override
+ public boolean isCurrentDirectoryRoot() {
+ return currentDirectory.equals(File.separator);
+ }
+
+ @Override
+ public void browseTo(int position) {
+ browseTo(getDir(position));
+ }
+
+ @Override
+ public void browseTo(String directory) {
+ currentDirectory = directory;
+ directoryNames.clear();
+ directoryListing.clear();
+ if (!isCurrentDirectoryRoot()) {
+ directoryNames.add(upOneLevel);
+ directoryListing.add(getParentPath(currentDirectory));
+ }
+
+ try {
+ Entry entries = dropbox.metadata(directory, 1000, null, true, null);
+
+ for (Entry e : entries.contents) {
+ if (e.isDir) {
+ directoryNames.add(e.fileName());
+ directoryListing.add(e.path);
+ }
+ }
+ } catch (DropboxException e) {
+ Log.d("MobileOrg",
+ "Failed to list directory for dropbox: " + e.toString());
+ }
+ }
+
+ private static String getParentPath(String path) {
+ int ind = path.lastIndexOf(File.separatorChar);
+ return path.substring(0, ind + 1);
+ }
+}
View
164 src/com/matburt/mobileorg/Gui/Wizard/Wizards/DropboxWizard.java
@@ -0,0 +1,164 @@
+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 FolderAdapter directoryAdapter;
+
+ 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() {
+ 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);
+ }
+ }
+ });
+
+ 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
+ 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();
+
+ setupDoneButton(view);
+ wizardView.addPage(view);
+ wizardView.enablePage(1);
+ // enable nav buttons on that page
+ wizardView.setNavButtonStateOnPage(2, true, WizardView.LAST_PAGE);
+
+ return view;
+ }
+
+ @Override
+ public void refresh() {
+ handleDropboxResume();
+ }
+
+ 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.putString("dropboxPath", directoryAdapter.getCheckedDirectory() + "/");
+ editor.commit();
+ }
+}
View
43 src/com/matburt/mobileorg/Gui/Wizard/Wizards/NullWizard.java
@@ -0,0 +1,43 @@
+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.content.SharedPreferences;
+import android.preference.PreferenceManager;
+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() {
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.wizard_null, null);
+
+ setupDoneButton(view);
+ wizardView.addPage(view);
+ wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
+ wizardView.enablePage(1);
+ }
+
+ @Override
+ public void saveSettings() {
+ SharedPreferences appSettings = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = appSettings.edit();
+
+ editor.putString("syncSource", "null");
+ editor.commit();
+ }
+}
View
62 src/com/matburt/mobileorg/Gui/Wizard/Wizards/SDCardWizard.java
@@ -0,0 +1,62 @@
+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() {
+ 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();
+
+ setupDoneButton(view);
+ 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
144 src/com/matburt/mobileorg/Gui/Wizard/Wizards/SSHWizard.java
@@ -0,0 +1,144 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+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.TextView;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+import com.matburt.mobileorg.Synchronizers.SSHSynchronizer;
+
+public class SSHWizard extends Wizard {
+ public static final int SSH_CHOOSE_PUB = 1;
+
+ private EditText sshUser;
+ private EditText sshPass;
+ private EditText sshPath;
+ private EditText sshHost;
+ private EditText sshPort;
+
+ private TextView sshPubFileActual;
+ private final String pubFileActual = sshPubFileActual.getText().toString();
+
+ public SSHWizard(WizardView wizardView, Context context) {
+ super(wizardView, context);
+ }
+
+
+ @Override
+ public void setupFirstPage() {
+ createSSHConfig();
+ }
+
+ public View createSSHConfig() {
+ 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);
+ sshPubFileActual = (TextView) view
+ .findViewById(R.id.wizard_ssh_pub_file_actual);
+ Button sshPubFileSelect = (Button) view
+ .findViewById(R.id.wizard_ssh_choose_pub_file);
+ sshPubFileSelect.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType("file/*");
+ ((Activity)context).startActivityForResult(intent, SSH_CHOOSE_PUB);
+ } catch (Exception e) {
+ }
+ }
+ });
+
+
+ Button webdavLoginButton = (Button) view
+ .findViewById(R.id.wizard_ssh_login_button);
+ webdavLoginButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ loginSSH();
+ }
+ });
+
+ setupDoneButton(view);
+ 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, pubFileActual);
+ if (extra != null) {
+ showToastRemote("Login failed: " + extra);
+ return;
+ }
+ showToastRemote("Login succeeded");
+ }
+ };
+ loginThread.start();
+ }
+
+ public void setPubFile(String pubfile) {
+ this.sshPubFileActual.setText(pubfile);
+ }
+
+ 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.putString("scpPubFile", sshPubFileActual.getText().toString());
+
+ editor.commit();
+ }
+}
View
56 src/com/matburt/mobileorg/Gui/Wizard/Wizards/UbuntuOneDirectoryBrowser.java
@@ -0,0 +1,56 @@
+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> {
+ private UbuntuOneSynchronizer synchronizer;
+
+ public UbuntuOneDirectoryBrowser(Context context, UbuntuOneSynchronizer synchronizer) {
+ super(context);
+ this.synchronizer = synchronizer;
+
+ browseTo(File.separator);
+ }
+
+ @Override
+ public boolean isCurrentDirectoryRoot() {
+ return currentDirectory.equals(File.separator);
+ }
+
+ @Override
+ public void browseTo(int position) {
+ browseTo(getDir(position));
+ }
+
+ @Override
+ public void browseTo(String directory) {
+ currentDirectory = directory;
+ directoryNames.clear();
+ directoryListing.clear();
+ if (!isCurrentDirectoryRoot()) {
+ directoryNames.add(upOneLevel);
+ directoryListing.add(getParentPath(currentDirectory));
+ Log.d("MobileOrg", "Current directory: " + currentDirectory);
+ Log.d("MobileOrg", "Parent path: "
+ + getParentPath(currentDirectory));
+ }
+ for (String item : synchronizer.getDirectoryList(directory)) {
+ directoryNames.add(item);
+ directoryListing.add(item);
+ }
+ }
+
+ private static String getParentPath(String path) {
+ if (path.charAt(path.length() - 1) == File.separatorChar) {
+ path = path.substring(0, path.length() - 1);
+ }
+ int ind = path.lastIndexOf(File.separatorChar);
+ return path.substring(0, ind + 1);
+ }
+}
View
130 src/com/matburt/mobileorg/Gui/Wizard/Wizards/UbuntuOneWizard.java
@@ -0,0 +1,130 @@
+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() {
+ 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) view.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
+
+ setupDoneButton(view);
+ 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
100 src/com/matburt/mobileorg/Gui/Wizard/Wizards/WebDAVWizard.java
@@ -0,0 +1,100 @@
+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();
+ }
+ });
+
+ setupDoneButton(view);
+ 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
123 src/com/matburt/mobileorg/Gui/Wizard/Wizards/Wizard.java
@@ -0,0 +1,123 @@
+package com.matburt.mobileorg.Gui.Wizard.Wizards;
+
+import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardView;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+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));
+
+ wizardView.removePagesAfter(1);
+ setupFirstPage();
+ }
+
+ public void setupDoneButton(View view) {
+ Button doneButton = (Button) view.findViewById(R.id.wizard_done_button);
+ doneButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ saveSettings();
+ ((Activity) context).finish();
+ }
+ });
+ }
+
+ public abstract void setupFirstPage();
+
+ public void refresh() {
+ }
+
+ 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;
+ }
+}
View
4 src/com/matburt/mobileorg/Services/CalendarSyncService.java
@@ -71,7 +71,11 @@ public void onDestroy() {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent == null)
+ return 0;
+
refreshPreferences();
+
final String[] fileList = intent.getStringArrayExtra(FILELIST);
final boolean clearDB = intent.getBooleanExtra(CLEARDB, false);
final boolean pull = intent.getBooleanExtra(PULL, false);
View
2 src/com/matburt/mobileorg/Settings/SettingsActivity.java
@@ -17,6 +17,7 @@
import com.actionbarsherlock.app.SherlockPreferenceActivity;
import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Wizard.WizardActivity;
import com.matburt.mobileorg.OrgData.OrgProviderUtils;
import com.matburt.mobileorg.Services.CalendarSyncService;
import com.matburt.mobileorg.Services.CalendarWrapper;
@@ -104,7 +105,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
}
private Preference.OnPreferenceClickListener onClearDBClick = new Preference.OnPreferenceClickListener() {
-
@Override
public boolean onPreferenceClick(Preference preference) {
new AlertDialog.Builder(SettingsActivity.this)
View
678 src/com/matburt/mobileorg/Settings/WizardActivity.java
<
@@ -1,678 +0,0 @@
-package com.matburt.mobileorg.Settings;
-
-import java.util.ArrayList;
-
-import android.app.Activity;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-import android.content.res.Resources;
-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.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-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.Views.PageFlipView;
-import com.matburt.mobileorg.util.OrgUtils;
-
-public class WizardActivity extends Activity {
-
- private final class UIHandler extends Handler
- {
- public static final int DISPLAY_UI_TOAST = 0;
-// public static final int DISPLAY_UI_DIALOG = 1;
-
- public UIHandler(Looper looper)
- {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg)
- {
- switch(msg.what)
- {
- case UIHandler.DISPLAY_UI_TOAST:
- {
- Context context = getApplicationContext();
- Toast t = Toast.makeText(context, (String)msg.obj, Toast.LENGTH_LONG);
- progress.dismiss();
- t.show();
- }
- default:
- break;
- }
- }
- }
-
-
- static String TAG="WizardActivity";
-
- //container
- PageFlipView wizard;
- //page 1 variables
- String syncSource;
- int syncWebDav, syncDropBox, syncUbuntuOne, syncSdCard, syncNull, syncSSH;
- RadioGroup syncGroup;
- //page 2 variables
- View loginPage;
- boolean loginAdded=false;
- Button loginButton;
- ProgressDialog progress;
- //dropbox variables
- DropboxAPI<AndroidAuthSession> dropboxApi;
- TextView dropboxAccountInfo;
- boolean dropboxLoginAttempted = false;
- boolean isLoggedIn=false;
- ArrayAdapter<String> dropboxFolders;
- //ubuntuone variables
- EditText ubuntuoneEmail;
- EditText ubuntuonePass;
- //sd card variables
- DirectoryBrowser directory;
- FolderAdapter directoryAdapter;
- String indexFilePath = "";
- //webdav variables
- EditText webdavUser;
- EditText webdavPass;
- EditText webdavUrl;
- Button webdavLoginButton;
- //ssh variables
- EditText sshUser;
- EditText sshPass;
- EditText sshPath;
- EditText sshHost;
- EditText sshPort;
- TextView sshPubFileActual;
- Button sshPubFileSelect;
- Button sshLoginButton;
- //page 3 variables
- ListView folderList;
- ArrayList<String> folders;
- Button doneButton;
- String dropboxPath = "";
-
- UIHandler uiHandler;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- OrgUtils.setTheme(this);
- super.onCreate(savedInstanceState);
- setContentView(R.layout.wizard);
- wizard = (PageFlipView) findViewById(R.id.wizard_parent);
- //setup page 1
- //get ids and pointers to sync radio buttons
- syncGroup = (RadioGroup)findViewById(R.id.sync_group);
- syncWebDav = ((RadioButton)findViewById(R.id.sync_webdav)).getId();
- syncDropBox = ((RadioButton)findViewById(R.id.sync_dropbox)).getId();
- syncUbuntuOne = ((RadioButton)findViewById(R.id.sync_ubuntuone)).getId();
- syncSdCard = ((RadioButton)findViewById(R.id.sync_sdcard)).getId();
- syncNull = ((RadioButton)findViewById(R.id.sync_null)).getId();
- syncSSH = ((RadioButton)findViewById(R.id.sync_ssh)).getId();
- syncGroup.clearCheck();
- syncGroup.setOnCheckedChangeListener(new Page1Listener());
- //setup dropbox
- Resources r = getResources();
- //setup progress dialog
- progress = new ProgressDialog(this);
- progress.setMessage(getString(R.string.please_wait));
- progress.setTitle(getString(R.string.signing_in));
- //when wizard first starts can't go to next page
- wizard.setNavButtonStateOnPage(0, false, PageFlipView.FIRST_PAGE );
- }
-
- /**
- * Upon being resumed we can retrieve the current state. This allows us
- * to update the state if it was changed at any time while paused.
- */
- @Override
- protected void onResume() {
- super.onResume();
- //wizard.restoreLastPage();
-
- 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();
- wizard.enablePage( 1 );
- } catch (IllegalStateException e) {
- showToast(String.format("Login failed: %s", e.toString()));
- }
- }
- }
-
- /**
- * Any time we are paused we need to save away the current state, so it
- * will be restored correctly when we are resumed.
- */
- @Override
- protected void onPause() {
- super.onPause();
- wizard.saveCurrentPage();
- }
-
- class Page1Listener implements RadioGroup.OnCheckedChangeListener {
-
- @Override
- public void onCheckedChanged(RadioGroup arg, int checkedId) {
- if (checkedId == syncWebDav) {
- syncSource = "webdav";
- createWebDAVConfig();
- }
- else if (checkedId == syncDropBox) {
- syncSource = "dropbox";
- createDropboxLogin();
- }
- else if (checkedId == syncUbuntuOne) {
- syncSource = "ubuntu";
- createUbuntuLogin();
- }
- else if (checkedId == syncSdCard) {
- syncSource = "sdcard";
- createSDcardFolderSelector();
- }
- else if (checkedId == syncSSH) {
- syncSource = "scp";
- createSSHConfig();
- }
- else if (checkedId == syncNull) {
- syncSource = "null";
- createNullConfig();
- }
- //allow scrolling to next page
- wizard.enablePage( 0 );
- //debug
- //createDropboxList();
- //wizard.enablePage(1);
- }
- }
-
- void createNullConfig() {
- wizard.removePagesAfter(1);
- wizard.addPage(R.layout.wizard_null);
- doneButton = (Button) findViewById(R.id.wizard_done_button);
- wizard.setNavButtonStateOnPage(1, true, PageFlipView.LAST_PAGE);
- wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
- wizard.enablePage(1);
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == 1) {
- if(resultCode==RESULT_OK){
- String filePath = data.getData().getPath();
- sshPubFileActual.setText(filePath);
- }
- }
- }
-
- void createSSHConfig() {
- wizard.removePagesAfter(1);
- wizard.addPage(R.layout.wizard_ssh);
- sshUser = (EditText) wizard.findViewById(R.id.wizard_ssh_username);
- sshPass = (EditText) wizard.findViewById(R.id.wizard_ssh_password);
- sshPath = (EditText) wizard.findViewById(R.id.wizard_ssh_path);
- sshHost = (EditText) wizard.findViewById(R.id.wizard_ssh_host);
- sshPort = (EditText) wizard.findViewById(R.id.wizard_ssh_port);
- sshPubFileActual = (TextView) wizard.findViewById(R.id.wizard_ssh_pub_file_actual);
- sshPubFileSelect = (Button)wizard.findViewById(R.id.wizard_ssh_choose_pub_file);
- sshPubFileSelect.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType("file/*");
- startActivityForResult(intent,1);
- } catch (Exception e) { }
- }
- });
- webdavLoginButton = (Button) wizard.findViewById(R.id.wizard_ssh_login_button);
- doneButton = (Button) findViewById(R.id.wizard_done_button);
- webdavLoginButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- loginSSH();
- }
- });
- wizard.setNavButtonStateOnPage(1, true, PageFlipView.LAST_PAGE);
- wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
- wizard.enablePage(1);
- }
-
- void createWebDAVConfig() {
- wizard.removePagesAfter(1);
- wizard.addPage(R.layout.wizard_webdav);
- webdavUser = (EditText) wizard.findViewById(R.id.wizard_webdav_username);
- webdavPass = (EditText) wizard.findViewById(R.id.wizard_webdav_password);
- webdavUrl = (EditText) wizard.findViewById(R.id.wizard_webdav_url);
- webdavLoginButton = (Button) wizard.findViewById(R.id.wizard_webdav_login_button);
- doneButton = (Button) findViewById(R.id.wizard_done_button);
- webdavLoginButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- loginWebdav();
- }
- });
- wizard.setNavButtonStateOnPage(1, true, PageFlipView.LAST_PAGE);
- wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
- wizard.enablePage(1);
- }
-
- void createSDcardFolderSelector() {
- wizard.removePagesAfter(1);
- //add folder listview to wizard
- wizard.addPage( R.layout.wizard_folder_pick_list );
- //enable nav buttons on that page
- wizard.setNavButtonStateOnPage(1,true,PageFlipView.LAST_PAGE);
- wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
-
- //setup directory browser
- directory = new DirectoryBrowser.LocalDirectoryBrowser(this);
- //setup directory browser adapter
- directoryAdapter = new FolderAdapter( this, R.layout.folder_adapter_row, directory.list() );
- directoryAdapter.setDoneButton( (Button) findViewById(R.id.wizard_done_button) );
- //bind adapter to browser
- directoryAdapter.setDirectoryBrowser( directory );
-
- //bind adapter to listview
- folderList = (ListView) wizard.findViewById(R.id.wizard_folder_list);
- folderList.setAdapter( directoryAdapter );
- directoryAdapter.notifyDataSetChanged();
- }
-
- void createDropboxLogin() {
- wizard.removePagesAfter( 1 );
- //add login page to wizard
- wizard.addPage( R.layout.wizard_dropbox );
- //enable nav buttons on that page
- wizard.setNavButtonStateOnPage(1, true, PageFlipView.MIDDLE_PAGE);
- wizard.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) wizard
- .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);
- }
- }
- });
- }
-
- 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() {
- final String pathActual = sshPath.getText().toString();
- final String passActual = sshPass.getText().toString();
- final String userActual = sshUser.getText().toString();
- final String hostActual = sshHost.getText().toString();
- final String pubFileActual = sshPubFileActual.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, pubFileActual);
- if (extra != null) {
- showToastRemote("Login failed: " + extra);
- return;
- }
- showToastRemote("Login succeeded");
- }
- };
- loginThread.start();
- }
-
- 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();
- }
-
- 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);
- wizard.enablePage( 1 );
- uos.getBaseUser();
- createUbuntuOneList();
- }
- else {
- showToastRemote("Login Failed");
- }
-
- }
-
- void showToast(String msg) {
- Toast error = Toast.makeText(this, msg, Toast.LENGTH_LONG);
- error.show();
- }
-
- protected void showToastRemote(String message)
- {
- Message msg = uiHandler.obtainMessage(UIHandler.DISPLAY_UI_TOAST);
- msg.obj = message;
- uiHandler.sendMessage(msg);
- }
-
- void shake(View b) {
- Animation shake = AnimationUtils
- .loadAnimation(this, R.anim.shake);
- b.startAnimation(shake);
- }
-
- 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();
- }
-
- void createDropboxList() {
- wizard.addPage( R.layout.wizard_folder_pick_list );
- wizard.enablePage( 1 );
- //enable nav buttons on that page
- wizard.setNavButtonStateOnPage(2, true, PageFlipView.LAST_PAGE);
- wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
- //setup directory browser
- directory = new DirectoryBrowser.DropboxDirectoryBrowser(this, dropboxApi);
- //setup directory browser adapter
- directoryAdapter = new FolderAdapter( this, R.layout.folder_adapter_row, directory.list() );
- directoryAdapter.setDoneButton( (Button) findViewById(R.id.wizard_done_button) );
- //bind adapter to browser
- directoryAdapter.setDirectoryBrowser( directory );
- //bind adapter to listview
- folderList = (ListView) wizard.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
- }
-
- void createUbuntuOneList() {
- wizard.addPage(R.layout.wizard_folder_pick_list);
- wizard.enablePage(1);
-
- //enable nav buttons on that page
- wizard.setNavButtonStateOnPage(2, true, PageFlipView.LAST_PAGE);
- wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
-
- //setup directory browser
- UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer((Context)this);
- uos.getBaseUser();
- directory = new DirectoryBrowser.UbuntuOneDirectoryBrowser(this, uos);
-
- //setup directory browser adapter
- directoryAdapter = new FolderAdapter( this, R.layout.folder_adapter_row, directory.list() );
- directoryAdapter.setDoneButton( (Button) findViewById(R.id.wizard_done_button) );
-
- //bind adapter to browser
- directoryAdapter.setDirectoryBrowser( directory );
-