瀏覽代碼

utils; begin fragments; cameras loading

tags/0.0.5
Robin Thoni 9 年之前
父節點
當前提交
603285fbfc
共有 26 個檔案被更改,包括 760 行新增76 行删除
  1. 1
    0
      app/build.gradle
  2. 17
    0
      app/src/main/java/com/rthoni/camotion/business/CamerasBusiness.java
  3. 23
    0
      app/src/main/java/com/rthoni/camotion/dataaccess/CamerasDataAccess.java
  4. 64
    0
      app/src/main/java/com/rthoni/camotion/dbo/CameraDbo.java
  5. 33
    2
      app/src/main/java/com/rthoni/camotion/dbo/LocationDbo.java
  6. 65
    10
      app/src/main/java/com/rthoni/camotion/ui/MainActivity.java
  7. 36
    5
      app/src/main/java/com/rthoni/camotion/ui/dialogs/LoginDialog.java
  8. 34
    5
      app/src/main/java/com/rthoni/camotion/ui/fragments/CamerasFragment.java
  9. 68
    0
      app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java
  10. 24
    0
      app/src/main/java/com/rthoni/camotion/ui/fragments/CommandsFragment.java
  11. 24
    0
      app/src/main/java/com/rthoni/camotion/ui/fragments/DefaultFragment.java
  12. 24
    0
      app/src/main/java/com/rthoni/camotion/ui/fragments/SensorsFragment.java
  13. 96
    0
      app/src/main/res/layout/commands_layout.xml
  14. 47
    0
      app/src/main/res/layout/default_layout.xml
  15. 96
    0
      app/src/main/res/layout/sensors_layout.xml
  16. 二進制
      libs/android-async-http-1.4.9.jar
  17. 0
    20
      luticateauth/src/main/java/com/luticate/auth/business/LuticateUsersBusiness.java
  18. 1
    1
      luticateauth/src/main/java/com/luticate/auth/dataaccess/LuticatePermissionsDataAccess.java
  19. 2
    2
      luticateauth/src/main/java/com/luticate/auth/dataaccess/LuticateUsersDataAccess.java
  20. 12
    0
      luticateauth/src/main/java/com/luticate/auth/dbo/LuFullLoginDbo.java
  21. 1
    1
      luticateauth/src/main/java/com/luticate/auth/dbo/LuPermissionDbo.java
  22. 1
    1
      luticateutils/build.gradle
  23. 80
    28
      luticateutils/src/main/java/com/luticate/utils/business/LuRequest.java
  24. 9
    0
      luticateutils/src/main/java/com/luticate/utils/dbo/LuDataAccessConfigDbo.java
  25. 1
    1
      settings.gradle
  26. 1
    0
      volley

+ 1
- 0
app/build.gradle 查看文件

@@ -25,4 +25,5 @@ dependencies {
25 25
     compile 'com.android.support:appcompat-v7:22.2.1'
26 26
     compile 'com.android.support:design:22.2.1'
27 27
     compile project(':luticateauth')
28
+    compile project(':luticateutils')
28 29
 }

+ 17
- 0
app/src/main/java/com/rthoni/camotion/business/CamerasBusiness.java 查看文件

@@ -0,0 +1,17 @@
1
+package com.rthoni.camotion.business;
2
+
3
+import com.luticate.utils.business.LuBusinessManager;
4
+import com.luticate.utils.business.LuPromise;
5
+import com.luticate.utils.dbo.LuDataAccessConfigDbo;
6
+import com.rthoni.camotion.dataaccess.CamerasDataAccess;
7
+import com.rthoni.camotion.dbo.CameraDbo;
8
+
9
+/**
10
+ * Created by robin on 12/3/15.
11
+ */
12
+public class CamerasBusiness extends LuBusinessManager {
13
+    public static LuPromise<CameraDbo.MultipleCameraDbo> getAll(LuDataAccessConfigDbo config, int page, int perPage)
14
+    {
15
+        return CamerasDataAccess.getAll(config, page, perPage);
16
+    }
17
+}

+ 23
- 0
app/src/main/java/com/rthoni/camotion/dataaccess/CamerasDataAccess.java 查看文件

@@ -0,0 +1,23 @@
1
+package com.rthoni.camotion.dataaccess;
2
+
3
+import com.luticate.utils.business.LuPromise;
4
+import com.luticate.utils.business.LuRequest;
5
+import com.luticate.utils.dataaccess.LuDataAccess;
6
+import com.luticate.utils.dbo.LuDataAccessConfigDbo;
7
+import com.rthoni.camotion.dbo.CameraDbo;
8
+
9
+import java.util.HashMap;
10
+
11
+/**
12
+ * Created by robin on 12/3/15.
13
+ */
14
+public class CamerasDataAccess extends LuDataAccess {
15
+
16
+    public static LuPromise<CameraDbo.MultipleCameraDbo> getAll(LuDataAccessConfigDbo config, int page, int perPage)
17
+    {
18
+        HashMap<String, String> params = new HashMap<>();
19
+        params.put("page", "" + page);
20
+        params.put("perPage", "" + perPage);
21
+        return LuRequest.get(config, CameraDbo.MultipleCameraDbo.class, "/api/cameras", params);
22
+    }
23
+}

+ 64
- 0
app/src/main/java/com/rthoni/camotion/dbo/CameraDbo.java 查看文件

