mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #6107 from hackbar/cleanup
Android UI: lots of cleanups, mainly around how Fragments are handled
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '25.0.2'
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion '26.0.2'
|
||||
|
||||
lintOptions {
|
||||
// This is important as it will run lint but not abort on error
|
||||
@@ -71,7 +71,7 @@ android {
|
||||
}
|
||||
|
||||
ext {
|
||||
androidSupportVersion = '25.3.0'
|
||||
androidSupportVersion = '26.1.0'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -12,13 +12,15 @@ import android.widget.Toast;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Class which contains methods that interact
|
||||
* with the native side of the Dolphin code.
|
||||
*/
|
||||
public final class NativeLibrary
|
||||
{
|
||||
public static EmulationActivity sEmulationActivity;
|
||||
public static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
|
||||
|
||||
/**
|
||||
* Button type for use in onTouchEvent
|
||||
@@ -379,25 +381,34 @@ public final class NativeLibrary
|
||||
public static void displayAlertMsg(final String alert)
|
||||
{
|
||||
Log.error("[NativeLibrary] Alert: " + alert);
|
||||
sEmulationActivity.runOnUiThread(new Runnable()
|
||||
final EmulationActivity emulationActivity = sEmulationActivity.get();
|
||||
if (emulationActivity != null)
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
emulationActivity.runOnUiThread(new Runnable()
|
||||
{
|
||||
Toast.makeText(sEmulationActivity, "Panic Alert: " + alert, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void endEmulationActivity()
|
||||
{
|
||||
Log.verbose("[NativeLibrary]Ending EmulationActivity.");
|
||||
sEmulationActivity.exitWithAnimation();
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Toast.makeText(emulationActivity, "Panic Alert: " + alert, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.warning("[NativeLibrary] EmulationActivity is null, can't do panic toast.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setEmulationActivity(EmulationActivity emulationActivity)
|
||||
{
|
||||
Log.verbose("[NativeLibrary]Registering EmulationActivity.");
|
||||
sEmulationActivity = emulationActivity;
|
||||
Log.verbose("[NativeLibrary] Registering EmulationActivity.");
|
||||
sEmulationActivity = new WeakReference<>(emulationActivity);
|
||||
}
|
||||
|
||||
public static void clearEmulationActivity()
|
||||
{
|
||||
Log.verbose("[NativeLibrary] Unregistering EmulationActivity.");
|
||||
|
||||
sEmulationActivity.clear();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
package org.dolphinemu.dolphinemu.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.AsyncQueryHandler;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -133,7 +133,7 @@ public class AddDirectoryActivity extends AppCompatActivity implements FileAdapt
|
||||
mToolbar.setSubtitle(path);
|
||||
}
|
||||
|
||||
public static void launch(Activity activity)
|
||||
public static void launch(FragmentActivity activity)
|
||||
{
|
||||
Intent fileChooser = new Intent(activity, AddDirectoryActivity.class);
|
||||
activity.startActivityForResult(fileChooser, MainPresenter.REQUEST_ADD_DIRECTORY);
|
||||
|
||||
+90
-195
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -1,9 +1,9 @@
|
||||
package org.dolphinemu.dolphinemu.adapters;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.database.Cursor;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -202,7 +202,7 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
{
|
||||
GameViewHolder holder = (GameViewHolder) view.getTag();
|
||||
|
||||
EmulationActivity.launch((Activity) view.getContext(),
|
||||
EmulationActivity.launch((FragmentActivity) view.getContext(),
|
||||
holder.path,
|
||||
holder.title,
|
||||
holder.screenshotPath,
|
||||
@@ -225,13 +225,13 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
// TODO This should be all we need to pass in, eventually.
|
||||
// String gameId = (String) holder.gameId;
|
||||
|
||||
Activity activity = (Activity) view.getContext();
|
||||
FragmentActivity activity = (FragmentActivity) view.getContext();
|
||||
GameDetailsDialog.newInstance(holder.title,
|
||||
holder.description,
|
||||
holder.country,
|
||||
holder.company,
|
||||
holder.path,
|
||||
holder.screenshotPath).show(activity.getFragmentManager(), "game_details");
|
||||
holder.screenshotPath).show(activity.getSupportFragmentManager(), "game_details");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package org.dolphinemu.dolphinemu.adapters;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v13.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ImageSpan;
|
||||
|
||||
+1
-1
@@ -2,9 +2,9 @@ package org.dolphinemu.dolphinemu.dialogs;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
+127
-80
@@ -1,9 +1,10 @@
|
||||
package org.dolphinemu.dolphinemu.fragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
@@ -14,15 +15,12 @@ import android.widget.Button;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.overlay.InputOverlay;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
public final class EmulationFragment extends Fragment implements SurfaceHolder.Callback
|
||||
{
|
||||
public static final String FRAGMENT_TAG = "emulation_fragment";
|
||||
|
||||
private static final String ARG_GAME_PATH = "game_path";
|
||||
|
||||
private SharedPreferences mPreferences;
|
||||
|
||||
private Surface mSurface;
|
||||
@@ -31,18 +29,22 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
|
||||
private Thread mEmulationThread;
|
||||
|
||||
private boolean mEmulationStarted;
|
||||
private boolean mEmulationRunning;
|
||||
private String mGamePath;
|
||||
private final EmulationState mEmulationState = new EmulationState();
|
||||
|
||||
public static EmulationFragment newInstance(String path)
|
||||
@Override
|
||||
public void onAttach(Context context)
|
||||
{
|
||||
EmulationFragment fragment = new EmulationFragment();
|
||||
super.onAttach(context);
|
||||
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putString(ARG_GAME_PATH, path);
|
||||
fragment.setArguments(arguments);
|
||||
|
||||
return fragment;
|
||||
if (context instanceof EmulationActivity)
|
||||
{
|
||||
NativeLibrary.setEmulationActivity((EmulationActivity) context);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("EmulationFragment must have EmulationActivity parent");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,38 +69,20 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
{
|
||||
View contents = inflater.inflate(R.layout.fragment_emulation, container, false);
|
||||
|
||||
SurfaceView surfaceView = (SurfaceView) contents.findViewById(R.id.surface_emulation);
|
||||
mInputOverlay = (InputOverlay) contents.findViewById(R.id.surface_input_overlay);
|
||||
|
||||
SurfaceView surfaceView = contents.findViewById(R.id.surface_emulation);
|
||||
surfaceView.getHolder().addCallback(this);
|
||||
|
||||
// If the input overlay was previously disabled, then don't show it.
|
||||
mInputOverlay = contents.findViewById(R.id.surface_input_overlay);
|
||||
if (mInputOverlay != null)
|
||||
{
|
||||
// If the input overlay was previously disabled, then don't show it.
|
||||
if (!mPreferences.getBoolean("showInputOverlay", true))
|
||||
{
|
||||
mInputOverlay.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState == null)
|
||||
{
|
||||
mEmulationThread = new Thread(mEmulationRunner);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Likely a rotation occurred.
|
||||
// TODO Pass native code the Surface, which will have been recreated, from surfaceChanged()
|
||||
// TODO Also, write the native code that will get the video backend to accept the new Surface as one of its own.
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState)
|
||||
{
|
||||
Button doneButton = (Button) view.findViewById(R.id.done_control_config);
|
||||
Button doneButton = contents.findViewById(R.id.done_control_config);
|
||||
if (doneButton != null)
|
||||
{
|
||||
doneButton.setOnClickListener(new View.OnClickListener()
|
||||
@@ -110,29 +94,29 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
startEmulation();
|
||||
// The new Surface created here will get passed to the native code via onSurfaceChanged.
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
pauseEmulation();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
public void onDetach()
|
||||
{
|
||||
super.onDestroyView();
|
||||
if (getActivity().isFinishing() && mEmulationStarted)
|
||||
{
|
||||
NativeLibrary.StopEmulation();
|
||||
}
|
||||
NativeLibrary.clearEmulationActivity();
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
public void setGamePath(String gamePath)
|
||||
{
|
||||
mGamePath = gamePath;
|
||||
}
|
||||
|
||||
public void toggleInputOverlayVisibility()
|
||||
@@ -171,6 +155,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
|
||||
{
|
||||
Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height);
|
||||
|
||||
if (mEmulationState.isPaused())
|
||||
{
|
||||
NativeLibrary.UnPauseEmulation();
|
||||
}
|
||||
|
||||
mSurface = holder.getSurface();
|
||||
NativeLibrary.SurfaceChanged(mSurface);
|
||||
}
|
||||
@@ -181,45 +171,57 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
Log.debug("[EmulationFragment] Surface destroyed.");
|
||||
NativeLibrary.SurfaceDestroyed();
|
||||
|
||||
if (mEmulationRunning)
|
||||
if (mEmulationState.isRunning())
|
||||
{
|
||||
pauseEmulation();
|
||||
}
|
||||
}
|
||||
|
||||
private void startEmulation()
|
||||
public void startEmulation()
|
||||
{
|
||||
if (!mEmulationStarted)
|
||||
synchronized (mEmulationState)
|
||||
{
|
||||
Log.debug("[EmulationFragment] Starting emulation thread.");
|
||||
if (mEmulationState.isStopped())
|
||||
{
|
||||
Log.debug("[EmulationFragment] Starting emulation thread.");
|
||||
|
||||
mEmulationThread.start();
|
||||
mEmulationThread = new Thread(mEmulationRunner, "NativeEmulation");
|
||||
mEmulationThread.start();
|
||||
// The thread will call mEmulationState.run()
|
||||
}
|
||||
else if (mEmulationState.isPaused())
|
||||
{
|
||||
Log.debug("[EmulationFragment] Resuming emulation.");
|
||||
NativeLibrary.UnPauseEmulation();
|
||||
mEmulationState.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.debug("[EmulationFragment] Bug, startEmulation called while running.");
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
public void stopEmulation() {
|
||||
synchronized (mEmulationState)
|
||||
{
|
||||
Log.debug("[EmulationFragment] Resuming emulation.");
|
||||
NativeLibrary.UnPauseEmulation();
|
||||
if (!mEmulationState.isStopped())
|
||||
{
|
||||
NativeLibrary.StopEmulation();
|
||||
mEmulationState.stop();
|
||||
}
|
||||
}
|
||||
|
||||
mEmulationRunning = true;
|
||||
}
|
||||
|
||||
private void pauseEmulation()
|
||||
{
|
||||
Log.debug("[EmulationFragment] Pausing emulation.");
|
||||
synchronized (mEmulationState)
|
||||
{
|
||||
Log.debug("[EmulationFragment] Pausing emulation.");
|
||||
|
||||
NativeLibrary.PauseEmulation();
|
||||
mEmulationRunning = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by containing activity to tell the Fragment emulation is already stopping,
|
||||
* so it doesn't try to stop emulation on its way to the garbage collector.
|
||||
*/
|
||||
public void notifyEmulationStopped()
|
||||
{
|
||||
mEmulationStarted = false;
|
||||
mEmulationRunning = false;
|
||||
NativeLibrary.PauseEmulation();
|
||||
mEmulationState.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable mEmulationRunner = new Runnable()
|
||||
@@ -227,18 +229,17 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mEmulationRunning = true;
|
||||
mEmulationStarted = true;
|
||||
// Busy-wait for surface to be set
|
||||
while (mSurface == null) {}
|
||||
|
||||
while (mSurface == null)
|
||||
if (!mEmulationRunning)
|
||||
return;
|
||||
|
||||
Log.info("[EmulationFragment] Starting emulation: " + mSurface);
|
||||
synchronized (mEmulationState)
|
||||
{
|
||||
Log.info("[EmulationFragment] Starting emulation: " + mSurface);
|
||||
|
||||
mEmulationState.run();
|
||||
}
|
||||
// Start emulation using the provided Surface.
|
||||
String path = getArguments().getString(ARG_GAME_PATH);
|
||||
NativeLibrary.Run(path);
|
||||
NativeLibrary.Run(mGamePath);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -258,4 +259,50 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
{
|
||||
return mInputOverlay.isInEditMode();
|
||||
}
|
||||
|
||||
private static class EmulationState
|
||||
{
|
||||
private enum State
|
||||
{
|
||||
STOPPED, RUNNING, PAUSED
|
||||
}
|
||||
|
||||
private State state;
|
||||
|
||||
EmulationState()
|
||||
{
|
||||
// Starting state is stopped.
|
||||
state = State.STOPPED;
|
||||
}
|
||||
|
||||
public boolean isStopped()
|
||||
{
|
||||
return state == State.STOPPED;
|
||||
}
|
||||
|
||||
public boolean isRunning()
|
||||
{
|
||||
return state == State.RUNNING;
|
||||
}
|
||||
|
||||
public boolean isPaused()
|
||||
{
|
||||
return state == State.PAUSED;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
state = State.RUNNING;
|
||||
}
|
||||
|
||||
public void pause()
|
||||
{
|
||||
state = State.PAUSED;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
state = State.STOPPED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-8
@@ -1,8 +1,8 @@
|
||||
package org.dolphinemu.dolphinemu.fragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -16,7 +16,7 @@ import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
|
||||
public final class MenuFragment extends Fragment implements View.OnClickListener
|
||||
{
|
||||
private TextView mTitleText;
|
||||
private static final String KEY_TITLE = "title";
|
||||
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
||||
static {
|
||||
buttonsActionsMap.append(R.id.menu_take_screenshot, EmulationActivity.MENU_ACTION_TAKE_SCREENSHOT);
|
||||
@@ -28,6 +28,17 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
||||
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
|
||||
}
|
||||
|
||||
public static MenuFragment newInstance(String title)
|
||||
{
|
||||
MenuFragment fragment = new MenuFragment();
|
||||
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putSerializable(KEY_TITLE, title);
|
||||
fragment.setArguments(arguments);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
@@ -42,7 +53,12 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
||||
button.setOnClickListener(this);
|
||||
}
|
||||
|
||||
mTitleText = (TextView) rootView.findViewById(R.id.text_game_title);
|
||||
TextView titleText = rootView.findViewById(R.id.text_game_title);
|
||||
String title = getArguments().getString(KEY_TITLE);
|
||||
if (title != null)
|
||||
{
|
||||
titleText.setText(title);
|
||||
}
|
||||
|
||||
return rootView;
|
||||
}
|
||||
@@ -57,9 +73,4 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
||||
((EmulationActivity) getActivity()).handleMenuAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitleText(String title)
|
||||
{
|
||||
mTitleText.setText(title);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
package org.dolphinemu.dolphinemu.fragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright 2013 Dolphin Emulator Project
|
||||
* Licensed under GPLv2+
|
||||
* Refer to the license.txt file included.
|
||||
*/
|
||||
|
||||
package org.dolphinemu.dolphinemu.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Work around a bug with the nVidia Shield.
|
||||
*/
|
||||
public final class NVidiaShieldWorkaroundView extends View
|
||||
{
|
||||
public NVidiaShieldWorkaroundView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
|
||||
// Setting this seems to workaround the bug
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -70,7 +70,8 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
|
||||
if (PermissionsHandler.hasWriteAccess(this))
|
||||
{
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(getFragmentManager(), this);
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
} else {
|
||||
mViewPager.setVisibility(View.INVISIBLE);
|
||||
@@ -162,7 +163,8 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
StartupHandler.copyAssetsIfNeeded(this);
|
||||
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(getFragmentManager(), this);
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
mViewPager.setVisibility(View.VISIBLE);
|
||||
@@ -205,6 +207,6 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
{
|
||||
String fragmentTag = "android:switcher:" + mViewPager.getId() + ":" + platform;
|
||||
|
||||
return (PlatformGamesView) getFragmentManager().findFragmentByTag(fragmentTag);
|
||||
return (PlatformGamesView) getSupportFragmentManager().findFragmentByTag(fragmentTag);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,12 +1,11 @@
|
||||
package org.dolphinemu.dolphinemu.ui.main;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.app.BrowseFragment;
|
||||
import android.support.v17.leanback.app.BrowseSupportFragment;
|
||||
import android.support.v17.leanback.database.CursorMapper;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.CursorObjectAdapter;
|
||||
@@ -17,6 +16,8 @@ import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -33,11 +34,11 @@ import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
|
||||
import org.dolphinemu.dolphinemu.utils.StartupHandler;
|
||||
import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;
|
||||
|
||||
public final class TvMainActivity extends Activity implements MainView
|
||||
public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
{
|
||||
private MainPresenter mPresenter = new MainPresenter(this);
|
||||
|
||||
private BrowseFragment mBrowseFragment;
|
||||
private BrowseSupportFragment mBrowseFragment;
|
||||
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
|
||||
@@ -57,8 +58,8 @@ public final class TvMainActivity extends Activity implements MainView
|
||||
}
|
||||
|
||||
void setupUI() {
|
||||
final FragmentManager fragmentManager = getFragmentManager();
|
||||
mBrowseFragment = new BrowseFragment();
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
mBrowseFragment = new BrowseSupportFragment();
|
||||
fragmentManager
|
||||
.beginTransaction()
|
||||
.add(R.id.content, mBrowseFragment, "BrowseFragment")
|
||||
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
package org.dolphinemu.dolphinemu.ui.platform;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package org.dolphinemu.dolphinemu.ui.settings;
|
||||
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -88,7 +88,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
||||
@Override
|
||||
public void showSettingsFragment(String menuTag, boolean addToStack)
|
||||
{
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
if (addToStack)
|
||||
{
|
||||
@@ -149,7 +149,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
||||
@Override
|
||||
public void popBackStack()
|
||||
{
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
getSupportFragmentManager().popBackStackImmediate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,6 +178,6 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
||||
|
||||
private SettingsFragment getFragment()
|
||||
{
|
||||
return (SettingsFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
|
||||
return (SettingsFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
package org.dolphinemu.dolphinemu.ui.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.ui.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.settings.Setting;
|
||||
import org.dolphinemu.dolphinemu.model.settings.SettingSection;
|
||||
@@ -48,7 +48,7 @@ public interface SettingsFragmentView
|
||||
/**
|
||||
* @return The Fragment's containing activity.
|
||||
*/
|
||||
Activity getActivity();
|
||||
FragmentActivity getActivity();
|
||||
|
||||
/**
|
||||
* Tell the Fragment to tell the containing Activity to show a new
|
||||
|
||||
@@ -2,55 +2,13 @@ package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
public final class Animations
|
||||
{
|
||||
private static final Interpolator DECELERATOR = new DecelerateInterpolator();
|
||||
private static final Interpolator ACCELERATOR = new AccelerateInterpolator();
|
||||
|
||||
private Animations()
|
||||
{
|
||||
}
|
||||
|
||||
public static ViewPropertyAnimator fadeViewOutToRight(View view)
|
||||
{
|
||||
return view.animate()
|
||||
.withLayer()
|
||||
.setDuration(200)
|
||||
.setInterpolator(ACCELERATOR)
|
||||
.alpha(0.0f)
|
||||
.translationX(view.getWidth());
|
||||
}
|
||||
|
||||
public static ViewPropertyAnimator fadeViewOutToLeft(View view)
|
||||
{
|
||||
return view.animate()
|
||||
.withLayer()
|
||||
.setDuration(200)
|
||||
.setInterpolator(ACCELERATOR)
|
||||
.alpha(0.0f)
|
||||
.translationX(-view.getWidth());
|
||||
}
|
||||
|
||||
public static ViewPropertyAnimator fadeViewInFromLeft(View view)
|
||||
{
|
||||
|
||||
view.setVisibility(View.VISIBLE);
|
||||
|
||||
view.setTranslationX(-view.getWidth());
|
||||
view.setAlpha(0.0f);
|
||||
|
||||
return view.animate()
|
||||
.withLayer()
|
||||
.setDuration(300)
|
||||
.setInterpolator(DECELERATOR)
|
||||
.alpha(1.0f)
|
||||
.translationX(0.0f);
|
||||
}
|
||||
|
||||
public static ViewPropertyAnimator fadeViewIn(View view)
|
||||
{
|
||||
view.setVisibility(View.VISIBLE);
|
||||
|
||||
+35
-17
@@ -1,6 +1,8 @@
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbConfiguration;
|
||||
import android.hardware.usb.UsbConstants;
|
||||
@@ -15,7 +17,6 @@ import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.services.USBPermService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class Java_GCAdapter {
|
||||
@@ -29,22 +30,31 @@ public class Java_GCAdapter {
|
||||
|
||||
private static void RequestPermission()
|
||||
{
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||
Context context = NativeLibrary.sEmulationActivity.get();
|
||||
if (context != null)
|
||||
{
|
||||
UsbDevice dev = pair.getValue();
|
||||
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||
{
|
||||
if (!manager.hasPermission(dev))
|
||||
UsbDevice dev = pair.getValue();
|
||||
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
PendingIntent pend_intent;
|
||||
intent.setClass(NativeLibrary.sEmulationActivity, USBPermService.class);
|
||||
pend_intent = PendingIntent.getService(NativeLibrary.sEmulationActivity, 0, intent, 0);
|
||||
manager.requestPermission(dev, pend_intent);
|
||||
if (!manager.hasPermission(dev))
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
PendingIntent pend_intent;
|
||||
intent.setClass(context, USBPermService.class);
|
||||
pend_intent = PendingIntent.getService(context, 0, intent, 0);
|
||||
manager.requestPermission(dev, pend_intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.warning("Cannot request GameCube Adapter permission as EmulationActivity is null.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void Shutdown()
|
||||
@@ -124,14 +134,22 @@ public class Java_GCAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
NativeLibrary.sEmulationActivity.runOnUiThread(new Runnable()
|
||||
final Activity emulationActivity = NativeLibrary.sEmulationActivity.get();
|
||||
if (emulationActivity != null)
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
emulationActivity.runOnUiThread(new Runnable()
|
||||
{
|
||||
Toast.makeText(NativeLibrary.sEmulationActivity, "GameCube Adapter couldn't be opened. Please re-plug the device.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Toast.makeText(emulationActivity, "GameCube Adapter couldn't be opened. Please re-plug the device.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.warning("Cannot show toast for GameCube Adapter failure.");
|
||||
}
|
||||
usb_con.close();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-11
@@ -1,6 +1,7 @@
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbConfiguration;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
@@ -33,23 +34,31 @@ public class Java_WiimoteAdapter
|
||||
|
||||
private static void RequestPermission()
|
||||
{
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||
Context context = NativeLibrary.sEmulationActivity.get();
|
||||
if (context != null)
|
||||
{
|
||||
UsbDevice dev = pair.getValue();
|
||||
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||
{
|
||||
if (!manager.hasPermission(dev))
|
||||
UsbDevice dev = pair.getValue();
|
||||
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
||||
{
|
||||
Log.warning("Requesting permission for Wii Remote adapter");
|
||||
Intent intent = new Intent();
|
||||
PendingIntent pend_intent;
|
||||
intent.setClass(NativeLibrary.sEmulationActivity, USBPermService.class);
|
||||
pend_intent = PendingIntent.getService(NativeLibrary.sEmulationActivity, 0, intent, 0);
|
||||
manager.requestPermission(dev, pend_intent);
|
||||
if (!manager.hasPermission(dev))
|
||||
{
|
||||
Log.warning("Requesting permission for Wii Remote adapter");
|
||||
Intent intent = new Intent();
|
||||
PendingIntent pend_intent;
|
||||
intent.setClass(context, USBPermService.class);
|
||||
pend_intent = PendingIntent.getService(context, 0, intent, 0);
|
||||
manager.requestPermission(dev, pend_intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.warning("Cannot request Wiimote adapter permission as EmulationActivity is null.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean QueryAdapter()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user