Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuoya committed Oct 16, 2019
1 parent b99aee9 commit 0542855
Show file tree
Hide file tree
Showing 88 changed files with 3,256 additions and 1,116 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,12 @@ git_describe(GIT_DESC --always --long --dirty)
git_branch_name(GIT_BRANCH)
get_timestamp(BUILD_DATE)

enable_testing()
if(NOT ANDROID)
enable_testing()
add_subdirectory(dist/installer)
endif()
add_subdirectory(externals)
add_subdirectory(src)
add_subdirectory(dist/installer)


# Set citra-qt project or citra project as default StartUp Project in Visual Studio depending on whether QT is enabled or not
Expand Down
10 changes: 9 additions & 1 deletion src/android/app/src/main/java/org/citra/emu/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void showInputBoxDialog(int maxLength, String hint, String button0
public static void showMiiSelectorDialog(boolean cancel, String title, String[] miis) {
EmulationActivity activity = EmulationActivity.get();
if (activity != null) {
activity.showMiiSelectorDialog(cancel, title, miis);
activity.runOnUiThread(() -> activity.showMiiSelectorDialog(cancel, title, miis));
}
}

Expand All @@ -84,6 +84,12 @@ public static void updateProgress(String name, int written, int total) {
}
}

public static boolean isValidFile(String filename) {
String name = filename.toLowerCase();
return (name.endsWith(".cia") || name.endsWith(".cci") || name.endsWith(".3ds") ||
name.endsWith(".cxi"));
}

public static native String GetAppId(String path);

public static native String GetAppTitle(String path);
Expand All @@ -92,6 +98,8 @@ public static void updateProgress(String name, int written, int total) {

public static native int GetAppRegion(String path);

public static native boolean IsAppExecutable(String path);

public static native void SaveScreenShot();

public static native void InstallCIA(String[] path);
Expand Down
24 changes: 24 additions & 0 deletions src/android/app/src/main/java/org/citra/emu/model/GameFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;

import java.nio.IntBuffer;
import org.citra.emu.NativeLibrary;
import org.citra.emu.R;
Expand Down Expand Up @@ -53,6 +62,21 @@ public Bitmap getIcon(Context context) {
mIcon = Bitmap.createBitmap(48, 48, Bitmap.Config.RGB_565);
mIcon.copyPixelsFromBuffer(IntBuffer.wrap(pixels));
}

// rounded corners
float radius = 5.0f;
Rect rect = new Rect(0, 0, mIcon.getWidth(), mIcon.getHeight());
Bitmap output = Bitmap.createBitmap(mIcon.getWidth(), mIcon.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
BitmapShader shader = new BitmapShader(mIcon, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
// rect contains the bounds of the shape
// radius is the radius in pixels of the rounded corners
// paint contains the shader that will texture the shape
canvas.drawRoundRect(new RectF(rect), radius, radius, paint);
mIcon = output;
}
return mIcon;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// Go back to immersive fullscreen mode in 3s
Handler handler = new Handler(getMainLooper());
handler.postDelayed(this ::enableFullscreenImmersive, 3000 /* 3s */);
handler.postDelayed(this::enableFullscreenImmersive, 3000 /* 3s */);
}
});
mStopEmulation = false;
Expand Down Expand Up @@ -213,7 +213,8 @@ public void showInputBoxDialog(int maxLength, String hint, String button0, Strin
}

public void showMiiSelectorDialog(boolean cancel, String title, String[] miis) {
// todo
MiiSelectorDialog.newInstance(cancel, title, miis)
.show(getSupportFragmentManager(), "MiiSelectorDialog");
}

public void refreshControls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.nononsenseapps.filepicker.FilePickerActivity;
import com.nononsenseapps.filepicker.FilePickerFragment;
import java.io.File;
import org.citra.emu.NativeLibrary;