@@ -0,0 +1,64 @@
1
+package com.rthoni.camotion.dbo;
2
+
3
+import com.luticate.utils.dbo.LuDbo;
4
+import com.luticate.utils.dbo.LuMultipleDbo;
5
+
6
+import org.json.JSONException;
7
+import org.json.JSONObject;
8
+
9
+import java.util.HashMap;
10
+
11
+/**
12
+ * Created by robin on 12/3/15.
13
+ */
14
+public class CameraDbo extends LuDbo {
15
+
16
+    private int _id;
17
+
18
+    private String _name;
19
+
20
+    public String getDescription() {
21
+        return _description;
22
+    }
23
+
24
+    public void setDescription(String description) {
25
+        _description = description;
26
+    }
27
+
28
+    public String getName() {
29
+        return _name;
30
+    }
31
+
32
+    public void setName(String name) {
33
+        _name = name;
34
+    }
35
+
36
+    public int getId() {
37
+        return _id;
38
+    }
39
+
40
+    public void setId(int id) {
41
+        _id = id;
42
+    }
43
+
44
+    private String _description;
45
+
46
+    public static class MultipleCameraDbo extends LuMultipleDbo<CameraDbo> {
47
+    }
48
+
49
+    @Override
50
+    public void fromJson(JSONObject json) throws JSONException {
51
+        _id = json.getInt("Id");
52
+        _description = json.getString("Description");
53
+        _name = json.getString("Name");
54
+    }
55
+
56
+    @Override
57
+    public HashMap<String, Object> toArray() {
58
+        HashMap<String, Object> array = new HashMap<>();
59
+        array.put("Id", _id);
60
+        array.put("Description", _description);
61
+        array.put("Name", _name);
62
+        return array;
63
+    }
64
+}

+ 33
- 2
app/src/main/java/com/rthoni/camotion/dbo/LocationDbo.java 查看文件

@@ -1,11 +1,15 @@
1 1
 package com.rthoni.camotion.dbo;
2 2
 
3
+import com.luticate.auth.dbo.LuFullLoginDbo;
4
+import com.luticate.auth.dbo.LuLoginDbo;
5
+import com.luticate.utils.dbo.LuDataAccessConfigDbo;
3 6
 import com.luticate.utils.dbo.LuDbo;
4 7
 
5 8
 import org.json.JSONException;
6 9
 import org.json.JSONObject;
7 10
 
8 11
 import java.util.HashMap;
12
+import java.util.Map;
9 13
 
