Skip to content

Commit 0b4f893

Browse files
committed
[update] Add a function to remove runtime pack.
1 parent 52010f4 commit 0b4f893

File tree

4 files changed

+82
-27
lines changed

4 files changed

+82
-27
lines changed

gamecontroller/src/main/java/com/aof/mcinabox/gamecontroller/controller/VirtualController.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import android.widget.ImageButton;
1818
import android.widget.LinearLayout;
1919
import android.widget.Switch;
20-
2120
import androidx.annotation.NonNull;
21+
import androidx.appcompat.widget.SwitchCompat;
2222
import androidx.core.content.ContextCompat;
23-
2423
import com.aof.mcinabox.definitions.id.AppEvent;
2524
import com.aof.mcinabox.gamecontroller.R;
2625
import com.aof.mcinabox.gamecontroller.event.BaseKeyEvent;
@@ -37,7 +36,6 @@
3736
import com.aof.mcinabox.gamecontroller.codes.Translation;
3837
import com.aof.utils.dialog.DialogUtils;
3938
import com.aof.utils.dialog.support.DialogSupports;
40-
4139
import java.util.HashMap;
4240
import java.util.Objects;
4341

@@ -64,28 +62,28 @@ public class VirtualController extends BaseController implements AppEvent , View
6462
//Dialog的控件
6563

6664
private ImageButton buttonCustomizeKeyboard;
67-
private Switch switchCustomizeKeyboard;
65+
private SwitchCompat switchCustomizeKeyboard;
6866

6967
private ImageButton buttonPCKeyboard;
70-
private Switch switchPCKeyboard;
68+
private SwitchCompat switchPCKeyboard;
7169

7270
private ImageButton buttonPCMouse;
73-
private Switch switchPCMouse;
71+
private SwitchCompat switchPCMouse;
7472

7573
private ImageButton buttonPEKeyboard;
76-
private Switch switchPEKeyboard;
74+
private SwitchCompat switchPEKeyboard;
7775

7876
private ImageButton buttonPEJoystick;
79-
private Switch switchPEJoystick;
77+
private SwitchCompat switchPEJoystick;
8078

8179
private ImageButton buttonPEItembar;
82-
private Switch switchPEItembar;
80+
private SwitchCompat switchPEItembar;
8381

8482
private ImageButton buttonTouchpad;
85-
private Switch switchTouchpad;
83+
private SwitchCompat switchTouchpad;
8684

8785
private ImageButton buttonInputBox;
88-
private Switch switchInputBox;
86+
private SwitchCompat switchInputBox;
8987

9088
private Button buttonOK;
9189

