Browse Source

initial upload

David Development 5 years ago
parent
commit
232336741d

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+/build

+ 78
- 0
AccountImporter.iml View File

@@ -0,0 +1,78 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="News-Android-App" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3
+  <component name="FacetManager">
4
+    <facet type="android-gradle" name="Android-Gradle">
5
+      <configuration>
6
+        <option name="GRADLE_PROJECT_PATH" value=":AccountImporter" />
7
+      </configuration>
8
+    </facet>
9
+    <facet type="android" name="Android">
10
+      <configuration>
11
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
12
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
13
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
14
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
15
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
16
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
17
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
18
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
19
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
20
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
21
+        <option name="LIBRARY_PROJECT" value="true" />
22
+      </configuration>
23
+    </facet>
24
+  </component>
25
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
26
+    <output url="file://$MODULE_DIR$/build/classes/debug" />
27
+    <exclude-output />
28
+    <content url="file://$MODULE_DIR$">
29
+      <sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" />
30
+      <sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" />
31
+      <sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" />
32
+      <sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" />
33
+      <sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" />
34
+      <sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" generated="true" />
35
+      <sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" generated="true" />
36
+      <sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" generated="true" />
37
+      <sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" generated="true" />
38
+      <sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
39
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
40
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
41
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
42
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
43
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
44
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
45
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
46
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
47
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
48
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
49
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
50
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
51
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
52
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
53
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
54
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
55
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
56
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
57
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
58
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
59
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
60
+      <excludeFolder url="file://$MODULE_DIR$/build/apk" />
61
+      <excludeFolder url="file://$MODULE_DIR$/build/assets" />
62
+      <excludeFolder url="file://$MODULE_DIR$/build/bundles" />
63
+      <excludeFolder url="file://$MODULE_DIR$/build/classes" />
64
+      <excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" />
65
+      <excludeFolder url="file://$MODULE_DIR$/build/incremental" />
66
+      <excludeFolder url="file://$MODULE_DIR$/build/libs" />
67
+      <excludeFolder url="file://$MODULE_DIR$/build/manifests" />
68
+      <excludeFolder url="file://$MODULE_DIR$/build/res" />
69
+      <excludeFolder url="file://$MODULE_DIR$/build/symbols" />
70
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
71
+    </content>
72
+    <orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
73
+    <orderEntry type="sourceFolder" forTests="false" />
74
+    <orderEntry type="library" exported="" name="support-v4-19.0.1" level="project" />
75
+    <orderEntry type="library" exported="" name="actionbarsherlock-4.4.0" level="project" />
76
+  </component>
77
+</module>
78
+

+ 27
- 0
build.gradle View File

@@ -0,0 +1,27 @@
1
+apply plugin: 'android-library'
2
+
3
+android {
4
+    compileSdkVersion 19
5
+    buildToolsVersion "19.0.0"
6
+
7
+    defaultConfig {
8
+        packageName "de.luhmer.owncloud.accountimporter"
9
+        minSdkVersion 7
10
+        targetSdkVersion 19
11
+        versionCode 1
12
+        versionName "1.0"
13
+    }
14
+    buildTypes {
15
+        release {
16
+            runProguard false
17
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18
+        }
19
+    }
20
+}
21
+
22
+dependencies {
23
+    compile 'com.android.support:support-v4:19.0.+'
24
+    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
25
+
26
+    compile fileTree(dir: 'libs', include: ['*.jar'])
27
+}

+ 17
- 0
proguard-rules.pro View File

@@ -0,0 +1,17 @@
1
+# Add project specific ProGuard rules here.
2
+# By default, the flags in this file are appended to flags specified
3
+# in C:/Program Files/Android/android-studio/sdk/tools/proguard/proguard-android.txt
4
+# You can edit the include path and order by changing the proguardFiles
5
+# directive in build.gradle.
6
+#
7
+# For more details, see
8
+#   http://developer.android.com/guide/developing/tools/proguard.html
9
+
10
+# Add any project specific keep options here:
11
+
12
+# If your project uses WebView with JS, uncomment the following
13
+# and specify the fully qualified class name to the JavaScript interface
14
+# class:
15
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16
+#   public *;
17
+#}

+ 10
- 0
src/main/AndroidManifest.xml View File

@@ -0,0 +1,10 @@
1
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+    package="de.luhmer.owncloud.accountimporter">
3
+
4
+    <application
5
+        android:label="@string/app_name"
6
+        android:icon="@drawable/ic_launcher">
7
+
8
+    </application>
9
+
10
+</manifest>