10 14
 /**
11 15
  * Created by robin on 11/28/15.
@@ -69,11 +73,38 @@ public class LocationDbo extends LuDbo {
69 73
 
70 74
     @Override
71 75
     public void fromJson(JSONObject json) throws JSONException {
72
-
76
+        _name = json.getString("Name");
77
+        _domain = json.getString("Domain");
78
+        _username = json.getString("Username");
79
+        _password = json.getString("Password");
80
+        _https = json.getBoolean("Https");
73 81
     }
74 82
 
75 83
     @Override
76 84
     public HashMap<String, Object> toArray() {
77
-        return null;
85
+        HashMap<String, Object> array = new HashMap<>();
86
+        array.put("Name", _name);
87
+        array.put("Domain", _domain);
88
+        array.put("Username", _username);
89
+        array.put("Password", _password);
90
+        array.put("Https", _https);
91
+        return array;
92
+    }
93
+
94
+    public LuDataAccessConfigDbo getConfig(final LuLoginDbo loginDbo)
95
+    {
96
+        LuDataAccessConfigDbo config = new LuDataAccessConfigDbo()
97
+        {
98
+            @Override
99
+            public Map<String, String> getHeaders() {
100
+                Map<String, String> map = super.getHeaders();
101
+                if (loginDbo != null) {
102
+                    map.put("X-Authorization", loginDbo.getToken());
103
+                }
104
+                return map;
105
+            }
106
+        };
107
+        config.setBaseUrl(getBaseUrl());
108
+        return config;
78 109
     }
79 110
 }

+ 65
- 10
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java 查看文件

@@ -1,8 +1,6 @@
1 1
 package com.rthoni.camotion.ui;
2 2
 
3
-import android.app.Fragment;
4 3
 import android.os.Bundle;
5
-import android.view.SubMenu;
6 4
 import android.support.design.widget.NavigationView;
7 5
 import android.support.v4.view.GravityCompat;
8 6
 import android.support.v4.widget.DrawerLayout;
@@ -10,13 +8,22 @@ import android.support.v7.app.ActionBarDrawerToggle;
10 8
 import android.support.v7.app.AppCompatActivity;
11 9
 import android.support.v7.widget.Toolbar;
12 10
 import android.view.MenuItem;
11
+import android.view.SubMenu;
13 12
 import android.widget.TextView;
13
+import android.widget.Toast;
14 14
 
15 15
 import com.luticate.auth.dbo.LuFullLoginDbo;
16
+import com.luticate.utils.business.LuPromise;
17
+import com.luticate.utils.business.LuRequest;
16 18
 import com.rthoni.camotion.R;
17 19
 import com.rthoni.camotion.business.CamotionBusiness;
18 20
 import com.rthoni.camotion.dbo.LocationDbo;
21
+import com.rthoni.camotion.ui.dialogs.LoginDialog;
19 22
 import com.rthoni.camotion.ui.fragments.CamerasFragment;
23
+import com.rthoni.camotion.ui.fragments.CamotionFragment;
24
+import com.rthoni.camotion.ui.fragments.CommandsFragment;
25
+import com.rthoni.camotion.ui.fragments.DefaultFragment;
26
+import com.rthoni.camotion.ui.fragments.SensorsFragment;
20 27
 
21 28
 import java.util.List;
22 29
 
@@ -25,6 +32,7 @@ public class MainActivity extends AppCompatActivity
25 32
 
26 33
     private LuFullLoginDbo _fullLoginDbo = null;
27 34
     private LocationDbo _currentLocation = null;
35
+
28 36
     private TextView _locationNameView;
29 37
     private SubMenu _locationsMenu;
30 38
     private NavigationView _navigationView;
@@ -32,6 +40,7 @@ public class MainActivity extends AppCompatActivity
32 40
     @Override
33 41
     protected void onCreate(Bundle savedInstanceState) {
34 42
         super.onCreate(savedInstanceState);
43
+        LuRequest.init(this);
35 44
         setContentView(R.layout.activity_main);
36 45
         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
37 46
         setSupportActionBar(toolbar);
@@ -73,21 +82,72 @@ public class MainActivity extends AppCompatActivity
73 82
         MenuItem item = _navigationView.getMenu().add("test42");
74 83
         _navigationView.getMenu().removeItem(item.getItemId());
75 84
         setLocation(locations.get(0));
85
+
76 86
     }
77 87
 
78 88
     private void setLocation(LocationDbo location)
79 89
     {
80 90
         _currentLocation = location;
91
+        _fullLoginDbo = null;
81 92
         _locationNameView.setText(_currentLocation.getName());
82
-        showView(R.id.nav_cameras);
93
+        showView(-1);
94
+        LoginDialog dlg = new LoginDialog(this);
95
+        dlg.loginFull(_currentLocation).then(new LuPromise.LuConsumer<LuFullLoginDbo>() {
96
+            @Override
97
+            public void execute(LuFullLoginDbo data) {
98
+                _fullLoginDbo = data;
99
+                showView(getDefaultView());
100
+            }
101
+        }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
102
+            @Override
103
+            public void execute(LuPromise.LuPromiseError error) {
104
+                showView(-1);
105
+                Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
106
+            }
107
+        });
108
+    }
109
+
110
+    private int getDefaultView()
111
+    {
112
+        if (_fullLoginDbo != null)
113
+        {
114
+            if (_fullLoginDbo.hasPermission("CAMOTION_CAMERA_GET"))
115
+            {
116
+                return R.id.nav_cameras;
117
+            }
118
+            else if (_fullLoginDbo.hasPermission("CAMOTION_SENSOR_GET"))
119
+            {
120
+                return R.id.nav_sensors;
121
+            }
122
+            else if (_fullLoginDbo.hasPermission("CAMOTION_COMMAND_GET"))
123
+            {
124
+                return R.id.nav_commands;
125
+            }
126
+        }
127
+        return -1;
83 128
     }
84 129
 
85 130
     private void showView(int view)
86 131
     {
87
-        Fragment fragment = null;
132
+        CamotionFragment fragment;
88 133
         if (view == R.id.nav_cameras) {
89 134
             fragment = new CamerasFragment();
90 135
         }
136
+        else if (view == R.id.nav_sensors) {
137
+            fragment = new SensorsFragment();
138
+        }
139
+        else if (view == R.id.nav_commands) {
140
+            fragment = new CommandsFragment();
141
+        }
142
+        else if (view == -1)
143
+        {
144
+            fragment = new DefaultFragment();
145
+        }
146
+        else
147
+        {
148
+            return;
149
+        }
150
+        fragment.setCamotionDbo(_fullLoginDbo, _currentLocation);
91 151
         getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
92 152
     }
93 153
 
@@ -101,16 +161,11 @@ public class MainActivity extends AppCompatActivity
101 161
         }
102 162
     }
103 163
 
104
-    @SuppressWarnings("StatementWithEmptyBody")
105 164
     @Override
106 165
     public boolean onNavigationItemSelected(MenuItem item) {
107 166
         int id = item.getItemId();
108 167
 
109
-        if (id == R.id.nav_cameras) {
110
-            showView(id);
111
-        } else if (id == R.id.nav_sensors) {
112
-            showView(id);
113
-        } else if (id == R.id.nav_commands) {
168
+        if (id == R.id.nav_cameras || id == R.id.nav_sensors || id == R.id.nav_commands) {
114 169
             showView(id);
115 170
         }
116 171
 

+ 36
- 5
app/src/main/java/com/rthoni/camotion/ui/dialogs/LoginDialog.java 查看文件

@@ -3,11 +3,12 @@ package com.rthoni.camotion.ui.dialogs;
3 3
 import android.app.ProgressDialog;
4 4
 import android.content.Context;
5 5
 
6
+import com.luticate.auth.business.LuticatePermissionsBusiness;
6 7
 import com.luticate.auth.business.LuticateUsersBusiness;
8
+import com.luticate.auth.dbo.LuFullLoginDbo;
7 9
 import com.luticate.auth.dbo.LuLoginDbo;
10
+import com.luticate.auth.dbo.LuPermissionDbo;
8 11
 import com.luticate.utils.business.LuPromise;
9
-import com.luticate.utils.dataaccess.LuDataAccess;
10
-import com.luticate.utils.dbo.LuDataAccessConfigDbo;
11 12
 import com.rthoni.camotion.R;
12 13
 import com.rthoni.camotion.dbo.LocationDbo;
13 14
 
@@ -21,15 +22,14 @@ public class LoginDialog extends ProgressDialog {
21 22
         setTitle(R.string.loading);
22 23
         setIndeterminate(true);
23 24
         setMessage(context.getString(R.string.login_progress));
25
+        setCancelable(false);
24 26
     }
25 27
 
26 28
     public LuPromise<LuLoginDbo> login(LocationDbo location)
27 29
     {
28 30
         final LuPromise<LuLoginDbo> promise = new LuPromise<>();
29 31
         show();
30
-        LuDataAccessConfigDbo config = new LuDataAccessConfigDbo();
31
-        config.setBaseUrl(location.getBaseUrl());
32
-        LuticateUsersBusiness.login(config, location.getUsername(), location.getPassword())
32
+        LuticateUsersBusiness.login(location.getConfig(null), location.getUsername(), location.getPassword())
33 33
                 .then(new LuPromise.LuConsumer<LuLoginDbo>() {
34 34
                     @Override
35 35
                     public void execute(LuLoginDbo data) {
@@ -45,4 +45,35 @@ public class LoginDialog extends ProgressDialog {
45 45
                 });
46 46
         return promise;
47 47
     }
48
+
49
+    public LuPromise<LuFullLoginDbo> loginFull(final LocationDbo location)
50
+    {
51
+        final LuPromise<LuFullLoginDbo> promise = new LuPromise<>();
52
+        show();
53
+        LuticateUsersBusiness.login(location.getConfig(null), location.getUsername(), location.getPassword())
54
+                .then(new LuPromise.LuConsumer<LuLoginDbo>() {
55
+                    @Override
56
+                    public void execute(final LuLoginDbo loginDbo) {
57
+
58
+                        LuticatePermissionsBusiness.getAllEffectiveMe(location.getConfig(loginDbo))
59
+                                .then(new LuPromise.LuConsumer<LuPermissionDbo.LuMultiplePermissionDbo>() {
60
+                                    @Override
61
+                                    public void execute(LuPermissionDbo.LuMultiplePermissionDbo permissions) {
62
+                                        LuFullLoginDbo dbo = new LuFullLoginDbo();
63
+                                        dbo.setPermissions(permissions.getData());
64
+                                        dbo.setLoginDbo(loginDbo);
65
+                                        hide();
66
+                                        promise.resolve(dbo);
67
+                                    }
68
+                                });
69
+                    }
70
+                }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
71
+                    @Override
72
+                    public void execute(LuPromise.LuPromiseError data) {
73
+                        hide();
74
+                        promise.reject(data);
75
+                    }
76
+                });
77
+        return promise;
78
+    }
48 79
 }

+ 34
- 5
app/src/main/java/com/rthoni/camotion/ui/fragments/CamerasFragment.java 查看文件

@@ -1,25 +1,54 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
-import android.app.Fragment;
4 3
 import android.os.Bundle;
5 4
 import android.view.LayoutInflater;
6 5
 import android.view.View;
7 6
 import android.view.ViewGroup;
7
+import android.widget.Toast;
8 8
 
9
+import com.luticate.utils.business.LuPromise;
9 10
 import com.rthoni.camotion.R;
11
+import com.rthoni.camotion.business.CamerasBusiness;
12
+import com.rthoni.camotion.dbo.CameraDbo;
10 13
 
11 14
 /**
12 15
  *
13 16
  * Created by robin on 11/29/15.
14 17
  */
