@byteplus/react-native-live-pull 1.1.1-rc.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/volcengine/velive/rn/pull/pictureInpicture/FloatingWindowHelper.java +1 -0
- package/android/src/main/java/com/volcengine/velive/rn/pull/pictureInpicture/FloatingWindowService.java +60 -5
- package/lib/commonjs/index.js +5 -2803
- package/lib/module/index.js +5 -2803
- package/package.json +1 -1
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
package com.volcengine.velive.rn.pull.pictureInpicture;
|
|
2
2
|
|
|
3
3
|
import android.app.Service;
|
|
4
|
+
import android.content.BroadcastReceiver;
|
|
5
|
+
import android.content.Context;
|
|
4
6
|
import android.content.Intent;
|
|
7
|
+
import android.content.IntentFilter;
|
|
5
8
|
import android.graphics.PixelFormat;
|
|
6
9
|
import android.os.Build;
|
|
10
|
+
import android.os.Handler;
|
|
7
11
|
import android.os.IBinder;
|
|
12
|
+
import android.os.Looper;
|
|
8
13
|
import android.provider.Settings;
|
|
9
14
|
import android.util.DisplayMetrics; // Import DisplayMetrics
|
|
10
15
|
import android.util.Log;
|
|
@@ -26,7 +31,10 @@ public class FloatingWindowService extends Service {
|
|
|
26
31
|
private WindowManager.LayoutParams mLayoutParams;
|
|
27
32
|
private SurfaceView mSurfaceView;
|
|
28
33
|
private View mSmallWindowView;
|
|
34
|
+
private ActivityLaunchReceiver mActivityLaunchReceiver;
|
|
29
35
|
|
|
36
|
+
public static final String ACTION_STOP_PIP_SERVICE =
|
|
37
|
+
"com.volcengine.velive.rn.pull.STOP_PIP_SERVICE";
|
|
30
38
|
public static final String INTENT_EXTRA_KEY_ASPECT_RATIO = "aspect_ratio";
|
|
31
39
|
public static final String INTENT_EXTRA_KEY_X_POS = "x_pos";
|
|
32
40
|
public static final String INTENT_EXTRA_KEY_Y_POS = "y_pos";
|
|
@@ -52,8 +60,14 @@ public class FloatingWindowService extends Service {
|
|
|
52
60
|
public void onDestroy() {
|
|
53
61
|
Log.d(TAG, "onDestroy");
|
|
54
62
|
super.onDestroy();
|
|
63
|
+
unregisterActivityLaunchReceiver(); // Ensure receiver is unregistered on
|
|
64
|
+
// destroy
|
|
55
65
|
if (mSmallWindowView != null) {
|
|
56
|
-
|
|
66
|
+
try {
|
|
67
|
+
mWindowManager.removeView(mSmallWindowView);
|
|
68
|
+
} catch (Exception e) {
|
|
69
|
+
Log.e(TAG, "Error removing view: " + e.getMessage());
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
72
|
FloatingWindowHelper.getInstance().onStopService();
|
|
59
73
|
}
|
|
@@ -117,12 +131,15 @@ public class FloatingWindowService extends Service {
|
|
|
117
131
|
mWindowManager.addView(mSmallWindowView, mLayoutParams);
|
|
118
132
|
mSurfaceView = mSmallWindowView.findViewById(R.id.surface_view);
|
|
119
133
|
mSmallWindowView.findViewById(R.id.surface_close_btn)
|
|
120
|
-
.setOnClickListener(v -> {
|
|
134
|
+
.setOnClickListener(v -> {
|
|
135
|
+
unregisterActivityLaunchReceiver();
|
|
136
|
+
stopSelf();
|
|
137
|
+
});
|
|
121
138
|
|
|
122
139
|
mSmallWindowView.findViewById(R.id.new_window_btn)
|
|
123
140
|
.setOnClickListener(v -> {
|
|
124
141
|
Log.d(TAG, "PIP window clicked");
|
|
125
|
-
|
|
142
|
+
|
|
126
143
|
try {
|
|
127
144
|
// Get the pacain activity
|
|
128
145
|
String packageName = this.getPackageName();
|
|
@@ -133,6 +150,8 @@ public class FloatingWindowService extends Service {
|
|
|
133
150
|
if (launchIntent != null) {
|
|
134
151
|
Log.d(TAG, "Launching app with intent: " + launchIntent);
|
|
135
152
|
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
153
|
+
// Register receiver to stop service when activity is launched
|
|
154
|
+
registerActivityLaunchReceiver();
|
|
136
155
|
this.startActivity(launchIntent);
|
|
137
156
|
} else {
|
|
138
157
|
Log.e(TAG, "Could not create launch intent for package: " +
|
|
@@ -141,13 +160,49 @@ public class FloatingWindowService extends Service {
|
|
|
141
160
|
} catch (Exception e) {
|
|
142
161
|
Log.e(TAG, "Error launching app: " + e.getMessage(), e);
|
|
143
162
|
}
|
|
144
|
-
|
|
145
|
-
stopSelf();
|
|
146
163
|
});
|
|
147
164
|
}
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
|
|
168
|
+
private void registerActivityLaunchReceiver() {
|
|
169
|
+
if (mActivityLaunchReceiver == null) {
|
|
170
|
+
mActivityLaunchReceiver = new ActivityLaunchReceiver();
|
|
171
|
+
IntentFilter filter = new IntentFilter(ACTION_STOP_PIP_SERVICE);
|
|
172
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
173
|
+
registerReceiver(mActivityLaunchReceiver, filter,
|
|
174
|
+
Context.RECEIVER_EXPORTED);
|
|
175
|
+
} else {
|
|
176
|
+
registerReceiver(mActivityLaunchReceiver, filter);
|
|
177
|
+
}
|
|
178
|
+
Log.d(TAG, "ActivityLaunchReceiver registered");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private void unregisterActivityLaunchReceiver() {
|
|
183
|
+
if (mActivityLaunchReceiver != null) {
|
|
184
|
+
try {
|
|
185
|
+
unregisterReceiver(mActivityLaunchReceiver);
|
|
186
|
+
mActivityLaunchReceiver = null;
|
|
187
|
+
Log.d(TAG, "ActivityLaunchReceiver unregistered");
|
|
188
|
+
} catch (IllegalArgumentException e) {
|
|
189
|
+
Log.e(TAG, "Receiver not registered: " + e.getMessage());
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// BroadcastReceiver to listen for activity launch confirmation
|
|
195
|
+
private class ActivityLaunchReceiver extends BroadcastReceiver {
|
|
196
|
+
@Override
|
|
197
|
+
public void onReceive(Context context, Intent intent) {
|
|
198
|
+
Log.d(TAG, "Received broadcast to stop PIP service");
|
|
199
|
+
if (ACTION_STOP_PIP_SERVICE.equals(intent.getAction())) {
|
|
200
|
+
stopSelf(); // Stop the service
|
|
201
|
+
unregisterActivityLaunchReceiver(); // Unregister receiver
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
151
206
|
private class FloatingOnTouchListener implements View.OnTouchListener {
|
|
152
207
|
private final int touchSlop =
|
|
153
208
|
ViewConfiguration
|