@byteplus/react-native-live-pull 1.1.1-rc.0 → 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.
@@ -174,6 +174,7 @@ public class FloatingWindowHelper implements IFloatingWindowHelper {
174
174
 
175
175
  mConfig = null;
176
176
  mExtraDataMap = null;
177
+ isRunning = false;
177
178
  }
178
179
 
179
180
  public static class AssistantActivity extends Activity {
@@ -1,21 +1,17 @@
1
- /**
2
- * Copyright (c) 2023 Beijing Volcano Engine Technology Ltd. All rights
3
- * reserved. Licensed under the MIT License (the "License"); you may not use
4
- * this file except in compliance with the License. You may obtain a copy of the
5
- * License at http://opensource.org/licenses/MIT Unless required by applicable
6
- * law or agreed to in writing, software distributed under the License is
7
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8
- * KIND, either express or implied. See the License for the specific language
9
- * governing permissions and limitations under the License.
10
- */
11
1
  package com.volcengine.velive.rn.pull.pictureInpicture;
12
2
 
13
3
  import android.app.Service;
4
+ import android.content.BroadcastReceiver;
5
+ import android.content.Context;
14
6
  import android.content.Intent;
7
+ import android.content.IntentFilter;
15
8
  import android.graphics.PixelFormat;
16
9
  import android.os.Build;
10
+ import android.os.Handler;
17
11
  import android.os.IBinder;
12
+ import android.os.Looper;
18
13
  import android.provider.Settings;
14
+ import android.util.DisplayMetrics; // Import DisplayMetrics
19
15
  import android.util.Log;
20
16
  import android.view.Gravity;
21
17
  import android.view.LayoutInflater;
@@ -29,13 +25,16 @@ import com.volcengine.velive.rn.pull.R;
29
25
 
30
26
  public class FloatingWindowService extends Service {
31
27
  private static final String TAG = FloatingWindowService.class.getSimpleName();
32
- private static final int LONGER_SIDE_MAX_LEN = 800;
28
+ private static final int LONGER_SIDE_MAX_LEN = 1000;
33
29
 
34
30
  private WindowManager mWindowManager;
35
31
  private WindowManager.LayoutParams mLayoutParams;
36
32
  private SurfaceView mSurfaceView;
37
33
  private View mSmallWindowView;
34
+ private ActivityLaunchReceiver mActivityLaunchReceiver;
38
35
 
36
+ public static final String ACTION_STOP_PIP_SERVICE =
37
+ "com.volcengine.velive.rn.pull.STOP_PIP_SERVICE";
39
38
  public static final String INTENT_EXTRA_KEY_ASPECT_RATIO = "aspect_ratio";
40
39
  public static final String INTENT_EXTRA_KEY_X_POS = "x_pos";
41
40
  public static final String INTENT_EXTRA_KEY_Y_POS = "y_pos";
@@ -61,8 +60,14 @@ public class FloatingWindowService extends Service {
61
60
  public void onDestroy() {
62
61
  Log.d(TAG, "onDestroy");
63
62
  super.onDestroy();
63
+ unregisterActivityLaunchReceiver(); // Ensure receiver is unregistered on
64
+ // destroy
64
65
  if (mSmallWindowView != null) {
65
- mWindowManager.removeView(mSmallWindowView);
66
+ try {
67
+ mWindowManager.removeView(mSmallWindowView);
68
+ } catch (Exception e) {
69
+ Log.e(TAG, "Error removing view: " + e.getMessage());
70
+ }
66
71
  }
67
72
  FloatingWindowHelper.getInstance().onStopService();
68
73
  }
@@ -86,16 +91,29 @@ public class FloatingWindowService extends Service {
86
91
  mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
87
92
  WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
88
93
 
94
+ // Get screen dimensions
95
+ DisplayMetrics displayMetrics = new DisplayMetrics();
96
+ mWindowManager.getDefaultDisplay().getMetrics(displayMetrics);
97
+ int screenWidth = displayMetrics.widthPixels;
98
+ int screenHeight = displayMetrics.heightPixels;
99
+
100
+ // Calculate the minimum screen dimension
101
+ int minScreenDim = Math.min(screenWidth, screenHeight);
102
+
103
+ // Determine the maximum length based on the smaller of 1000 and
104
+ // minScreenDim
105
+ int maxLen = Math.min(LONGER_SIDE_MAX_LEN, minScreenDim);
106
+
89
107
  // Limit the floating window size to prevent it from being too large or too
90
- // small, control the longer side to LONGER_SIDE_MAX_LEN, scale the shorter
108
+ // small, control the longer side to maxLen, scale the shorter
91
109
  // side proportionally
92
110
  int width, height;
93
111
  if (aspectRatio >= 1) {
94
- height = (int)(LONGER_SIDE_MAX_LEN / aspectRatio);
95
- width = LONGER_SIDE_MAX_LEN;
112
+ height = (int)(maxLen / aspectRatio);
113
+ width = maxLen;
96
114
  } else {
97
- width = (int)(LONGER_SIDE_MAX_LEN * aspectRatio);
98
- height = LONGER_SIDE_MAX_LEN;
115
+ width = (int)(maxLen * aspectRatio);
116
+ height = maxLen;
99
117
  }
100
118
  mLayoutParams.width = width;
101
119
  mLayoutParams.height = height;
@@ -114,9 +132,73 @@ public class FloatingWindowService extends Service {
114
132
  mSurfaceView = mSmallWindowView.findViewById(R.id.surface_view);
115
133
  mSmallWindowView.findViewById(R.id.surface_close_btn)
116
134
  .setOnClickListener(v -> {
117
- FloatingWindowHelper.getInstance().performClose(
118
- FloatingWindowService.this);
135
+ unregisterActivityLaunchReceiver();
136
+ stopSelf();
119
137
  });
138
+
139
+ mSmallWindowView.findViewById(R.id.new_window_btn)
140
+ .setOnClickListener(v -> {
141
+ Log.d(TAG, "PIP window clicked");
142
+
143
+ try {
144
+ // Get the pacain activity
145
+ String packageName = this.getPackageName();
146
+ Intent launchIntent =
147
+ this.getPackageManager().getLaunchIntentForPackage(
148
+ packageName);
149
+
150
+ if (launchIntent != null) {
151
+ Log.d(TAG, "Launching app with intent: " + launchIntent);
152
+ launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
153
+ // Register receiver to stop service when activity is launched
154
+ registerActivityLaunchReceiver();
155
+ this.startActivity(launchIntent);
156
+ } else {
157
+ Log.e(TAG, "Could not create launch intent for package: " +
158
+ packageName);
159
+ }
160
+ } catch (Exception e) {
161
+ Log.e(TAG, "Error launching app: " + e.getMessage(), e);
162
+ }
163
+ });
164
+ }
165
+ }
166
+ }
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
120
202
  }
121
203
  }
