mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-05-03 00:30:28 +00:00
2.6
This commit is contained in:
parent
e724a517a8
commit
a6d138dfb8
47 changed files with 1169 additions and 954 deletions
|
|
@ -108,7 +108,7 @@ public class Config {
|
|||
return cacheDir.toString();
|
||||
}
|
||||
public static final String getBasefileDir() {
|
||||
return getCacheDir() + "/vectras/";
|
||||
return AppConfig.basefiledir;
|
||||
}
|
||||
|
||||
public static String machineFolder = "machines/";
|
||||
|
|
|
|||
|
|
@ -451,13 +451,13 @@ public class MainSDLActivity extends SDLActivity {
|
|||
}
|
||||
|
||||
|
||||
private void onMouseMode() {
|
||||
public void onMouseMode() {
|
||||
|
||||
String[] items = {"Trackpad Mouse (Phone)",
|
||||
"Bluetooth/USB Mouse (Desktop mode)", //Physical mouse for Chromebook, Android x86 PC, or Bluetooth Mouse
|
||||
};
|
||||
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(this);
|
||||
mBuilder.setTitle("Mouse");
|
||||
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(this, R.style.MainDialogTheme);
|
||||
mBuilder.setTitle("Mouse Mode");
|
||||
mBuilder.setSingleChoiceItems(items, Config.mouseMode.ordinal(), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int i) {
|
||||
|
|
@ -531,13 +531,6 @@ public class MainSDLActivity extends SDLActivity {
|
|||
final AlertDialog alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(activity).create();
|
||||
alertDialog.setTitle("Desktop Mode");
|
||||
|
||||
LinearLayout mLayout = new LinearLayout(this);
|
||||
mLayout.setPadding(20, 20, 20, 20);
|
||||
mLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView textView = new TextView(activity);
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
String desktopInstructions = this.getString(R.string.desktopInstructions);
|
||||
if (!checkVMResolutionFits()) {
|
||||
String resolutionWarning = "Warning: MainActivity.vmexecutor resolution "
|
||||
|
|
@ -547,17 +540,7 @@ public class MainSDLActivity extends SDLActivity {
|
|||
"Reduce display resolution within the Guest OS for better experience.\n\n";
|
||||
desktopInstructions = resolutionWarning + desktopInstructions;
|
||||
}
|
||||
textView.setText(desktopInstructions);
|
||||
|
||||
ScrollView scrollView = new ScrollView(this);
|
||||
scrollView.addView(textView);
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
mLayout.addView(scrollView, params);
|
||||
|
||||
alertDialog.setView(mLayout);
|
||||
|
||||
alertDialog.setMessage(desktopInstructions);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setUIModeDesktop();
|
||||
|
|
@ -934,7 +917,6 @@ public class MainSDLActivity extends SDLActivity {
|
|||
ImageButton ctrlBtn = findViewById(R.id.ctrlBtn);
|
||||
ImageButton altBtn = findViewById(R.id.altBtn);
|
||||
ImageButton delBtn = findViewById(R.id.delBtn);
|
||||
Button ctrlAltDelBtn = findViewById(R.id.ctrlAltDelBtn);
|
||||
ImageButton qmpBtn = findViewById(R.id.btnQmp);
|
||||
ImageButton btnLogs = findViewById(R.id.btnLogs);
|
||||
btnLogs.setOnClickListener(new View.OnClickListener() {
|
||||
|
|
@ -1049,7 +1031,7 @@ public class MainSDLActivity extends SDLActivity {
|
|||
delayKey(100);
|
||||
SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ENTER);
|
||||
delayKey(100);
|
||||
SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ENTER);
|
||||
SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ENTER);
|
||||
}
|
||||
});
|
||||
ctrlBtn.setOnClickListener(new View.OnClickListener() {
|
||||
|
|
@ -1091,12 +1073,6 @@ public class MainSDLActivity extends SDLActivity {
|
|||
SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DEL);
|
||||
}
|
||||
});
|
||||
ctrlAltDelBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sendCtrlAltKey(KeyEvent.KEYCODE_DEL);
|
||||
}
|
||||
});
|
||||
qmpBtn.setVisibility(View.GONE);
|
||||
if (monitorMode) {
|
||||
qmpBtn.setImageDrawable(getResources().getDrawable(R.drawable.round_terminal_24));
|
||||
|
|
@ -1156,6 +1132,7 @@ public class MainSDLActivity extends SDLActivity {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
private void createUI(int w, int h) {
|
||||
mSurface = new MainSDLSurface(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -755,6 +755,32 @@ public class MainSettingsManager extends AppCompatActivity
|
|||
return prefs.getString("TbSize", "2048");
|
||||
}
|
||||
|
||||
public static void setBoot(Activity activity, String boot) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putString("boot", boot);
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
public static String getBoot(Activity activity) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
return prefs.getString("boot", "c");
|
||||
}
|
||||
|
||||
|
||||
public static void setCpu(Activity activity, String cpu) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putString("cpu", cpu);
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
public static String getCpu(Activity activity) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
return prefs.getString("cpu", "qemu64");
|
||||
}
|
||||
|
||||
|
||||
public static void setVmUi(Activity activity, String vmUi) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ public class MainVNCActivity extends VncCanvasActivity {
|
|||
public boolean ctrlClicked = false;
|
||||
public boolean altClicked = false;
|
||||
private ImageButton qmpBtn;
|
||||
public static MainVNCActivity activity;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle b) {
|
||||
|
|
@ -102,6 +103,7 @@ public class MainVNCActivity extends VncCanvasActivity {
|
|||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
super.onCreate(b);
|
||||
activity = this;
|
||||
|
||||
this.vncCanvas.setFocusableInTouchMode(true);
|
||||
|
||||
|
|
@ -132,7 +134,6 @@ public class MainVNCActivity extends VncCanvasActivity {
|
|||
ImageButton altBtn = findViewById(R.id.altBtn);
|
||||
ImageButton delBtn = findViewById(R.id.delBtn);
|
||||
ImageButton btnLogs = findViewById(R.id.btnLogs);
|
||||
Button ctrlAltDelBtn = findViewById(R.id.ctrlAltDelBtn);
|
||||
qmpBtn = findViewById(R.id.btnQmp);
|
||||
btnLogs.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
@ -279,12 +280,6 @@ public class MainVNCActivity extends VncCanvasActivity {
|
|||
keyDownUp(KeyEvent.KEYCODE_DEL);
|
||||
}
|
||||
});
|
||||
ctrlAltDelBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sendCtrlAtlDelKey();
|
||||
}
|
||||
});
|
||||
qmpBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -630,7 +625,7 @@ public class MainVNCActivity extends VncCanvasActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void onMouseMode() {
|
||||
public void onMouseMode() {
|
||||
|
||||
String[] items = {"Trackpad Mouse (Phone)",
|
||||
"Bluetooth/USB Mouse (Desktop mode)", //Physical mouse for Chromebook, Android x86 PC, or Bluetooth Mouse
|
||||
|
|
@ -732,32 +727,16 @@ public class MainVNCActivity extends VncCanvasActivity {
|
|||
final AlertDialog alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle("Desktop mode");
|
||||
|
||||
LinearLayout mLayout = new LinearLayout(this);
|
||||
mLayout.setPadding(20, 20, 20, 20);
|
||||
mLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView textView = new TextView(activity);
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
|
||||
String desktopInstructions = this.getString(R.string.desktopInstructions);
|
||||
if (!checkVMResolutionFits()) {
|
||||
String resolutionWarning = "Warning: Machine resolution "
|
||||
String resolutionWarning = "Warning: MainActivity.vmexecutor resolution "
|
||||
+ vncCanvas.rfb.framebufferWidth + "x" + vncCanvas.rfb.framebufferHeight +
|
||||
" is too high for Desktop Mode. " +
|
||||
"Scaling will be used and Mouse Alignment will not be accurate. " +
|
||||
"Reduce display resolution for better experience\n\n";
|
||||
"Reduce display resolution within the Guest OS for better experience.\n\n";
|
||||
desktopInstructions = resolutionWarning + desktopInstructions;
|
||||
}
|
||||
textView.setText(desktopInstructions);
|
||||
|
||||
LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
ScrollView scrollView = new ScrollView(this);
|
||||
scrollView.addView(textView);
|
||||
mLayout.addView(scrollView, textViewParams);
|
||||
alertDialog.setView(mLayout);
|
||||
|
||||
alertDialog.setMessage(desktopInstructions);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
|
|
|
|||
|
|
@ -155,8 +155,9 @@ public class StartVM {
|
|||
this.libqemu = FileUtils.getNativeLibDir(context) + "/libqemu-system-x86_64.so";
|
||||
this.arch = "x86_64";
|
||||
this.machine_type = "pc";
|
||||
this.cpu = "qemu64";
|
||||
this.cpu = MainSettingsManager.getCpu(MainActivity.activity);
|
||||
}
|
||||
bootdevice = MainSettingsManager.getBoot(MainActivity.activity);
|
||||
this.sound_card = MainSettingsManager.getSoundCard(MainActivity.activity);
|
||||
this.cpuNum = MainSettingsManager.getCpuNum(MainActivity.activity);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.os.Environment;
|
|||
import android.widget.ImageView.ScaleType;
|
||||
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
|
|
@ -39,9 +40,17 @@ public class AppConfig {
|
|||
}
|
||||
|
||||
// App config
|
||||
public static final String datadirpath = SplashActivity.activity.getExternalFilesDir("data") + "/";
|
||||
public static final String sharedFolder = datadirpath + "Vectras/ProgramFiles/";
|
||||
public static final String basefiledir = datadirpath + "Vectras/.qemu/";
|
||||
public static final String maindirpath = datadirpath + "Vectras/";
|
||||
public static final String datadirpath() {
|
||||
File f = new File(SplashActivity.activity.getExternalFilesDir("data") + "/Vectras");
|
||||
if (f.exists())
|
||||
return SplashActivity.activity.getExternalFilesDir("data") + "/Vectras";
|
||||
else
|
||||
return FileUtils.getExternalFilesDirectory(SplashActivity.activity).getPath();
|
||||
}
|
||||
|
||||
;
|
||||
public static final String sharedFolder = datadirpath() + "/SharedFolder/";
|
||||
public static final String basefiledir = datadirpath() + "/.qemu/";
|
||||
public static final String maindirpath = datadirpath() + "/";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package com.vectras.vm;
|
|||
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
|
|
@ -17,6 +19,8 @@ import com.google.android.gms.ads.initialization.OnInitializationCompleteListene
|
|||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.vm.Fragment.HomeFragment;
|
||||
import com.vectras.vm.MainRoms.AdapterMainRoms;
|
||||
import com.vectras.vm.MainRoms.DataMainRoms;
|
||||
import com.vectras.vm.logger.VectrasStatus;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
|
@ -24,10 +28,13 @@ import com.vectras.vm.utils.UIUtils;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.Editable;
|
||||
import android.text.Html;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -43,6 +50,7 @@ import org.json.JSONArray;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -54,6 +62,8 @@ import java.io.OutputStream;
|
|||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class CustomRomActivity extends AppCompatActivity {
|
||||
|
||||
|
|
@ -78,6 +88,8 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
|
||||
menu.add(0, 0, 0, "arch").setShortcut('3', 'c').setIcon(R.drawable.ic_arch).setShowAsAction(1);
|
||||
|
||||
menu.add(1, 1, 1, "custom rom").setShortcut('3', 'c').setIcon(R.drawable.input_circle).setShowAsAction(1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -88,6 +100,19 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
case 0:
|
||||
startActivity(new Intent(activity, SetArchActivity.class));
|
||||
return true;
|
||||
case 1:
|
||||
Intent intent = new Intent(ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
|
||||
// Optionally, specify a URI for the file that should appear in the
|
||||
// system file picker when it loads.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Environment.DIRECTORY_DOWNLOADS);
|
||||
}
|
||||
|
||||
startActivityForResult(intent, 0);
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
|
|
@ -191,6 +216,11 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
addRomBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String CREDENTIAL_SHARED_PREF = "settings_prefs";
|
||||
SharedPreferences credentials = activity.getSharedPreferences(CREDENTIAL_SHARED_PREF, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = credentials.edit();
|
||||
editor.putBoolean("isFirstLaunch", Boolean.TRUE);
|
||||
editor.apply();
|
||||
loadingPb.setVisibility(View.VISIBLE);
|
||||
final File jsonFile = new File(AppConfig.maindirpath + "roms-data" + ".json");
|
||||
RomsJso obj = new RomsJso();
|
||||
|
|
@ -245,7 +275,6 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
}
|
||||
VectrasStatus.logInfo("Welcome to Vectras ♡");
|
||||
}
|
||||
MainActivity.activity.finish();
|
||||
finish();
|
||||
activity.startActivity(new Intent(activity, SplashActivity.class));
|
||||
}
|
||||
|
|
@ -419,8 +448,94 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
if (requestCode == 1000 && resultCode == RESULT_CANCELED) {
|
||||
} else if (requestCode == 0 && resultCode == RESULT_OK) {
|
||||
Uri content_describer = ReturnedIntent.getData();
|
||||
File selectedFilePath = new File(getPath(content_describer));
|
||||
if (selectedFilePath.getName().endsWith(".cvbi")) {
|
||||
|
||||
loadingPb.setVisibility(View.VISIBLE);
|
||||
custom.setVisibility(View.GONE);
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
FileInputStream zipFile = null;
|
||||
try {
|
||||
zipFile = (FileInputStream) getContentResolver().openInputStream(content_describer);
|
||||
File targetDirectory = new File(AppConfig.maindirpath + selectedFilePath.getName().replace(".cvbi", ""));
|
||||
ZipInputStream zis = null;
|
||||
zis = new ZipInputStream(
|
||||
new BufferedInputStream(zipFile));
|
||||
try {
|
||||
ZipEntry ze;
|
||||
int count;
|
||||
byte[] buffer = new byte[8192];
|
||||
while ((ze = zis.getNextEntry()) != null) {
|
||||
File file = new File(targetDirectory, ze.getName());
|
||||
File dir = ze.isDirectory() ? file : file.getParentFile();
|
||||
if (!dir.isDirectory() && !dir.mkdirs())
|
||||
throw new FileNotFoundException("Failed to ensure directory: " +
|
||||
dir.getAbsolutePath());
|
||||
if (ze.isDirectory())
|
||||
continue;
|
||||
try (FileOutputStream fout = new FileOutputStream(file)) {
|
||||
while ((count = zis.read(buffer)) != -1)
|
||||
fout.write(buffer, 0, count);
|
||||
}
|
||||
/* if time should be restored as well
|
||||
long time = ze.getTime();
|
||||
if (time > 0)
|
||||
file.setLastModified(time);
|
||||
*/
|
||||
}
|
||||
} catch (IOException e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadingPb.setVisibility(View.GONE);
|
||||
custom.setVisibility(View.VISIBLE);
|
||||
try {
|
||||
|
||||
JSONObject jObj = new JSONObject(FileUtils.readFromFile(MainActivity.activity, new File(AppConfig.maindirpath
|
||||
+ selectedFilePath.getName().replace(".cvbi", "") + "/rom-data.json")));
|
||||
|
||||
title.setText(jObj.getString("title"));
|
||||
icon.setText(AppConfig.maindirpath
|
||||
+ selectedFilePath.getName().replace(".cvbi", "") + "/" + jObj.getString("icon"));
|
||||
drive.setText(AppConfig.maindirpath
|
||||
+ selectedFilePath.getName().replace(".cvbi", "") + "/" + jObj.getString("drive"));
|
||||
qemu.setText(jObj.getString("qemu"));
|
||||
ImageView ivIcon = findViewById(R.id.ivIcon);
|
||||
Bitmap bmImg = BitmapFactory.decodeFile(AppConfig.maindirpath
|
||||
+ selectedFilePath.getName().replace(".cvbi", "") + "/" + jObj.getString("icon"));
|
||||
ivIcon.setImageBitmap(bmImg);
|
||||
MainActivity.UIAlert("DESCRIPTION", "rom by:\n" + jObj.getString("author") + "\n\n" + Html.fromHtml(jObj.getString("desc")), activity);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
activity.runOnUiThread(runnable);
|
||||
try {
|
||||
zis.close();
|
||||
} catch (IOException e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
|
||||
} else {
|
||||
MainActivity.UIAlert("File not supported", "please select cvbi vailed file to continue.", activity);
|
||||
}
|
||||
|
||||
} else if (requestCode == 1000 && resultCode == RESULT_CANCELED) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.vectras.vm.Fragment;
|
|||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -36,7 +37,9 @@ public class DialogSettingsFragment extends Fragment {
|
|||
//Check to see which item was being clicked and perform appropriate action
|
||||
int id = menuItem.getItemId();
|
||||
if (id == R.id.uiInterface) {
|
||||
|
||||
final FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.fragment, new UiSettingsFragment(), "UiSettingsFragmentTag");
|
||||
ft.commit();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import androidx.fragment.app.Fragment;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.vectras.qemu.MainSDLActivity;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.qemu.MainVNCActivity;
|
||||
import com.vectras.vm.R;
|
||||
|
||||
public class UiSettingsFragment extends Fragment {
|
||||
|
|
@ -16,12 +20,25 @@ public class UiSettingsFragment extends Fragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_ui_settings, container, false);
|
||||
TextView btnMouseMode = v.findViewById(R.id.btnMouseMode);
|
||||
btnMouseMode.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (MainSettingsManager.getVmUi(getActivity()).equals("SDL")) {
|
||||
MainSDLActivity.activity.onMouseMode();
|
||||
} else if (MainSettingsManager.getVmUi(getActivity()).equals("VNC")) {
|
||||
MainVNCActivity.activity.onMouseMode();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_ui_settings, container, false);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
|
||||
|
|
@ -52,6 +55,8 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
|
@ -84,6 +89,7 @@ import com.vectras.vm.Fragment.HomeFragment;
|
|||
import com.vectras.vm.Fragment.LoggerFragment;
|
||||
import com.vectras.vm.MainRoms.AdapterMainRoms;
|
||||
import com.vectras.vm.logger.VectrasStatus;
|
||||
import com.vectras.vm.ui.login.VerifyEmailActivity;
|
||||
import com.vectras.vm.utils.AppUpdater;
|
||||
import com.vectras.qemu.utils.FileInstaller;
|
||||
import com.vectras.qemu.utils.RamInfo;
|
||||
|
|
@ -144,6 +150,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
ad = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
ad.setTitle(title);
|
||||
ad.setMessage(body);
|
||||
ad.setCancelable(false);
|
||||
ad.setButton(Dialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
|
|
@ -152,8 +159,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
ad.show();
|
||||
}
|
||||
|
||||
public static ProgressBar loadingPbb;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
|
|
@ -161,7 +166,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
loadingPbb = findViewById(R.id.loadingPb);
|
||||
activity = this;
|
||||
clearNotifications();
|
||||
setupFolders();
|
||||
|
|
@ -174,10 +178,40 @@ public class MainActivity extends AppCompatActivity {
|
|||
initNavigationMenu();
|
||||
FileInstaller.installFiles(activity, false);
|
||||
getWindow().setNavigationBarColor(SurfaceColors.SURFACE_2.getColor(this));
|
||||
requestPermissions();
|
||||
//updateApp(true);
|
||||
//mAuth = FirebaseAuth.getInstance();
|
||||
}
|
||||
|
||||
private void requestPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (ContextCompat.checkSelfPermission(this, POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this, R.style.MainDialogTheme);
|
||||
alertDialog.setTitle(R.string.permission_title);
|
||||
alertDialog.setMessage(R.string.permission_notification_text);
|
||||
alertDialog.setPositiveButton("ALLOW", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
ActivityCompat.requestPermissions(MainActivity.this, new String[]{POST_NOTIFICATIONS}, 11003);
|
||||
}
|
||||
});
|
||||
alertDialog.create().show();
|
||||
} else {
|
||||
ActivityCompat.shouldShowRequestPermissionRationale(this, POST_NOTIFICATIONS);
|
||||
}
|
||||
}
|
||||
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{ACCESS_FINE_LOCATION}, 11003);
|
||||
} else {
|
||||
ActivityCompat.shouldShowRequestPermissionRationale(this, ACCESS_FINE_LOCATION);
|
||||
}
|
||||
if (ContextCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{ACCESS_COARSE_LOCATION}, 11003);
|
||||
} else {
|
||||
ActivityCompat.shouldShowRequestPermissionRationale(this, ACCESS_COARSE_LOCATION);
|
||||
}
|
||||
}
|
||||
|
||||
public static PackageInfo getAppInfo(Context context) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
|
|
@ -616,6 +650,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (!mCurrentUser.isEmailVerified()) {
|
||||
startActivity(new Intent(activity, VerifyEmailActivity.class));
|
||||
activity.finish();
|
||||
}
|
||||
try {
|
||||
HomeFragment.loadDataVbi();
|
||||
} catch (Exception ignored) {
|
||||
|
|
@ -1091,35 +1129,53 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (requestCode == 1004 && resultCode == RESULT_OK) {
|
||||
Uri content_describer = ReturnedIntent.getData();
|
||||
File selectedFilePath = new File(getPath(content_describer));
|
||||
FileInputStream isoFile = null;
|
||||
try {
|
||||
isoFile = (FileInputStream) getContentResolver().openInputStream(content_describer);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ProgressBar loading = findViewById(R.id.loading);
|
||||
if (selectedFilePath.toString().endsWith(".iso")) {
|
||||
loadingPbb.setVisibility(View.VISIBLE);
|
||||
try {
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(new File(AppConfig.maindirpath + "/drive.iso"));
|
||||
loading.setVisibility(View.VISIBLE);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FileInputStream File = null;
|
||||
try {
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = isoFile.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
File = (FileInputStream) getContentResolver().openInputStream(content_describer);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(new File(AppConfig.maindirpath + "/drive.iso"));
|
||||
try {
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = File.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
} finally {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loading.setVisibility(View.GONE);
|
||||
}
|
||||
};
|
||||
activity.runOnUiThread(runnable);
|
||||
File.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loading.setVisibility(View.GONE);
|
||||
}
|
||||
};
|
||||
activity.runOnUiThread(runnable);
|
||||
UIAlert("error", e.toString(), activity);
|
||||
}
|
||||
} finally {
|
||||
loadingPbb.setVisibility(View.GONE);
|
||||
isoFile.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
loadingPbb.setVisibility(View.GONE);
|
||||
UIAlert("error", e.toString(), activity);
|
||||
}
|
||||
}).start();
|
||||
} else
|
||||
UIAlert("NOT VAILED FILE", "please select iso file", activity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
package com.vectras.vm.MainRoms;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -24,6 +28,9 @@ import androidx.cardview.widget.CardView;
|
|||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.vectras.qemu.Config;
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.vectras.vm.Fragment.HomeFragment;
|
||||
|
|
@ -34,14 +41,23 @@ import com.vectras.vm.utils.UIUtils;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.zeroturnaround.zip.FileSource;
|
||||
import org.zeroturnaround.zip.ZipEntrySource;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
|
|
@ -66,6 +82,8 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
return holder;
|
||||
}
|
||||
|
||||
public static final String CREDENTIAL_SHARED_PREF = "settings_prefs";
|
||||
|
||||
// Bind data
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
|
|
@ -110,6 +128,90 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
}
|
||||
}
|
||||
});
|
||||
Button exportRomBtn = d.findViewById(R.id.exportRomBtn);
|
||||
exportRomBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final File jsonFile = new File(MainActivity.activity.getExternalFilesDir("data") + "/rom-data.json");
|
||||
AlertDialog ad;
|
||||
ad = new AlertDialog.Builder(MainActivity.activity).create();
|
||||
ad.setTitle("Export Rom");
|
||||
ad.setMessage("Are you sure?");
|
||||
final TextInputLayout Description = new TextInputLayout(MainActivity.activity);
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT);
|
||||
Description.setHint("DESCRIPTION (html supported)");
|
||||
Description.setLayoutParams(lp);
|
||||
Description.setPadding(10, 10, 10, 10);
|
||||
final TextInputEditText DescriptionET = new TextInputEditText(MainActivity.activity);
|
||||
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT);
|
||||
DescriptionET.setLayoutParams(lp2);
|
||||
Description.addView(DescriptionET);
|
||||
DescriptionET.setText("null");
|
||||
DescriptionET.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
DescriptionET.setSelectAllOnFocus(true);
|
||||
ad.setView(Description);
|
||||
ad.setButton(Dialog.BUTTON_POSITIVE, "EXPORT", (dialog, which) -> {
|
||||
RomJson obj = new RomJson();
|
||||
JSONObject jsonObject = obj.makeJSONObject(current.itemName, current.itemArch, FirebaseAuth.getInstance().getCurrentUser().getDisplayName(), DescriptionET.getText().toString(), new File(current.itemIcon).getName(), new File(current.itemPath).getName(), qemu.getText().toString());
|
||||
|
||||
try {
|
||||
Writer output = null;
|
||||
output = new BufferedWriter(new FileWriter(jsonFile));
|
||||
output.write(jsonObject.toString().replace("\\", "").replace("//", "/"));
|
||||
output.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
SharedPreferences credentials = MainActivity.activity.getSharedPreferences(CREDENTIAL_SHARED_PREF, Context.MODE_PRIVATE);
|
||||
|
||||
ProgressDialog progressDialog = new ProgressDialog(MainActivity.activity);
|
||||
progressDialog.setTitle("Compressing CVBI");
|
||||
progressDialog.setMessage("Please wait...");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show(); // Showing Progress Dialog
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
ZipEntrySource[] addedEntries = new ZipEntrySource[]{
|
||||
new FileSource("/" + new File(current.itemPath).getName(), new File(current.itemPath)),
|
||||
new FileSource("/" + new File(current.itemIcon).getName(), new File(current.itemIcon)),
|
||||
new FileSource("/" + new File(MainActivity.activity.getExternalFilesDir("data") + "/rom-data.json").getName(), new File(MainActivity.activity.getExternalFilesDir("data") + "/rom-data.json"))
|
||||
};
|
||||
ZipUtil.pack(addedEntries, new File(AppConfig.datadirpath() + "/cvbi/" + current.itemName + ".cvbi"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressDialog.cancel(); // cancelling Dialog.
|
||||
MainActivity.UIAlert("ERROR!", e.toString(), MainActivity.activity);
|
||||
}
|
||||
};
|
||||
MainActivity.activity.runOnUiThread(runnable);
|
||||
} finally {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressDialog.cancel(); // cancelling Dialog.}
|
||||
MainActivity.UIAlert("DONE!", AppConfig.datadirpath() + "/cvbi/" + current.itemName + ".cvbi", MainActivity.activity);
|
||||
}
|
||||
};
|
||||
MainActivity.activity.runOnUiThread(runnable);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
return;
|
||||
});
|
||||
ad.setButton(Dialog.BUTTON_NEGATIVE, "CLOSE", (dialog, which) -> {
|
||||
return;
|
||||
});
|
||||
ad.show();
|
||||
}
|
||||
});
|
||||
d.show();
|
||||
}
|
||||
});
|
||||
|
|
@ -177,6 +279,29 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
});
|
||||
}
|
||||
|
||||
public class RomJson extends JSONObject {
|
||||
|
||||
public JSONObject makeJSONObject(String imgName, String imgArch, String imgAuthor, String imgDesc, String imgIcon, String imgDrive, String imgQemu) {
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
obj.put("title", imgName);
|
||||
obj.put("arch", imgArch);
|
||||
obj.put("author", imgAuthor);
|
||||
obj.put("desc", imgDesc);
|
||||
obj.put("kernel", "windows");
|
||||
obj.put("icon", imgIcon);
|
||||
obj.put("drive", imgDrive);
|
||||
obj.put("qemu", imgQemu);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
private void showDialog(String title, String path, String pathIcon) {
|
||||
|
||||
final Dialog dialog = new Dialog(MainActivity.activity, R.style.MainDialogTheme);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import android.text.Editable;
|
|||
import android.text.TextWatcher;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -148,6 +149,15 @@ public class ProfileActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
Button singoutBtn = findViewById(R.id.signout);
|
||||
singoutBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FirebaseAuth.getInstance().signOut();
|
||||
MainActivity.activity.finish();
|
||||
startActivity(new Intent(activity, SplashActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package com.vectras.vm.Roms;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.graphics.Color;
|
||||
import android.os.Environment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -27,6 +29,10 @@ import com.vectras.vm.MainActivity;
|
|||
import com.vectras.vm.R;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -36,6 +42,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
|
||||
import android.content.DialogInterface;
|
||||
import android.app.Dialog;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class AdapterRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
|
|
@ -82,7 +89,7 @@ public class AdapterRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||
} else {
|
||||
myHolder.checkBox.setEnabled(true);
|
||||
myHolder.textAvail.setTextColor(Color.GREEN);
|
||||
myHolder.textAvail.setText("availability: available");
|
||||
myHolder.textAvail.setText("available");
|
||||
}
|
||||
myHolder.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
@ -95,10 +102,30 @@ public class AdapterRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||
RomsManagerActivity.selectedName = current.itemName + " " + current.itemArch;
|
||||
RomsManagerActivity.selectedLink = current.itemUrl;
|
||||
RomsManagerActivity.selectedIcon = current.itemIcon;
|
||||
myHolder.ivIcon.buildDrawingCache();
|
||||
Bitmap bm = myHolder.ivIcon.getDrawingCache();
|
||||
OutputStream fOut = null;
|
||||
Uri outputFileUri;
|
||||
try {
|
||||
File root = new File(AppConfig.maindirpath + "/icons/");
|
||||
root.mkdirs();
|
||||
File sdImageMainDirectory = new File(root, current.itemPath.replace(".IMG", ".jpg"));
|
||||
outputFileUri = Uri.fromFile(sdImageMainDirectory);
|
||||
fOut = new FileOutputStream(sdImageMainDirectory);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
myHolder.textAvail.setText("availability: unavailable");
|
||||
myHolder.textAvail.setText("unavailable");
|
||||
myHolder.textAvail.setTextColor(Color.RED);
|
||||
myHolder.checkBox.setEnabled(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import android.database.Cursor;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
|
|
@ -42,6 +44,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.vm.AppConfig;
|
||||
|
|
@ -71,6 +74,7 @@ import java.io.OutputStream;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
|
|
@ -95,13 +99,11 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
|
||||
public static MaterialButton goBtn;
|
||||
|
||||
public static CheckBox acceptLiceneseChkBox;
|
||||
public static AlertDialog ad;
|
||||
|
||||
public static String license;
|
||||
public static RecyclerView mRVRoms;
|
||||
public static AdapterRoms mAdapter;
|
||||
public static String Data;
|
||||
public static List<DataRoms> data;
|
||||
public static Boolean selected = false;
|
||||
public static String selectedPath = null;
|
||||
|
|
@ -142,6 +144,29 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CHECK WHETHER INTERNET CONNECTION IS AVAILABLE OR NOT
|
||||
*/
|
||||
public boolean checkConnection(Context context) {
|
||||
final ConnectivityManager connMgr = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (connMgr != null) {
|
||||
NetworkInfo activeNetworkInfo = connMgr.getActiveNetworkInfo();
|
||||
|
||||
if (activeNetworkInfo != null) { // connected to the internet
|
||||
// connected to the mobile provider's data plan
|
||||
if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||
// connected to wifi
|
||||
return true;
|
||||
} else
|
||||
return activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
|
|
@ -150,6 +175,10 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
|
||||
super.onCreate(savedInstanceState);
|
||||
activity = this;
|
||||
SharedPreferences prefs = getSharedPreferences(CREDENTIAL_SHARED_PREF, Context.MODE_PRIVATE);
|
||||
boolean isAccessed = prefs.getBoolean("isFirstLaunch", false);
|
||||
if (!isAccessed && !checkConnection(activity))
|
||||
MainActivity.UIAlert("No internet connection!", "for first time you need internet connection to load app data!", activity);
|
||||
setContentView(R.layout.activity_roms_manager);
|
||||
loadingPb = findViewById(R.id.loadingPb);
|
||||
filterToggle = findViewById(R.id.filterToggle);
|
||||
|
|
@ -188,7 +217,7 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
else
|
||||
filter = null;
|
||||
}
|
||||
new RomsManagerActivity.AsyncLogin().execute();
|
||||
loadData();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -198,59 +227,8 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
setTitle("Roms Manager " + MainSettingsManager.getArch(activity));
|
||||
|
||||
new RomsManagerActivity.AsyncLogin().execute();
|
||||
new Thread(new Runnable() {
|
||||
loadData();
|
||||
|
||||
public void run() {
|
||||
|
||||
BufferedReader reader = null;
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
try {
|
||||
// Create a URL for the desired page
|
||||
URL url = new URL(AppConfig.vectrasTerms); //My text file location
|
||||
//First open the connection
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(60000); // timing out in a minute
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
//t=(TextView)findViewById(R.id.TextView1); // ideally do this in onCreate()
|
||||
String str;
|
||||
while ((str = in.readLine()) != null) {
|
||||
builder.append(str);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
acceptLiceneseChkBox.setEnabled(false);
|
||||
UIUtils.toastLong(activity, "no internet connection " + e.toString());
|
||||
}
|
||||
|
||||
//since we are in background thread, to post results we have to go back to ui thread. do the following for that
|
||||
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
license = builder.toString(); // My TextFile has 3 lines
|
||||
acceptLiceneseChkBox.setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
acceptLiceneseChkBox = findViewById(R.id.acceptLiceneseChkBox);
|
||||
|
||||
acceptLiceneseChkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
UIAlertLicense("Terms&Conditions", license, activity);
|
||||
} else {
|
||||
goBtn.setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
goBtn = (MaterialButton) findViewById(R.id.goBtn);
|
||||
|
||||
goBtn.setOnClickListener(new View.OnClickListener() {
|
||||
|
|
@ -272,126 +250,48 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
public static void UIAlertLicense(String title, String html, final Activity activity) {
|
||||
AlertDialog alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(title);
|
||||
alertDialog.setCancelable(true);
|
||||
private void loadData() {
|
||||
data = new ArrayList<>();
|
||||
|
||||
alertDialog.setMessage(Html.fromHtml(html));
|
||||
try {
|
||||
JSONArray jArray = new JSONArray(FileUtils.readFromFile(activity, new File(AppConfig.maindirpath + "roms.json")));
|
||||
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "I Acknowledge", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
acceptLiceneseChkBox.setChecked(true);
|
||||
goBtn.setEnabled(true);
|
||||
return;
|
||||
// Extract data from json and store into ArrayList as class objects
|
||||
for (int i = 0; i < jArray.length(); i++) {
|
||||
JSONObject json_data = jArray.getJSONObject(i);
|
||||
DataRoms romsData = new DataRoms();
|
||||
romsData.itemName = json_data.getString("rom_name");
|
||||
romsData.itemIcon = json_data.getString("rom_icon");
|
||||
romsData.itemUrl = json_data.getString("rom_url");
|
||||
romsData.itemPath = json_data.getString("rom_path");
|
||||
romsData.itemAvail = json_data.getBoolean("rom_avail");
|
||||
romsData.itemSize = json_data.getString("rom_size");
|
||||
romsData.itemArch = json_data.getString("rom_arch");
|
||||
romsData.itemKernel = json_data.getString("rom_kernel");
|
||||
romsData.itemExtra = json_data.getString("rom_extra");
|
||||
if (filter != null) {
|
||||
if (romsData.itemKernel.toLowerCase().contains(filter.toLowerCase())) {
|
||||
data.add(romsData);
|
||||
}
|
||||
} else {
|
||||
data.add(romsData);
|
||||
}
|
||||
}
|
||||
});
|
||||
alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
acceptLiceneseChkBox.setChecked(false);
|
||||
goBtn.setEnabled(false);
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
|
||||
// Setup and Handover data to recyclerview
|
||||
|
||||
} catch (JSONException e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
}
|
||||
mRVRoms = (RecyclerView) activity.findViewById(R.id.romsRv);
|
||||
mAdapter = new AdapterRoms(activity, data);
|
||||
mRVRoms.setAdapter(mAdapter);
|
||||
mRVRoms.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
|
||||
}
|
||||
|
||||
|
||||
public static String filter = null;
|
||||
|
||||
public static class AsyncLogin extends AsyncTask<String, String, String> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
//this method will be running on UI thread
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
HttpsURLConnection con = null;
|
||||
try {
|
||||
URL u = new URL(AppConfig.romsJson(activity));
|
||||
con = (HttpsURLConnection) u.openConnection();
|
||||
|
||||
con.connect();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
br.close();
|
||||
Data = sb.toString();
|
||||
|
||||
return (Data);
|
||||
|
||||
} catch (MalformedURLException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (con != null) {
|
||||
try {
|
||||
con.disconnect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ("unsuccessful!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
|
||||
//this method will be running on UI thread
|
||||
data = new ArrayList<>();
|
||||
|
||||
try {
|
||||
|
||||
JSONArray jArray = new JSONArray(Data);
|
||||
|
||||
// Extract data from json and store into ArrayList as class objects
|
||||
for (int i = 0; i < jArray.length(); i++) {
|
||||
JSONObject json_data = jArray.getJSONObject(i);
|
||||
DataRoms romsData = new DataRoms();
|
||||
romsData.itemName = json_data.getString("rom_name");
|
||||
romsData.itemIcon = json_data.getString("rom_icon");
|
||||
romsData.itemUrl = json_data.getString("rom_url");
|
||||
romsData.itemPath = json_data.getString("rom_path");
|
||||
romsData.itemAvail = json_data.getBoolean("rom_avail");
|
||||
romsData.itemSize = json_data.getString("rom_size");
|
||||
romsData.itemArch = json_data.getString("rom_arch");
|
||||
romsData.itemKernel = json_data.getString("rom_kernel");
|
||||
romsData.itemExtra = json_data.getString("rom_extra");
|
||||
if (filter != null) {
|
||||
if (romsData.itemKernel.toLowerCase().contains(filter.toLowerCase())) {
|
||||
data.add(romsData);
|
||||
}
|
||||
} else {
|
||||
data.add(romsData);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup and Handover data to recyclerview
|
||||
|
||||
} catch (JSONException e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
}
|
||||
mRVRoms = (RecyclerView) activity.findViewById(R.id.romsRv);
|
||||
mAdapter = new AdapterRoms(activity, data);
|
||||
mRVRoms.setAdapter(mAdapter);
|
||||
mRVRoms.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RomsJso extends JSONObject {
|
||||
|
||||
public JSONObject makeJSONObject(String imgName, String imgIcon, String imgArch, String imgPath, String imgExtra) {
|
||||
|
|
@ -412,30 +312,10 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public static class RomsJso2 extends JSONObject {
|
||||
|
||||
public JSONObject makeJSONObject(String imgName, String imgIcon, String imgArch, String imgPath, String imgExtra) {
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
obj.put("imgName", imgName);
|
||||
obj.put("imgIcon", imgIcon);
|
||||
obj.put("imgArch", imgArch);
|
||||
obj.put("imgPath", imgPath);
|
||||
obj.put("imgExtra", imgExtra);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String CREDENTIAL_SHARED_PREF = "settings_prefs";
|
||||
|
||||
private void startIconDownload() {
|
||||
new DownloadsImage().execute(selectedIcon);
|
||||
|
||||
}
|
||||
|
||||
public void onFirstStartup() {
|
||||
|
|
@ -582,7 +462,6 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
try {
|
||||
loadingPb.setVisibility(View.VISIBLE);
|
||||
goBtn.setEnabled(false);
|
||||
acceptLiceneseChkBox.setEnabled(false);
|
||||
mRVRoms.setVisibility(View.GONE);
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
|
|
@ -627,7 +506,6 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
public void run() {
|
||||
loadingPb.setVisibility(View.GONE);
|
||||
goBtn.setEnabled(true);
|
||||
acceptLiceneseChkBox.setEnabled(true);
|
||||
mRVRoms.setVisibility(View.VISIBLE);
|
||||
onFirstStartup();
|
||||
}
|
||||
|
|
@ -646,7 +524,6 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
} catch (Exception e) {
|
||||
loadingPb.setVisibility(View.GONE);
|
||||
goBtn.setEnabled(true);
|
||||
acceptLiceneseChkBox.setEnabled(true);
|
||||
mRVRoms.setVisibility(View.VISIBLE);
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -659,7 +536,7 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
static class DownloadsImage extends AsyncTask<String, Void, Void> {
|
||||
public static class DownloadsImage extends AsyncTask<String, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... strings) {
|
||||
|
|
|
|||
|
|
@ -1,24 +1,56 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.*;
|
||||
import android.content.pm.*;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.*;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.qemu.utils.RamInfo;
|
||||
import com.vectras.vm.Fragment.HomeFragment;
|
||||
import com.vectras.vm.MainRoms.AdapterMainRoms;
|
||||
import com.vectras.vm.MainRoms.DataMainRoms;
|
||||
import com.vectras.vm.ui.login.LoginActivity;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SplashActivity extends AppCompatActivity implements Runnable {
|
||||
public AlertDialog ad;
|
||||
public static SplashActivity activity;
|
||||
private FirebaseAuth mAuth;
|
||||
private final String TAG = "SplashActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
|
|
@ -32,7 +64,19 @@ public class SplashActivity extends AppCompatActivity implements Runnable {
|
|||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
new Handler().postDelayed(this, 3000);
|
||||
SharedPreferences prefs = getSharedPreferences(CREDENTIAL_SHARED_PREF, Context.MODE_PRIVATE);
|
||||
|
||||
boolean isAccessed = prefs.getBoolean("isFirstLaunch", false);
|
||||
if (isAccessed && !checkConnection(activity)) {
|
||||
new Handler().postDelayed(this, 3000);
|
||||
} else {
|
||||
try {
|
||||
new DownloadFileAsync().execute(AppConfig.romsJson(activity));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
File sharedDir = new File(AppConfig.sharedFolder);
|
||||
if (!sharedDir.exists()) {
|
||||
sharedDir.mkdirs();
|
||||
|
|
@ -41,6 +85,14 @@ public class SplashActivity extends AppCompatActivity implements Runnable {
|
|||
if (!mainDir.exists()) {
|
||||
mainDir.mkdirs();
|
||||
}
|
||||
File iconsDir = new File(AppConfig.maindirpath + "/icons/");
|
||||
if (!iconsDir.exists()) {
|
||||
iconsDir.mkdirs();
|
||||
}
|
||||
File cvbiDir = new File(AppConfig.maindirpath + "/cvbi/");
|
||||
if (!cvbiDir.exists()) {
|
||||
cvbiDir.mkdirs();
|
||||
}
|
||||
// Initialize Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
RamInfo.activity = activity;
|
||||
|
|
@ -65,4 +117,99 @@ public class SplashActivity extends AppCompatActivity implements Runnable {
|
|||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* CHECK WHETHER INTERNET CONNECTION IS AVAILABLE OR NOT
|
||||
*/
|
||||
public boolean checkConnection(Context context) {
|
||||
final ConnectivityManager connMgr = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (connMgr != null) {
|
||||
NetworkInfo activeNetworkInfo = connMgr.getActiveNetworkInfo();
|
||||
|
||||
if (activeNetworkInfo != null) { // connected to the internet
|
||||
// connected to the mobile provider's data plan
|
||||
if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||
// connected to wifi
|
||||
return true;
|
||||
} else
|
||||
return activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
|
||||
private ProgressDialog mProgressDialog;
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case DIALOG_DOWNLOAD_PROGRESS:
|
||||
mProgressDialog = new ProgressDialog(this, R.style.MainDialogTheme);
|
||||
mProgressDialog.setMessage("loading app data..");
|
||||
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
mProgressDialog.setCancelable(false);
|
||||
mProgressDialog.show();
|
||||
return mProgressDialog;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadFileAsync extends AsyncTask<String, String, String> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
showDialog(DIALOG_DOWNLOAD_PROGRESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... aurl) {
|
||||
int count;
|
||||
|
||||
try {
|
||||
URL url = new URL(aurl[0]);
|
||||
URLConnection conexion = url.openConnection();
|
||||
conexion.connect();
|
||||
|
||||
int lenghtOfFile = conexion.getContentLength();
|
||||
Log.d(TAG, "Lenght of file: " + lenghtOfFile);
|
||||
String fileName = URLUtil.guessFileName(url.getFile(),null,null);
|
||||
InputStream input = new BufferedInputStream(url.openStream());
|
||||
OutputStream output = new FileOutputStream(AppConfig.maindirpath+fileName);
|
||||
|
||||
byte data[] = new byte[1024];
|
||||
|
||||
long total = 0;
|
||||
|
||||
while ((count = input.read(data)) != -1) {
|
||||
total += count;
|
||||
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
|
||||
output.flush();
|
||||
output.close();
|
||||
input.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
protected void onProgressUpdate(String... progress) {
|
||||
Log.d(TAG, progress[0]);
|
||||
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String unused) {
|
||||
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
|
||||
new Handler().postDelayed(activity, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
package com.vectras.vm.ui.login;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.Html;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
|
@ -32,13 +37,23 @@ import com.google.firebase.auth.AuthResult;
|
|||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
import com.google.firebase.auth.UserProfileChangeRequest;
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.vectras.vm.R;
|
||||
import com.vectras.vm.RomsManagerActivity;
|
||||
import com.vectras.vm.SplashActivity;
|
||||
import com.vectras.vm.utils.UIUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
private FirebaseAuth mAuth;
|
||||
private TextView mStatusTextView;
|
||||
public String license;
|
||||
|
||||
// ...
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -46,6 +61,44 @@ public class LoginActivity extends AppCompatActivity {
|
|||
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
|
||||
BufferedReader reader = null;
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
try {
|
||||
// Create a URL for the desired page
|
||||
URL url = new URL(AppConfig.vectrasTerms); //My text file location
|
||||
//First open the connection
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(60000); // timing out in a minute
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
//t=(TextView)findViewById(R.id.TextView1); // ideally do this in onCreate()
|
||||
String str;
|
||||
while ((str = in.readLine()) != null) {
|
||||
builder.append(str);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
UIUtils.toastLong(LoginActivity.this, "no internet connection " + e.toString());
|
||||
}
|
||||
|
||||
//since we are in background thread, to post results we have to go back to ui thread. do the following for that
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
license = builder.toString();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
MaterialButton signinButton = findViewById(R.id.signinBtn);
|
||||
|
||||
MaterialButton signupButton = findViewById(R.id.signupBtn);
|
||||
|
|
@ -58,6 +111,16 @@ public class LoginActivity extends AppCompatActivity {
|
|||
|
||||
mStatusTextView = findViewById(R.id.errorTxt);
|
||||
|
||||
TextView ppTxt = findViewById(R.id.ppTxt);
|
||||
|
||||
ppTxt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (license != null)
|
||||
UIAlertLicense("Terms&Conditions", license, LoginActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
TextWatcher afterTextChangedListener = new TextWatcher() {
|
||||
|
|
@ -118,6 +181,28 @@ public class LoginActivity extends AppCompatActivity {
|
|||
|
||||
}
|
||||
|
||||
public static void UIAlertLicense(String title, String html, final Activity activity) {
|
||||
AlertDialog alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(title);
|
||||
alertDialog.setCancelable(true);
|
||||
|
||||
alertDialog.setMessage(Html.fromHtml(html));
|
||||
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "I Acknowledge", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
public void updateUI(Object USER) {
|
||||
if (USER != null) {
|
||||
FirebaseAuth auth = FirebaseAuth.getInstance();
|
||||
|
|
@ -128,7 +213,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
startActivity(new Intent(LoginActivity.this, RomsManagerActivity.class));
|
||||
finish();
|
||||
startActivity(new Intent(LoginActivity.this, SplashActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.google.firebase.auth.FirebaseUser;
|
|||
import com.google.firebase.auth.UserProfileChangeRequest;
|
||||
import com.vectras.vm.R;
|
||||
import com.vectras.vm.RomsManagerActivity;
|
||||
import com.vectras.vm.SplashActivity;
|
||||
|
||||
public class SignupActivity extends AppCompatActivity {
|
||||
|
||||
|
|
@ -127,7 +128,8 @@ public class SignupActivity extends AppCompatActivity {
|
|||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
startActivity(new Intent(SignupActivity.this, RomsManagerActivity.class));
|
||||
finish();
|
||||
startActivity(new Intent(SignupActivity.this, SplashActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.vectras.vm.ui.login;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.vectras.vm.MainActivity;
|
||||
import com.vectras.vm.R;
|
||||
import com.vectras.vm.SplashActivity;
|
||||
|
||||
public class VerifyEmailActivity extends AppCompatActivity {
|
||||
|
||||
public static VerifyEmailActivity activity;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_verify_email);
|
||||
activity = this;
|
||||
TextView emailTxt = findViewById(R.id.email);
|
||||
emailTxt.setText(FirebaseAuth.getInstance().getCurrentUser().getEmail());
|
||||
Button singoutBtn = findViewById(R.id.signout);
|
||||
singoutBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FirebaseAuth.getInstance().signOut();
|
||||
MainActivity.activity.finish();
|
||||
startActivity(new Intent(activity, SplashActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,9 @@ import android.os.Looper;
|
|||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.vectras.vm.MainActivity;
|
||||
import com.vectras.vm.AppConfig;
|
||||
import java.io.BufferedReader;
|
||||
|
|
@ -51,6 +54,10 @@ import java.util.HashMap;
|
|||
* @author dev
|
||||
*/
|
||||
public class FileUtils {
|
||||
@NonNull
|
||||
public static File getExternalFilesDirectory(Context context) {
|
||||
return new File(Environment.getExternalStorageDirectory(), "Documents/VectrasVM");
|
||||
}
|
||||
|
||||
private static Uri contentUri = null;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue