Skip to content

Commit

Permalink
[update] Add a function to remove runtime pack.
Browse files Browse the repository at this point in the history
  • Loading branch information
longjunyu2 committed Sep 28, 2020
1 parent 52010f4 commit 0b4f893
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Switch;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.content.ContextCompat;

import com.aof.mcinabox.definitions.id.AppEvent;
import com.aof.mcinabox.gamecontroller.R;
import com.aof.mcinabox.gamecontroller.event.BaseKeyEvent;
Expand All @@ -37,7 +36,6 @@
import com.aof.mcinabox.gamecontroller.codes.Translation;
import com.aof.utils.dialog.DialogUtils;
import com.aof.utils.dialog.support.DialogSupports;

import java.util.HashMap;
import java.util.Objects;

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

private ImageButton buttonCustomizeKeyboard;
private Switch switchCustomizeKeyboard;
private SwitchCompat switchCustomizeKeyboard;

private ImageButton buttonPCKeyboard;
private Switch switchPCKeyboard;
private SwitchCompat switchPCKeyboard;

private ImageButton buttonPCMouse;
private Switch switchPCMouse;
private SwitchCompat switchPCMouse;

private ImageButton buttonPEKeyboard;
private Switch switchPEKeyboard;
private SwitchCompat switchPEKeyboard;

private ImageButton buttonPEJoystick;
private Switch switchPEJoystick;
private SwitchCompat switchPEJoystick;

private ImageButton buttonPEItembar;
private Switch switchPEItembar;
private SwitchCompat switchPEItembar;

private ImageButton buttonTouchpad;
private Switch switchTouchpad;
private SwitchCompat switchTouchpad;

private ImageButton buttonInputBox;
private Switch switchInputBox;
private SwitchCompat switchInputBox;

private Button buttonOK;

