Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Minor cleanup #9042

Merged
merged 2 commits into from Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,7 +30,6 @@ public class AppLinkActivity extends FragmentActivity

private AppLinkHelper.PlayAction playAction;
private DirectoryStateReceiver directoryStateReceiver;
private BroadcastReceiver gameFileCacheReceiver;

@Override
protected void onCreate(Bundle savedInstanceState)
Expand Down Expand Up @@ -96,18 +95,17 @@ else if (directoryInitializationState ==
}
});

gameFileCacheReceiver =
new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if (DirectoryInitialization.areDolphinDirectoriesReady())
{
tryPlay(playAction);
}
}
};
BroadcastReceiver gameFileCacheReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if (DirectoryInitialization.areDolphinDirectoriesReady())
{
tryPlay(playAction);
}
}
};

LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
broadcastManager.registerReceiver(directoryStateReceiver, directoryStateIntentFilter);
Expand Down
Expand Up @@ -67,7 +67,6 @@ public final class EmulationActivity extends AppCompatActivity

private SharedPreferences mPreferences;
private MotionListener mMotionListener;
private ControllerMappingHelper mControllerMappingHelper;

private Settings mSettings;

Expand Down Expand Up @@ -317,7 +316,6 @@ protected void onCreate(Bundle savedInstanceState)
sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE;
mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen");
mMotionListener = new MotionListener(this);
mControllerMappingHelper = new ControllerMappingHelper();

int themeId;
if (mDeviceHasTouchScreen)
Expand Down Expand Up @@ -445,19 +443,17 @@ public void onBackPressed()
protected void onActivityResult(int requestCode, int resultCode, Intent result)
{
super.onActivityResult(requestCode, resultCode, result);
switch (requestCode)
if (requestCode == REQUEST_CHANGE_DISC)
{
case REQUEST_CHANGE_DISC:
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
String newDiscPath = FileBrowserHelper.getSelectedPath(result);
if (!TextUtils.isEmpty(newDiscPath))
{
String newDiscPath = FileBrowserHelper.getSelectedPath(result);
if (!TextUtils.isEmpty(newDiscPath))
{
NativeLibrary.ChangeDisc(newDiscPath);
}
NativeLibrary.ChangeDisc(newDiscPath);
}
break;
}
}
}

Expand Down Expand Up @@ -1041,14 +1037,14 @@ private void chooseOrientation()

private void setIRSensitivity()
{
int ir_pitch = Integer.valueOf(
int ir_pitch = Integer.parseInt(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_PITCH + mSelectedGameId, "15"));

LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_ir_sensitivity, null);

TextView text_slider_value_pitch = (TextView) view.findViewById(R.id.text_ir_pitch);
TextView units = (TextView) view.findViewById(R.id.text_ir_pitch_units);
TextView text_slider_value_pitch = view.findViewById(R.id.text_ir_pitch);
TextView units = view.findViewById(R.id.text_ir_pitch_units);
SeekBar seekbar_pitch = view.findViewById(R.id.seekbar_pitch);

text_slider_value_pitch.setText(String.valueOf(ir_pitch));
Expand All @@ -1074,11 +1070,11 @@ private void setIRSensitivity()
}
});

int ir_yaw = Integer.valueOf(
int ir_yaw = Integer.parseInt(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_YAW + mSelectedGameId, "15"));

TextView text_slider_value_yaw = (TextView) view.findViewById(R.id.text_ir_yaw);
TextView units_yaw = (TextView) view.findViewById(R.id.text_ir_yaw_units);
TextView text_slider_value_yaw = view.findViewById(R.id.text_ir_yaw);
TextView units_yaw = view.findViewById(R.id.text_ir_yaw_units);
SeekBar seekbar_yaw = view.findViewById(R.id.seekbar_width);

text_slider_value_yaw.setText(String.valueOf(ir_yaw));
Expand All @@ -1105,14 +1101,12 @@ private void setIRSensitivity()
});


int ir_vertical_offset = Integer.valueOf(
int ir_vertical_offset = Integer.parseInt(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET + mSelectedGameId,
"10"));

