android: install buttons.png and reload it. Record audio permission.
install buttons.png when saving settings (home dir may have changed) reload buttons.png if previous load failed when rendering hide surface view when microphone is enabled to ask for permission
This commit is contained in:
parent
91c7417c22
commit
45ed8cbc02
|
@ -1435,8 +1435,10 @@ static void osd_gen_vertices()
|
|||
|
||||
void OSD_DRAW(bool clear_screen)
|
||||
{
|
||||
#ifndef TARGET_PANDORA
|
||||
if (osd_tex)
|
||||
#ifdef _ANDROID
|
||||
if (osd_tex == 0)
|
||||
gl_load_osd_resources();
|
||||
if (osd_tex != 0)
|
||||
{
|
||||
osd_gen_vertices();
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -13,6 +14,7 @@ import com.reicast.emulator.emu.JNIdc;
|
|||
|
||||
public class Emulator extends Application {
|
||||
private static Context context;
|
||||
private static Activity currentActivity;
|
||||
|
||||
// see MapleDeviceType in hw/maple/maple_devs.h
|
||||
public static final int MDT_SegaController = 0;
|
||||
|
@ -67,6 +69,11 @@ public class Emulator extends Application {
|
|||
prefs.edit()
|
||||
.putString(Config.pref_home, homeDirectory).apply();
|
||||
AudioBackend.getInstance().enableSound(!Emulator.nosound);
|
||||
|
||||
FileBrowser.installButtons(prefs);
|
||||
if (micPluggedIn() && currentActivity instanceof NativeGLActivity) {
|
||||
((NativeGLActivity)currentActivity).requestRecordAudioPermission();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean micPluggedIn() {
|
||||
|
@ -88,6 +95,14 @@ public class Emulator extends Application {
|
|||
return Emulator.context;
|
||||
}
|
||||
|
||||
public static Activity getCurrentActivity() {
|
||||
return Emulator.currentActivity;
|
||||
}
|
||||
|
||||
public static void setCurrentActivity(Activity activity) {
|
||||
Emulator.currentActivity = activity;
|
||||
}
|
||||
|
||||
static {
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ public class FileBrowser extends Fragment {
|
|||
if (temp == null || !new File(temp).isDirectory()) {
|
||||
showToastMessage(getActivity().getString(R.string.config_home), Snackbar.LENGTH_LONG);
|
||||
}
|
||||
installButtons();
|
||||
installButtons(mPrefs);
|
||||
if (!games) {
|
||||
new LocateGames(this, R.array.flash).execute(home_directory);
|
||||
} else {
|
||||
|
@ -185,19 +185,21 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void installButtons() {
|
||||
public static void installButtons(SharedPreferences prefs) {
|
||||
try {
|
||||
File buttons = null;
|
||||
String theme = mPrefs.getString(Config.pref_theme, null);
|
||||
// TODO button themes
|
||||
String theme = prefs.getString(Config.pref_theme, null);
|
||||
if (theme != null) {
|
||||
buttons = new File(theme);
|
||||
}
|
||||
String home_directory = prefs.getString(Config.pref_home, Environment.getExternalStorageDirectory().getAbsolutePath());
|
||||
File file = new File(home_directory, "data/buttons.png");
|
||||
InputStream in = null;
|
||||
if (buttons != null && buttons.exists()) {
|
||||
in = new FileInputStream(buttons);
|
||||
} else if (!file.exists() || file.length() == 0) {
|
||||
in = getActivity().getAssets().open("buttons.png");
|
||||
in = Emulator.getAppContext().getAssets().open("buttons.png");
|
||||
}
|
||||
if (in != null) {
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -40,6 +41,7 @@ public final class NativeGLActivity extends BaseNativeGLActivity implements Acti
|
|||
public static byte[] syms;
|
||||
private float[][] vjoy_d_cached; // Used for VJoy editing
|
||||
private AudioBackend audioBackend;
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -48,6 +50,7 @@ public final class NativeGLActivity extends BaseNativeGLActivity implements Acti
|
|||
|
||||
Emulator app = (Emulator)getApplicationContext();
|
||||
app.getConfigurationPrefs();
|
||||
Emulator.setCurrentActivity(this);
|
||||
|
||||
OuyaController.init(this);
|
||||
|
||||
|
@ -73,19 +76,8 @@ public final class NativeGLActivity extends BaseNativeGLActivity implements Acti
|
|||
// FIXME Maple microphone can be plugged at any time with in-game gui
|
||||
// so this perm may be required at any time as well
|
||||
//setup mic
|
||||
if (Emulator.micPluggedIn()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{
|
||||
Manifest.permission.RECORD_AUDIO
|
||||
},
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
onRequestPermissionsResult(0, new String[] { Manifest.permission.RECORD_AUDIO }, new int[] { PackageManager.PERMISSION_GRANTED });
|
||||
}
|
||||
}
|
||||
if (Emulator.micPluggedIn())
|
||||
requestRecordAudioPermission();
|
||||
}
|
||||
|
||||
private boolean showMenu() {
|
||||
|
@ -165,6 +157,29 @@ public final class NativeGLActivity extends BaseNativeGLActivity implements Acti
|
|||
InputDeviceManager.getInstance().stopListening();
|
||||
register(null);
|
||||
audioBackend.release();
|
||||
Emulator.setCurrentActivity(null);
|
||||
}
|
||||
|
||||
void requestRecordAudioPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.setVisibility(View.INVISIBLE);
|
||||
ActivityCompat.requestPermissions(NativeGLActivity.this,
|
||||
new String[]{
|
||||
Manifest.permission.RECORD_AUDIO
|
||||
},
|
||||
0);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
onRequestPermissionsResult(0, new String[] { Manifest.permission.RECORD_AUDIO },
|
||||
new int[] { PackageManager.PERMISSION_GRANTED });
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -175,6 +190,8 @@ public final class NativeGLActivity extends BaseNativeGLActivity implements Acti
|
|||
sip.startRecording();
|
||||
JNIdc.setupMic(sip);
|
||||
}
|
||||
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void showToastMessage(String message, int duration) {
|
||||
|
|
Loading…
Reference in New Issue