4
4
import android .content .Intent ;
5
5
import android .os .IBinder ;
6
6
import android .os .RemoteException ;
7
- import android .view .WindowManager ;
8
7
8
+ import com .android .mxlibrary .util .XLog ;
9
9
import com .codemx .effectivecard .launcherclient .ILauncherOverlay ;
10
10
import com .codemx .effectivecard .launcherclient .ILauncherOverlayCallback ;
11
+ import com .codemx .effectivecard .launcherclient .MxLayoutParams ;
12
+
13
+ import java .lang .ref .WeakReference ;
11
14
12
15
/**
13
16
* Created by yuchuan
17
20
public class CardService extends Service {
18
21
19
22
private ILauncherOverlay .Stub mStub ;
20
- private ILauncherOverlayCallback mCallback ;
23
+ // 向Launcher通信的回调函数,对应LauncherOverlayCallbacks
24
+ private ILauncherOverlayCallback mOverlayCallback ;
21
25
22
26
@ Override
23
27
public void onCreate () {
24
28
super .onCreate ();
25
- mStub = new CardBinder ();
29
+ XLog .d (XLog .getTag (), "onCreate" );
30
+ mStub = new CardBinder (this );
26
31
}
27
32
28
33
@ Override
29
34
public IBinder onBind (Intent intent ) {
30
35
return mStub ;
31
36
}
32
37
38
+ @ Override
39
+ public int onStartCommand (Intent intent , int flags , int startId ) {
40
+ XLog .d (XLog .getTag (), "onStartCommand" );
41
+ return super .onStartCommand (intent , flags , startId );
42
+ }
43
+
44
+ @ Override
45
+ public boolean onUnbind (Intent intent ) {
46
+ XLog .d (XLog .getTag (), "onUnbind" );
47
+ return super .onUnbind (intent );
48
+ }
49
+
50
+ @ Override
51
+ public void onDestroy () {
52
+ super .onDestroy ();
53
+ XLog .d (XLog .getTag (), "onDestroy" );
54
+ }
55
+
33
56
// Launcher通过服务会调用这里的函数来达到与launcher同步,然后控制window滑动
34
57
private static class CardBinder extends ILauncherOverlay .Stub {
58
+ private WeakReference <CardService > mWeakReference ;
59
+
60
+ CardBinder (CardService service ) {
61
+ mWeakReference = new WeakReference <>(service );
62
+ }
35
63
36
64
@ Override
37
65
public void startScroll () throws RemoteException {
66
+ XLog .d (XLog .getTag (), "startScroll" );
38
67
}
39
68
40
69
@ Override
41
- public void onScroll (float progress ) throws RemoteException {
70
+ public void onScroll (float progress , boolean isRtl ) throws RemoteException {
71
+ XLog .d (XLog .getTag (), "startScroll#progress= " + progress + " ,isRtl= " + isRtl );
42
72
}
43
73
44
74
@ Override
45
75
public void endScroll () throws RemoteException {
76
+ XLog .d (XLog .getTag (), "endScroll" );
46
77
}
47
78
48
79
@ Override
49
- public void windowAttached (WindowManager .LayoutParams layoutParams ,
50
- ILauncherOverlayCallback overlayCallback , int flags ) throws RemoteException {
51
-
80
+ public void windowAttached (MxLayoutParams layoutParams , ILauncherOverlayCallback overlayCallback , int flags ) throws RemoteException {
81
+ XLog .d (XLog .getTag (), "windowAttached " + layoutParams );
82
+ if (mWeakReference != null && mWeakReference .get () != null ) {
83
+ mWeakReference .get ().registerCallback (overlayCallback );
84
+ }
52
85
}
53
86
54
87
@ Override
55
88
public void windowDetached (boolean isChangingConfigurations ) throws RemoteException {
89
+ XLog .d (XLog .getTag (), "windowDetached " + isChangingConfigurations );
56
90
}
57
91
58
92
@ Override
59
93
public void closeOverlay (int flags ) throws RemoteException {
60
-
94
+ XLog . d ( XLog . getTag (), "closeOverlay " + flags );
61
95
}
62
96
63
97
@ Override
64
98
public void onPause () throws RemoteException {
99
+ XLog .d (XLog .getTag (), "onPause " );
65
100
}
66
101
67
102
@ Override
68
103
public void onResume () throws RemoteException {
104
+ XLog .d (XLog .getTag (), "onResume " );
69
105
}
70
106
71
107
@ Override
72
108
public void openOverlay (int flags ) throws RemoteException {
109
+ XLog .d (XLog .getTag (), "openOverlay " + flags );
73
110
}
74
111
75
112
@ Override
76
113
public void requestVoiceDetection (boolean start ) throws RemoteException {
77
-
114
+ XLog . d ( XLog . getTag (), "requestVoiceDetection " + start );
78
115
}
79
116
80
117
@ Override
@@ -89,7 +126,7 @@ public boolean isVoiceDetectionRunning() throws RemoteException {
89
126
90
127
@ Override
91
128
public void enableScroll (boolean left , boolean right ) throws RemoteException {
92
-
129
+ XLog . d ( XLog . getTag (), "enableScroll left: " + left + " ,right: " + right );
93
130
}
94
131
95
132
@ Override
@@ -103,4 +140,8 @@ public void enableLoopWithOverlay(boolean enableLoop) throws RemoteException {
103
140
}
104
141
}
105
142
143
+ private void registerCallback (ILauncherOverlayCallback overlayCallback ) {
144
+ this .mOverlayCallback = overlayCallback ;
145
+ }
146
+
106
147
}
0 commit comments