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