122
204
  }
@@ -187,29 +187,6 @@ public class PictureInPictureManager {
187
187
  if (mListener != null) {
188
188
  mListener.onClickPictureInPicture();
189
189
  }
190
- Log.d(TAG, "PIP window clicked");
191
-
192
- try {
193
- // Get the package manager and launch the app's main activity
194
- String packageName = context.getPackageName();
195
- Intent launchIntent =
196
- context.getPackageManager().getLaunchIntentForPackage(
197
- packageName);
198
-
199
- if (launchIntent != null) {
200
- Log.d(TAG, "Launching app with intent: " + launchIntent);
201
- launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
202
- context.startActivity(launchIntent);
203
- } else {
204
- Log.e(TAG, "Could not create launch intent for package: " +
205
- packageName);
206
- }
207
- } catch (Exception e) {
208
- Log.e(TAG, "Error launching app: " + e.getMessage(), e);
209
- }
210
-
211
- // Close the floating window
212
- mFloatingWindowHelper.closeFloatingWindow(context);
213
190
  }
214
191
 
215
192
  @Override
@@ -1,14 +1,9 @@
1
1
  <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
- android:width="24dp"
3
- android:height="24dp"
4
- android:autoMirrored="true"
5
- android:viewportWidth="612"
6
- android:viewportHeight="612">
2
+ android:width="24dp"
3
+ android:height="24dp"
4
+ android:viewportWidth="24"
5
+ android:viewportHeight="24">
7
6
  <path
8
- android:fillColor="#FF000000"
9
- android:pathData="M612,306C612,137.004 474.995,0 306,0C137.004,0 0,137.004 0,
10
- 306c0,168.995 137.004,306 306,306C474.995,612 612,474.995 612,
11
- 306zM168.3,424.032L286.333,306L168.3,187.967l19.667,-19.667L306,
12
- 286.333L424.032,168.3l19.668,19.667L325.667,306L443.7,424.032L424.032,
13
- 443.7L306,325.667L187.967,443.7L168.3,424.032z" />
7
+ android:fillColor="#FFFFFF"
8
+ android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
14
9
  </vector>
@@ -0,0 +1,16 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="48dp"
3
+ android:height="48dp"
4
+ android:viewportWidth="48.0"
5
+ android:viewportHeight="48.0">
6
+ <path
7
+ android:fillColor="#FFFFFF"
8
+ android:pathData="M6,4H22V8H8V40H40V26H44V42C44,43.1046 43.1046,44 42,44H6C4.89543,44 4,43.1046 4,42V6C4,4.89543 4.89543,4 6,4Z"/>
9
+ <path
10
+ android:fillColor="#FFFFFF"
11
+ android:pathData="M44,20V6C44,4.89543 43.1046,4 42,4H28V8H40V20H44Z"/>
12
+ <path
13
+ android:fillColor="#FFFFFF"
14
+ android:fillType="evenOdd"
15
+ android:pathData="M42.0711,4C43.1756,4 44.0711,4.89543 44.0711,6V20H40.0711V10.828L28.1213,22.7782C27.7308,23.1687 27.0976,23.1687 26.7071,22.7782L25.2929,21.364C24.9024,20.9734 24.9024,20.3403 25.2929,19.9497L37.2421,7.999L28.0711,8V4L42.0711,4Z"/>
16
+ </vector>
@@ -2,13 +2,14 @@
2
2
  <RelativeLayout
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  android:layout_width="match_parent"
5
- android:layout_height="match_parent">
5
+ android:layout_height="match_parent"
6
+ >
6
7
 
7
8
  <SurfaceView
8
9
  android:id="@+id/surface_view"
9
10
  android:layout_width="match_parent"
10
- android:layout_height="match_parent">
11
- </SurfaceView>
11
+ android:layout_height="match_parent"
12
+ ></SurfaceView>
12
13
  <Button
13
14
  android:id="@+id/surface_close_btn"
14
15
  android:background="@drawable/button_close"
@@ -16,4 +17,13 @@
16
17
  android:layout_height="20dp"
17
18
  android:layout_marginTop="4dp"
18
19
  android:layout_marginStart="4dp" />
20
+ <Button
21
+ android:id="@+id/new_window_btn"
22
+ android:background="@drawable/new_window"
23
+ android:layout_width="16dp"
24
+ android:layout_height="16dp"
25
+ android:layout_marginTop="4dp"
26
+ android:layout_marginEnd="4dp"
27
+ android:layout_alignParentTop="true"
28
+ android:layout_alignParentEnd="true" />
19
29
  </RelativeLayout>