15
-public class CamerasFragment extends Fragment {
18
+public class CamerasFragment extends CamotionFragment {
19
+
20
+    private CameraDbo.MultipleCameraDbo _cameras = null;
21
+
22
+    private int _page = 0;
23
+
24
+    private int _perPage = 6;
16 25
 
17 26
     @Override
18
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
19
-                             Bundle savedInstanceState)
27
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
20 28
     {
21
-        Bundle args = getArguments();
22 29
         View rootView = inflater.inflate(R.layout.cameras_layout, container, false);
23 30
         return rootView;
24 31
     }
32
+
33
+    @Override
34
+    public void onResume() {
35
+        super.onResume();
36
+        if (_cameras == null) {
37
+            showProgress(true);
38
+            CamerasBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _page, _perPage)
39
+                    .then(new LuPromise.LuConsumer<CameraDbo.MultipleCameraDbo>() {
40
+                        @Override
41
+                        public void execute(CameraDbo.MultipleCameraDbo data) {
42
+                            _cameras = data;
43
+                            showProgress(false);
44
+                        }
45
+                    }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
46
+                        @Override
47
+                        public void execute(LuPromise.LuPromiseError error) {
48
+                            Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
49
+                            showProgress(false);
50
+                        }
51
+                    });
52
+        }
53
+    }
25 54
 }

+ 68
- 0
app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java 查看文件

@@ -0,0 +1,68 @@
1
+package com.rthoni.camotion.ui.fragments;
2
+
3
+import android.animation.Animator;
4
+import android.animation.AnimatorListenerAdapter;
5
+import android.app.Fragment;
6
+import android.os.Build;
7
+import android.view.View;
8
+
9
+import com.luticate.auth.dbo.LuFullLoginDbo;
10
+import com.rthoni.camotion.R;
11
+import com.rthoni.camotion.dbo.LocationDbo;
12
+
13
+/**
14
+ * Created by robin on 12/3/15.
15
+ */
16
+public abstract class CamotionFragment extends Fragment {
17
+    protected LuFullLoginDbo _fullLoginDbo = null;
18
+    protected LocationDbo _currentLocation = null;
19
+
20
+    public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
21
+    {
22
+        _fullLoginDbo = fullLoginDbo;
23
+        _currentLocation = currentLocation;
24
+    }
25
+
26
+    protected void showProgress(final boolean show)
27
+    {
28
+        View v = getView();
29
+        if (!isAdded() || v == null)
30
+            return;
31
+
32
+        final View imagesScrollView = v.findViewById(R.id.imagesScrollView);
33
+        final View loadingView = v.findViewById(R.id.loadStatus);
34
+
35
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
36
+        {
37
+            int shortAnimTime =
38
+                    getResources().getInteger(android.R.integer.config_shortAnimTime);
39
+
40
+            loadingView.setVisibility(View.VISIBLE);
41
+            loadingView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
42
+                    .setListener(new AnimatorListenerAdapter()
43
+                    {
44
+                        @Override
45
+                        public void onAnimationEnd(Animator animation)
46
+                        {
47
+                            loadingView.setVisibility(show ? View.VISIBLE : View.GONE);
48
+                        }
49
+                    });
50
+
51
+            imagesScrollView.setVisibility(View.VISIBLE);
52
+            imagesScrollView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
53
+                    .setListener(new AnimatorListenerAdapter()
54
+                    {
55
+                        @Override
56
+                        public void onAnimationEnd(Animator animation)
57
+                        {
58
+                            imagesScrollView.setVisibility(show ? View.GONE : View.VISIBLE);
59
+                        }
60
+                    });
61
+        }
62
+        else
63
+        {
64
+            loadingView.setVisibility(show ? View.VISIBLE : View.GONE);
65
+            imagesScrollView.setVisibility(show ? View.GONE : View.VISIBLE);
66
+        }
67
+    }
68
+}

+ 24
- 0
app/src/main/java/com/rthoni/camotion/ui/fragments/CommandsFragment.java 查看文件

@@ -0,0 +1,24 @@
1
+package com.rthoni.camotion.ui.fragments;
2
+
3
+import android.os.Bundle;
4
+import android.view.LayoutInflater;
5
+import android.view.View;
6
+import android.view.ViewGroup;
7
+
8
+import com.rthoni.camotion.R;
9
+
10
+/**
11
+ *
12
+ * Created by robin on 11/29/15.
13
+ */
14
+public class CommandsFragment extends CamotionFragment {
15
+
16
+    @Override
17
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
18
+                             Bundle savedInstanceState)
19
+    {
20
+        Bundle args = getArguments();
21
+        View rootView = inflater.inflate(R.layout.commands_layout, container, false);
22
+        return rootView;
23
+    }
24
+}

