Quellcode durchsuchen

begin camera view

tags/0.0.5
Robin Thoni vor 9 Jahren
Ursprung
Commit
a4d8528ab5

+ 27
- 0
app/src/main/java/com/rthoni/camotion/business/CamerasBusiness.java Datei anzeigen

@@ -1,10 +1,15 @@
1 1
 package com.rthoni.camotion.business;
2 2
 
3
+import android.graphics.Bitmap;
4
+import android.graphics.BitmapFactory;
5
+import android.util.Base64;
6
+
3 7
 import com.luticate.utils.business.LuBusinessManager;
4 8
 import com.luticate.utils.business.LuPromise;
5 9
 import com.luticate.utils.dbo.LuDataAccessConfigDbo;
6 10
 import com.rthoni.camotion.dataaccess.CamerasDataAccess;
7 11
 import com.rthoni.camotion.dbo.CameraDbo;
12
+import com.rthoni.camotion.dbo.CameraImageDbo;
8 13
 
9 14
 /**
10 15
  * Created by robin on 12/3/15.
@@ -14,4 +19,26 @@ public class CamerasBusiness extends LuBusinessManager {
14 19
     {
15 20
         return CamerasDataAccess.getAll(config, page, perPage);
16 21
     }
22
+
23
+    public static LuPromise<Bitmap> getImage(LuDataAccessConfigDbo config, CameraDbo camera)
24
+    {
25
+        final LuPromise<Bitmap> promise = new LuPromise<>();
26
+
27
+        CamerasDataAccess.getImage(config, camera.getId()).then(new LuPromise.LuConsumer<CameraImageDbo>() {
28
+            @Override
29
+            public void execute(CameraImageDbo image) {
30
+                try
31
+                {
32
+                    byte[] data = Base64.decode(image.getImage(), Base64.DEFAULT);
33
+                    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
34
+                    promise.resolve(bitmap);
35
+                } catch (Exception e)
36
+                {
37
+                    promise.reject(new LuPromise.LuPromiseError(e.getMessage(), 200));
38
+                }
39
+            }
40
+        }, promise.rejectConsumer());
41
+
42
+        return promise;
43
+    }
17 44
 }

+ 6
- 0
app/src/main/java/com/rthoni/camotion/dataaccess/CamerasDataAccess.java Datei anzeigen

@@ -5,6 +5,7 @@ import com.luticate.utils.business.LuRequest;
5 5
 import com.luticate.utils.dataaccess.LuDataAccess;
6 6
 import com.luticate.utils.dbo.LuDataAccessConfigDbo;
7 7
 import com.rthoni.camotion.dbo.CameraDbo;
8
+import com.rthoni.camotion.dbo.CameraImageDbo;
8 9
 
9 10
 import java.util.HashMap;
10 11
 
@@ -20,4 +21,9 @@ public class CamerasDataAccess extends LuDataAccess {
20 21
         params.put("perPage", "" + perPage);
21 22
         return LuRequest.get(config, CameraDbo.MultipleCameraDbo.class, "/api/cameras", params);
22 23
     }
24
+
25
+    public static LuPromise<CameraImageDbo> getImage(LuDataAccessConfigDbo config, int id)
26
+    {
27
+        return LuRequest.post(config, CameraImageDbo.class, "/api/cameras/" + id + "/image");
28
+    }
23 29
 }

+ 35
- 0
app/src/main/java/com/rthoni/camotion/dbo/CameraImageDbo.java Datei anzeigen

@@ -0,0 +1,35 @@
1
+package com.rthoni.camotion.dbo;
2
+
3
+import com.luticate.utils.dbo.LuDbo;
4
+
5
+import org.json.JSONException;
6
+import org.json.JSONObject;
7
+
8
+import java.util.HashMap;
9
+
10
+/**
11
+ * Created by robin on 12/3/15.
12
+ */
13
+public class CameraImageDbo extends LuDbo {
14
+    private String _image;
15
+
16
+    public String getImage() {
17
+        return _image;
18
+    }
19
+
20
+    public void setImage(String image) {
21
+        _image = image;
22
+    }
23
+
24
+    @Override
25
+    public void fromJson(JSONObject json) throws JSONException {
26
+        _image = json.getString("Image");
27
+    }
28
+
29
+    @Override
30
+    public HashMap<String, Object> toArray() {
31
+        HashMap<String, Object> array = new HashMap<>();
32
+        array.put("Image", _image);
33
+        return array;
34
+    }
35
+}

+ 15
- 0
app/src/main/java/com/rthoni/camotion/ui/fragments/CamerasFragment.java Datei anzeigen