+ 101
- 0
src/main/java/de/luhmer/owncloud/accountimporter/ImportAccountsDialogFragment.java View File

@@ -0,0 +1,101 @@
1
+package de.luhmer.owncloud.accountimporter;
2
+
3
+import android.accounts.Account;
4
+import android.annotation.SuppressLint;
5
+import android.annotation.TargetApi;
6
+import android.app.Activity;
7
+import android.app.AlertDialog;
8
+import android.app.Dialog;
9
+import android.content.DialogInterface;
10
+import android.os.Build;
11
+import android.os.Bundle;
12
+import android.support.v4.app.DialogFragment;
13
+import android.support.v4.app.FragmentActivity;
14
+import android.view.View;
15
+import android.widget.Checkable;
16
+import android.widget.ListView;
17
+
18
+import java.util.ArrayList;
19
+import java.util.List;
20
+import java.util.regex.Pattern;
21
+
22
+import de.luhmer.owncloud.accountimporter.adapter.AccountImporterAdapter;
23
+import de.luhmer.owncloud.accountimporter.helper.AccountImporter;
24
+import de.luhmer.owncloud.accountimporter.interfaces.IAccountImport;
25
+
26
+
27
+/**
28
+ * Created by David on 16.05.2014.
29
+ */
30
+@SuppressLint("ValidFragment")
31
+@TargetApi(Build.VERSION_CODES.HONEYCOMB)
32
+public class ImportAccountsDialogFragment extends DialogFragment {
33
+
34
+    public IAccountImport accountImport;
35
+
36
+    public static void show(FragmentActivity activity, IAccountImport accountImport) {
37
+        ImportAccountsDialogFragment selectDialogFragment = newInstance(accountImport);
38
+        selectDialogFragment.show(activity.getSupportFragmentManager(), "dialog");
39
+    }
40
+
41
+    private static ImportAccountsDialogFragment newInstance(IAccountImport accountImport) {
42
+        return new ImportAccountsDialogFragment(accountImport);
43
+    }
44
+
45
+    @SuppressLint("ValidFragment")
46
+    public ImportAccountsDialogFragment(IAccountImport accountImport) {
47
+        this.accountImport = accountImport;
48
+    }
49
+
50
+    @Override
51
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
52
+        View view = getActivity().getLayoutInflater().inflate(R.layout.import_accounts_fragment, null);
53
+
54
+        lvAccounts = (ListView) view.findViewById(R.id.lvAccounts);
55
+
56
+        final List<Account> accounts = AccountImporter.findAccounts(getActivity());
57
+        List<AccountImporterAdapter.SingleAccount> accountList = new ArrayList<AccountImporterAdapter.SingleAccount>();
58
+        for(Account account : accounts) {
59
+            accountList.add(new AccountImporterAdapter.SingleAccount(account.type, account.name, false));
60
+        }
61
+
62
+        lvAccounts.setAdapter(new AccountImporterAdapter(getActivity(), accountList.toArray(new AccountImporterAdapter.SingleAccount[accountList.size()]), lvAccounts));
63
+
64
+        lvAccounts.setItemsCanFocus(false);
65
+        lvAccounts.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
66
+
67
+
68
+        return new AlertDialog.Builder(getActivity())
69
+                .setView(view)
70
+                .setTitle(R.string.import_account_dialog_title)
71
+                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
72
+                    @Override
73
+                    public void onClick(DialogInterface dialogInterface, int x) {
74
+
75
+                        for (int i = 0; i < lvAccounts.getAdapter().getCount(); i++) {
76
+                            if (lvAccounts.getChildAt(i) instanceof Checkable && ((Checkable) lvAccounts.getChildAt(i)).isChecked()) {
77
+
78
+                                AccountImporter.getAuthTokenForAccount(getActivity(), accounts.get(i), accountImport);
79
+
80
+                                /*
81
+                                Intent intent = new Intent(getActivity(), LoginActivity.class);
82
+                                //intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
83
+                                intent.putExtra(LoginActivity.NEW_ACCOUNT, true);
84
+                                intent.putExtra(URL_STRING, calendars.get(i));
85
+                                intent.putExtra(USERNAME_STRING, username);
86
+                                intent.putExtra(PASSWORD_STRING, password);
87
+                                startActivity(intent);
88
+                                */
89
+                            }
90
+                        }
91
+                    }
92
+                })
93
+                .setNegativeButton(android.R.string.no, null)
94
+                .create();
95
+    }
96
+
97
+    ListView lvAccounts;
98
+
99
+
100
+
101
+}