+ 24
- 0
app/src/main/java/com/rthoni/camotion/ui/fragments/DefaultFragment.java 查看文件

@@ -0,0 +1,24 @@
1
+package com.rthoni.camotion.ui.fragments;
2
+
3
+import android.os.Bundle;
4
+import android.view.LayoutInflater;
5
+import android.view.View;
6
+import android.view.ViewGroup;
7
+
8
+import com.rthoni.camotion.R;
9
+
10
+/**
11
+ *
12
+ * Created by robin on 11/29/15.
13
+ */
14
+public class DefaultFragment extends CamotionFragment {
15
+
16
+    @Override
17
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
18
+                             Bundle savedInstanceState)
19
+    {
20
+        Bundle args = getArguments();
21
+        View rootView = inflater.inflate(R.layout.default_layout, container, false);
22
+        return rootView;
23
+    }
24
+}

+ 24
- 0
app/src/main/java/com/rthoni/camotion/ui/fragments/SensorsFragment.java 查看文件

@@ -0,0 +1,24 @@
1
+package com.rthoni.camotion.ui.fragments;
2
+
3
+import android.os.Bundle;
4
+import android.view.LayoutInflater;
5
+import android.view.View;
6
+import android.view.ViewGroup;
7
+
8
+import com.rthoni.camotion.R;
9
+
10
+/**
11
+ *
12
+ * Created by robin on 11/29/15.
13
+ */
14
+public class SensorsFragment extends CamotionFragment {
15
+
16
+    @Override
17
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
18
+                             Bundle savedInstanceState)
19
+    {
20
+        Bundle args = getArguments();
21
+        View rootView = inflater.inflate(R.layout.sensors_layout, container, false);
22
+        return rootView;
23
+    }
24
+}

+ 96
- 0
app/src/main/res/layout/commands_layout.xml 查看文件

@@ -0,0 +1,96 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              android:layout_width="match_parent"
4
+              android:layout_height="match_parent"
5
+              android:orientation="vertical" >
6
+
7
+    <!-- Loading progress -->
8
+
9
+    <LinearLayout
10
+        android:id="@+id/loadStatus"
11
+        android:layout_width="wrap_content"
12
+        android:layout_height="wrap_content"
13
+        android:layout_gravity="center"
14
+        android:gravity="center_horizontal"
15
+        android:orientation="vertical"
16
+        android:visibility="gone" >
17
+
18
+        <ProgressBar
19
+            style="?android:attr/progressBarStyleLarge"
20
+            android:layout_width="wrap_content"
21
+            android:layout_height="wrap_content"
22
+            android:layout_marginBottom="8dp" />
23
+
24
+        <TextView
25
+            android:id="@+id/loading_status_message"
26
+            android:layout_width="wrap_content"
27
+            android:layout_height="wrap_content"
28
+            android:layout_marginBottom="16dp"
29
+            android:text="@string/loading"
30
+            android:textAppearance="?android:attr/textAppearanceMedium" />
31
+    </LinearLayout>
32
+
33
+    <!-- Layout -->
34
+
35
+    <ScrollView
36
+        android:id="@+id/imagesScrollView"
37
+        android:layout_width="match_parent"
38
+        android:layout_height="0dp"
39
+        android:layout_weight="0.33" >
40
+
41
+        <LinearLayout
42
+            android:id="@+id/imagesLayoutScrollView"
43
+            android:layout_width="wrap_content"
44
+            android:layout_height="match_parent"
45
+            android:orientation="vertical" >
46
+
47
+            <ImageView
48
+                android:contentDescription="42"
49
+                android:layout_width="match_parent"
50
+                android:layout_height="wrap_content"
51
+                android:layout_margin="10px"
52
+                android:adjustViewBounds="true"
53
+                android:src="@drawable/camera_loading" />
54
+
55
+            <ImageView
56
+                android:contentDescription="42"
57
+                android:layout_width="match_parent"
58
+                android:layout_height="wrap_content"
59
+                android:layout_margin="10px"
60
+                android:adjustViewBounds="true"
61
+                android:src="@drawable/camera_loading" />
62
+
63
+            <ImageView
64
+                android:contentDescription="42"
65
+                android:layout_width="match_parent"
66
+                android:layout_height="wrap_content"
67
+                android:layout_margin="10px"
68
+                android:adjustViewBounds="true"
69
+                android:src="@drawable/camera_loading" />
70
+
71
+            <ImageView
72
+                android:contentDescription="42"
73
+                android:layout_width="match_parent"
74
+                android:layout_height="wrap_content"
75
+                android:layout_margin="10px"
76
+                android:adjustViewBounds="true"
77
+                android:src="@drawable/camera_loading" />
78
+
79
+            <ImageView
80
+                android:contentDescription="42"
81
+                android:layout_width="match_parent"
82
+                android:layout_height="wrap_content"
83
+                android:layout_margin="10px"
84
+                android:adjustViewBounds="true"
85
+                android:src="@drawable/camera_loading" />
86
+
87
+            <ImageView
88
+                android:contentDescription="42"
89
+                android:layout_width="match_parent"
90
+                android:layout_height="wrap_content"
91
+                android:layout_margin="10px"
92
+                android:adjustViewBounds="true"
93
+                android:src="@drawable/camera_loading" />
94
+        </LinearLayout>
95
+    </ScrollView>
96
+</LinearLayout>

+ 47
- 0
app/src/main/res/layout/default_layout.xml 查看文件

