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: Implement amiibo option #51

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/jni_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ AlberFunction(jboolean, LoadRom)(JNIEnv* env, jobject obj, jstring path) {
return romLoaded;
}

AlberFunction(void, LoadAmiibo)(JNIEnv* env, jobject obj, jstring path) {
const char* pathStr = env->GetStringUTFChars(path, nullptr);
emulator->loadAmiibo(pathStr);
env->ReleaseStringUTFChars(path, pathStr);
}

AlberFunction(void, LoadLuaScript)(JNIEnv* env, jobject obj, jstring script) {
const char* scriptStr = env->GetStringUTFChars(script, nullptr);
emulator->getLua().loadString(scriptStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class AlberDriver {
public static native void Pause();
public static native void Resume();
public static native void LoadLuaScript(String script);
public static native void LoadAmiibo(String path);
public static native byte[] GetSmdh();

public static native void setShaderJitEnabled(boolean enable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
import androidx.appcompat.widget.AppCompatTextView;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import android.content.pm.ActivityInfo;
import android.content.Intent;
import android.net.Uri;

import com.google.android.material.navigation.NavigationView;
import com.panda3ds.pandroid.AlberDriver;
Expand All @@ -24,6 +29,8 @@
import com.panda3ds.pandroid.view.gamesgrid.GameIconView;

public class DrawerFragment extends Fragment implements DrawerLayout.DrawerListener, NavigationView.OnNavigationItemSelectedListener {
private final ActivityResultContracts.OpenDocument openAmiiboFile = new ActivityResultContracts.OpenDocument();
private ActivityResultLauncher<String[]> pickFileRequest;
private DrawerLayout drawerContainer;
private View drawerLayout;
private EmulatorCallback emulator;
Expand All @@ -48,6 +55,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
drawerContainer.setVisibility(View.GONE);
drawerLayout = view.findViewById(R.id.drawer_layout);

pickFileRequest = registerForActivityResult(
openAmiiboFile,
this::amiiboResult
);

((NavigationView)view.findViewById(R.id.menu)).setNavigationItemSelectedListener(this);
refresh();
}
Expand All @@ -65,6 +77,11 @@ private void refresh() {

@Override
public void onDetach() {
if (pickFileRequest != null) {
pickFileRequest.unregister();
pickFileRequest = null;
}

if (drawerContainer != null) {
drawerContainer.removeDrawerListener(this);
}
Expand Down Expand Up @@ -126,6 +143,8 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
} else if (id == R.id.change_orientation) {
boolean isLandscape = getResources().getDisplayMetrics().widthPixels > getResources().getDisplayMetrics().heightPixels;
requireActivity().setRequestedOrientation(isLandscape ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else if (id == R.id.load_amiibo) {
pickFileRequest.launch(new String[] {"*/*"});
}

return false;
Expand All @@ -134,4 +153,10 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
public boolean isOpened() {
return drawerContainer.isOpen();
}

private void amiiboResult(Uri path) {
if (path != null) {
AlberDriver.LoadAmiibo(path.toString());
}
}
}
10 changes: 10 additions & 0 deletions src/pandroid/app/src/main/res/drawable/ic_amiibo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M280,680L440,680L440,520L280,520L280,680ZM520,680L680,680L680,520L520,520L520,680ZM280,440L440,440L440,280L280,280L280,440ZM520,440L680,440L680,280L520,280L520,440ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840Z"/>
</vector>
4 changes: 4 additions & 0 deletions src/pandroid/app/src/main/res/menu/game_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
android:id="@+id/lua_script"
android:icon="@drawable/ic_code"
android:title="@string/lua_script" />
<item
android:id="@+id/load_amiibo"
android:icon="@drawable/ic_amiibo"
android:title="@string/load_amiibo" />
</menu>
</item>
</menu>
1 change: 1 addition & 0 deletions src/pandroid/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<string name="resume">Resume</string>
<string name="hacks">Hacks</string>
<string name="lua_script">Lua script</string>
<string name="load_amiibo">Amiibo</string>
<string name="scripts">Scripts</string>
<string name="file_not_supported">File type isn\'t supported</string>
<string name="save_and_exit">Save and exit</string>
Expand Down
Loading