mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Use mutex lock instead of "Thread.sleep()"
This commit is contained in:
parent
d1be63ab8b
commit
2cf9777991
@ -28,6 +28,9 @@ import org.apache.commons.io.*;
|
|||||||
public class PojavLoginActivity extends AppCompatActivity
|
public class PojavLoginActivity extends AppCompatActivity
|
||||||
// MineActivity
|
// MineActivity
|
||||||
{
|
{
|
||||||
|
private Object mLockStoragePerm = new Object(),
|
||||||
|
mLockSelectJRE = new Object();
|
||||||
|
|
||||||
private EditText edit2, edit3;
|
private EditText edit2, edit3;
|
||||||
private int REQUEST_STORAGE_REQUEST_CODE = 1;
|
private int REQUEST_STORAGE_REQUEST_CODE = 1;
|
||||||
private ProgressBar prb;
|
private ProgressBar prb;
|
||||||
@ -37,9 +40,6 @@ public class PojavLoginActivity extends AppCompatActivity
|
|||||||
private ImageView imageLogo;
|
private ImageView imageLogo;
|
||||||
private TextView startupTextView;
|
private TextView startupTextView;
|
||||||
|
|
||||||
private boolean isPromptingGrant = false;
|
|
||||||
// private boolean isPermGranted = false;
|
|
||||||
|
|
||||||
private SharedPreferences firstLaunchPrefs;
|
private SharedPreferences firstLaunchPrefs;
|
||||||
// private final String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
|
// private final String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
|
||||||
public static final String PREF_IS_INSTALLED_JAVARUNTIME = "isJavaRuntimeInstalled";
|
public static final String PREF_IS_INSTALLED_JAVARUNTIME = "isJavaRuntimeInstalled";
|
||||||
@ -124,12 +124,12 @@ public class PojavLoginActivity extends AppCompatActivity
|
|||||||
Toast.makeText(PojavLoginActivity.this, R.string.toast_permission_denied, Toast.LENGTH_LONG).show();
|
Toast.makeText(PojavLoginActivity.this, R.string.toast_permission_denied, Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
isPromptingGrant = true;
|
|
||||||
requestStoragePermission();
|
|
||||||
while (isPromptingGrant) {
|
|
||||||
Thread.sleep(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
requestStoragePermission();
|
||||||
|
|
||||||
|
synchronized (mLockStoragePerm) {
|
||||||
|
mLockStoragePerm.wait();
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,6 +356,10 @@ public class PojavLoginActivity extends AppCompatActivity
|
|||||||
if (file.getName().endsWith(".tar.xz")) {
|
if (file.getName().endsWith(".tar.xz")) {
|
||||||
selectedFile.append(path);
|
selectedFile.append(path);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
|
synchronized (mLockSelectJRE) {
|
||||||
|
mLockSelectJRE.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -364,8 +368,8 @@ public class PojavLoginActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
while (selectedFile.length() == 0) {
|
synchronized (mLockSelectJRE) {
|
||||||
Thread.sleep(500);
|
mLockSelectJRE.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new File(selectedFile.toString());
|
return new File(selectedFile.toString());
|
||||||
@ -681,11 +685,10 @@ public class PojavLoginActivity extends AppCompatActivity
|
|||||||
// This method will be called when the user will tap on allow or deny
|
// This method will be called when the user will tap on allow or deny
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
|
||||||
//Checking the request code of our request
|
|
||||||
if (requestCode == REQUEST_STORAGE_REQUEST_CODE){
|
if (requestCode == REQUEST_STORAGE_REQUEST_CODE){
|
||||||
isPromptingGrant = false;
|
synchronized (mLockStoragePerm) {
|
||||||
// isPermGranted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED;
|
mLockStoragePerm.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user