@@ -0,0 +1,47 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              android:layout_width="match_parent"
4
+              android:layout_height="match_parent"
5
+              android:orientation="vertical" >
6
+
7
+    <!-- Loading progress -->
8
+
9
+    <LinearLayout
10
+        android:id="@+id/loadStatus"
11
+        android:layout_width="wrap_content"
12
+        android:layout_height="wrap_content"
13
+        android:layout_gravity="center"
14
+        android:gravity="center_horizontal"
15
+        android:orientation="vertical"
16
+        android:visibility="gone" >
17
+
18
+        <ProgressBar
19
+            style="?android:attr/progressBarStyleLarge"
20
+            android:layout_width="wrap_content"
21
+            android:layout_height="wrap_content"
22
+            android:layout_marginBottom="8dp" />
23
+
24
+        <TextView
25
+            android:id="@+id/loading_status_message"
26
+            android:layout_width="wrap_content"
27
+            android:layout_height="wrap_content"
28
+            android:layout_marginBottom="16dp"
29
+            android:text="@string/loading"
30
+            android:textAppearance="?android:attr/textAppearanceMedium" />
31
+    </LinearLayout>
32
+
33
+    <!-- Layout -->
34
+
35
+    <ScrollView
36
+        android:id="@+id/imagesScrollView"
37
+        android:layout_width="match_parent"
38
+        android:layout_height="0dp"
39
+        android:layout_weight="0.33" >
40
+
41
+        <TextView
42
+            android:layout_width="wrap_content"
43
+            android:layout_height="wrap_content"
44
+            android:text="Default"
45
+            android:id="@+id/textView2"/>
46
+    </ScrollView>
47
+</LinearLayout>

+ 96
- 0
app/src/main/res/layout/sensors_layout.xml 查看文件

@@ -0,0 +1,96 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              android:layout_width="match_parent"
4
+              android:layout_height="match_parent"
5
+              android:orientation="vertical" >
6
+
7
+    <!-- Loading progress -->
8
+
9
+    <LinearLayout
10
+        android:id="@+id/loadStatus"
11
+        android:layout_width="wrap_content"
12
+        android:layout_height="wrap_content"
13
+        android:layout_gravity="center"
14
+        android:gravity="center_horizontal"
15
+        android:orientation="vertical"
16
+        android:visibility="gone" >
17
+
18
+        <ProgressBar
19
+            style="?android:attr/progressBarStyleLarge"
20
+            android:layout_width="wrap_content"
21
+            android:layout_height="wrap_content"
22
+            android:layout_marginBottom="8dp" />
23
+
24
+        <TextView
25
+            android:id="@+id/loading_status_message"
26
+            android:layout_width="wrap_content"
27
+            android:layout_height="wrap_content"
28
+            android:layout_marginBottom="16dp"
29
+            android:text="@string/loading"
30
+            android:textAppearance="?android:attr/textAppearanceMedium" />
31
+    </LinearLayout>
32
+
33
+    <!-- Layout -->
34
+
35
+    <ScrollView
36
+        android:id="@+id/imagesScrollView"
37
+        android:layout_width="match_parent"
38
+        android:layout_height="0dp"
39
+        android:layout_weight="0.33" >
40
+
41
+        <LinearLayout
42
+            android:id="@+id/imagesLayoutScrollView"
43
+            android:layout_width="wrap_content"
44
+            android:layout_height="match_parent"
45
+            android:orientation="vertical" >
46
+
47
+            <ImageView
48
+                android:contentDescription="42"
49
+                android:layout_width="match_parent"
50
+                android:layout_height="wrap_content"
51
+                android:layout_margin="10px"
52
+                android:adjustViewBounds="true"
53
+                android:src="@drawable/camera_loading" />
54
+
55
+            <ImageView
56
+                android:contentDescription="42"
57
+                android:layout_width="match_parent"
58
+                android:layout_height="wrap_content"
59
+                android:layout_margin="10px"
60
+                android:adjustViewBounds="true"
61
+                android:src="@drawable/camera_loading" />
62
+
63
+            <ImageView
64
+                android:contentDescription="42"
65
+                android:layout_width="match_parent"
66
+                android:layout_height="wrap_content"
67
+                android:layout_margin="10px"
68
+                android:adjustViewBounds="true"
69
+                android:src="@drawable/camera_loading" />
70
+
71
+            <ImageView
72
+                android:contentDescription="42"
73
+                android:layout_width="match_parent"
74
+                android:layout_height="wrap_content"
75
+                android:layout_margin="10px"
76
+                android:adjustViewBounds="true"
77
+                android:src="@drawable/camera_loading" />
78
+
79
+            <ImageView
80
+                android:contentDescription="42"
81
+                android:layout_width="match_parent"
82
+                android:layout_height="wrap_content"
83
+                android:layout_margin="10px"
84
+                android:adjustViewBounds="true"
85
+                android:src="@drawable/camera_loading" />
86
+
87
+            <ImageView
88
+                android:contentDescription="42"
89
+                android:layout_width="match_parent"
90
+                android:layout_height="wrap_content"
91
+                android:layout_margin="10px"
92
+                android:adjustViewBounds="true"
93
+                android:src="@drawable/camera_loading" />
94
+        </LinearLayout>
95
+    </ScrollView>
96
+</LinearLayout>

二進制
libs/android-async-http-1.4.9.jar 查看文件


+ 0
- 20
luticateauth/src/main/java/com/luticate/auth/business/LuticateUsersBusiness.java 查看文件

@@ -23,24 +23,4 @@ public class LuticateUsersBusiness extends LuBusinessManager {
23 23
     {
24 24
         return LuticateUsersDataAccess.logout(config);
25 25
     }
26
-
27
-    public static LuPromise<LuFullLoginDbo> loginFull(final LuDataAccessConfigDbo config, String username, String password)
28
-    {
29
-        final LuPromise<LuFullLoginDbo> promise = new LuPromise<>();
30
-        login(config, username, password).then(new LuPromise.LuConsumer<LuLoginDbo>() {
31
-            @Override
32
-            public void execute(final LuLoginDbo user) {
33
-                LuticatePermissionsBusiness.getAllEffectiveMe(config).then(new LuPromise.LuConsumer<LuPermissionDbo.LuMultiplePermissionDbo>() {
34
-                    @Override
35
-                    public void execute(LuPermissionDbo.LuMultiplePermissionDbo permissions) {
36
-                        LuFullLoginDbo dbo = new LuFullLoginDbo();
37
-                        dbo.setLoginDbo(user);
38
-                        dbo.setPermissions(permissions.getData());
39
-                        promise.resolve(dbo);
40
-                    }
41
-                }, promise.rejectConsumer());
42
-            }
43
-        }, promise.rejectConsumer());
44
-        return promise;
45
-    }
46 26
 }

