mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-28 06:19:49 +00:00
- Added software and drivers. - Fixed the issue of virtual machines not running with X11.
151 lines
No EOL
6.8 KiB
Java
151 lines
No EOL
6.8 KiB
Java
package com.vectras.vm;
|
|
|
|
import android.Manifest;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.provider.Settings;
|
|
import android.util.Log;
|
|
import android.widget.Button;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.vectras.vm.main.MainActivity;
|
|
import com.vectras.vm.utils.FileUtils;
|
|
import com.vectras.vm.utils.JSONUtils;
|
|
import com.vectras.vm.utils.PermissionUtils;
|
|
import com.vectras.vm.utils.UIUtils;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Objects;
|
|
|
|
public class CqcmActivity extends AppCompatActivity {
|
|
|
|
private final Intent gotoActivity = new Intent();
|
|
private final Intent openURL = new Intent();
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if(!PermissionUtils.storagepermission(this,false)) {
|
|
UIUtils.edgeToEdge(this);
|
|
setContentView(R.layout.activity_cqcm);
|
|
UIUtils.setOnApplyWindowInsetsListener(findViewById(R.id.main));
|
|
|
|
Button buttonallow = findViewById(R.id.buttonallow);
|
|
buttonallow.setOnClickListener(v -> {
|
|
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
intent.setData(Uri.parse("package:" + getPackageName()));
|
|
startActivity(intent);
|
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.find_and_allow_access_to_storage_in_settings), Toast.LENGTH_LONG).show();
|
|
} else {
|
|
ActivityCompat.requestPermissions(CqcmActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
Log.i("CqcmActivity", "Checking access to storage...");
|
|
if(PermissionUtils.storagepermission(this,false)) {
|
|
if (getIntent().hasExtra("command")) {
|
|
runCommand(getIntent().getStringExtra("command"));
|
|
} else {
|
|
startAdd();
|
|
}
|
|
}
|
|
|
|
}
|
|
private void startAdd() {
|
|
HashMap<String, Object> mapForCreateNewVM;
|
|
String _map;
|
|
String imgName = "";
|
|
String imgIcon = "";
|
|
String imgPath = "";
|
|
String imgArch = "";
|
|
String imgCdrom = "";
|
|
String imgExtra = "";
|
|
String vmID = VMManager.idGenerator();
|
|
|
|
if (!FileUtils.isFileExists(AppConfig.romsdatajson)) {
|
|
FileUtils.writeToFile(AppConfig.maindirpath, "roms-data.json", "[]");
|
|
}
|
|
|
|
if (JSONUtils.isValidFromFile(AppConfig.romsdatajson)) {
|
|
if (getIntent().hasExtra("content")) {
|
|
if (Objects.requireNonNull(getIntent().getStringExtra("content")).endsWith("}]")) {
|
|
_map = Objects.requireNonNull(getIntent().getStringExtra("content")).substring(0, Objects.requireNonNull(getIntent().getStringExtra("content")).length() - 1);
|
|
} else {
|
|
_map = Objects.requireNonNull(getIntent().getStringExtra("content"));
|
|
}
|
|
if (JSONUtils.isValidFromString(_map)) {
|
|
mapForCreateNewVM = new Gson().fromJson(_map, new TypeToken<HashMap<String, Object>>(){}.getType());
|
|
if (mapForCreateNewVM.containsKey("imgName")) {
|
|
imgName = Objects.requireNonNull(mapForCreateNewVM.get("imgName")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgIcon")) {
|
|
imgIcon = Objects.requireNonNull(mapForCreateNewVM.get("imgIcon")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgPath")) {
|
|
imgPath = Objects.requireNonNull(mapForCreateNewVM.get("imgPath")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgArch")) {
|
|
imgArch = Objects.requireNonNull(mapForCreateNewVM.get("imgArch")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgCdrom")) {
|
|
imgCdrom = Objects.requireNonNull(mapForCreateNewVM.get("imgCdrom")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgExtra")) {
|
|
imgExtra = Objects.requireNonNull(mapForCreateNewVM.get("imgExtra")).toString();
|
|
}
|
|
VMManager.createNewVM(imgName, imgIcon, imgPath, imgArch, imgCdrom, imgExtra, vmID, VMManager.startRandomPort());
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "The data for the new virtual machine is corrupted and cannot be created.", Toast.LENGTH_LONG).show();
|
|
}
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "There is no data about the new virtual machine to create.", Toast.LENGTH_LONG).show();
|
|
}
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "The virtual machine list data is corrupted and new virtual machines cannot be added right now.", Toast.LENGTH_LONG).show();
|
|
}
|
|
if(!MainActivity.isActivate) {
|
|
Log.i("CqcmActivity", "Vectras VM is not opening.");
|
|
gotoActivity.setClass(getApplicationContext(), SplashActivity.class);
|
|
startActivity(gotoActivity);
|
|
Log.i("CqcmActivity", "Opened SplashActivity");
|
|
} else {
|
|
Log.i("CqcmActivity", "Vectras VM is opening.");
|
|
openURL.setAction(Intent.ACTION_VIEW);
|
|
openURL.setData(Uri.parse("android-app://com.vectras.vm"));
|
|
startActivity(openURL);
|
|
Log.i("CqcmActivity", "Opened Vectras VM using URL.");
|
|
}
|
|
finish();
|
|
}
|
|
|
|
private void runCommand(String _command) {
|
|
AppConfig.pendingCommand = _command;
|
|
|
|
if(!MainActivity.isActivate) {
|
|
Log.i("CqcmActivity", "Vectras VM is not opening.");
|
|
gotoActivity.setClass(getApplicationContext(), SplashActivity.class);
|
|
startActivity(gotoActivity);
|
|
Log.i("CqcmActivity", "Opened SplashActivity");
|
|
} else {
|
|
Log.i("CqcmActivity", "Vectras VM is opening.");
|
|
Intent intent = new Intent();
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
intent.setClass(this, MainActivity.class);
|
|
startActivity(intent);
|
|
Log.i("CqcmActivity", "Opened HomeActivity.");
|
|
}
|
|
finish();
|
|
}
|
|
} |