Address review

This commit is contained in:
zhupengfei 2020-04-18 20:29:11 +08:00 committed by bunnei
parent 1a659ae4b6
commit 5cfc37470e
8 changed files with 37 additions and 35 deletions

4
.gitmodules vendored
View File

@ -50,5 +50,5 @@
path = externals/zstd path = externals/zstd
url = https://github.com/facebook/zstd.git url = https://github.com/facebook/zstd.git
[submodule "libyuv"] [submodule "libyuv"]
path = externals/libyuv path = externals/libyuv
url = https://github.com/lemenkov/libyuv.git url = https://github.com/lemenkov/libyuv.git

View File

@ -6,17 +6,12 @@ package org.citra.citra_emu.camera;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore; import android.provider.MediaStore;
import com.squareup.picasso.Picasso;
import org.citra.citra_emu.NativeLibrary; import org.citra.citra_emu.NativeLibrary;
import org.citra.citra_emu.R; import org.citra.citra_emu.R;
import org.citra.citra_emu.activities.EmulationActivity; import org.citra.citra_emu.activities.EmulationActivity;
import org.citra.citra_emu.utils.FileBrowserHelper; import org.citra.citra_emu.utils.PicassoUtils;
import java.io.IOException;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -53,11 +48,7 @@ public final class StillImageCameraHelper {
// Called from EmulationActivity. // Called from EmulationActivity.
public static void OnFilePickerResult(Intent result) { public static void OnFilePickerResult(Intent result) {
if (result == null) { filePickerPath = result == null ? null : result.getDataString();
filePickerPath = null;
} else {
filePickerPath = result.getDataString();
}
synchronized (filePickerLock) { synchronized (filePickerLock) {
filePickerLock.notifyAll(); filePickerLock.notifyAll();
@ -67,15 +58,6 @@ public final class StillImageCameraHelper {
// Blocking call. Load image from file and crop/resize it to fit in width x height. // Blocking call. Load image from file and crop/resize it to fit in width x height.
@Nullable @Nullable
public static Bitmap LoadImageFromFile(String uri, int width, int height) { public static Bitmap LoadImageFromFile(String uri, int width, int height) {
try { return PicassoUtils.LoadBitmapFromFile(uri, width, height);
return Picasso.get()
.load(Uri.parse(uri))
.config(Bitmap.Config.ARGB_8888)
.centerCrop()
.resize(width, height)
.get();
} catch (IOException e) {
return null;
}
} }
} }

View File

@ -192,17 +192,19 @@ public final class SettingsFragmentPresenter {
supportedCameraIdList.add(id); supportedCameraIdList.add(id);
final int facing = Objects.requireNonNull(characteristics.get(CameraCharacteristics.LENS_FACING)); final int facing = Objects.requireNonNull(characteristics.get(CameraCharacteristics.LENS_FACING));
int stringId = R.string.camera_facing_external;
switch (facing) { switch (facing) {
case CameraCharacteristics.LENS_FACING_FRONT: case CameraCharacteristics.LENS_FACING_FRONT:
supportedCameraNameList.add(String.format("%1$s (%2$s)", id, activity.getString(R.string.camera_facing_front))); stringId = R.string.camera_facing_front;
break; break;
case CameraCharacteristics.LENS_FACING_BACK: case CameraCharacteristics.LENS_FACING_BACK:
supportedCameraNameList.add(String.format("%1$s (%2$s)", id, activity.getString(R.string.camera_facing_back))); stringId = R.string.camera_facing_back;
break; break;
case CameraCharacteristics.LENS_FACING_EXTERNAL: case CameraCharacteristics.LENS_FACING_EXTERNAL:
supportedCameraNameList.add(String.format("%1$s (%2$s)", id, activity.getString(R.string.camera_facing_external))); stringId = R.string.camera_facing_external;
break; break;
} }
supportedCameraNameList.add(String.format("%1$s (%2$s)", id, stringId));
} }
} catch (CameraAccessException e) { } catch (CameraAccessException e) {
Log.error("Couldn't retrieve camera list"); Log.error("Couldn't retrieve camera list");

View File

@ -8,12 +8,10 @@ import android.os.Build;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class PermissionsHandler { public class PermissionsHandler {
public static final int REQUEST_CODE_WRITE_PERMISSION = 500; public static final int REQUEST_CODE_WRITE_PERMISSION = 500;
public static final int REQUEST_CODE_CAMERA = 700;
// We use permissions acceptance as an indicator if this is a first boot for the user. // We use permissions acceptance as an indicator if this is a first boot for the user.
public static boolean isFirstBoot(final FragmentActivity activity) { public static boolean isFirstBoot(final FragmentActivity activity) {

View File

@ -8,6 +8,10 @@ import com.squareup.picasso.Picasso;
import org.citra.citra_emu.R; import org.citra.citra_emu.R;
import java.io.IOException;
import androidx.annotation.Nullable;
public class PicassoUtils { public class PicassoUtils {
public static void loadGameIcon(ImageView imageView, String gamePath) { public static void loadGameIcon(ImageView imageView, String gamePath) {
Picasso picassoInstance = new Picasso.Builder(imageView.getContext()) Picasso picassoInstance = new Picasso.Builder(imageView.getContext())
@ -25,4 +29,19 @@ public class PicassoUtils {
.transform(new PicassoRoundedCornersTransformation()) .transform(new PicassoRoundedCornersTransformation())
.into(imageView); .into(imageView);
} }
// Blocking call. Load image from file and crop/resize it to fit in width x height.
@Nullable
public static Bitmap LoadBitmapFromFile(String uri, int width, int height) {
try {
return Picasso.get()
.load(Uri.parse(uri))
.config(Bitmap.Config.ARGB_8888)
.centerCrop()
.resize(width, height)
.get();
} catch (IOException e) {
return null;
}
}
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <string_view>
#include <unordered_map> #include <unordered_map>
#include <camera/NdkCameraManager.h> #include <camera/NdkCameraManager.h>
#include "common/common_types.h" #include "common/common_types.h"
@ -47,8 +48,8 @@ private:
}; };
// Placeholders to mean 'use any front/back camera' // Placeholders to mean 'use any front/back camera'
constexpr char FrontCameraPlaceholder[] = "_front"; constexpr std::string_view FrontCameraPlaceholder = "_front";
constexpr char BackCameraPlaceholder[] = "_back"; constexpr std::string_view BackCameraPlaceholder = "_back";
class Factory final : public CameraFactory { class Factory final : public CameraFactory {
public: public:

View File

@ -208,19 +208,19 @@ void Config::ReadValues() {
Settings::values.camera_name[OuterRightCamera] = Settings::values.camera_name[OuterRightCamera] =
sdl2_config->GetString("Camera", "camera_outer_right_name", "ndk"); sdl2_config->GetString("Camera", "camera_outer_right_name", "ndk");
Settings::values.camera_config[OuterRightCamera] = sdl2_config->GetString( Settings::values.camera_config[OuterRightCamera] = sdl2_config->GetString(
"Camera", "camera_outer_right_config", Camera::NDK::BackCameraPlaceholder); "Camera", "camera_outer_right_config", std::string{Camera::NDK::BackCameraPlaceholder});
Settings::values.camera_flip[OuterRightCamera] = Settings::values.camera_flip[OuterRightCamera] =
sdl2_config->GetInteger("Camera", "camera_outer_right_flip", 0); sdl2_config->GetInteger("Camera", "camera_outer_right_flip", 0);
Settings::values.camera_name[InnerCamera] = Settings::values.camera_name[InnerCamera] =
sdl2_config->GetString("Camera", "camera_inner_name", "ndk"); sdl2_config->GetString("Camera", "camera_inner_name", "ndk");
Settings::values.camera_config[InnerCamera] = sdl2_config->GetString( Settings::values.camera_config[InnerCamera] = sdl2_config->GetString(
"Camera", "camera_inner_config", Camera::NDK::FrontCameraPlaceholder); "Camera", "camera_inner_config", std::string{Camera::NDK::FrontCameraPlaceholder});
Settings::values.camera_flip[InnerCamera] = Settings::values.camera_flip[InnerCamera] =
sdl2_config->GetInteger("Camera", "camera_inner_flip", 0); sdl2_config->GetInteger("Camera", "camera_inner_flip", 0);
Settings::values.camera_name[OuterLeftCamera] = Settings::values.camera_name[OuterLeftCamera] =
sdl2_config->GetString("Camera", "camera_outer_left_name", "ndk"); sdl2_config->GetString("Camera", "camera_outer_left_name", "ndk");
Settings::values.camera_config[OuterLeftCamera] = sdl2_config->GetString( Settings::values.camera_config[OuterLeftCamera] = sdl2_config->GetString(
"Camera", "camera_outer_left_config", Camera::NDK::BackCameraPlaceholder); "Camera", "camera_outer_left_config", std::string{Camera::NDK::BackCameraPlaceholder});
Settings::values.camera_flip[OuterLeftCamera] = Settings::values.camera_flip[OuterLeftCamera] =
sdl2_config->GetInteger("Camera", "camera_outer_left_flip", 0); sdl2_config->GetInteger("Camera", "camera_outer_left_flip", 0);

View File

@ -173,8 +173,8 @@ void Java_org_citra_citra_1emu_NativeLibrary_SurfaceChanged(JNIEnv* env,
LOG_INFO(Frontend, "Surface changed"); LOG_INFO(Frontend, "Surface changed");
} }
void Java_org_citra_citra_1emu_NativeLibrary_SurfaceDestroyed( void Java_org_citra_citra_1emu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
JNIEnv* env, [[maybe_unused]][[maybe_unused]] jclass clazz) { [[maybe_unused]] jclass clazz) {
ANativeWindow_release(s_surf); ANativeWindow_release(s_surf);
s_surf = nullptr; s_surf = nullptr;
if (window) { if (window) {