public final class GameFilePickerActivity extends FilePickerActivity {
@Override
Expand Down Expand Up @@ -41,8 +42,7 @@ protected boolean isItemVisible(final File file) {
return false;
if (file.isDirectory())
return true;
String filename = file.getName().toLowerCase();
return filename.endsWith(".cci") || filename.endsWith(".cia");
return NativeLibrary.isValidFile(file.getName());
}
}
}
13 changes: 7 additions & 6 deletions src/android/app/src/main/java/org/citra/emu/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
Expand Down Expand Up @@ -223,7 +221,7 @@ public void refreshLibrary() {

public void addGamesInDirectory(String directory) {
File[] files = new File(directory).listFiles((File dir, String name) -> {
if (name.toLowerCase().endsWith(".cci")) {
if (NativeLibrary.isValidFile(name)) {
String path = dir.getPath() + File.separator + name;
for (GameFile game : mGames) {
if (path.equals(game.getPath())) {
Expand All @@ -240,7 +238,9 @@ public void addGamesInDirectory(String directory) {
}

for (File f : files) {
mGames.add(new GameFile(f.getPath()));
String path = f.getPath();
if (NativeLibrary.IsAppExecutable(path))
mGames.add(new GameFile(path));
}
}

Expand All @@ -252,7 +252,7 @@ public void saveGameList() {
}

File cache = getGameListCache();
FileWriter writer = null;
FileWriter writer;
try {
writer = new FileWriter(cache);
writer.write(sb.toString());
Expand All @@ -277,7 +277,8 @@ public void loadGameList() {

mGames.clear();
for (String path : content.split(";")) {
if (!path.isEmpty() && path.endsWith(".cci") && new File(path).exists()) {
if (NativeLibrary.isValidFile(path) && new File(path).exists() &&
NativeLibrary.IsAppExecutable(path)) {
mGames.add(new GameFile(path));
}
}
Expand Down
136 changes: 136 additions & 0 deletions src/android/app/src/main/java/org/citra/emu/ui/MiiSelectorDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package org.citra.emu.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.nononsenseapps.filepicker.DividerItemDecoration;
import java.util.ArrayList;
import org.citra.emu.R;

public class MiiSelectorDialog extends DialogFragment {
private static final String ARG_CANCEL = "cancel";
private static final String ARG_TITLE = "title";
private static final String ARG_MIIS = "miis";

public static MiiSelectorDialog newInstance(boolean cancel, String title, String[] miis) {
MiiSelectorDialog fragment = new MiiSelectorDialog();
Bundle arguments = new Bundle();
arguments.putBoolean(ARG_CANCEL, cancel);
arguments.putString(ARG_TITLE, title);
arguments.putStringArray(ARG_MIIS, miis);
fragment.setArguments(arguments);
return fragment;
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
ViewGroup contents = (ViewGroup)getActivity().getLayoutInflater().inflate(
R.layout.dialog_mii_selector, null);

Drawable lineDivider = getContext().getDrawable(R.drawable.line_divider);
RecyclerView recyclerView = contents.findViewById(R.id.list_settings);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
MiisAdapter adapter = new MiisAdapter();
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DividerItemDecoration(lineDivider));
builder.setView(contents);
return builder.create();
}

@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
}

public class SettingsItem {}

public abstract class SettingViewHolder
extends RecyclerView.ViewHolder implements View.OnClickListener {
public SettingViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
findViews(itemView);
}

protected abstract void findViews(View root);

public abstract void bind(SettingsItem item);

public abstract void onClick(View clicked);
}

public final class CheckBoxSettingViewHolder
extends SettingViewHolder implements CompoundButton.OnCheckedChangeListener {
SettingsItem mItem;
private TextView mTextSettingName;
private CheckBox mCheckbox;

public CheckBoxSettingViewHolder(View itemView) {
super(itemView);
}

@Override
protected void findViews(View root) {
mTextSettingName = root.findViewById(R.id.text_setting_name);
mCheckbox = root.findViewById(R.id.checkbox);
mCheckbox.setOnCheckedChangeListener(this);
}

@Override
public void bind(SettingsItem item) {
mItem = item;
// mTextSettingName.setText(item.getName());
// mCheckbox.setChecked(mItem.getValue() > 0);
}

@Override
public void onClick(View clicked) {
mCheckbox.toggle();
// mItem.setValue(mCheckbox.isChecked() ? 1 : 0);
}

@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
// mItem.setValue(isChecked ? 1 : 0);
}
}

public class MiisAdapter extends RecyclerView.Adapter<SettingViewHolder> {
private ArrayList<SettingsItem> mSettings;

public MiisAdapter() {}

@NonNull
@Override
public SettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.list_item_running_checkbox, parent, false);
return new CheckBoxSettingViewHolder(itemView);
}

@Override
public int getItemCount() {
return mSettings.size();
}

@Override
public void onBindViewHolder(@NonNull SettingViewHolder holder, int position) {
holder.bind(mSettings.get(position));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
ViewGroup contents = (ViewGroup)getActivity().getLayoutInflater().inflate(
R.layout.dialog_running_settings, null);

int columns = 1;
Drawable lineDivider = getContext().getDrawable(R.drawable.line_divider);
RecyclerView recyclerView = contents.findViewById(R.id.list_settings);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.citra.emu.utils;

import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;

import android.annotation.TargetApi;
Expand All @@ -15,6 +16,7 @@

public final class PermissionsHandler {
public static final int REQUEST_CODE_WRITE_PERMISSION = 500;
public static final int REQUEST_CODE_CAMERA_PERMISSION = 501;

@TargetApi(Build.VERSION_CODES.M)
public static boolean checkWritePermission(final Activity activity) {
Expand Down Expand Up @@ -43,6 +45,29 @@ public static boolean checkWritePermission(final Activity activity) {
return true;
}

@TargetApi(Build.VERSION_CODES.M)
public static boolean checkCameraPermission(final Activity activity) {
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}

int permission = ContextCompat.checkSelfPermission(activity, CAMERA);
if (permission != PackageManager.PERMISSION_GRANTED) {
if (activity.shouldShowRequestPermissionRationale(CAMERA)) {
showMessageOKCancel(activity, activity.getString(R.string.camera_permission_needed),
(dialog, which)
-> activity.requestPermissions(
new String[] {CAMERA}, REQUEST_CODE_CAMERA_PERMISSION));
return false;
}

activity.requestPermissions(new String[] {CAMERA}, REQUEST_CODE_CAMERA_PERMISSION);
return false;
}

return true;
}

public static boolean hasWriteAccess(Context context) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int hasWritePermission =
Expand Down
31 changes: 31 additions & 0 deletions src/android/app/src/main/res/layout/dialog_mii_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/text_title"
android:text="@string/preferences_settings"
android:textAlignment="center"
android:textColor="@android:color/white"
android:background="@color/citra_orange"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button_cancel"
android:layout_alignParentBottom="true"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>

<android.support.v7.widget.RecyclerView
android:id="@+id/list_settings"
android:background="@android:color/white"
android:layout_below="@id/text_title"
android:layout_above="@id/button_cancel"
android:layout_width="match_parent"
android:layout_height="300dp"/>

</RelativeLayout>
1 change: 1 addition & 0 deletions src/android/app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<string name="save">保存</string>
<string name="cheat_code">金手指</string>
<string name="write_permission_needed">You need to allow write access to external storage for the emulator to work.</string>
<string name="camera_permission_needed">You need to allow take photos for the emulator to work.</string>

<string name="region_invalid">未知</string>
<string name="region_japan">日本</string>
Expand Down
Loading

2 comments on commit 0542855

@Eselter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greate update. Now on Xiaomi Mi6 I have 29-30 FPS in Pokémon X in town instead 15-17. Game now is playable.

@Superking123
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice update. In Xiaomi Mi Mix 2s, before in Pokémon Ruby Omega it was 2327fps, now 2930fps in almost all game :D

Please sign in to comment.