TextView text_slider_value_vertical_offset =
(TextView) view.findViewById(R.id.text_ir_vertical_offset);
TextView units_vertical_offset =
(TextView) view.findViewById(R.id.text_ir_vertical_offset_units);
TextView text_slider_value_vertical_offset = view.findViewById(R.id.text_ir_vertical_offset);
TextView units_vertical_offset = view.findViewById(R.id.text_ir_vertical_offset_units);
SeekBar seekbar_vertical_offset = view.findViewById(R.id.seekbar_vertical_offset);

text_slider_value_vertical_offset.setText(String.valueOf(ir_vertical_offset));
Expand Down Expand Up @@ -1176,9 +1170,7 @@ private void resetOverlay()
new AlertDialog.Builder(this, R.style.DolphinDialogBase)
.setTitle(getString(R.string.emulation_touch_overlay_reset))
.setPositiveButton(R.string.yes, (dialogInterface, i) ->
{
mEmulationFragment.resetInputOverlay();
})
mEmulationFragment.resetInputOverlay())
.setNegativeButton(R.string.cancel, (dialogInterface, i) ->
{
})
Expand Down Expand Up @@ -1210,7 +1202,7 @@ public boolean dispatchGenericMotionEvent(MotionEvent event)
{
int axis = range.getAxis();
float origValue = event.getAxisValue(axis);
float value = mControllerMappingHelper.scaleAxis(input, axis, origValue);
float value = ControllerMappingHelper.scaleAxis(input, axis, origValue);
// If the input is still in the "flat" area, that means it's really zero.
// This is used to compensate for imprecision in joysticks.
if (Math.abs(value) > range.getFlat())
Expand Down
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
Expand All @@ -28,10 +29,11 @@ public class PlatformPagerAdapter extends FragmentPagerAdapter

public PlatformPagerAdapter(FragmentManager fm, Context context)
{
super(fm);
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
mContext = context;
}

@NonNull
@Override
public Fragment getItem(int position)
{
Expand Down
Expand Up @@ -73,7 +73,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
textCountry.setText(country);
textCompany.setText(gameFile.getCompany());
textGameId.setText(gameFile.getGameId());
textRevision.setText(Integer.toString(gameFile.getRevision()));
textRevision.setText(String.valueOf(gameFile.getRevision()));

if (!gameFile.shouldShowFileFormatDetails())
{
Expand Down
Expand Up @@ -44,20 +44,17 @@ public MotionAlertDialog(Context context, InputBindingSetting setting)
public boolean onKeyEvent(int keyCode, KeyEvent event)
{
Log.debug("[MotionAlertDialog] Received key event: " + event.getAction());
switch (event.getAction())
if (event.getAction() == KeyEvent.ACTION_UP)
{
case KeyEvent.ACTION_UP:
if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
{
setting.onKeyInput(event);
dismiss();
}
// Even if we ignore the key, we still consume it. Thus return true regardless.
return true;

default:
return false;
if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
{
setting.onKeyInput(event);
dismiss();
}
// Even if we ignore the key, we still consume it. Thus return true regardless.
return true;
}
return false;
}

@Override
Expand Down
@@ -1,5 +1,7 @@
package org.dolphinemu.dolphinemu.features.settings.ui;

import androidx.annotation.NonNull;

public enum MenuTag
{
CONFIG("config"),
Expand Down Expand Up @@ -46,6 +48,7 @@ public enum MenuTag
this.subType = subtype;
}

@NonNull
@Override
public String toString()
{
Expand Down
Expand Up @@ -143,11 +143,10 @@ public void onStop(boolean finishing)

public boolean handleOptionsItem(int itemId)
{
switch (itemId)
if (itemId == R.id.menu_save_exit)
{
case R.id.menu_save_exit:
mView.finish();
return true;
mView.finish();
return true;
}

return false;
Expand Down
Expand Up @@ -2,8 +2,6 @@

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -45,7 +43,6 @@
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.Log;

import java.security.InvalidParameterException;
import java.util.ArrayList;
Expand Down Expand Up @@ -97,7 +94,7 @@ public SettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType)

case SettingsItem.TYPE_SLIDER:
view = inflater.inflate(R.layout.list_item_setting, parent, false);
return new SliderViewHolder(view, this);
return new SliderViewHolder(view, this, mContext);

case SettingsItem.TYPE_SUBMENU:
view = inflater.inflate(R.layout.list_item_setting_submenu, parent, false);
Expand All @@ -120,8 +117,7 @@ public SettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
return new ConfirmRunnableViewHolder(view, this, mContext, mView);

default:
Log.error("[SettingsAdapter] Invalid view type: " + viewType);
return null;
throw new IllegalArgumentException("Invalid view type: " + viewType);
}
}

Expand Down Expand Up @@ -243,13 +239,13 @@ public void onSliderClick(SliderSetting item, int position)
builder.setPositiveButton(R.string.ok, this);
mDialog = builder.show();

mTextSliderValue = (TextView) view.findViewById(R.id.text_value);
mTextSliderValue = view.findViewById(R.id.text_value);
mTextSliderValue.setText(String.valueOf(mSeekbarProgress));

TextView units = (TextView) view.findViewById(R.id.text_units);
TextView units = view.findViewById(R.id.text_units);
units.setText(item.getUnits());

SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekbar);
SeekBar seekbar = view.findViewById(R.id.seekbar);

seekbar.setMax(item.getMax());
seekbar.setProgress(mSeekbarProgress);
Expand All @@ -273,21 +269,13 @@ public void onInputBindingClick(final InputBindingSetting item, final int positi
mContext.getString(item.getNameId())));
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, mContext.getString(R.string.cancel), this);
dialog.setButton(AlertDialog.BUTTON_NEUTRAL, mContext.getString(R.string.clear),
(dialogInterface, i) ->
{
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(mContext);
item.clearValue();
});
(dialogInterface, i) -> item.clearValue());
dialog.setOnDismissListener(dialog1 ->
{
StringSetting setting = new StringSetting(item.getKey(), item.getSection(), item.getValue());
notifyItemChanged(position);

if (setting != null)
{
mView.putSetting(setting);
}
mView.putSetting(setting);

mView.onSettingChanged(item.getKey());
});
Expand Down
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand Down Expand Up @@ -84,7 +85,7 @@ public static Fragment newInstance(MenuTag menuTag, String gameId, Bundle extras
}