@@ -4,12 +4,15 @@ import android.os.Bundle;
4 4
 import android.view.LayoutInflater;
5 5
 import android.view.View;
6 6
 import android.view.ViewGroup;
7
+import android.widget.ImageView;
8
+import android.widget.LinearLayout;
7 9
 import android.widget.Toast;
8 10
 
9 11
 import com.luticate.utils.business.LuPromise;
10 12
 import com.rthoni.camotion.R;
11 13
 import com.rthoni.camotion.business.CamerasBusiness;
12 14
 import com.rthoni.camotion.dbo.CameraDbo;
15
+import com.rthoni.camotion.ui.views.CameraView;
13 16
 
14 17
 /**
15 18
  *
@@ -40,6 +43,18 @@ public class CamerasFragment extends CamotionFragment {
40 43
                         @Override
41 44
                         public void execute(CameraDbo.MultipleCameraDbo data) {
42 45
                             _cameras = data;
46
+
47
+                            LinearLayout layout = (LinearLayout) getView().findViewById(R.id.imagesLayoutScrollView);
48
+
49
+                            for (CameraDbo camera : _cameras.getData())
50
+                            {
51
+                                CameraView imageView = new CameraView(getActivity());
52
+                                imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
53
+                                imageView.setCamera(camera);
54
+                                imageView.togglePlay();
55
+                                layout.addView(imageView);
56
+                            }
57
+
43 58
                             showProgress(false);
44 59
                         }
45 60
                     }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {

+ 1
- 1
app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java Datei anzeigen

@@ -29,7 +29,7 @@ public abstract class CamotionFragment extends Fragment {
29 29
         if (!isAdded() || v == null)
30 30
             return;
31 31
 
32
-        final View imagesScrollView = v.findViewById(R.id.imagesScrollView);
32
+        final View imagesScrollView = v.findViewById(R.id.mainScrollView);
33 33
         final View loadingView = v.findViewById(R.id.loadStatus);
34 34
 
35 35
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)

+ 96
- 0
app/src/main/java/com/rthoni/camotion/ui/views/CameraView.java Datei anzeigen

@@ -0,0 +1,96 @@
1
+package com.rthoni.camotion.ui.views;
2
+
3
+import android.content.Context;
4
+import android.graphics.Bitmap;
5
+import android.util.AttributeSet;
6
+import android.view.View;
7
+import android.widget.ImageView;
8
+import android.widget.RelativeLayout;
9
+import android.widget.TextView;
10
+
11
+import com.luticate.auth.dbo.LuFullLoginDbo;
12
+import com.luticate.utils.business.LuPromise;
13
+import com.rthoni.camotion.R;
14
+import com.rthoni.camotion.business.CamerasBusiness;
15
+import com.rthoni.camotion.dbo.CameraDbo;
16
+import com.rthoni.camotion.dbo.LocationDbo;
17
+
18
+/**
19
+ * Created by robin on 12/4/15.
20
+ */
21
+public class CameraView extends RelativeLayout {
22
+    private LuFullLoginDbo _fullLoginDbo = null;
23
+    private LocationDbo _currentLocation = null;
24
+
25
+    private CameraDbo _camera;
26
+
27
+    private ImageView _imageView;
28
+
29
+    public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
30
+    {
31
+        _fullLoginDbo = fullLoginDbo;
32
+        _currentLocation = currentLocation;
33
+    }
34
+
35
+    public CameraDbo getCamera() {
36
+        return _camera;
37
+    }
38
+
39
+    public void setCamera(CameraDbo camera) {
40
+        _camera = camera;
41
+
42
+        ((TextView)findViewById(R.id.textViewName)).setText(_camera.getName());
43
+
44
+        findViewById(R.id.imageView).setOnClickListener(new OnClickListener() {
45
+            @Override
46
+            public void onClick(View v) {
47
+                togglePlay();
48
+            }
49
+        });
50
+
51
+        _imageView = (ImageView) findViewById(R.id.imageView);
52
+        _imageView.setContentDescription(_camera.getDescription());
53
+        _imageView.setOnClickListener(new OnClickListener() {
54
+            @Override
55
+            public void onClick(View v) {
56
+                togglePlay();
57
+            }
58
+        });
59
+    }
60
+
61
+    public CameraView(Context context) {
62
+        super(context);
63
+        init();
64
+    }
65
+
66
+    public CameraView(Context context, AttributeSet attrs) {
67
+        super(context, attrs);
68
+        init();
69
+    }
70
+
71
+    public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
72
+        super(context, attrs, defStyleAttr);
73
+        init();
74
+    }
75
+
76
+    private void init()
77
+    {
78
+        inflate(getContext(), R.layout.camera_view, this);
79
+    }
80
+
81
+    public void togglePlay()
82
+    {
83
+        CamerasBusiness.getImage(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _camera)
84
+                .then(new LuPromise.LuConsumer<Bitmap>() {
85
+                    @Override
86
+                    public void execute(Bitmap image) {
87
+                        _imageView.setImageBitmap(image);
88
+                    }
89
+                }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
90
+                    @Override
91
+                    public void execute(LuPromise.LuPromiseError data) {
92
+
93
+                    }
94
+                });
95
+    }
96
+}

