[feature] Custom cursor

This commit is contained in:
ShirosakiMio 2024-08-24 20:28:21 +08:00
parent aeaea5419c
commit 2771c49274
7 changed files with 107 additions and 0 deletions

View File

@ -1,5 +1,8 @@
package com.tungsten.fcl.control;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -555,6 +558,12 @@ public class GameMenu implements MenuCallback, View.OnClickListener {
initRightMenu();
viewManager.setup();
if (new File(FCLPath.FILES_DIR, "cursor.png").exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(new File(FCLPath.FILES_DIR, "cursor.png").getAbsolutePath());
BitmapDrawable drawable = new BitmapDrawable(getActivity().getResources(), bitmap);
getCursor().setImageDrawable(drawable);
}
}
@Override

View File

@ -67,9 +67,11 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
private FCLButton theme;
private FCLButton ltBackground;
private FCLButton dkBackground;
private FCLButton cursor;
private FCLButton resetTheme;
private FCLButton resetLtBackground;
private FCLButton resetDkBackground;
private FCLButton resetCursor;
private FCLSwitch ignoreNotch;
private FCLSeekBar animationSpeed;
private FCLTextView animationSpeedText;
@ -94,9 +96,11 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
theme = findViewById(R.id.theme);
ltBackground = findViewById(R.id.background_lt);
dkBackground = findViewById(R.id.background_dk);
cursor = findViewById(R.id.cursor);
resetTheme = findViewById(R.id.reset_theme);
resetLtBackground = findViewById(R.id.reset_background_lt);
resetDkBackground = findViewById(R.id.reset_background_dk);
resetCursor = findViewById(R.id.reset_cursor);
ignoreNotch = findViewById(R.id.ignore_notch);
animationSpeed = findViewById(R.id.animation_speed);
animationSpeedText = findViewById(R.id.animation_speed_text);
@ -113,9 +117,11 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
theme.setOnClickListener(this);
ltBackground.setOnClickListener(this);
dkBackground.setOnClickListener(this);
cursor.setOnClickListener(this);
resetTheme.setOnClickListener(this);
resetLtBackground.setOnClickListener(this);
resetDkBackground.setOnClickListener(this);
resetCursor.setOnClickListener(this);
ArrayList<String> languageList = new ArrayList<>();
languageList.add(getContext().getString(R.string.settings_launcher_language_system));
@ -311,6 +317,28 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
}
}));
}
if(v == cursor) {
FileBrowser.Builder builder = new FileBrowser.Builder(getContext());
builder.setLibMode(LibMode.FILE_CHOOSER);
builder.setSelectionMode(SelectionMode.SINGLE_SELECTION);
ArrayList<String> suffix = new ArrayList<>();
suffix.add(".png");
builder.setSuffix(suffix);
builder.create().browse(getActivity(), RequestCodes.SELECT_CURSOR_CODE, ((requestCode, resultCode, data) -> {
if (requestCode == RequestCodes.SELECT_CURSOR_CODE && resultCode == Activity.RESULT_OK && data != null) {
String path = FileBrowser.getSelectedFiles(data).get(0);
Uri uri = Uri.parse(path);
if (AndroidUtils.isDocUri(uri)) {
AndroidUtils.copyFile(getActivity(), uri, new File(FCLPath.FILES_DIR, "cursor.png"));
} else {
try {
FileUtils.copyFile(new File(path), new File(FCLPath.FILES_DIR, "cursor.png"));
} catch (IOException ignore) {
}
}
}
}));
}
if (v == resetTheme) {
ThemeEngine.getInstance().applyAndSave(getContext(), ThemeEngine.getWallpaperColor(getContext()), false);
}
@ -330,6 +358,9 @@ public class LauncherSettingPage extends FCLCommonPage implements View.OnClickLi
Schedulers.androidUIThread().execute(() -> ThemeEngine.getInstance().applyAndSave(getContext(), ((MainActivity) getActivity()).bind.background, null, null));
}).start();
}
if (v == resetCursor) {
new File(FCLPath.FILES_DIR, "cursor.png").delete();
}
}
@Override

View File

@ -146,6 +146,22 @@ public class AndroidUtils {
return dest.getAbsolutePath();
}
public static String copyFile(Activity activity, Uri uri, File dest) {
try {
InputStream inputStream = activity.getContentResolver().openInputStream(uri);
if (inputStream == null) {
throw new IOException("Failed to open content stream");
}
try (FileOutputStream outputStream = new FileOutputStream(dest)) {
IOUtils.copyTo(inputStream, outputStream);
}
inputStream.close();
} catch (Exception e) {
}
return dest.getAbsolutePath();
}
public static boolean isDocUri(Uri uri) {
return Objects.equals(uri.getScheme(), ContentResolver.SCHEME_FILE) || Objects.equals(uri.getScheme(),ContentResolver.SCHEME_CONTENT);
}

View File

@ -35,4 +35,6 @@ public class RequestCodes {
public static final int SELECT_DATAPACK_CODE = 750;
public static final int SELECT_LAUNCHER_BACKGROUND_CODE = 800;
public static final int SELECT_CURSOR_CODE = 850;
}

View File

@ -313,6 +313,53 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<androidx.appcompat.widget.LinearLayoutCompat
android:minHeight="48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<com.tungsten.fcllibrary.component.view.FCLTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:auto_text_tint="true"
android:layout_gravity="center"
android:singleLine="true"
android:text="@string/settings_launcher_cursor"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLButton
app:ripple="true"
android:text="@string/button_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/reset_cursor"/>
<com.tungsten.fcllibrary.component.view.FCLButton
app:ripple="true"
android:layout_marginStart="10dp"
android:text="@string/button_set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/cursor"/>
</androidx.appcompat.widget.LinearLayoutCompat>
<View
android:layout_width="match_parent"
android:layout_height="1dp"

View File

@ -751,6 +751,7 @@
<string name="settings_launcher_theme">主题</string>
<string name="settings_launcher_background_lt">亮色模式启动器背景图片</string>
<string name="settings_launcher_background_dk">暗色模式启动器背景图片</string>
<string name="settings_launcher_cursor">鼠标图片</string>
<string name="settings_launcher_ignore_notch">忽略刘海屏</string>
<string name="settings_launcher_animation_speed">动画速度</string>

View File

@ -797,6 +797,7 @@
<string name="settings_launcher_theme">Theme</string>
<string name="settings_launcher_background_lt">Light Mode Launcher Background</string>
<string name="settings_launcher_background_dk">Dark Mode Launcher Background</string>
<string name="settings_launcher_cursor">Cursor Picture</string>
<string name="settings_launcher_ignore_notch">Ignore Notch</string>
<string name="settings_launcher_animation_speed">Animation Speed</string>