Moves AlertDialogs imports to AndroidX and fix tabs background color

Original commit by rafaeltoledo for Dolphin-emu.
This commit is contained in:
FearlessTobi 2020-03-29 19:05:07 +02:00 committed by bunnei
parent 6a348ad5a3
commit a7e83a5e70
7 changed files with 60 additions and 67 deletions

View File

@ -6,7 +6,8 @@
package org.citra.citra_emu; package org.citra.citra_emu;
import android.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;

View File

@ -1,13 +1,17 @@
package org.citra.citra_emu.activities; package org.citra.citra_emu.activities;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -15,6 +19,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import android.view.InputDevice; import android.view.InputDevice;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -206,7 +211,7 @@ public final class EmulationActivity extends AppCompatActivity {
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString(EXTRA_SELECTED_GAME, mPath); outState.putString(EXTRA_SELECTED_GAME, mPath);
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle); outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -249,10 +254,6 @@ public final class EmulationActivity extends AppCompatActivity {
} }
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
}
private void enableFullscreenImmersive() { private void enableFullscreenImmersive() {
// It would be nice to use IMMERSIVE_STICKY, but that doesn't show the toolbar. // It would be nice to use IMMERSIVE_STICKY, but that doesn't show the toolbar.
mDecorView.setSystemUiVisibility( mDecorView.setSystemUiVisibility(

View File

@ -1,6 +1,8 @@
package org.citra.citra_emu.dialogs; package org.citra.citra_emu.dialogs;
import android.app.AlertDialog; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.view.InputDevice; import android.view.InputDevice;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -16,8 +18,7 @@ import java.util.List;
* {@link AlertDialog} derivative that listens for * {@link AlertDialog} derivative that listens for
* motion events from controllers and joysticks. * motion events from controllers and joysticks.
*/ */
public final class MotionAlertDialog extends AlertDialog public final class MotionAlertDialog extends AlertDialog {
{
// The selected input preference // The selected input preference
private final InputBindingSetting setting; private final InputBindingSetting setting;
private final ArrayList<Float> mPreviousValues = new ArrayList<>(); private final ArrayList<Float> mPreviousValues = new ArrayList<>();
@ -30,18 +31,15 @@ public final class MotionAlertDialog extends AlertDialog
* @param context The current {@link Context}. * @param context The current {@link Context}.
* @param setting The Preference to show this dialog for. * @param setting The Preference to show this dialog for.
*/ */
public MotionAlertDialog(Context context, InputBindingSetting setting) public MotionAlertDialog(Context context, InputBindingSetting setting) {
{
super(context); super(context);
this.setting = setting; this.setting = setting;
} }
public boolean onKeyEvent(int keyCode, KeyEvent event) public boolean onKeyEvent(int keyCode, KeyEvent event) {
{
Log.debug("[MotionAlertDialog] Received key event: " + event.getAction()); Log.debug("[MotionAlertDialog] Received key event: " + event.getAction());
switch (event.getAction()) switch (event.getAction()) {
{
case KeyEvent.ACTION_UP: case KeyEvent.ACTION_UP:
setting.onKeyInput(event); setting.onKeyInput(event);
dismiss(); dismiss();
@ -54,27 +52,23 @@ public final class MotionAlertDialog extends AlertDialog
} }
@Override @Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) public boolean onKeyLongPress(int keyCode, @NonNull KeyEvent event) {
{
return super.onKeyLongPress(keyCode, event); return super.onKeyLongPress(keyCode, event);
} }
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) public boolean dispatchKeyEvent(KeyEvent event) {
{
// Handle this key if we care about it, otherwise pass it down the framework // Handle this key if we care about it, otherwise pass it down the framework
return onKeyEvent(event.getKeyCode(), event) || super.dispatchKeyEvent(event); return onKeyEvent(event.getKeyCode(), event) || super.dispatchKeyEvent(event);
} }
@Override @Override
public boolean dispatchGenericMotionEvent(MotionEvent event) public boolean dispatchGenericMotionEvent(@NonNull MotionEvent event) {
{
// Handle this event if we care about it, otherwise pass it down the framework // Handle this event if we care about it, otherwise pass it down the framework
return onMotionEvent(event) || super.dispatchGenericMotionEvent(event); return onMotionEvent(event) || super.dispatchGenericMotionEvent(event);
} }
private boolean onMotionEvent(MotionEvent event) private boolean onMotionEvent(MotionEvent event) {
{
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
return false; return false;
if (event.getAction() != MotionEvent.ACTION_MOVE) if (event.getAction() != MotionEvent.ACTION_MOVE)
@ -84,8 +78,7 @@ public final class MotionAlertDialog extends AlertDialog
List<InputDevice.MotionRange> motionRanges = input.getMotionRanges(); List<InputDevice.MotionRange> motionRanges = input.getMotionRanges();
if (input.getId() != mPrevDeviceId) if (input.getId() != mPrevDeviceId) {
{
mPreviousValues.clear(); mPreviousValues.clear();
} }
mPrevDeviceId = input.getId(); mPrevDeviceId = input.getId();
@ -95,34 +88,27 @@ public final class MotionAlertDialog extends AlertDialog
float axisMoveValue = 0.0f; float axisMoveValue = 0.0f;
InputDevice.MotionRange lastMovedRange = null; InputDevice.MotionRange lastMovedRange = null;
char lastMovedDir = '?'; char lastMovedDir = '?';
if (mWaitingForEvent) if (mWaitingForEvent) {
{ for (int i = 0; i < motionRanges.size(); i++) {
for (int i = 0; i < motionRanges.size(); i++)
{
InputDevice.MotionRange range = motionRanges.get(i); InputDevice.MotionRange range = motionRanges.get(i);
int axis = range.getAxis(); int axis = range.getAxis();
float origValue = event.getAxisValue(axis); float origValue = event.getAxisValue(axis);
float value = origValue;//ControllerMappingHelper.scaleAxis(input, axis, origValue); float value = origValue;//ControllerMappingHelper.scaleAxis(input, axis, origValue);
if (firstEvent) if (firstEvent) {
{
mPreviousValues.add(value); mPreviousValues.add(value);
} } else {
else
{
float previousValue = mPreviousValues.get(i); float previousValue = mPreviousValues.get(i);
// Only handle the axes that are not neutral (more than 0.5) // Only handle the axes that are not neutral (more than 0.5)
// but ignore any axis that has a constant value (e.g. always 1) // but ignore any axis that has a constant value (e.g. always 1)
if (Math.abs(value) > 0.5f && value != previousValue) if (Math.abs(value) > 0.5f && value != previousValue) {
{
// It is common to have multiple axes with the same physical input. For example, // It is common to have multiple axes with the same physical input. For example,
// shoulder butters are provided as both AXIS_LTRIGGER and AXIS_BRAKE. // shoulder butters are provided as both AXIS_LTRIGGER and AXIS_BRAKE.
// To handle this, we ignore an axis motion that's the exact same as a motion // To handle this, we ignore an axis motion that's the exact same as a motion
// we already saw. This way, we ignore axes with two names, but catch the case // we already saw. This way, we ignore axes with two names, but catch the case
// where a joystick is moved in two directions. // where a joystick is moved in two directions.
// ref: bottom of https://developer.android.com/training/game-controllers/controller-input.html // ref: bottom of https://developer.android.com/training/game-controllers/controller-input.html
if (value != axisMoveValue) if (value != axisMoveValue) {
{
axisMoveValue = value; axisMoveValue = value;
numMovedAxis++; numMovedAxis++;
lastMovedRange = range; lastMovedRange = range;
@ -132,8 +118,7 @@ public final class MotionAlertDialog extends AlertDialog
// Special case for d-pads (axis value jumps between 0 and 1 without any values // Special case for d-pads (axis value jumps between 0 and 1 without any values
// in between). Without this, the user would need to press the d-pad twice // in between). Without this, the user would need to press the d-pad twice
// due to the first press being caught by the "if (firstEvent)" case further up. // due to the first press being caught by the "if (firstEvent)" case further up.
else if (Math.abs(value) < 0.25f && Math.abs(previousValue) > 0.75f) else if (Math.abs(value) < 0.25f && Math.abs(previousValue) > 0.75f) {
{
numMovedAxis++; numMovedAxis++;
lastMovedRange = range; lastMovedRange = range;
lastMovedDir = previousValue < 0.0f ? '-' : '+'; lastMovedDir = previousValue < 0.0f ? '-' : '+';
@ -144,8 +129,7 @@ public final class MotionAlertDialog extends AlertDialog
} }
// If only one axis moved, that's the winner. // If only one axis moved, that's the winner.
if (numMovedAxis == 1) if (numMovedAxis == 1) {
{
mWaitingForEvent = false; mWaitingForEvent = false;
setting.onMotionInput(input, lastMovedRange, lastMovedDir); setting.onMotionInput(input, lastMovedRange, lastMovedDir);
dismiss(); dismiss();

View File

@ -6,9 +6,12 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -56,7 +59,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
} }
@Override @Override
public boolean onSupportNavigateUp(){ public boolean onSupportNavigateUp() {
onBackPressed(); onBackPressed();
return true; return true;
@ -76,7 +79,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
// Critical: If super method is not called, rotations will be busted. // Critical: If super method is not called, rotations will be busted.
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
mPresenter.saveState(outState); mPresenter.saveState(outState);

View File

@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;

View File

@ -1,9 +1,12 @@
package org.citra.citra_emu.utils; package org.citra.citra_emu.utils;
import android.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import android.text.TextUtils; import android.text.TextUtils;
import org.citra.citra_emu.R; import org.citra.citra_emu.R;

View File

@ -5,11 +5,17 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<FrameLayout
android:id="@+id/games_platform_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" > android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_main" android:id="@+id/toolbar_main"
@ -19,10 +25,4 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/games_platform_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>