+ 43
- 0
app/src/main/res/layout/camera_view.xml Datei anzeigen

@@ -0,0 +1,43 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              android:orientation="vertical"
4
+              android:layout_width="match_parent"
5
+              android:layout_height="match_parent">
6
+
7
+    <RelativeLayout
8
+        android:layout_width="match_parent"
9
+        android:layout_height="wrap_content"
10
+        android:layout_alignParentTop="true"
11
+        android:layout_alignParentLeft="true"
12
+        android:layout_alignParentStart="true"
13
+        android:id="@+id/imageViewLayout">
14
+
15
+        <ImageView
16
+            android:layout_width="match_parent"
17
+            android:layout_height="wrap_content"
18
+            android:id="@+id/imageView"
19
+            android:layout_alignParentTop="true"
20
+            android:layout_centerHorizontal="true"
21
+            android:src="@drawable/camera_loading"
22
+            android:adjustViewBounds="true"
23
+            android:scaleType="fitCenter"/>
24
+
25
+        <ImageView
26
+            android:layout_width="wrap_content"
27
+            android:layout_height="wrap_content"
28
+            android:id="@+id/imageViewPause"
29
+            android:layout_centerVertical="true"
30
+            android:layout_centerHorizontal="true"
31
+            android:translationZ="10dp"
32
+            android:src="@drawable/abc_btn_radio_to_on_mtrl_015"/>
33
+    </RelativeLayout>
34
+
35
+    <TextView
36
+        android:layout_width="wrap_content"
37
+        android:layout_height="wrap_content"
38
+        android:textAppearance="?android:attr/textAppearanceLarge"
39
+        android:text="Name"
40
+        android:id="@+id/textViewName"
41
+        android:layout_below="@+id/imageViewLayout"
42
+        android:layout_centerHorizontal="true"/>
43
+</RelativeLayout>

+ 1
- 49
app/src/main/res/layout/cameras_layout.xml Datei anzeigen

@@ -33,7 +33,7 @@
33 33
     <!-- Layout -->
34 34
 
35 35
     <ScrollView
36
-        android:id="@+id/imagesScrollView"
36
+        android:id="@+id/mainScrollView"
37 37
         android:layout_width="match_parent"
38 38
         android:layout_height="0dp"
39 39
         android:layout_weight="0.33" >
@@ -43,54 +43,6 @@
43 43
             android:layout_width="wrap_content"
44 44
             android:layout_height="match_parent"
45 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 46
         </LinearLayout>
95 47
     </ScrollView>
96 48
 </LinearLayout>

+ 1
- 1
app/src/main/res/layout/commands_layout.xml Datei anzeigen

@@ -33,7 +33,7 @@
33 33
     <!-- Layout -->
34 34
 
35 35
     <ScrollView
36
-        android:id="@+id/imagesScrollView"
36
+        android:id="@+id/mainScrollView"
37 37
         android:layout_width="match_parent"
38 38
         android:layout_height="0dp"
39 39
         android:layout_weight="0.33" >

+ 1
- 1
app/src/main/res/layout/default_layout.xml Datei anzeigen

@@ -33,7 +33,7 @@
33 33
     <!-- Layout -->
34 34
 
35 35
     <ScrollView
36
-        android:id="@+id/imagesScrollView"
36
+        android:id="@+id/mainScrollView"
37 37
         android:layout_width="match_parent"
38 38
         android:layout_height="0dp"
39 39
         android:layout_weight="0.33" >

+ 1
- 1
app/src/main/res/layout/sensors_layout.xml Datei anzeigen

@@ -33,7 +33,7 @@
33 33
     <!-- Layout -->
34 34
 
35 35
     <ScrollView
36
-        android:id="@+id/imagesScrollView"
36
+        android:id="@+id/mainScrollView"
37 37
         android:layout_width="match_parent"
38 38
         android:layout_height="0dp"
39 39
         android:layout_weight="0.33" >

Laden…
Abbrechen
Speichern