Browse Source

finished camera view

tags/0.0.5
Robin Thoni 9 years ago
parent
commit
43753c8a4d

+ 1
- 0
app/src/main/AndroidManifest.xml View File

@@ -15,6 +15,7 @@
15 15
         android:supportsRtl="true"
16 16
         android:theme="@style/AppTheme">
17 17
         <activity
18
+            android:screenOrientation="portrait"
18 19
             android:name=".ui.MainActivity"
19 20
             android:label="@string/app_name"
20 21
             android:theme="@style/AppTheme.NoActionBar">

+ 22
- 11
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java View File

@@ -1,6 +1,8 @@
1 1
 package com.rthoni.camotion.ui;
2 2
 
3
+import android.content.res.Configuration;
3 4
 import android.os.Bundle;
5
+import android.os.PersistableBundle;
4 6
 import android.support.design.widget.NavigationView;
5 7
 import android.support.v4.view.GravityCompat;
6 8
 import android.support.v4.widget.DrawerLayout;
@@ -60,6 +62,12 @@ public class MainActivity extends AppCompatActivity
60 62
         init();
61 63
     }
62 64
 
65
+    @Override
66
+    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
67
+        super.onSaveInstanceState(outState, outPersistentState);
68
+
69
+    }
70
+
63 71
     private void init()
64 72
     {
65 73
         List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
@@ -81,7 +89,10 @@ public class MainActivity extends AppCompatActivity
81 89
         // Force drawer update; need a fix
82 90
         MenuItem item = _navigationView.getMenu().add("test42");
83 91
         _navigationView.getMenu().removeItem(item.getItemId());
84
-        setLocation(locations.get(0));
92
+
93
+        if (_currentLocation == null) {
94
+            setLocation(locations.get(0));
95
+        }
85 96
 
86 97
     }
87 98
 
@@ -132,19 +143,13 @@ public class MainActivity extends AppCompatActivity
132 143
         CamotionFragment fragment;
133 144
         if (view == R.id.nav_cameras) {
134 145
             fragment = new CamerasFragment();
135
-        }
136
-        else if (view == R.id.nav_sensors) {
146
+        } else if (view == R.id.nav_sensors) {
137 147
             fragment = new SensorsFragment();
138
-        }
139
-        else if (view == R.id.nav_commands) {
148
+        } else if (view == R.id.nav_commands) {
140 149
             fragment = new CommandsFragment();
141
-        }
142
-        else if (view == -1)
143
-        {
150
+        } else if (view == -1) {
144 151
             fragment = new DefaultFragment();
145
-        }
146
-        else
147
-        {
152
+        } else {
148 153
             return;
149 154
         }
150 155
         fragment.setCamotionDbo(_fullLoginDbo, _currentLocation);
@@ -173,4 +178,10 @@ public class MainActivity extends AppCompatActivity
173 178
         drawer.closeDrawer(GravityCompat.START);
174 179
         return true;
175 180
     }
181
+
182
+    @Override
183
+    public void onConfigurationChanged(Configuration newConfig)
184
+    {
185
+        super.onConfigurationChanged(newConfig);
186
+    }
176 187
 }

+ 45
- 3
app/src/main/java/com/rthoni/camotion/ui/views/CameraView.java View File

@@ -2,6 +2,7 @@ package com.rthoni.camotion.ui.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.graphics.Bitmap;
5
+import android.os.Handler;
5 6
 import android.util.AttributeSet;
6 7
 import android.view.View;
7 8
 import android.widget.ImageView;
