Skip to content

Commit ac3ac18

Browse files
committed
feat: 使用视频作为启动器背景 #1261
1 parent c0e2cb4 commit ac3ac18

File tree

7 files changed

+137
-1
lines changed

7 files changed

+137
-1
lines changed

FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
267267
permissionResultLauncher =
268268
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
269269
}
270+
setupLiveBackground()
270271
}
271272

272273
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
@@ -280,11 +281,24 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
280281
override fun onPause() {
281282
super.onPause()
282283
_uiManager?.onPause()
284+
if (shouldPlayVideo() && binding.videoView.isPlaying) {
285+
binding.videoView.pause()
286+
}
283287
}
284288

285289
override fun onResume() {
286290
super.onResume()
287291
_uiManager?.onResume()
292+
if (shouldPlayVideo() && !binding.videoView.isPlaying) {
293+
binding.videoView.start()
294+
}
295+
}
296+
297+
override fun onDestroy() {
298+
super.onDestroy()
299+
if (shouldPlayVideo()) {
300+
binding.videoView.stopPlayback()
301+
}
288302
}
289303

290304
override fun onSelect(view: FCLMenuView) {
@@ -377,6 +391,9 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
377391
}.getOrNull() ?: DriverPlugin.driverList[0]
378392
DisplayUtil.refreshDisplayMetrics(this@MainActivity)
379393
Versions.launch(this@MainActivity, selectedProfile)
394+
if (shouldPlayVideo()) {
395+
binding.videoView.stopPlayback()
396+
}
380397
}
381398
}
382399
}
@@ -551,6 +568,7 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
551568
}
552569

553570
}
571+
554572
private fun initBackground() {
555573
theme = object : IntegerPropertyBase() {
556574
override fun invalidated() {
@@ -718,4 +736,29 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
718736
permissionResultLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
719737
}
720738
}
739+
740+
private fun shouldPlayVideo(): Boolean {
741+
return File(FCLPath.LIVE_BACKGROUND_PATH).exists()
742+
}
743+
744+
fun setupLiveBackground() {
745+
if (shouldPlayVideo()) {
746+
binding.videoView.visibility = View.VISIBLE
747+
binding.videoView.setVideoPath(FCLPath.LIVE_BACKGROUND_PATH)
748+
binding.videoView.setOnPreparedListener {
749+
it.isLooping = true
750+
binding.videoView.start()
751+
}
752+
binding.videoView.setOnCompletionListener {
753+
binding.videoView.seekTo(0)
754+
binding.videoView.start()
755+
}
756+
binding.videoView.setOnErrorListener { mp, what, extra ->
757+
return@setOnErrorListener true
758+
}
759+
} else {
760+
binding.videoView.visibility = View.GONE
761+
binding.videoView.stopPlayback()
762+
}
763+
}
721764
}

