Android: Prevent getSetting ClassCastExceptions in ItemViews

This commit is contained in:
Ryan Meredith 2020-08-21 11:09:24 -04:00
parent 905df6756b
commit d5ea4b4b80
8 changed files with 24 additions and 25 deletions

View File

@ -16,7 +16,7 @@ public final class CheckBoxSetting extends SettingsItem
public boolean isChecked()
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
{
return mDefaultValue;
}
@ -34,7 +34,7 @@ public final class CheckBoxSetting extends SettingsItem
*/
public BooleanSetting setChecked(boolean checked)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
{
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked);
setSetting(setting);

View File

@ -25,14 +25,13 @@ public final class FilePicker extends SettingsItem
public String getSelectedValue()
{
StringSetting setting = (StringSetting) getSetting();
if (setting == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
return mDefaultValue;
}
else
{
StringSetting setting = (StringSetting) getSetting();
return setting.getValue();
}
}

View File

@ -22,7 +22,7 @@ public class InputBindingSetting extends SettingsItem
public String getValue()
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
return "";
}
@ -78,7 +78,7 @@ public class InputBindingSetting extends SettingsItem
editor.putString(getKey() + gameId, ui);
editor.apply();
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
StringSetting setting = new StringSetting(getKey(), getSection(), bind);
setSetting(setting);

View File

@ -22,7 +22,7 @@ public class RumbleBindingSetting extends InputBindingSetting
@Override
public String getValue()
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
return "";
}

View File

@ -40,14 +40,14 @@ public final class SingleChoiceSetting extends SettingsItem
public int getSelectedValue()
{
if (getSetting() != null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
return mDefaultValue;
}
else
{
return mDefaultValue;
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
}
}
@ -65,7 +65,7 @@ public final class SingleChoiceSetting extends SettingsItem
*/
public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
setSetting(setting);

View File

@ -59,14 +59,14 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
public int getSelectedValue()
{
if (getSetting() != null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
return mDefaultValue;
}
else
{
return mDefaultValue;
IntSetting setting = (IntSetting) getSetting();
return setting.getValue();
}
}
@ -84,7 +84,7 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
*/
public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
setSetting(setting);

View File

@ -75,7 +75,7 @@ public final class SliderSetting extends SettingsItem
*/
public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof IntSetting))
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
setSetting(setting);
@ -98,7 +98,7 @@ public final class SliderSetting extends SettingsItem
*/
public FloatSetting setSelectedValue(float selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof FloatSetting))
{
FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
setSetting(setting);

View File

@ -71,14 +71,14 @@ public class StringSingleChoiceSetting extends SettingsItem
public String getSelectedValue()
{
if (getSetting() != null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
StringSetting setting = (StringSetting) getSetting();
return setting.getValue();
return mDefaultValue;
}
else
{
return mDefaultValue;
StringSetting setting = (StringSetting) getSetting();
return setting.getValue();
}
}
@ -110,7 +110,7 @@ public class StringSingleChoiceSetting extends SettingsItem
*/
public StringSetting setSelectedValue(String selection)
{
if (getSetting() == null)
if (getSetting() == null || !(getSetting() instanceof StringSetting))
{
StringSetting setting = new StringSetting(getKey(), getSection(), selection);
setSetting(setting);