Expand Down Expand Up @@ -190,9 +188,11 @@ public void run(){
for(View v : new View[]{buttonCustomizeKeyboard,buttonOK,buttonResetPos,buttonPCKeyboard , buttonPCMouse , buttonPEKeyboard , buttonPEJoystick , buttonPEItembar ,buttonTouchpad, buttonInputBox}){
v.setOnClickListener(this);
}
for(Switch s : new Switch[]{switchCustomizeKeyboard,switchPCKeyboard , switchPCMouse , switchPEKeyboard , switchPEJoystick , switchPEItembar , switchTouchpad, switchInputBox}){

for(SwitchCompat s : new SwitchCompat[]{switchCustomizeKeyboard,switchPCKeyboard , switchPCMouse , switchPEKeyboard , switchPEJoystick , switchPEItembar , switchTouchpad, switchInputBox}){
s.setOnCheckedChangeListener(this);
}

checkboxLock.setOnCheckedChangeListener(this);

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

if(v == buttonOK){
saveConfigToFile();
settingDialog.dismiss();
return;
}
Expand All @@ -312,7 +313,7 @@ public void runWhenPositive(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if(buttonView instanceof Switch && bindingViews.containsKey(buttonView)){
if(buttonView instanceof SwitchCompat && bindingViews.containsKey(buttonView)){
if(isChecked){
(Objects.requireNonNull(bindingViews.get(buttonView))).setEnable(true);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.aof.mcinabox.MainActivity;
import com.aof.mcinabox.R;
Expand Down Expand Up @@ -35,12 +36,15 @@ public class RuntimeManager {
**/
public static void installRuntimeFromPath(final Context context, String globalPath) {

final TaskDialog mDialog = DialogUtils.createTaskDialog(context, context.getString(R.string.tips_installing_runtime),"",false);
final TaskDialog mDialog = DialogUtils.createTaskDialog(context,"","",false);
mDialog.show();
@SuppressLint("HandlerLeak") final Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg){
switch (msg.what) {
case 3:
mDialog.setTotalTaskName(context.getString(R.string.tips_installing_runtime));
break;
case 4:
Toast.makeText(MainActivity.CURRENT_ACTIVITY, MainActivity.CURRENT_ACTIVITY.getString(R.string.tips_runtime_notfound), Toast.LENGTH_SHORT).show();
mDialog.dismiss();
Expand All @@ -62,35 +66,33 @@ public void handleMessage(Message msg){
new Thread() {
@Override
public void run() {
sendMsg(3);
File packageFile = new File(mpackagePath);
if (!packageFile.exists()) {

Message msg_1 = new Message();
msg_1.what = 4;
mHandler.sendMessage(msg_1);
sendMsg(4);
return;

} else {
if (packageFile.isDirectory()) {
Toast.makeText(context, "Runtime packs should not be directories!", Toast.LENGTH_LONG).show();
return;
}
}
Message msg_2 = new Message();
Message msg_3 = new Message();
msg_2.what = 5;
mHandler.sendMessage(msg_2);
File dir = new File(AppManifest.BOAT_RUNTIME_HOME);
if(!dir.exists()){
FileTool.makeFloder(dir.getAbsolutePath());
}
BoatUtils.extractTarXZ(mpackagePath, AppManifest.BOAT_RUNTIME_HOME);
if (BoatUtils.setExecutable(AppManifest.BOAT_RUNTIME_HOME)) {
msg_3.what = 6;
sendMsg(6);
} else {
msg_3.what = 7;
sendMsg(7);
}
mHandler.sendMessage(msg_3);
}

public void sendMsg(int what){
Message msg = new Message();
msg.what = what;
mHandler.sendMessage(msg);
}
}.start();
}
Expand Down Expand Up @@ -149,4 +151,42 @@ public static RuntimePackInfo.Manifest[] getRutinmeInfoManifest(String infoPath,
public static RuntimePackInfo.Manifest[] getRutinmeInfoManifest(VersionJson version){
return getRutinmeInfoManifest(AppManifest.BOAT_RUNTIME_INFO_JSON, version);
}

public static void clearRuntime(final Context context){

final TaskDialog mDialog = DialogUtils.createTaskDialog(context,"","",false);
mDialog.show();
@SuppressLint("HandlerLeak") final Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg){
switch (msg.what) {
case 1:
mDialog.setTotalTaskName(context.getString(R.string.tips_installing_runtime));
break;
case 2:
mDialog.dismiss();
break;
}
super.handleMessage(msg);
}
};

new Thread(){
@Override
public void run(){
sendMsg(1);
File file = new File(AppManifest.BOAT_RUNTIME_HOME);
if(file.exists()){
FileTool.deleteDir(file.getAbsolutePath());
}
sendMsg(2);
}

public void sendMsg(int what){
Message msg = new Message();
msg.what = what;
mHandler.sendMessage(msg);
}
}.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public LauncherSettingUI(Context context) {
private Button buttonImportRuntime;
private Button buttonInstallForge;
private Button buttonShowControbutors;
private Button buttonClearRuntime;
private SwitchCompat switchAutoBackground;
private SwitchCompat switchFullscreen;
private Animation showAnim;
Expand All @@ -59,14 +60,15 @@ public void onCreate() {
listForgeInstallers = layout_setting.findViewById(R.id.launchersetting_spinner_forgeinstaller);
buttonInstallForge = layout_setting.findViewById(R.id.launchersetting_button_forgeinstaller);
buttonShowControbutors = layout_setting.findViewById(R.id.setting_show_contributors);
buttonClearRuntime = layout_setting.findViewById(R.id.launchersetting_button_clear_runtime);
switchAutoBackground = layout_setting.findViewById(R.id.launchersetting_switch_auto_background);
switchFullscreen = layout_setting.findViewById(R.id.launchersetting_switch_fullscreen);

switchAutoBackground.setChecked(setting.isBackgroundAutoSwitch());
switchFullscreen.setChecked(setting.isFullscreen());

//设定监听器
for (View v : new View[]{buttonInstallForge, buttonImportRuntime, buttonShowControbutors}) {
for (View v : new View[]{buttonInstallForge, buttonImportRuntime, buttonShowControbutors, buttonClearRuntime}) {
v.setOnClickListener(clickListener);
}
for(SwitchCompat sc : new SwitchCompat[]{switchAutoBackground,switchFullscreen}){
Expand Down Expand Up @@ -211,6 +213,9 @@ public void fileSelected(File file) {
if (v == buttonShowControbutors) {
new ContributorsDialog(mContext).show();
}
if(v == buttonClearRuntime){
RuntimeManager.clearRuntime(mContext);
}
}
};

Expand Down
9 changes: 9 additions & 0 deletions mcinabox/src/main/res/layout/ui_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight="1"/>

<Button
android:id="@+id/launchersetting_button_import"
style="@style/LauncherButton_1"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text="@string/title_import" />

<Button
android:id="@+id/launchersetting_button_clear_runtime"
style="@style/LauncherButton_1"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text="@string/title_clear" />

</LinearLayout>

<View
Expand Down Expand Up @@ -124,6 +132,7 @@
android:layout_marginEnd="5dp"
android:text="@string/title_install" />


</LinearLayout>


Expand Down

0 comments on commit 0b4f893

Please sign in to comment.