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

+ 22
- 11
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.res.Configuration;
3
 import android.os.Bundle;
4
 import android.os.Bundle;
5
+import android.os.PersistableBundle;
4
 import android.support.design.widget.NavigationView;
6
 import android.support.design.widget.NavigationView;
5
 import android.support.v4.view.GravityCompat;
7
 import android.support.v4.view.GravityCompat;
6
 import android.support.v4.widget.DrawerLayout;
8
 import android.support.v4.widget.DrawerLayout;
60
         init();
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
     private void init()
71
     private void init()
64
     {
72
     {
65
         List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
73
         List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
81
         // Force drawer update; need a fix
89
         // Force drawer update; need a fix
82
         MenuItem item = _navigationView.getMenu().add("test42");
90
         MenuItem item = _navigationView.getMenu().add("test42");
83
         _navigationView.getMenu().removeItem(item.getItemId());
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
         CamotionFragment fragment;
143
         CamotionFragment fragment;
133
         if (view == R.id.nav_cameras) {
144
         if (view == R.id.nav_cameras) {
134
             fragment = new CamerasFragment();
145
             fragment = new CamerasFragment();
135
-        }
136
-        else if (view == R.id.nav_sensors) {
146
+        } else if (view == R.id.nav_sensors) {
137
             fragment = new SensorsFragment();
147
             fragment = new SensorsFragment();
138
-        }
139
-        else if (view == R.id.nav_commands) {
148
+        } else if (view == R.id.nav_commands) {
140
             fragment = new CommandsFragment();
149
             fragment = new CommandsFragment();
141
-        }
142
-        else if (view == -1)
143
-        {
150
+        } else if (view == -1) {
144
             fragment = new DefaultFragment();
151
             fragment = new DefaultFragment();
145
-        }
146
-        else
147
-        {
152
+        } else {
148
             return;
153
             return;
149
         }
154
         }
150
         fragment.setCamotionDbo(_fullLoginDbo, _currentLocation);
155
         fragment.setCamotionDbo(_fullLoginDbo, _currentLocation);
173
         drawer.closeDrawer(GravityCompat.START);
178
         drawer.closeDrawer(GravityCompat.START);
174
         return true;
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
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
 import android.graphics.Bitmap;
4
 import android.graphics.Bitmap;
5
+import android.os.Handler;
5
 import android.util.AttributeSet;
6
 import android.util.AttributeSet;
6
 import android.view.View;
7
 import android.view.View;
7
 import android.widget.ImageView;
8
 import android.widget.ImageView;
26
 
27
 
27
     private ImageView _imageView;
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
     public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
35
     public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
30
     {
36
     {
31
         _fullLoginDbo = fullLoginDbo;
37
         _fullLoginDbo = fullLoginDbo;
41
 
47
 
42
         ((TextView)findViewById(R.id.textViewName)).setText(_camera.getName());
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
             @Override
51
             @Override
46
             public void onClick(View v) {
52
             public void onClick(View v) {
47
                 togglePlay();
53
                 togglePlay();
80
 
86
 
81
     public void togglePlay()
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
                 .then(new LuPromise.LuConsumer<Bitmap>() {
117
                 .then(new LuPromise.LuConsumer<Bitmap>() {
85
                     @Override
118
                     @Override
86
                     public void execute(Bitmap image) {
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
                 }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
131
                 }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
90
                     @Override
132
                     @Override

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


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

29
             android:layout_centerVertical="true"
29
             android:layout_centerVertical="true"
30
             android:layout_centerHorizontal="true"
30
             android:layout_centerHorizontal="true"
31
             android:translationZ="10dp"
31
             android:translationZ="10dp"
32
-            android:src="@drawable/abc_btn_radio_to_on_mtrl_015"/>
32
+            android:src="@mipmap/pause"/>
33
     </RelativeLayout>
33
     </RelativeLayout>
34
 
34
 
35
     <TextView
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
 
73
 
74
     private LuPromiseError _error = null;
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
         _onFailed = onFailed;
78
         _onFailed = onFailed;
79
         if (_status == LuPromiseStatus.Failed) {
79
         if (_status == LuPromiseStatus.Failed) {
80
             _onFailed.execute(_error);
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
         _onSuccess = onSuccess;
87
         _onSuccess = onSuccess;
88
         if (_status == LuPromiseStatus.Resolved) {
88
         if (_status == LuPromiseStatus.Resolved) {
89
             _onSuccess.execute(_data);
89
             _onSuccess.execute(_data);
90
         }
90
         }
91
+        return this;
91
     }
92
     }
92
 
93
 
93
     public void resolve(T data)
94
     public void resolve(T data)

Loading…
Cancel
Save