+ 103
- 0
src/main/java/de/luhmer/owncloud/accountimporter/adapter/AccountImporterAdapter.java View File

@@ -0,0 +1,103 @@
1
+package de.luhmer.owncloud.accountimporter.adapter;
2
+
3
+import android.app.Activity;
4
+import android.content.Context;
5
+import android.view.LayoutInflater;
6
+import android.view.View;
7
+import android.view.ViewGroup;
8
+import android.widget.AdapterView;
9
+import android.widget.ArrayAdapter;
10
+import android.widget.CheckBox;
11
+import android.widget.ListView;
12
+import android.widget.TextView;
13
+
14
+import de.luhmer.owncloud.accountimporter.R;
15
+import de.luhmer.owncloud.accountimporter.helper.CheckableLinearLayout;
16
+
17
+/**
18
+ * Created by David on 29.05.2014.
19
+ */
20
+public class AccountImporterAdapter extends ArrayAdapter<AccountImporterAdapter.SingleAccount> implements AdapterView.OnItemClickListener {
21
+
22
+    Context context;
23
+    LayoutInflater inflater;
24
+
25
+    public AccountImporterAdapter(Activity context, SingleAccount[] accounts, ListView listView) {
26
+        super(context, R.layout.simple_list_item_single_choice, accounts);
27
+        this.context = context;
28
+
29
+        listView.setOnItemClickListener(this);
30
+
31
+        inflater = context.getLayoutInflater();
32
+    }
33
+
34
+    @Override
35
+    public View getView(final int position, View view, ViewGroup parent) {
36
+        ViewHolder holder;
37
+
38
+        if (view != null) {
39
+            holder = (ViewHolder) view.getTag();
40
+        } else {
41
+            view = inflater.inflate(R.layout.simple_list_item_single_choice, parent, false);
42
+            TextView text1 = (TextView) view.findViewById(R.id.text1);
43
+            TextView text2 = (TextView) view.findViewById(R.id.text2);
44
+            CheckBox cbChecked = (CheckBox) view.findViewById(R.id.checkbox);
45
+            holder = new ViewHolder(text1, text2, cbChecked);
46
+
47
+            view.setTag(holder);
48
+        }
49
+
50
+        holder.text1.setText(getItem(position).type);
51
+        holder.text2.setText(getItem(position).url);
52
+        holder.cbChecked.setChecked(getItem(position).checked);
53
+
54
+
55
+        return view;
56
+    }
57
+
58
+    @Override
59
+    public void onItemClick(AdapterView<?> adapterView, View view, int id, long l) {
60
+        for (int i = 0; i < getCount(); i++) {
61
+            getItem(i).checked = false;
62
+        }
63
+        ((CheckableLinearLayout)view).toggle();
64
+
65
+
66
+        view.findViewById(R.id.text1);
67
+
68
+        notifyDataSetChanged();
69
+    }
70
+
71
+
72
+
73
+    static class ViewHolder {
74
+        TextView text1;
75
+        TextView text2;
76
+        CheckBox cbChecked;
77
+
78
+        public ViewHolder(TextView text1, TextView text2,CheckBox cbChecked) {
79
+            this.text1 = text1;
80
+            this.text2 = text2;
81
+            this.cbChecked = cbChecked;
82
+        }
83
+    }
84
+
85
+
86
+
87
+
88
+
89
+    public static class SingleAccount {
90
+
91
+        public SingleAccount(String type, String url, Boolean checked) {
92
+            this.type = type;
93
+            this.url = url;
94
+            this.checked = checked;
95
+        }
96
+
97
+        public String type;
98
+        public String url;
99
+
100
+        public boolean checked;
101
+    }
102
+
103
+}

+ 154
- 0
src/main/java/de/luhmer/owncloud/accountimporter/helper/AccountImporter.java View File