FCL/src/main/java/com/tungsten/fcl/ui/setting/LauncherSettingPage.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
8484
private FCLButton theme2Dark;
8585
private FCLButton ltBackground;
8686
private FCLButton dkBackground;
87+
private FCLButton liveBackground;
8788
private FCLButton cursor;
8889
private FCLButton menuIcon;
8990
private FCLButton resetTheme;
@@ -94,6 +95,7 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
9495
private FCLButton fetchBackgroundColor2Dark;
9596
private FCLButton resetLtBackground;
9697
private FCLButton resetDkBackground;
98+
private FCLButton resetLiveBackground;
9799
private FCLButton resetCursor;
98100
private FCLButton resetMenuIcon;
99101
private FCLSwitch ignoreNotch;
@@ -128,6 +130,7 @@ public void onCreate() {
128130
theme2Dark = findViewById(R.id.theme2_dark);
129131
ltBackground = findViewById(R.id.background_lt);
130132
dkBackground = findViewById(R.id.background_dk);
133+
liveBackground = findViewById(R.id.background_live);
131134
cursor = findViewById(R.id.cursor);
132135
menuIcon = findViewById(R.id.menu_icon);
133136
resetTheme = findViewById(R.id.reset_theme);
@@ -138,6 +141,7 @@ public void onCreate() {
138141
fetchBackgroundColor2Dark = findViewById(R.id.fetch_background_color2_dark);
139142
resetLtBackground = findViewById(R.id.reset_background_lt);
140143
resetDkBackground = findViewById(R.id.reset_background_dk);
144+
resetLiveBackground = findViewById(R.id.reset_background_live);
141145
resetCursor = findViewById(R.id.reset_cursor);
142146
resetMenuIcon = findViewById(R.id.reset_menu_icon);
143147
ignoreNotch = findViewById(R.id.ignore_notch);
@@ -160,6 +164,7 @@ public void onCreate() {
160164
theme2Dark.setOnClickListener(this);
161165
ltBackground.setOnClickListener(this);
162166
dkBackground.setOnClickListener(this);
167+
liveBackground.setOnClickListener(this);
163168
cursor.setOnClickListener(this);
164169
menuIcon.setOnClickListener(this);
165170
resetTheme.setOnClickListener(this);
@@ -168,6 +173,7 @@ public void onCreate() {
168173
fetchBackgroundColor2.setOnClickListener(this);
169174
resetLtBackground.setOnClickListener(this);
170175
resetDkBackground.setOnClickListener(this);
176+
resetLiveBackground.setOnClickListener(this);
171177
resetCursor.setOnClickListener(this);
172178
resetMenuIcon.setOnClickListener(this);
173179

@@ -427,6 +433,29 @@ public void onNegative(int initColor) {
427433
}
428434
}));
429435
}
436+
if (v == liveBackground) {
437+
FileBrowser.Builder builder = new FileBrowser.Builder(getContext());
438+
builder.setLibMode(LibMode.FILE_CHOOSER);
439+
builder.setSelectionMode(SelectionMode.SINGLE_SELECTION);
440+
ArrayList<String> suffix = new ArrayList<>();
441+
suffix.add(".mp4");
442+
builder.setSuffix(suffix);
443+
builder.create().browse(getActivity(), RequestCodes.SELECT_LAUNCHER_BACKGROUND_CODE, ((requestCode, resultCode, data) -> {
444+
if (requestCode == RequestCodes.SELECT_LAUNCHER_BACKGROUND_CODE && resultCode == Activity.RESULT_OK && data != null) {
445+
String path = FileBrowser.getSelectedFiles(data).get(0);
446+
Uri uri = Uri.parse(path);
447+
if (AndroidUtils.isDocUri(uri)) {
448+
AndroidUtils.copyFile(getActivity(), uri, new File(FCLPath.LIVE_BACKGROUND_PATH));
449+
} else {
450+
try {
451+
FileUtils.copyFile(new File(path), new File(FCLPath.LIVE_BACKGROUND_PATH));
452+
} catch (IOException ignore) {
453+
}
454+
}
455+
MainActivity.getInstance().setupLiveBackground();
456+
}
457+
}));
458+
}
430459
if (v == cursor) {
431460
FileBrowser.Builder builder = new FileBrowser.Builder(getContext());
432461
builder.setLibMode(LibMode.FILE_CHOOSER);
@@ -491,6 +520,13 @@ public void onNegative(int initColor) {
491520
if (v == resetTheme2Dark) {
492521
ThemeEngine.getInstance().applyAndSave2Dark(getContext(), Color.parseColor("#000000"));
493522
}
523+
if (v == resetLiveBackground) {
524+
try {
525+
FileUtils.forceDelete(new File(FCLPath.LIVE_BACKGROUND_PATH));
526+
MainActivity.getInstance().setupLiveBackground();
527+
} catch (IOException ignore) {
528+
}
529+
}
494530
if (v == fetchBackgroundColor || v == fetchBackgroundColor2 || v == fetchBackgroundColor2Dark) {
495531
boolean isDarkMode = (getContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
496532

@@ -508,7 +544,7 @@ public void onNegative(int initColor) {
508544
color = palette.getLightVibrantColor(dominantColor);
509545
}
510546
ThemeEngine.getInstance().applyAndSave(getContext(), color);
511-
} else if (v == fetchBackgroundColor2){
547+
} else if (v == fetchBackgroundColor2) {
512548
ThemeEngine.getInstance().applyAndSave2(getContext(), palette.getVibrantColor(dominantColor));
513549
} else {
514550
ThemeEngine.getInstance().applyAndSave2Dark(getContext(), palette.getVibrantColor(dominantColor));

FCL/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
android:transitionName="background"
99
tools:context=".activity.MainActivity">
1010

11+
<VideoView
12+
android:id="@+id/video_view"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent"/>
15+
1116
<androidx.constraintlayout.widget.ConstraintLayout
1217
android:id="@+id/left_menu"
1318
android:layout_width="wrap_content"

FCL/src/main/res/layout/page_setting_launcher.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,54 @@
539539

540540
</androidx.appcompat.widget.LinearLayoutCompat>
541541

542+
<View
543+
android:layout_width="match_parent"
544+
android:layout_height="1dp"
545+
android:background="@android:color/darker_gray" />
546+
547+
<androidx.appcompat.widget.LinearLayoutCompat
548+
android:layout_width="match_parent"
549+
android:layout_height="wrap_content"
550+
android:minHeight="48dp"
551+
android:orientation="horizontal"
552+
android:paddingStart="12dp"
553+
android:paddingTop="8dp"
554+
android:paddingEnd="12dp"
555+
android:paddingBottom="8dp">
556+
557+
<com.tungsten.fcllibrary.component.view.FCLTextView
558+
android:layout_width="wrap_content"
559+
android:layout_height="wrap_content"
560+
android:layout_gravity="center"
561+
android:singleLine="true"
562+
android:text="@string/settings_launcher_background_video"
563+
app:auto_text_tint="true" />
564+
565+
<View
566+
android:layout_width="0dp"
567+
android:layout_height="0dp"
568+
android:layout_weight="1" />
569+
570+
<com.tungsten.fcllibrary.component.view.FCLButton
571+
android:id="@+id/reset_background_live"
572+
android:layout_width="wrap_content"
573+
android:layout_height="wrap_content"
574+
android:layout_gravity="center"
575+
android:text="@string/button_reset"
576+
app:ripple="true" />
577+
578+
<com.tungsten.fcllibrary.component.view.FCLButton
579+
android:id="@+id/background_live"
580+
android:layout_width="wrap_content"
581+
android:layout_height="wrap_content"
582+
android:layout_gravity="center"
583+
android:layout_marginStart="10dp"
584+
android:text="@string/button_set"
585+
app:ripple="true" />
586+
587+
</androidx.appcompat.widget.LinearLayoutCompat>
588+
589+
542590
<View
543591
android:layout_width="match_parent"
544592
android:layout_height="1dp"

FCL/src/main/res/values-zh/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@
834834
<string name="settings_launcher_theme_fetch_background">从背景图片提取</string>
835835
<string name="settings_launcher_background_lt">亮色模式启动器背景图片(最大分辨率5120x5120)</string>
836836
<string name="settings_launcher_background_dk">暗色模式启动器背景图片(最大分辨率5120x5120)</string>
837+
<string name="settings_launcher_background_video">启动器背景(视频 .mp4)</string>
837838
<string name="settings_launcher_cursor">鼠标图片</string>
838839
<string name="settings_launcher_menu_icon">菜单键图标</string>
839840
<string name="settings_launcher_ignore_notch">忽略刘海屏(全屏)</string>

FCL/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@
895895
<string name="settings_launcher_theme_fetch_background">Extract from background image</string>
896896
<string name="settings_launcher_background_lt">Light Mode Launcher Background (Max 5120x5120)</string>
897897
<string name="settings_launcher_background_dk">Dark Mode Launcher Background (Max 5120x5120)</string>
898+
<string name="settings_launcher_background_video">Launcher Background (Video .mp4)</string>
898899
<string name="settings_launcher_cursor">Cursor Picture</string>
899900
<string name="settings_launcher_menu_icon">Menu View Icon</string>
900901
<string name="settings_launcher_ignore_notch">Ignore Notch</string>

FCLauncher/src/main/java/com/tungsten/fclauncher/utils/FCLPath.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class FCLPath {
3939
public static String MIO_LAUNCH_WRAPPER;
4040
public static String LT_BACKGROUND_PATH;
4141
public static String DK_BACKGROUND_PATH;
42+
public static String LIVE_BACKGROUND_PATH;
4243

4344
public static void loadPaths(Context context) {
4445
CONTEXT = context;
@@ -73,6 +74,7 @@ public static void loadPaths(Context context) {
7374
MIO_LAUNCH_WRAPPER = PLUGIN_DIR + "/MioLaunchWrapper.jar";
7475
LT_BACKGROUND_PATH = BACKGROUND_DIR + "/lt.png";
7576
DK_BACKGROUND_PATH = BACKGROUND_DIR + "/dk.png";
77+
LIVE_BACKGROUND_PATH = BACKGROUND_DIR + "/live.mp4";
7678

7779
init(LOG_DIR);
7880
init(CACHE_DIR);

0 commit comments

Comments
 (0)