31
31
import com .troop .freedcam .R ;
32
32
33
33
import freed .cam .apis .basecamera .CameraWrapperInterface ;
34
+ import freed .cam .apis .basecamera .modules .ModuleChangedEvent ;
34
35
import freed .cam .apis .basecamera .modules .ModuleHandlerAbstract ;
35
36
import freed .cam .apis .basecamera .modules .ModuleHandlerAbstract .CaptureStates ;
36
37
import freed .settings .Settings ;
41
42
/**
42
43
* Created by troop on 20.06.2015.
43
44
*/
44
- public class ShutterButton extends android .support .v7 .widget .AppCompatButton implements ModuleHandlerAbstract .CaptureStateChanged {
45
+ public class ShutterButton extends android .support .v7 .widget .AppCompatButton implements ModuleHandlerAbstract .CaptureStateChanged , ModuleChangedEvent {
45
46
private CameraWrapperInterface cameraUiWrapper ;
46
47
47
48
private final String TAG = ShutterButton .class .getSimpleName ();
@@ -53,9 +54,11 @@ public class ShutterButton extends android.support.v7.widget.AppCompatButton imp
53
54
* Starts a background thread and its {@link Handler}.
54
55
*/
55
56
private void startBackgroundThread () {
56
- mBackgroundThread = new HandlerThread ("ShutterDraw" );
57
- mBackgroundThread .start ();
58
- animationHandler = new ShutterAnimationHandler (mBackgroundThread .getLooper (),getResources (),this );
57
+ if (mBackgroundThread == null || !mBackgroundThread .isAlive ()) {
58
+ mBackgroundThread = new HandlerThread ("ShutterDraw" );
59
+ mBackgroundThread .start ();
60
+ animationHandler = new ShutterAnimationHandler (mBackgroundThread .getLooper (), getResources (), this );
61
+ }
59
62
}
60
63
61
64
/**
@@ -103,6 +106,7 @@ protected void onDetachedFromWindow() {
103
106
104
107
private void init (Context context ) {
105
108
109
+ startBackgroundThread ();
106
110
//set background img that get then overdrawn
107
111
setBackgroundResource (R .drawable .shutter5 );
108
112
@@ -139,9 +143,12 @@ public void SetCameraUIWrapper(CameraWrapperInterface cameraUiWrapper, UserMessa
139
143
if (cameraUiWrapper .getModuleHandler () == null )
140
144
return ;
141
145
this .cameraUiWrapper = cameraUiWrapper ;
146
+ cameraUiWrapper .getModuleHandler ().addListner (this );
142
147
cameraUiWrapper .getModuleHandler ().setWorkListner (this );
143
- if (cameraUiWrapper .getModuleHandler ().getCurrentModule () != null )
148
+ if (cameraUiWrapper .getModuleHandler ().getCurrentModule () != null ) {
144
149
onCaptureStateChanged (cameraUiWrapper .getModuleHandler ().getCurrentModule ().getCurrentCaptureState ());
150
+
151
+ }
145
152
Log .d (this .TAG , "Set cameraUiWrapper to ShutterButton" );
146
153
}
147
154
@@ -207,4 +214,10 @@ protected void onDraw(Canvas canvas)
207
214
animationHandler .onDraw (canvas );
208
215
}
209
216
217
+ @ Override
218
+ public void onModuleChanged (String module ) {
219
+ if (cameraUiWrapper .getModuleHandler ().getCurrentModule () != null ) {
220
+ onCaptureStateChanged (cameraUiWrapper .getModuleHandler ().getCurrentModule ().getCurrentCaptureState ());
221
+ }
222
+ }
210
223
}
0 commit comments