Browse Source

launch add account when no accounts

tags/0.0.5
Robin Thoni 9 years ago
parent
commit
dddd6deeb8

+ 0
- 8
app/src/main/java/com/rthoni/camotion/business/CamotionAccountBusiness.java View File

19
  * Created by robin on 11/28/15.
19
  * Created by robin on 11/28/15.
20
  */
20
  */
21
 public class CamotionAccountBusiness extends Service {
21
 public class CamotionAccountBusiness extends Service {
22
-    /**
23
-     * The tag used for the logs.
24
-     */
25
-    private static final String LOG_TAG = CamotionAccountBusiness.class.getSimpleName();
26
 
22
 
27
     /**
23
     /**
28
      * The implementation of the class |AccountAuthenticatorImpl|.
24
      * The implementation of the class |AccountAuthenticatorImpl|.
44
      */
40
      */
45
     @Override
41
     @Override
46
     public IBinder onBind(Intent intent) {
42
     public IBinder onBind(Intent intent) {
47
-        Log.v(CamotionAccountBusiness.LOG_TAG, "Binding the service");
48
         IBinder ret = null;
43
         IBinder ret = null;
49
         if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
44
         if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
50
             ret = getAuthenticator().getIBinder();
45
             ret = getAuthenticator().getIBinder();
90
                                  String authTokenType,
85
                                  String authTokenType,
91
                                  String[] requiredFeatures,
86
                                  String[] requiredFeatures,
92
                                  Bundle options) throws NetworkErrorException {
87
                                  Bundle options) throws NetworkErrorException {
93
-            Log.d(CamotionAccountBusiness.LOG_TAG, "Adding new account");
94
             Bundle reply = new Bundle();
88
             Bundle reply = new Bundle();
95
 
89
 
96
-            Log.d(CamotionAccountBusiness.LOG_TAG, "The auth token type is " + authTokenType);
97
             Intent i = new Intent(mContext, AddAccountActivity.class);
90
             Intent i = new Intent(mContext, AddAccountActivity.class);
98
-            i.setAction("com.gowex.pista.addnewaccount");
99
             i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
91
             i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
100
             i.putExtra("AuthTokenType", authTokenType);
92
             i.putExtra("AuthTokenType", authTokenType);
101
             reply.putParcelable(AccountManager.KEY_INTENT, i);
93
             reply.putParcelable(AccountManager.KEY_INTENT, i);

+ 24
- 0
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java View File

1
 package com.rthoni.camotion.ui;
1
 package com.rthoni.camotion.ui;
2
 
2
 
3
+import android.content.Intent;
3
 import android.content.res.Configuration;
4
 import android.content.res.Configuration;
4
 import android.os.Bundle;
5
 import android.os.Bundle;
5
 import android.os.PersistableBundle;
6
 import android.os.PersistableBundle;
7
+import android.provider.Settings;
6
 import android.support.design.widget.NavigationView;
8
 import android.support.design.widget.NavigationView;
7
 import android.support.v4.view.GravityCompat;
9
 import android.support.v4.view.GravityCompat;
8
 import android.support.v4.widget.DrawerLayout;
10
 import android.support.v4.widget.DrawerLayout;
38
     private SubMenu _locationsMenu;
40
     private SubMenu _locationsMenu;
39
     private NavigationView _navigationView;
41
     private NavigationView _navigationView;
40
 
42
 
43
+    private int _lastView = -1;
44
+
45
+    private static final int REQUEST_CODE_ADD_ACCOUNT = 0;
46
+
41
     @Override
47
     @Override
42
     protected void onCreate(Bundle savedInstanceState) {
48
     protected void onCreate(Bundle savedInstanceState) {
43
         super.onCreate(savedInstanceState);
49
         super.onCreate(savedInstanceState);
70
     private void init()
76
     private void init()
71
     {
77
     {
72
         List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
78
         List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
79
+
80
+        if (locations.isEmpty())
81
+        {
82
+            Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
83
+            intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[]{getResources().getString(R.string.account_type)});
84
+            startActivityForResult(intent, REQUEST_CODE_ADD_ACCOUNT);
85
+            return;
86
+        }
87
+
73
         _locationsMenu.clear();
88
         _locationsMenu.clear();
74
         if (locations.isEmpty()) {
89
         if (locations.isEmpty()) {
75
             return;
90
             return;
95
 
110
 
96
     }
111
     }
97
 
112
 
113
+    @Override
114
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
115
+        super.onActivityResult(requestCode, resultCode, data);
116
+        if (requestCode == REQUEST_CODE_ADD_ACCOUNT)
117
+        {
118
+            init();
119
+        }
120
+    }
121
+
98
     private void setLocation(LocationDbo location)
122
     private void setLocation(LocationDbo location)
99
     {
123
     {
100
         _currentLocation = location;
124
         _currentLocation = location;

+ 1
- 1
app/src/main/res/values/strings.xml View File

22
     <string name="error_username">Username is required</string>
22
     <string name="error_username">Username is required</string>
23
     <string name="error_password">Password is required</string>
23
     <string name="error_password">Password is required</string>
24
     <string name="error_domain">Domain is required</string>
24
     <string name="error_domain">Domain is required</string>
25
-    <string name="account_type">com.rthoni.luticate.account</string>
25
+    <string name="account_type">com.rthoni.camotion.account</string>
26
 
26
 
27
     <string name="loading">Loading…</string>
27
     <string name="loading">Loading…</string>
28
     <string name="login_progress">Logging in…</string>
28
     <string name="login_progress">Logging in…</string>

+ 1
- 1
app/src/main/res/xml/authenticator.xml View File

1
 <?xml version="1.0" encoding="utf-8"?>
1
 <?xml version="1.0" encoding="utf-8"?>
2
 <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
2
 <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
3
-                       android:accountType="com.rthoni.luticate.account"
3
+                       android:accountType="@string/account_type"
4
                        android:icon="@mipmap/ic_launcher"
4
                        android:icon="@mipmap/ic_launcher"
5
                        android:smallIcon="@mipmap/ic_launcher"
5
                        android:smallIcon="@mipmap/ic_launcher"
6
                        android:label="@string/app_name"
6
                        android:label="@string/app_name"

Loading…
Cancel
Save