@@ -26,6 +27,11 @@ public class CameraView extends RelativeLayout {
26 27
 
27 28
     private ImageView _imageView;
28 29
 
30
+    private int _interval = 500;
31
+
32
+    private boolean _playing = false;
33
+    private LuPromise<Bitmap> _promise = null;
34
+
29 35
     public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
30 36
     {
31 37
         _fullLoginDbo = fullLoginDbo;
@@ -41,7 +47,7 @@ public class CameraView extends RelativeLayout {
41 47
 
42 48
         ((TextView)findViewById(R.id.textViewName)).setText(_camera.getName());
43 49
 
44
-        findViewById(R.id.imageView).setOnClickListener(new OnClickListener() {
50
+        findViewById(R.id.imageViewPause).setOnClickListener(new OnClickListener() {
45 51
             @Override
46 52
             public void onClick(View v) {
47 53
                 togglePlay();
@@ -80,11 +86,47 @@ public class CameraView extends RelativeLayout {
80 86
 
81 87
     public void togglePlay()
82 88
     {
83
-        CamerasBusiness.getImage(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _camera)
89
+        if (_playing)
90
+        {
91
+            pause();
92
+        }
93
+        else
94
+        {
95
+            play();
96
+        }
97
+    }
98
+
99
+    public void pause()
100
+    {
101
+        _playing = false;
102
+        findViewById(R.id.imageViewPause).setVisibility(VISIBLE);
103
+    }
104
+
105
+    public void play()
106
+    {
107
+        _playing = true;
108
+        findViewById(R.id.imageViewPause).setVisibility(GONE);
109
+        if (_promise == null || _promise.getStatus() != LuPromise.LuPromiseStatus.Running) {
110
+            _play();
111
+        }
112
+    }
113
+
114
+    private void _play()
115
+    {
116
+        _promise = CamerasBusiness.getImage(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _camera)
84 117
                 .then(new LuPromise.LuConsumer<Bitmap>() {
85 118
                     @Override
86 119
                     public void execute(Bitmap image) {
87
-                        _imageView.setImageBitmap(image);
120
+                        if (_playing) {
121
+                            _imageView.setImageBitmap(image);
122
+                            Handler h = new Handler();
123
+                            h.postDelayed(new Runnable() {
124
+                                @Override
125
+                                public void run() {
126
+                                    _play();
127
+                                }
128
+                            }, _interval);
129
+                        }
88 130
                     }
89 131
                 }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
90 132
                     @Override

BIN
app/src/main/pause-web.png View File


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

@@ -29,7 +29,7 @@
29 29
             android:layout_centerVertical="true"
30 30
             android:layout_centerHorizontal="true"
31 31
             android:translationZ="10dp"
32
-            android:src="@drawable/abc_btn_radio_to_on_mtrl_015"/>
32
+            android:src="@mipmap/pause"/>
33 33
     </RelativeLayout>
34 34
 
35 35
     <TextView

BIN
app/src/main/res/mipmap-hdpi/pause.png View File


BIN
app/src/main/res/mipmap-mdpi/pause.png View File


BIN
app/src/main/res/mipmap-xhdpi/pause.png View File


BIN
app/src/main/res/mipmap-xxhdpi/pause.png View File


BIN
app/src/main/res/mipmap-xxxhdpi/pause.png View File


+ 4
- 3
luticateutils/src/main/java/com/luticate/utils/business/LuPromise.java View File

@@ -73,21 +73,22 @@ public class LuPromise<T> {
73 73
 
74 74
     private LuPromiseError _error = null;
75 75
 
76
-    public void then(LuConsumer<T> onSuccess, LuConsumer<LuPromiseError> onFailed)
76
+    public LuPromise<T> then(LuConsumer<T> onSuccess, LuConsumer<LuPromiseError> onFailed)
77 77
     {
78 78
         _onFailed = onFailed;
79 79
         if (_status == LuPromiseStatus.Failed) {
80 80
             _onFailed.execute(_error);
81 81
         }
82
-        then(onSuccess);
82
+        return then(onSuccess);
83 83
     }
84 84
 
85
-    public void then(LuConsumer<T> onSuccess)
85
+    public LuPromise<T> then(LuConsumer<T> onSuccess)
86 86
     {
87 87
         _onSuccess = onSuccess;
88 88
         if (_status == LuPromiseStatus.Resolved) {
89 89
             _onSuccess.execute(_data);
90 90
         }
91
+        return this;
91 92
     }
92 93
 
93 94
     public void resolve(T data)

Loading…
Cancel
Save