mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-19 00:55:45 -04:00
Android: Fix some crashes reported via Play Store
This commit is contained in:
@ -104,4 +104,8 @@ public class AndroidHostInterface {
|
||||
static public AndroidHostInterface getInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
static public boolean hasInstanceAndEmulationThreadIsRunning() {
|
||||
return hasInstance() && getInstance().isEmulationThreadRunning();
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +116,16 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||
mApplySettingsOnSurfaceRestored = true;
|
||||
}
|
||||
|
||||
/// Ends the activity if it was restored without properly being created.
|
||||
private boolean checkActivityIsValid() {
|
||||
if (!AndroidHostInterface.hasInstance() || !AndroidHostInterface.getInstance().isEmulationThreadRunning()) {
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
}
|
||||
@ -227,7 +237,9 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
updateOrientation(newConfig.orientation);
|
||||
|
||||
if (checkActivityIsValid())
|
||||
updateOrientation(newConfig.orientation);
|
||||
}
|
||||
|
||||
private void updateOrientation() {
|
||||
|
@ -42,6 +42,9 @@ public final class FileUtil {
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
private static String getVolumePath(final String volumeId, Context context) {
|
||||
if (volumeId == null)
|
||||
return null;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;
|
||||
try {
|
||||
StorageManager mStorageManager =
|
||||
@ -113,18 +116,26 @@ public final class FileUtil {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private static String getVolumeIdFromUri(final Uri treeUri) {
|
||||
final String docId = DocumentsContract.getDocumentId(treeUri);
|
||||
final String[] split = docId.split(":");
|
||||
if (split.length > 0) return split[0];
|
||||
else return null;
|
||||
try {
|
||||
final String docId = DocumentsContract.getDocumentId(treeUri);
|
||||
final String[] split = docId.split(":");
|
||||
if (split.length > 0) return split[0];
|
||||
else return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private static String getDocumentPathFromUri(final Uri treeUri) {
|
||||
final String docId = DocumentsContract.getDocumentId(treeUri);
|
||||
final String[] split = docId.split(":");
|
||||
if ((split.length >= 2) && (split[1] != null)) return split[1];
|
||||
else return File.separator;
|
||||
try {
|
||||
final String docId = DocumentsContract.getDocumentId(treeUri);
|
||||
final String[] split = docId.split(":");
|
||||
if ((split.length >= 2) && (split[1] != null)) return split[1];
|
||||
else return File.separator;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -143,6 +143,9 @@ public class TouchscreenControllerView extends FrameLayout {
|
||||
private boolean handleTouchEvent(MotionEvent event) {
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_UP: {
|
||||
if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning())
|
||||
return false;
|
||||
|
||||
for (TouchscreenControllerButtonView buttonView : mButtonViews) {
|
||||
buttonView.setPressed(false);
|
||||
}
|
||||
@ -158,6 +161,9 @@ public class TouchscreenControllerView extends FrameLayout {
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning())
|
||||
return false;
|
||||
|
||||
Rect rect = new Rect();
|
||||
final int pointerCount = event.getPointerCount();
|
||||
final int liftedPointerIndex = (event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) ? event.getActionIndex() : -1;
|
||||
|
Reference in New Issue
Block a user