Skip to content

Commit 8a6c6fd

Browse files
committed
fix large screen fit
1 parent f9ede58 commit 8a6c6fd

59 files changed

Lines changed: 869 additions & 318 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/app/src/main/AndroidManifest.xml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
2626
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
2727
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
28+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
29+
<uses-permission android:name="android.permission.NFC" />
2830
<uses-permission android:name="android.permission.INTERNET" />
2931
<uses-permission android:name="android.permission.WAKE_LOCK" />
3032
<uses-permission android:name="android.permission.READ_LOGS" />
@@ -46,6 +48,7 @@
4648
<application
4749
android:name="com.alipay.hulu.activity.MyApplication"
4850
android:icon="@mipmap/ic_launcher"
51+
android:usesCleartextTraffic="true"
4952
android:label="@string/app_name"
5053
tools:node="merge"
5154
android:largeHeap="true"
@@ -70,6 +73,7 @@
7073
<activity
7174
android:name=".activity.CaseEditActivity"
7275
android:label="@string/activity__case_edit"
76+
android:configChanges="orientation|keyboard|screenSize"
7377
android:screenOrientation="unspecified"/>
7478
<activity
7579
android:name=".activity.InfoActivity"
@@ -87,6 +91,7 @@
8791
<activity
8892
android:name=".activity.CaseReplayResultActivity"
8993
android:label="@string/activity__replay_result"
94+
android:configChanges="orientation|keyboard|screenSize"
9095
android:screenOrientation="unspecified"/>
9196
<activity
9297
android:name=".activity.NewReplayListActivity"
@@ -118,7 +123,8 @@
118123

119124
<activity android:name=".activity.BatchReplayResultActivity"
120125
android:label="@string/activity__batch_replay_result"
121-
android:screenOrientation="unspecified"/>
126+
android:configChanges="orientation|keyboard|screenSize"
127+
android:screenOrientation="unspecified"/>
122128
<activity android:name=".activity.LicenseActivity"
123129
android:label="@string/activity__license"
124130
android:screenOrientation="unspecified" />

‎src/app/src/main/java/com/alipay/hulu/activity/BaseActivity.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
import android.annotation.TargetApi;
1919
import android.app.ProgressDialog;
20+
import android.app.Service;
21+
import android.content.ComponentName;
2022
import android.content.Context;
23+
import android.content.Intent;
2124
import android.content.res.Configuration;
2225
import android.content.res.Resources;
2326
import android.os.Build;
@@ -36,6 +39,7 @@
3639

3740
import com.alipay.hulu.R;
3841
import com.alipay.hulu.common.application.LauncherApplication;
42+
import com.alipay.hulu.common.utils.ClassUtil;
3943
import com.alipay.hulu.common.utils.DeviceInfoUtil;
4044
import com.alipay.hulu.common.utils.LogUtil;
4145

@@ -134,6 +138,20 @@ public void showInputMethod() {
134138
imManager.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
135139
}
136140