+ 1
- 1
luticateauth/src/main/java/com/luticate/auth/dataaccess/LuticatePermissionsDataAccess.java 查看文件

@@ -14,6 +14,6 @@ public class LuticatePermissionsDataAccess extends LuDataAccess {
14 14
 
15 15
     public static LuPromise<LuPermissionDbo.LuMultiplePermissionDbo> getAllEffectiveMe(LuDataAccessConfigDbo config)
16 16
     {
17
-        return LuRequest.get(LuPermissionDbo.LuMultiplePermissionDbo.class, config.getBaseUrl() + "/api/luticate/permissions/effective/me");
17
+        return LuRequest.get(config, LuPermissionDbo.LuMultiplePermissionDbo.class, "/api/luticate/permissions/effective/me");
18 18
     }
19 19
 }

+ 2
- 2
luticateauth/src/main/java/com/luticate/auth/dataaccess/LuticateUsersDataAccess.java 查看文件

@@ -19,11 +19,11 @@ public class LuticateUsersDataAccess extends LuDataAccess {
19 19
         HashMap<String, String> array = new HashMap<>();
20 20
         array.put("username", username);
21 21
         array.put("password", password);
22
-        return LuRequest.post(LuLoginDbo.class, config.getBaseUrl() + "/api/luticate/users/login", array);
22
+        return LuRequest.post(config, LuLoginDbo.class, "/api/luticate/users/login", array);
23 23
     }
24 24
 
25 25
     public static LuPromise<LuLoginDbo> logout(LuDataAccessConfigDbo config)
26 26
     {
27
-        return LuRequest.post(LuLoginDbo.class, config.getBaseUrl() + "/api/luticate/users/logout");
27
+        return LuRequest.post(config, LuLoginDbo.class, "/api/luticate/users/logout");
28 28
     }
29 29
 }

+ 12
- 0
luticateauth/src/main/java/com/luticate/auth/dbo/LuFullLoginDbo.java 查看文件

@@ -60,4 +60,16 @@ public class LuFullLoginDbo extends LuDbo {
60 60
         array.put("Permissions", permissions);
61 61
         return array;
62 62
     }
63
+
64
+    public boolean hasPermission(String permission)
65
+    {
66
+        for (LuPermissionDbo perm : _permissions)
67
+        {
68
+            if (perm.getName().equals(permission))
69
+            {
70
+                return perm.getValue();
71
+            }
72
+        }
73
+        return false;
74
+    }
63 75
 }

+ 1
- 1
luticateauth/src/main/java/com/luticate/auth/dbo/LuPermissionDbo.java 查看文件

@@ -30,7 +30,7 @@ public class LuPermissionDbo extends LuDbo {
30 30
         _name = name;
31 31
     }
32 32
 