@@ -0,0 +1,154 @@
1
+package de.luhmer.owncloud.accountimporter.helper;
2
+
3
+import android.accounts.Account;
4
+import android.accounts.AccountManager;
5
+import android.accounts.AccountManagerCallback;
6
+import android.accounts.AccountManagerFuture;
7
+import android.accounts.OperationCanceledException;
8
+import android.app.Activity;
9
+import android.app.AlertDialog;
10
+import android.os.Bundle;
11
+import android.os.Handler;
12
+
13
+import java.net.URL;
14
+import java.util.ArrayList;
15
+import java.util.List;
16
+
17
+import de.luhmer.owncloud.accountimporter.ImportAccountsDialogFragment;
18
+import de.luhmer.owncloud.accountimporter.interfaces.IAccountImport;
19
+
20
+/**
21
+ * Created by david on 28.05.14.
22
+ */
23
+public class AccountImporter {
24
+
25
+    public static List<Account> findAccounts(Activity activity) {
26
+        final AccountManager accMgr = AccountManager.get(activity);
27
+        final Account[] accounts = accMgr.getAccounts();
28
+
29
+        List<Account> accountsAvailable = new ArrayList<Account>();
30
+        for (Account account : accounts) {
31
+            String aType = account.type.intern();
32
+
33
+            if (//aType.equals("org.dmfs.caldav.account") ||
34
+                // aType.equals("org.dmfs.carddav.account") ||
35
+                    aType.equals("de.luhmer.tasksync") ||
36
+                            aType.equals("owncloud")) {
37
+                //accountsAvailable.add(accounts[index].type);
38
+                accountsAvailable.add(account);
39
+            }
40
+        }
41
+
42
+        return accountsAvailable;
43
+    }
44
+
45
+
46
+
47
+
48
+    public static void getAuthTokenForAccount(Activity activity, final Account account, final IAccountImport accountImport) {
49
+
50
+
51
+        final AccountManager accMgr = AccountManager.get(activity);
52
+        /*
53
+        accMgr.getAuthToken(account, AccountGeneral.ACCOUNT_TYPE, null, activity, new AccountManagerCallback<Bundle>() {
54
+            public void run(AccountManagerFuture<Bundle> future) {
55
+                try {
56
+                    // If the user has authorized your application to use the tasks API
57
+                    // a token is available.
58
+                    String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
59
+                    // Now you can use the Tasks API...
60
+                    if(accountImport != null) {
61
+                        accountImport.accountAccessGranted(account, token);
62
+                    }
63
+                } catch (OperationCanceledException e) {
64
+                    e.printStackTrace();
65
+                    // TODO: The user has denied you access to the API, you should handle that
66
+                } catch (Exception e) {
67
+                    e.printStackTrace();
68
+                }
69
+            }
70
+        }, null);
71
+        */
72
+
73
+
74
+        /*
75
+        if(accountImport != null) {
76
+            accountImport.accountAccessGranted(account, null);
77
+        }
78
+        */
79
+
80
+        //accMgr.invalidateAuthToken(account.type, AccountGeneral.ACCOUNT_TYPE);
81
+        //accMgr.invalidateAuthToken(account.type, null);
82
+
83
+        final AlertDialog aDialog = new AlertDialog.Builder(activity)
84
+                                    .setTitle("Account Importer")
85
+                                    .setMessage("Please grant access to the selected account in the notification bar!")
86
+                                    .create();
87
+
88
+        aDialog.show();
89
+
90
+        String authTokenType;
91
+        if(account.type.equals("owncloud")) {
92
+            authTokenType = "owncloud.password";
93
+        } else {
94
+            authTokenType = "de.luhmer.tasksync";
95
+        }
96
+
97
+
98
+        final Handler handler = new Handler();
99
+        accMgr.getAuthToken(account, authTokenType, true,
100
+                new AccountManagerCallback<Bundle>() {
101
+
102
+                    @Override
103
+                    public void run(AccountManagerFuture<Bundle> future) {
104
+
105
+                        try {
106
+                            // If the user has authorized your application to use the tasks API
107
+                            // a token is available.
108
+                            //String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
109
+                            // Now you can use the Tasks API...
110
+                            if(accountImport != null) {
111
+                                accountImport.accountAccessGranted(HandleResult(account, future.getResult()));
112
+                            }
113
+                        } catch (OperationCanceledException e) {
114
+                            e.printStackTrace();
115
+                            // TODO: The user has denied you access to the API, you should handle that
116
+                        } catch (Exception e) {
117
+                            e.printStackTrace();
118
+                        }
119
+
120
+                        aDialog.dismiss();
121
+
122
+                    }
123
+                }, handler
124
+
125
+        );
126
+    }
127
+
128
+    private static OwnCloudAccount HandleResult(Account account, Bundle data) {
129
+        int lastAtPos = account.name.lastIndexOf("@");
130
+        String urlString = account.name.substring(lastAtPos + 1);
131
+        String username = account.name.substring(0, lastAtPos);
132
+
133
+        if(!urlString.startsWith("http"))
134
+            urlString = "https://" + urlString;
135
+
136
+        String password = data.getString(AccountManager.KEY_AUTHTOKEN);
137
+
138
+
139
+        try {
140
+            final String urlStringOrig = urlString;
141
+            URL url = new URL(urlStringOrig);
142
+            urlString = url.getProtocol() + "://" + url.getHost();
143
+            if(url.getPath().contains("/owncloud")) {
144
+                urlString += url.getPath().substring(0, url.getPath().indexOf("/owncloud") + 9);
145
+            } else if(url.getPath().contains("/")) {
146
+                urlString += url.getPath().substring(0, url.getPath().indexOf("/"));
147
+            }
148
+        } catch(Exception ex) {
149
+            ex.printStackTrace();
150
+        }
151
+
152
+        return new OwnCloudAccount(username, password, urlString);
153
+    }
154
+}