141+
@Override
142+
public ComponentName startService(Intent service) {
143+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && service.getComponent() != null) {
144+
String className = service.getComponent().getClassName();
145+
Class<?> clazz = ClassUtil.getClassByName(className);
146+
if (Service.class.isAssignableFrom(clazz)) {
147+
if (LauncherApplication.getInstance().isServiceForeGround((Class<? extends Service>) clazz)) {
148+
return super.startForegroundService(service);
149+
}
150+
}
151+
}
152+
return super.startService(service);
153+
}
154+
137155
//隐藏输入法
138156
public void hideSoftInputMethod() {
139157
View view = getWindow().peekDecorView();

‎src/app/src/main/java/com/alipay/hulu/activity/NewReplayListActivity.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.support.v4.app.FragmentManager;
2525
import android.support.v4.app.FragmentPagerAdapter;
2626
import android.support.v4.view.ViewPager;
27+
import android.util.TypedValue;
2728
import android.view.LayoutInflater;
2829
import android.view.View;
2930
import android.view.ViewGroup;
@@ -63,6 +64,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6364
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
6465
params.setMarginEnd(ContextUtil.dip2px(this, 16));
6566
rightTitle.setTextColor(Color.WHITE);
67+
rightTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.textsize_13));
6668
rightTitle.setText(R.string.constant__batch_replay);
6769
rightTitle.setOnClickListener(new View.OnClickListener() {
6870
@Override

‎src/app/src/main/java/com/alipay/hulu/activity/SettingsActivity.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.alipay.hulu.shared.node.tree.export.bean.OperationStep;
5252
import com.alipay.hulu.ui.HeadControlPanel;
5353
import com.alipay.hulu.upgrade.PatchRequest;
54+
import com.alipay.hulu.util.DialogUtils;
5455
import com.alipay.hulu.util.DialogUtils.OnDialogResultListener;
5556
import com.zhy.view.flowlayout.FlowLayout;
5657
import com.zhy.view.flowlayout.TagAdapter;

‎src/app/src/main/java/com/alipay/hulu/replay/AbstractStepProvider.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void onCancel(DialogInterface dialog) {
144144
dialog.dismiss();
145145
}
146146
}).create();
147-
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
147+
dialog.getWindow().setType(com.alipay.hulu.common.constant.Constant.TYPE_ALERT);
148148
dialog.setCanceledOnTouchOutside(false);
149149
dialog.show();
150150
} catch (Exception e) {

‎src/app/src/main/java/com/alipay/hulu/scheme/PerformanceSchemeResolver.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.alipay.hulu.common.tools.BackgroundExecutor;
3131
import com.alipay.hulu.common.utils.PermissionUtil;
3232
import com.alipay.hulu.common.utils.StringUtil;
33+
import com.alipay.hulu.screenRecord.Notifications;
3334
import com.alipay.hulu.shared.display.DisplayProvider;
3435
import com.alipay.hulu.shared.display.items.base.RecordPattern;
3536
import com.alipay.hulu.util.RecordUtil;
@@ -116,7 +117,7 @@ public void onPermissionResult(boolean result, String reason) {
116117
displayProvider.startDisplay(name);
117118
}
118119
displayProvider.startRecording();
119-
notification = new Notification.Builder(context)
120+
notification = Notifications.generateNotificationBuilder(context)
120121
.setContentTitle(context.getString(R.string.performance__recording))
121122
.setOngoing(true)
122123
.setOnlyAlertOnce(true)

‎src/app/src/main/java/com/alipay/hulu/screenRecord/Notifications.java‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import android.annotation.TargetApi;
1919
import android.app.Notification;
20+
import android.app.NotificationChannel;
2021
import android.app.NotificationManager;
2122
import android.app.PendingIntent;
2223
import android.content.Context;
@@ -34,6 +35,7 @@
3435
*/
3536
@TargetApi(value = Build.VERSION_CODES.LOLLIPOP)
3637
public class Notifications extends ContextWrapper {
38+
private static final String HULU_NOTIFICATIONS_CHANNEL_ID = "hulu-notifications";
3739
private static final int id = 0x1fff;
3840
private static final String ACTION_STOP = "com.hulu.alipay.ACTION_STOP";
3941

@@ -62,7 +64,7 @@ public void recording(long timeMs) {
6264

6365
private Notification.Builder getBuilder() {
6466
if (mBuilder == null) {
65-
mBuilder = new Notification.Builder(this)
67+
mBuilder = generateNotificationBuilder(this)
6668
.setContentTitle("屏幕录制中")
6769
.setOngoing(true)
6870
.setLocalOnly(true)
@@ -75,6 +77,20 @@ private Notification.Builder getBuilder() {
7577
return mBuilder;
7678
}
7779

80+
public static Notification.Builder generateNotificationBuilder(Context context) {
81+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
82+
String channelId = HULU_NOTIFICATIONS_CHANNEL_ID;
83+
NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_DEFAULT);
84+
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
85+
if (nm.getNotificationChannel(channelId) == null) {
86+
nm.createNotificationChannel(channel);
87+
}
88+
return new Notification.Builder(context, channelId);
89+
} else {
90+
return new Notification.Builder(context);
91+
}
92+
}
93+
7894
private Notification.Action stopAction() {
7995
if (mStopAction == null) {
8096
Intent intent = new Intent(ACTION_STOP).setPackage(getPackageName());

‎src/app/src/main/java/com/alipay/hulu/screenRecord/RecordService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void onClick(View v) {
246246

247247
wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
248248
wmParams = ((MyApplication)getApplication()).getFloatWinParams();
249-
wmParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
249+
wmParams.type = com.alipay.hulu.common.constant.Constant.TYPE_ALERT;
250250
wmParams.flags |= 8;
251251
wmParams.gravity = Gravity.LEFT | Gravity.TOP; // 调整悬浮窗口至左上角
252252
// 以屏幕左上角为原点,设置x、y初始值

‎src/app/src/main/java/com/alipay/hulu/screenRecord/SimpleRecordService.java‎

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package com.alipay.hulu.screenRecord;
1717

1818
import android.annotation.TargetApi;
19-
import android.app.Service;
2019
import android.content.Context;
2120
import android.content.Intent;
21+
import android.graphics.Color;
2222
import android.media.MediaCodecInfo;
2323
import android.media.projection.MediaProjection;
2424
import android.media.projection.MediaProjectionManager;
@@ -28,9 +28,18 @@
2828
import android.os.IBinder;
2929
import android.support.annotation.NonNull;
3030
import android.support.annotation.Nullable;
31-
31+
import android.view.Gravity;
32+
import android.view.View;
33+
import android.view.WindowManager;
34+
35+
import com.alipay.hulu.R;
36+
import com.alipay.hulu.activity.MyApplication;
37+
import com.alipay.hulu.common.application.LauncherApplication;
38+
import com.alipay.hulu.common.injector.InjectorService;
39+
import com.alipay.hulu.common.utils.ContextUtil;
3240
import com.alipay.hulu.common.utils.FileUtils;
3341
import com.alipay.hulu.common.utils.LogUtil;
42+
import com.alipay.hulu.service.BaseService;
3443
import com.alipay.hulu.util.VideoUtils;
3544

3645
import java.io.File;
@@ -45,22 +54,31 @@
4554
* Created by qiaoruikai on 2019/1/9 3:31 PM.
4655
*/
4756
@TargetApi(value = Build.VERSION_CODES.LOLLIPOP)
48-
public class SimpleRecordService extends Service {
57+
public class SimpleRecordService extends BaseService {
4958

5059
public static final String INTENT_WIDTH = "INTENT_WIDTH";
5160
public static final String INTENT_HEIGHT = "INTENT_HEIGHT";
5261
public static final String INTENT_FRAME_RATE = "INTENT_FRAME_RATE";
5362
public static final String INTENT_VIDEO_BITRATE = "INTENT_VIDEO_BITRATE";
5463
public static final String INTENT_EXCEPT_DIFF = "INTENT_EXCEPT_DIFF";
64+
public static final String VIDEO_DIR = "ScreenCaptures";
65+
66+
private static final String TAG = RecordService.class.getSimpleName();
67+
private static final int NOTIFICATION_ID = 19222;
5568

56-
private static final String TAG = SimpleRecordService.class.getSimpleName();
57-
private static final String VIDEO_DIR = "ScreenCaptures";
69+
private static final int TYPE_TOAST = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY: WindowManager.LayoutParams.TYPE_TOAST;
70+
71+
static {
72+
LauncherApplication.getInstance().registerSelfAsForegroundService(SimpleRecordService.class);
73+
}
5874

5975
private boolean isRecording;
6076
private MediaProjectionManager mMediaProjectionManager;
77+
private WindowManager wm;
6178
private ScreenRecorder mRecorder;
6279
private Notifications mNotifications;
6380
private Handler mHandler;
81+
private View view;
6482

6583

6684
private String lastVideoPath;
@@ -75,6 +93,13 @@ public void onCreate() {
7593
super.onCreate();
7694
mHandler = new Handler();
7795
LogUtil.d(TAG, "onCreate");
96+
InjectorService.g().register(this);
97+
98+
try {
99+
initView();
100+
} catch (Throwable e) {
101+
LogUtil.e(TAG, "Fail to create one pixel point", e);
102+
}
78103

79104
mMediaProjectionManager = (MediaProjectionManager)getSystemService(Context.MEDIA_PROJECTION_SERVICE);
80105
mNotifications = new Notifications(getApplicationContext());
@@ -83,17 +108,40 @@ public void onCreate() {
83108
@Nullable
84109
@Override
85110
public IBinder onBind(Intent intent) {
86-
return new RecordBinder(this);
111+
return new SimpleRecordService.RecordBinder(this);
87112
}
88113

89114
@Override
90115
public int onStartCommand(Intent intent, int flags, int startId) {
91116
LogUtil.d(TAG, "onStart");
92-
stopForeground(false);
117+
// stopForeground(false);
93118

94119
return super.onStartCommand(intent, flags, startId);
95120
}
96121

122+
private void initView() {
123+
// 获取WindowManager
124+
wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
125+
// 设置LayoutParams(全局变量)相关参数
126+
WindowManager.LayoutParams wmParams = ((MyApplication) getApplication()).getFloatWinParams();
127+
wmParams.type = TYPE_TOAST;
128+
wmParams.flags |= 8;
129+
wmParams.gravity = Gravity.LEFT | Gravity.TOP; // 调整悬浮窗口至左上角
130+
// 以屏幕左上角为原点,设置x、y初始值
131+
wmParams.x = 0;
132+
wmParams.y = 0;
133+
// 设置悬浮窗口长宽数据
134+
wmParams.width = 1;
135+
wmParams.height = 1;
136+
wmParams.format = 1;
137+
wmParams.alpha = 1F;
138+
139+
view = new View(ContextUtil.getContextThemeWrapper(this, R.style.AppDialogTheme));
140+
view.setBackgroundColor(Color.RED);
141+
142+
wm.addView(view, wmParams);
143+
}
144+
97145
private File initRecorder(Intent intent) {
98146
try {
99147
mMediaProjection = mMediaProjectionManager.getMediaProjection(RESULT_OK, intent);
@@ -145,9 +193,9 @@ private File generateVideoPath() {
145193

146194
@Override
147195
public void onDestroy() {
148-
LogUtil.d(TAG, "onDestroy");
149-
150196
super.onDestroy();
197+
LogUtil.d(TAG, "onDestroy");
198+
wm.removeView(view);
151199
}
152200

153201

@@ -204,6 +252,7 @@ private long stopRecorder() {
204252
return lastRecorderStartTime;
205253
}
206254

255+
207256
private VideoEncodeConfig createVideoConfig(Intent intent) {
208257
// 不同系统,不同硬件,codec不一样,无法传递
209258
MediaCodecInfo[] codecs = VideoUtils.findEncodersByType(ScreenRecorder.VIDEO_AVC);
@@ -249,5 +298,9 @@ public File startRecord(Intent intent) {
249298
public long stopRecord() {
250299
return recordRef.get().stopRecorder();
251300
}
301+
302+
public Context loadContext() {
303+
return recordRef.get();
304+
}
252305
}
253306
}

‎src/app/src/main/java/com/alipay/hulu/service/BaseService.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package com.alipay.hulu.service;
1717

1818
import android.annotation.TargetApi;
19+
import android.app.Notification;
20+
import android.app.NotificationChannel;
21+
import android.app.NotificationManager;
1922
import android.app.Service;
2023
import android.content.Context;
2124
import android.content.res.Configuration;
@@ -33,9 +36,13 @@
3336
* Created by qiaoruikai on 2019/1/25 3:16 PM.
3437
*/
3538
public abstract class BaseService extends Service {
39+
private static final String HULU_SERVICE_CHANNEL_ID = "hulu-service";
40+
protected NotificationManager mNotificationManager;
41+
3642
@Override
3743
public void onCreate() {
3844
super.onCreate();
45+
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);;
3946

4047
LauncherApplication.getInstance().notifyCreate(this);
4148
}
@@ -65,4 +72,18 @@ private static Context updateResources(Context context) {
6572
configuration.setLocales(new LocaleList(locale));
6673
return context.createConfigurationContext(configuration);
6774
}
75+
76+
public Notification.Builder generateNotificationBuilder() {
77+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
78+
String channelId = HULU_SERVICE_CHANNEL_ID;
79+
NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_DEFAULT);
80+
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
81+
if (nm.getNotificationChannel(channelId) == null) {
82+
nm.createNotificationChannel(channel);
83+
}
84+
return new Notification.Builder(this, channelId);
85+
} else {
86+
return new Notification.Builder(this);
87+
}
88+
}
6889
}

0 commit comments

Comments
 (0)