Wrap some android code in api version checks

This commit is contained in:
Aaron Kling 2018-05-01 09:56:14 -05:00
parent dd1fc5f3da
commit c9218bbd23
3 changed files with 49 additions and 36 deletions

View File

@ -49,6 +49,7 @@ public class RetroActivityCommon extends RetroActivityLocation
long[] pattern = {16}; long[] pattern = {16};
int[] strengths = {strength}; int[] strengths = {strength};
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
if (id == -1) if (id == -1)
vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
else else
@ -58,6 +59,7 @@ public class RetroActivityCommon extends RetroActivityLocation
if (dev != null) if (dev != null)
vibrator = dev.getVibrator(); vibrator = dev.getVibrator();
} }
}
if (vibrator == null) if (vibrator == null)
return; return;
@ -72,7 +74,7 @@ public class RetroActivityCommon extends RetroActivityLocation
else else
pattern[0] = 1000; pattern[0] = 1000;
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
if (id >= 0) if (id >= 0)
Log.i("RetroActivity", "Vibrate id " + id + ": strength " + strength); Log.i("RetroActivity", "Vibrate id " + id + ": strength " + strength);

View File

@ -40,6 +40,8 @@ public final class MainMenuActivity extends PreferenceActivity
} }
private boolean addPermission(List<String> permissionsList, String permission) private boolean addPermission(List<String> permissionsList, String permission)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{ {
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED)
{ {
@ -49,13 +51,14 @@ public final class MainMenuActivity extends PreferenceActivity
if (!shouldShowRequestPermissionRationale(permission)) if (!shouldShowRequestPermissionRationale(permission))
return false; return false;
} }
}
return true; return true;
} }
public void checkRuntimePermissions() public void checkRuntimePermissions()
{ {
if (android.os.Build.VERSION.SDK_INT >= 23) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{ {
// Android 6.0+ needs runtime permission checks // Android 6.0+ needs runtime permission checks
List<String> permissionsNeeded = new ArrayList<String>(); List<String> permissionsNeeded = new ArrayList<String>();
@ -89,6 +92,8 @@ public final class MainMenuActivity extends PreferenceActivity
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
if (which == AlertDialog.BUTTON_POSITIVE) if (which == AlertDialog.BUTTON_POSITIVE)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{ {
requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS); REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
@ -96,6 +101,7 @@ public final class MainMenuActivity extends PreferenceActivity
Log.i("MainMenuActivity", "User accepted request for external storage permissions."); Log.i("MainMenuActivity", "User accepted request for external storage permissions.");
} }
} }
}
}); });
} }
else else

View File

@ -40,6 +40,8 @@ public final class RetroActivityFuture extends RetroActivityCamera {
// Check for Android UI specific parameters // Check for Android UI specific parameters
Intent retro = getIntent(); Intent retro = getIntent();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
String refresh = retro.getStringExtra("REFRESH"); String refresh = retro.getStringExtra("REFRESH");
// If REFRESH parameter is provided then try to set refreshrate accordingly // If REFRESH parameter is provided then try to set refreshrate accordingly
@ -48,6 +50,7 @@ public final class RetroActivityFuture extends RetroActivityCamera {
params.preferredRefreshRate = Integer.parseInt(refresh); params.preferredRefreshRate = Integer.parseInt(refresh);
getWindow().setAttributes(params); getWindow().setAttributes(params);
} }
}
// If QUITFOCUS parameter is provided then enable that Retroarch quits when focus is lost // If QUITFOCUS parameter is provided then enable that Retroarch quits when focus is lost
quitfocus = retro.hasExtra("QUITFOCUS"); quitfocus = retro.hasExtra("QUITFOCUS");
@ -61,6 +64,7 @@ public final class RetroActivityFuture extends RetroActivityCamera {
public void hideMouseCursor() { public void hideMouseCursor() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
// Check for NVIDIA extensions and minimum SDK version // Check for NVIDIA extensions and minimum SDK version
Method mInputManager_setCursorVisibility; Method mInputManager_setCursorVisibility;
try { mInputManager_setCursorVisibility = try { mInputManager_setCursorVisibility =
@ -76,6 +80,7 @@ public final class RetroActivityFuture extends RetroActivityCamera {
catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) { }
catch (IllegalAccessException iae) { } catch (IllegalAccessException iae) { }
} }
}
@Override @Override
public void onStop() { public void onStop() {