@Override
public void onAttach(Context context)
public void onAttach(@NonNull Context context)
{
super.onAttach(context);

Expand Down Expand Up @@ -115,7 +116,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
{
Bundle args = getArguments();
MenuTag menuTag = (MenuTag) args.getSerializable(ARGUMENT_MENU_TAG);
Expand Down
Expand Up @@ -59,8 +59,8 @@ public SettingsFragmentPresenter(SettingsFragmentView view)
public void onCreate(MenuTag menuTag, String gameId, Bundle extras)
{
mGameID = gameId;

this.mMenuTag = menuTag;

if (menuTag.isGCPadMenu() || menuTag.isWiimoteExtensionMenu())
{
mControllerNumber = menuTag.getSubType();
Expand All @@ -70,10 +70,6 @@ else if (menuTag.isWiimoteMenu())
{
mControllerNumber = menuTag.getSubType();
}
else
{
mMenuTag = menuTag;
}
}

public void onViewCreated(MenuTag menuTag, Settings settings)
Expand Down
Expand Up @@ -9,8 +9,6 @@
*/
public final class SettingsFrameLayout extends FrameLayout
{
private float mVisibleness = 1.0f;

public SettingsFrameLayout(Context context)
{
super(context);
Expand Down Expand Up @@ -44,7 +42,7 @@ public void setYFraction(float yFraction)

public float getVisibleness()
{
return mVisibleness;
return 1.0f;
}

public void setVisibleness(float visibleness)
Expand Down
Expand Up @@ -28,9 +28,9 @@ public CheckBoxSettingViewHolder(View itemView, SettingsAdapter adapter)
@Override
protected void findViews(View root)
{
mTextSettingName = (TextView) root.findViewById(R.id.text_setting_name);
mTextSettingDescription = (TextView) root.findViewById(R.id.text_setting_description);
mCheckbox = (CheckBox) root.findViewById(R.id.checkbox);
mTextSettingName = root.findViewById(R.id.text_setting_name);
mTextSettingDescription = root.findViewById(R.id.text_setting_description);
mCheckbox = root.findViewById(R.id.checkbox);
}

@Override
Expand Down