这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ android {
enable true
reset()

include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
universalApk true //generate an additional APK that contains all the ABIs
include "arm64-v8a"

}
}

Expand Down Expand Up @@ -99,4 +99,5 @@ dependencies {
implementation 'androidx.annotation:annotation:1.6.0'
implementation 'androidx.drawerlayout:drawerlayout:1.2.0'
compileOnly project(':shell-loader:stub')

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="internalOnly">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/termux/x11/LoriePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import android.os.Environment;
import java.nio.file.Files;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import android.annotation.SuppressLint;
import android.app.Dialog;
Expand Down Expand Up @@ -83,6 +88,29 @@ public static class LoriePreferenceFragment extends PreferenceFragmentCompat imp
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
addPreferencesFromResource(R.xml.preferences);
}

@Override
public void onDetach() {

// SharedPreferences sp = getContext().getSharedPreferences("com.eltechs.ed.CONTAINER_CONFIG_0", Context.MODE_PRIVATE);
SharedPreferences sp = android.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
String res = null;
String mode = sp.getString("displayResolutionMode", "native");
if ("exact".equals(mode))
res = sp.getString("displayResolutionExact", "1280x1024");
else if("custom".equals(mode))
res = sp.getString("displayResolutionCustom", "1280x1024");
try {
File file = new File(Environment.getExternalStorageDirectory(), "Box64Droid/resolution.conf");
if (!file.exists())
file.createNewFile();
if (res != null && file.canWrite())
Files.write(file.toPath(),res.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
super.onDetach();
}

@SuppressWarnings("ConstantConditions")
void updatePreferencesLayout() {
Expand Down
72 changes: 72 additions & 0 deletions app/src/main/java/com/termux/x11/LorieView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.termux.x11;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.SurfaceView;

import java.util.regex.PatternSyntaxException;

public class LorieView extends SurfaceView {
public LorieView(Context context) {
super(context);
}

public LorieView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public LorieView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public LorieView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try {

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean shouldResize = sp.getBoolean("should_full_screen_with_ratio", true); //full_screen_with_ratio是字符串类型了

float ratio; //宽除以高
String[] res = null;
switch (sp.getString("displayResolutionMode", "native")) {
case "exact": {
res = sp.getString("displayResolutionExact", "1280x1024").split("x");
break;
}
case "custom": {
try {
res = sp.getString("displayResolutionCustom", "1280x1024").split("x");
} catch (NumberFormatException | PatternSyntaxException ignored) {
}
break;
}
default:
break;
}

ratio = res != null ? Integer.parseInt(res[0]) * 1.0f / Integer.parseInt(res[1]) : 0f;

if (ratio != 0 && shouldResize) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
//左右黑边
if (width * 1f / height > ratio) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (height * ratio), MeasureSpec.EXACTLY);
}
//上下黑边
else {
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (width / ratio), MeasureSpec.EXACTLY);
}
}
} catch (Exception e) {
e.printStackTrace();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
4 changes: 3 additions & 1 deletion app/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:layout_height="match_parent">

<FrameLayout
android:background="#000000"
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -16,7 +17,8 @@
android:paddingRight="0dp"
android:paddingBottom="0dp">

<SurfaceView
<com.termux.x11.LorieView
android:layout_gravity="center"
android:id="@+id/lorieView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:key="output" android:title="输出">

<SwitchPreferenceCompat
android:defaultValue="true"
android:summary="开启后按比例居中全屏,否则拉伸全屏(使用自定义或预设分辨率时)"
android:key="should_full_screen_with_ratio"
android:title="按比例居中全屏" />

<ListPreference
android:title="显示模式"
android:key="displayResolutionMode"
Expand Down