+ 53
- 0
src/main/java/de/luhmer/owncloud/accountimporter/helper/CheckableLinearLayout.java View File

@@ -0,0 +1,53 @@
1
+package de.luhmer.owncloud.accountimporter.helper;
2
+
3
+
4
+import android.content.Context;
5
+import android.util.AttributeSet;
6
+import android.view.View;
7
+import android.widget.CheckBox;
8
+import android.widget.Checkable;
9
+import android.widget.LinearLayout;
10
+
11
+/**
12
+ * Created by David on 29.05.2014.
13
+ */
14
+
15
+public class CheckableLinearLayout extends LinearLayout implements Checkable {
16
+    private CheckBox _checkbox;
17
+
18
+    public CheckableLinearLayout(Context context, AttributeSet attrs) {
19
+        super(context, attrs);
20
+    }
21
+
22
+    @Override
23
+    protected void onFinishInflate() {
24
+        super.onFinishInflate();
25
+        // find checked text view
26
+        int childCount = getChildCount();
27
+        for (int i = 0; i < childCount; ++i) {
28
+            View v = getChildAt(i);
29
+            if (v instanceof CheckBox) {
30
+                _checkbox = (CheckBox)v;
31
+            }
32
+        }
33
+    }
34
+
35
+    @Override
36
+    public boolean isChecked() {
37
+        return _checkbox != null ? _checkbox.isChecked() : false;
38
+    }
39
+
40
+    @Override
41
+    public void setChecked(boolean checked) {
42
+        if (_checkbox != null) {
43
+            _checkbox.setChecked(checked);
44
+        }
45
+    }
46
+
47
+    @Override
48
+    public void toggle() {
49
+        if (_checkbox != null) {
50
+            _checkbox.toggle();
51
+        }
52
+    }
53
+}

+ 38
- 0
src/main/java/de/luhmer/owncloud/accountimporter/helper/OwnCloudAccount.java View File

@@ -0,0 +1,38 @@
1
+package de.luhmer.owncloud.accountimporter.helper;
2
+
3
+import java.util.regex.Pattern;
4
+
5
+import de.luhmer.owncloud.accountimporter.ImportAccountsDialogFragment;
6
+
7
+/**
8
+ * Created by David on 05.06.2014.
9
+ */
10
+public class OwnCloudAccount {
11
+    String url;
12
+    String username;
13
+    String password;
14
+
15
+    public OwnCloudAccount(String username, String password, String url) {
16
+        this.username = username;
17
+        this.password = password;
18
+        this.url = validateURL(url);
19
+    }
20
+
21
+    public String getUrl() {
22
+        return url;
23
+    }
24
+
25
+    public String getUsername() {
26
+        return username;
27
+    }
28
+
29
+    public String getPassword() {
30
+        return password;
31
+    }
32
+
33
+
34
+    static final Pattern RemoveAllDoubleSlashes = Pattern.compile("(?<!:)\\/\\/");
35
+    public static String validateURL(String url) {
36
+        return RemoveAllDoubleSlashes.matcher(url).replaceAll("/");
37
+    }
38
+}

+ 15
- 0
src/main/java/de/luhmer/owncloud/accountimporter/interfaces/IAccountImport.java View File

@@ -0,0 +1,15 @@
1
+package de.luhmer.owncloud.accountimporter.interfaces;
2
+
3
+import android.accounts.Account;
4
+import android.os.Bundle;
5
+
6
+import de.luhmer.owncloud.accountimporter.helper.OwnCloudAccount;
7
+
8
+/**
9
+ * Created by David on 28.05.2014.
10
+ */
11
+public interface IAccountImport {
12
+    //public void accountAccessGranted(Account account, Bundle data);
13
+
14
+    public void accountAccessGranted(OwnCloudAccount account);
15
+}