@@ -190,9 +188,11 @@ public void run(){
190188
for(View v : new View[]{buttonCustomizeKeyboard,buttonOK,buttonResetPos,buttonPCKeyboard , buttonPCMouse , buttonPEKeyboard , buttonPEJoystick , buttonPEItembar ,buttonTouchpad, buttonInputBox}){
191189
v.setOnClickListener(this);
192190
}
193-
for(Switch s : new Switch[]{switchCustomizeKeyboard,switchPCKeyboard , switchPCMouse , switchPEKeyboard , switchPEJoystick , switchPEItembar , switchTouchpad, switchInputBox}){
191+
192+
for(SwitchCompat s : new SwitchCompat[]{switchCustomizeKeyboard,switchPCKeyboard , switchPCMouse , switchPEKeyboard , switchPEJoystick , switchPEItembar , switchTouchpad, switchInputBox}){
194193
s.setOnCheckedChangeListener(this);
195194
}
195+
196196
checkboxLock.setOnCheckedChangeListener(this);
197197

198198
//绑定Input对象与ImageButton和Switch
@@ -295,6 +295,7 @@ public void onClick(View v) {
295295
}
296296

297297
if(v == buttonOK){
298+
saveConfigToFile();
298299
settingDialog.dismiss();
299300
return;
300301
}
@@ -312,7 +313,7 @@ public void runWhenPositive(){
312313
@Override
313314
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
314315

315-
if(buttonView instanceof Switch && bindingViews.containsKey(buttonView)){
316+
if(buttonView instanceof SwitchCompat && bindingViews.containsKey(buttonView)){
316317
if(isChecked){
317318
(Objects.requireNonNull(bindingViews.get(buttonView))).setEnable(true);
318319
}else{

mcinabox/src/main/java/com/aof/mcinabox/launcher/runtime/RuntimeManager.java

+53-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.os.Handler;
66
import android.os.Message;
7+
import android.util.Log;
78
import android.widget.Toast;
89
import com.aof.mcinabox.MainActivity;
910
import com.aof.mcinabox.R;
@@ -35,12 +36,15 @@ public class RuntimeManager {
3536
**/
3637
public static void installRuntimeFromPath(final Context context, String globalPath) {
3738

38-
final TaskDialog mDialog = DialogUtils.createTaskDialog(context, context.getString(R.string.tips_installing_runtime),"",false);
39+
final TaskDialog mDialog = DialogUtils.createTaskDialog(context,"","",false);
3940
mDialog.show();
4041
@SuppressLint("HandlerLeak") final Handler mHandler = new Handler(){
4142
@Override
4243
public void handleMessage(Message msg){
4344
switch (msg.what) {
45+
case 3:
46+
mDialog.setTotalTaskName(context.getString(R.string.tips_installing_runtime));
47+
break;
4448
case 4:
4549
Toast.makeText(MainActivity.CURRENT_ACTIVITY, MainActivity.CURRENT_ACTIVITY.getString(R.string.tips_runtime_notfound), Toast.LENGTH_SHORT).show();
4650
mDialog.dismiss();
@@ -62,35 +66,33 @@ public void handleMessage(Message msg){
6266
new Thread() {
6367
@Override
6468
public void run() {
69+
sendMsg(3);
6570
File packageFile = new File(mpackagePath);
6671
if (!packageFile.exists()) {
67-
68-
Message msg_1 = new Message();
69-
msg_1.what = 4;
70-
mHandler.sendMessage(msg_1);
72+
sendMsg(4);
7173
return;
72-
7374
} else {
7475
if (packageFile.isDirectory()) {
7576
Toast.makeText(context, "Runtime packs should not be directories!", Toast.LENGTH_LONG).show();
7677
return;
7778
}
7879
}
79-
Message msg_2 = new Message();
80-
Message msg_3 = new Message();
81-
msg_2.what = 5;
82-
mHandler.sendMessage(msg_2);
8380
File dir = new File(AppManifest.BOAT_RUNTIME_HOME);
8481
if(!dir.exists()){
8582
FileTool.makeFloder(dir.getAbsolutePath());
8683
}
8784
BoatUtils.extractTarXZ(mpackagePath, AppManifest.BOAT_RUNTIME_HOME);
8885
if (BoatUtils.setExecutable(AppManifest.BOAT_RUNTIME_HOME)) {
89-
msg_3.what = 6;
86+
sendMsg(6);
9087
} else {
91-
msg_3.what = 7;
88+
sendMsg(7);
9289
}
93-
mHandler.sendMessage(msg_3);
90+
}
91+
92+
public void sendMsg(int what){
93+
Message msg = new Message();
94+
msg.what = what;
95+
mHandler.sendMessage(msg);
9496
}
9597
}.start();
9698
}
@@ -149,4 +151,42 @@ public static RuntimePackInfo.Manifest[] getRutinmeInfoManifest(String infoPath,
149151
public static RuntimePackInfo.Manifest[] getRutinmeInfoManifest(VersionJson version){
150152
return getRutinmeInfoManifest(AppManifest.BOAT_RUNTIME_INFO_JSON, version);
151153
}
154+
155+
public static void clearRuntime(final Context context){
156+
157+
final TaskDialog mDialog = DialogUtils.createTaskDialog(context,"","",false);
158+
mDialog.show();
159+
@SuppressLint("HandlerLeak") final Handler mHandler = new Handler(){
160+
@Override
161+
public void handleMessage(Message msg){
162+
switch (msg.what) {
163+
case 1:
164+
mDialog.setTotalTaskName(context.getString(R.string.tips_installing_runtime));
165+
break;
166+
case 2:
167+
mDialog.dismiss();
168+
break;
169+
}
170+
super.handleMessage(msg);
171+
}
172+
};
173+
174+
new Thread(){
175+
@Override
176+
public void run(){
177+
sendMsg(1);
178+
File file = new File(AppManifest.BOAT_RUNTIME_HOME);
179+
if(file.exists()){
180+
FileTool.deleteDir(file.getAbsolutePath());
181+
}
182+
sendMsg(2);
183+
}
184+
185+
public void sendMsg(int what){
186+
Message msg = new Message();
187+
msg.what = what;
188+
mHandler.sendMessage(msg);
189+
}
190+
}.start();
191+
}
152192
}

mcinabox/src/main/java/com/aof/mcinabox/launcher/uis/LauncherSettingUI.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public LauncherSettingUI(Context context) {
4343
private Button buttonImportRuntime;
4444
private Button buttonInstallForge;
4545
private Button buttonShowControbutors;
46+
private Button buttonClearRuntime;
4647
private SwitchCompat switchAutoBackground;
4748
private SwitchCompat switchFullscreen;
4849
private Animation showAnim;
@@ -59,14 +60,15 @@ public void onCreate() {
5960
listForgeInstallers = layout_setting.findViewById(R.id.launchersetting_spinner_forgeinstaller);
6061
buttonInstallForge = layout_setting.findViewById(R.id.launchersetting_button_forgeinstaller);
6162
buttonShowControbutors = layout_setting.findViewById(R.id.setting_show_contributors);
63+
buttonClearRuntime = layout_setting.findViewById(R.id.launchersetting_button_clear_runtime);
6264
switchAutoBackground = layout_setting.findViewById(R.id.launchersetting_switch_auto_background);
6365
switchFullscreen = layout_setting.findViewById(R.id.launchersetting_switch_fullscreen);
6466

6567
switchAutoBackground.setChecked(setting.isBackgroundAutoSwitch());
6668
switchFullscreen.setChecked(setting.isFullscreen());
6769

6870
//设定监听器
69-
for (View v : new View[]{buttonInstallForge, buttonImportRuntime, buttonShowControbutors}) {
71+
for (View v : new View[]{buttonInstallForge, buttonImportRuntime, buttonShowControbutors, buttonClearRuntime}) {
7072
v.setOnClickListener(clickListener);
7173
}
7274
for(SwitchCompat sc : new SwitchCompat[]{switchAutoBackground,switchFullscreen}){
@@ -211,6 +213,9 @@ public void fileSelected(File file) {
211213
if (v == buttonShowControbutors) {
212214
new ContributorsDialog(mContext).show();
213215
}
216+
if(v == buttonClearRuntime){
217+
RuntimeManager.clearRuntime(mContext);
218+
}
214219
}
215220
};
216221

mcinabox/src/main/res/layout/ui_setting.xml

+9
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,21 @@
7676
android:layout_height="wrap_content"
7777
android:visibility="invisible"
7878
android:layout_weight="1"/>
79+
7980
<Button
8081
android:id="@+id/launchersetting_button_import"
8182
style="@style/LauncherButton_1"
8283
android:layout_marginStart="5dp"
8384
android:layout_marginEnd="5dp"
8485
android:text="@string/title_import" />
8586

87+
<Button
88+
android:id="@+id/launchersetting_button_clear_runtime"
89+
style="@style/LauncherButton_1"
90+
android:layout_marginStart="5dp"
91+
android:layout_marginEnd="5dp"
92+
android:text="@string/title_clear" />
93+
8694
</LinearLayout>
8795

8896
<View
@@ -124,6 +132,7 @@
124132
android:layout_marginEnd="5dp"
125133
android:text="@string/title_install" />
126134

135+
127136
</LinearLayout>
128137

129138

0 commit comments

Comments
 (0)