33
-    public boolean isValue() {
33
+    public boolean getValue() {
34 34
         return _value;
35 35
     }
36 36
 

+ 1
- 1
luticateutils/build.gradle 查看文件

@@ -22,5 +22,5 @@ dependencies {
22 22
     compile fileTree(dir: 'libs', include: ['*.jar'])
23 23
     testCompile 'junit:junit:4.12'
24 24
     compile 'com.android.support:appcompat-v7:22.2.1'
25
-    compile 'com.loopj.android:android-async-http:1.4.9'
25
+    compile project(':volley')
26 26
 }

+ 80
- 28
luticateutils/src/main/java/com/luticate/utils/business/LuRequest.java 查看文件

@@ -1,15 +1,21 @@
1 1
 package com.luticate.utils.business;
2 2
 
3
-import com.loopj.android.http.AsyncHttpClient;
4
-import com.loopj.android.http.JsonHttpResponseHandler;
5
-import com.loopj.android.http.RequestParams;
3
+import android.content.Context;
4
+
5
+import com.android.volley.AuthFailureError;
6
+import com.android.volley.Request;
7
+import com.android.volley.RequestQueue;
8
+import com.android.volley.Response;
9
+import com.android.volley.VolleyError;
10
+import com.android.volley.toolbox.StringRequest;
11
+import com.android.volley.toolbox.Volley;
12
+import com.luticate.utils.dbo.LuDataAccessConfigDbo;
6 13
 import com.luticate.utils.dbo.LuDbo;
7 14
 
8 15
 import org.json.JSONObject;
9 16
 
10 17
 import java.util.HashMap;
11
-
12
-import cz.msebera.android.httpclient.Header;
18
+import java.util.Map;
13 19
 
14 20
 /**
15 21
  *
@@ -17,63 +23,109 @@ import cz.msebera.android.httpclient.Header;
17 23
  */
18 24
 public class LuRequest {
19 25
 
20
-    private static AsyncHttpClient client = new AsyncHttpClient();
26
+    private static RequestQueue _requestQueue = null;
21 27
 
22
-    protected static <T extends LuDbo> JsonHttpResponseHandler getHandler(final Class<T> type, final LuPromise<T> promise)
28
+    public static void init(Context ctx)
23 29
     {
24
-        return new JsonHttpResponseHandler()
30
+        _requestQueue = Volley.newRequestQueue(ctx.getApplicationContext());
31
+    }
32
+
33
+    protected static <T extends LuDbo> Response.Listener<String> getListener(final Class<T> type, final LuPromise<T> promise)
34
+    {
35
+        return new Response.Listener<String>()
25 36
         {
26 37
             @Override
27
-            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
38
+            public void onResponse(String response) {
28 39
                 try {
29 40
                     T dbo = type.newInstance();
30 41
                     try {
31
-                        dbo.fromJson(response.getJSONObject("Data"));
42
+                        JSONObject json = new JSONObject(response);
43
+                        dbo.fromJson(json.getJSONObject("Data"));
32 44
                         promise.resolve(dbo);
33 45
                     } catch (Exception e)
34 46
                     {
35 47
                         e.printStackTrace();
36
-                        promise.reject(new LuPromise.LuPromiseError("Failed to parse success server response", statusCode));
48
+                        promise.reject(new LuPromise.LuPromiseError("Failed to parse success server response", 200));
37 49
                     }
38 50
                 } catch (Exception e) {
39 51
                     e.printStackTrace();
40
-                    promise.reject(new LuPromise.LuPromiseError("Failed to initialize server response", statusCode));
52
+                    promise.reject(new LuPromise.LuPromiseError("Failed to initialize server response", 200));
41 53
                 }
42 54
             }
55
+        };
56
+    }
43 57
 
58
+    protected static <T extends LuDbo> Response.ErrorListener getErrorListener(final LuPromise<T> promise)
59
+    {
60
+        return new Response.ErrorListener() {
44 61
             @Override
45
-            public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
46
-                try {
47
-                    promise.reject(new LuPromise.LuPromiseError(errorResponse.getString("Message"), statusCode));
48
-                } catch (Exception e) {
49
-                    e.printStackTrace();
50
-                    promise.reject(new LuPromise.LuPromiseError("Failed to parse error server response", statusCode));
62
+            public void onErrorResponse(VolleyError error) {
63
+                int code = 0;
64
+                if (error != null && error.networkResponse != null)
65
+                {
66
+                    code = error.networkResponse.statusCode;
51 67
                 }
68
+                try
69
+                {
70
+                    JSONObject data = new JSONObject(new String(error.networkResponse.data));
71
+                    promise.reject(new LuPromise.LuPromiseError(data.getString("Message"), code));
72
+                } catch (Exception e)
73
+                {
74
+                    promise.reject(new LuPromise.LuPromiseError(e.getMessage(), code));
75
+                }
76
+                promise.reject(new LuPromise.LuPromiseError(error.toString(), code));
52 77
             }
53 78
         };
54 79
     }
55 80
 
56
-    public static <T extends LuDbo> LuPromise<T> get(Class<T> type, String url, HashMap<String, String> getParams)
81
+    protected static <T extends LuDbo> LuPromise<T> request(final LuDataAccessConfigDbo config,
82
+                                                            int method, Class<T> type, String url,
83
+                                                            final HashMap<String, String> params)
57 84
     {
58 85
         LuPromise<T> promise = new LuPromise<>();
59
-        client.get(url, new RequestParams(getParams), getHandler(type, promise));
86
+        StringRequest request = new StringRequest(method, config.getBaseUrl() + url,
87
+                getListener(type, promise), getErrorListener(promise))
88
+        {
89
+            @Override
90
+            public String getBodyContentType() {
91
+                return "application/x-www-form-urlencoded; charset=UTF-8";
92
+            }
93
+
94
+            @Override
95
+            protected Map<String, String> getParams() throws AuthFailureError {
96
+                return params;
97
+            }
98
+
99
+            @Override
100
+            public Map<String, String> getHeaders() throws AuthFailureError {
101
+                return config.getHeaders();
102
+            }
103
+        };
104
+        _requestQueue.add(request);
60 105
         return promise;
61 106
     }
62 107
 
63
-    public static <T extends LuDbo> LuPromise<T> get(Class<T> type, String url)
108
+    public static <T extends LuDbo> LuPromise<T> get(LuDataAccessConfigDbo config, Class<T> type,
109
+                                                     String url, HashMap<String, String> getParams)
64 110
     {
65
-        return get(type, url, new HashMap<String, String>());
111
+        return request(config, Request.Method.GET, type, url, getParams);
66 112
     }
67 113
 
68
-    public static <T extends LuDbo> LuPromise<T> post(Class<T> type, String url, HashMap<String, String> postParams)
114
+    public static <T extends LuDbo> LuPromise<T> get(LuDataAccessConfigDbo config, Class<T> type,
115
+                                                     String url)
69 116
     {
70
-        LuPromise<T> promise = new LuPromise<>();
71
-        client.post(url, new RequestParams(postParams), getHandler(type, promise));
72
-        return promise;
117
+        return get(config, type, url, new HashMap<String, String>());
118
+    }
119
+
120
+    public static <T extends LuDbo> LuPromise<T> post(LuDataAccessConfigDbo config, Class<T> type,
121
+                                                      String url, final HashMap<String, String> postParams)
122
+    {
123
+        return request(config, Request.Method.POST, type, url, postParams);
73 124
     }
74 125
 
75
-    public static <T extends LuDbo> LuPromise<T> post(Class<T> type, String url)
126
+    public static <T extends LuDbo> LuPromise<T> post(LuDataAccessConfigDbo config, Class<T> type,
127
+                                                      String url)
76 128
     {
77
-        return post(type, url, new HashMap<String, String>());
129
+        return post(config, type, url, new HashMap<String, String>());
78 130
     }
79 131
 }

+ 9
- 0
luticateutils/src/main/java/com/luticate/utils/dbo/LuDataAccessConfigDbo.java 查看文件

@@ -1,5 +1,8 @@
1 1
 package com.luticate.utils.dbo;
2 2
 
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
3 6
 /**
4 7
  *
5 8
  * Created by robin on 11/28/15.
@@ -15,4 +18,10 @@ public class LuDataAccessConfigDbo {
15 18
     public void setBaseUrl(String baseUrl) {
16 19
         _baseUrl = baseUrl;
17 20
     }
21
+
22
+    public Map<String, String> getHeaders()
23
+    {
24
+        Map<String, String> map = new HashMap<>();
25
+        return map;
26
+    }
18 27
 }

+ 1
- 1
settings.gradle 查看文件

@@ -1 +1 @@
1
-include ':app', ':luticateutils', ':luticateauth'
1
+include ':app', ':luticateutils', ':luticateauth', ':volley'

+ 1
- 0
volley

@@ -0,0 +1 @@
1
+Subproject commit 96c4d0b9f58229b9dbba51f1776addedc66f4749

Loading…
取消
儲存