BIN
src/main/res/drawable-hdpi/ic_launcher.png View File


BIN
src/main/res/drawable-mdpi/ic_launcher.png View File


BIN
src/main/res/drawable-xhdpi/ic_launcher.png View File


BIN
src/main/res/drawable-xxhdpi/ic_launcher.png View File


+ 23
- 0
src/main/res/layout/import_accounts_fragment.xml View File

@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4
+    android:orientation="vertical" android:layout_width="match_parent"
5
+    android:layout_height="match_parent">
6
+
7
+
8
+    <ListView
9
+        android:id="@+id/lvAccounts"
10
+        android:layout_width="match_parent"
11
+        android:layout_height="match_parent" />
12
+
13
+
14
+    <!--
15
+    <ProgressBar
16
+        android:id="@+id/pbProgress"
17
+        android:layout_margin="10dp"
18
+        android:layout_width="wrap_content"
19
+        android:layout_height="match_parent"
20
+        android:layout_gravity="center"/>
21
+
22
+        -->
23
+</LinearLayout>

+ 74
- 0
src/main/res/layout/simple_list_item_single_choice.xml View File

@@ -0,0 +1,74 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- Copyright (C) 2008 The Android Open Source Project
3
+
4
+     Licensed under the Apache License, Version 2.0 (the "License");
5
+     you may not use this file except in compliance with the License.
6
+     You may obtain a copy of the License at
7
+
8
+          http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+     Unless required by applicable law or agreed to in writing, software
11
+     distributed under the License is distributed on an "AS IS" BASIS,
12
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+     See the License for the specific language governing permissions and
14
+     limitations under the License.
15
+-->
16
+
17
+<de.luhmer.owncloud.accountimporter.helper.CheckableLinearLayout
18
+    xmlns:android="http://schemas.android.com/apk/res/android"
19
+    android:layout_width="match_parent"
20
+    android:layout_height="50dp"
21
+    android:layout_margin="5dp"
22
+    android:paddingLeft="5dp"
23
+    android:paddingRight="5dp"
24
+    android:orientation="horizontal" >
25
+
26
+    <LinearLayout
27
+        android:layout_width="0dip"
28
+        android:layout_weight="1"
29
+        android:layout_height="match_parent"
30
+        android:orientation="vertical">
31
+
32
+        <TextView
33
+            android:id="@+id/text1"
34
+            android:layout_width="match_parent"
35
+            android:layout_height="0dip"
36
+            android:layout_weight="1"
37
+            android:text="dahsjkfasd"
38
+            android:textSize="17dp"
39
+            android:gravity="center_vertical" />
40
+
41
+        <TextView
42
+            android:id="@+id/text2"
43
+            android:layout_width="match_parent"
44
+            android:layout_height="0dip"
45
+            android:layout_weight="1"
46
+            android:text="dsfjhkafadsjhkas@fdsjfk hld lfdhsjkfldh sajkflh jdaskfhjdkla sfhjdksla fhl"
47
+            android:singleLine="true"
48
+            android:ellipsize="middle"
49
+            android:gravity="center_vertical"
50
+            android:textSize="15dp"/>
51
+    </LinearLayout>
52
+
53
+    <CheckBox
54
+        android:id="@+id/checkbox"
55
+        android:layout_width="wrap_content"
56
+        android:layout_height="match_parent"
57
+        android:focusable="false"/>
58
+
59
+</de.luhmer.owncloud.accountimporter.helper.CheckableLinearLayout>
60
+
61
+    <!--
62
+<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
63
+    android:id="@android:id/text1"
64
+    android:layout_width="match_parent"
65
+    android:layout_height="?android:attr/listPreferredItemHeightSmall"
66
+    android:textAppearance="?android:attr/textAppearanceListItemSmall"
67
+    android:gravity="center_vertical"
68
+    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
69
+    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
70
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
71
+    android:maxLines="2"
72
+    android:ellipsize="marquee"
73
+    />
74
+    -->

+ 7
- 0
src/main/res/values/strings.xml View File

@@ -0,0 +1,7 @@
1
+<resources>
2
+    <string name="app_name">ownCloud Account Importer</string>
3
+
4
+    <!-- Import Accounts -->
5
+    <string name="import_account_dialog_title">Import Account</string>
6
+
7
+</resources>