mirror of
https://github.com/u0u0/Cocos2d-Lua-Community.git
synced 2026-06-05 19:25:22 +08:00
external垃圾清理,android build fix.
This commit is contained in:
@@ -30,8 +30,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -49,7 +47,6 @@ import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
|
||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
||||
// ===========================================================
|
||||
@@ -71,8 +68,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||
private Cocos2dxEditBoxHelper mEditBoxHelper = null;
|
||||
private boolean hasFocus = false;
|
||||
private boolean showVirtualButton = false;
|
||||
private boolean gainAudioFocus = false;
|
||||
private boolean paused = true;
|
||||
|
||||
public Cocos2dxGLSurfaceView getGLSurfaceView(){
|
||||
return mGLSurfaceView;
|
||||
@@ -96,18 +91,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||
this.showVirtualButton = value;
|
||||
}
|
||||
|
||||
public void setEnableAudioFocusGain(boolean value) {
|
||||
if(gainAudioFocus != value) {
|
||||
if(!paused) {
|
||||
if (value)
|
||||
Cocos2dxAudioFocusManager.registerAudioFocusListener(this);
|
||||
else
|
||||
Cocos2dxAudioFocusManager.unregisterAudioFocusListener(this);
|
||||
}
|
||||
gainAudioFocus = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onLoadNativeLibraries() {
|
||||
try {
|
||||
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
|
||||
@@ -163,9 +146,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||
|
||||
Window window = this.getWindow();
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
|
||||
// Audio configuration
|
||||
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
|
||||
//native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions
|
||||
@@ -182,10 +162,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.d(TAG, "onResume()");
|
||||
paused = false;
|
||||
super.onResume();
|
||||
if(gainAudioFocus)
|
||||
Cocos2dxAudioFocusManager.registerAudioFocusListener(this);
|
||||
this.hideVirtualButton();
|
||||
resumeIfHasFocus();
|
||||
}
|
||||
@@ -214,18 +191,13 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.d(TAG, "onPause()");
|
||||
paused = true;
|
||||
super.onPause();
|
||||
if(gainAudioFocus)
|
||||
Cocos2dxAudioFocusManager.unregisterAudioFocusListener(this);
|
||||
Cocos2dxHelper.onPause();
|
||||
mGLSurfaceView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if(gainAudioFocus)
|
||||
Cocos2dxAudioFocusManager.unregisterAudioFocusListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -295,7 +267,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||
// Set framelayout as the content view
|
||||
setContentView(mFrameLayout);
|
||||
}
|
||||
|
||||
|
||||
public Cocos2dxGLSurfaceView onCreateView() {
|
||||
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2016 Chukong Technologies Inc.
|
||||
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
*
|
||||
* http://www.cocos2d-x.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.util.Log;
|
||||
|
||||
class Cocos2dxAudioFocusManager {
|
||||
|
||||
private final static String TAG = "AudioFocusManager";
|
||||
// Audio focus values synchronized with which in cocos/platform/android/javaactivity-android.cpp
|
||||
private final static int AUDIOFOCUS_GAIN = 0;
|
||||
private final static int AUDIOFOCUS_LOST = 1;
|
||||
private final static int AUDIOFOCUS_LOST_TRANSIENT = 2;
|
||||
private final static int AUDIOFOCUS_LOST_TRANSIENT_CAN_DUCK = 3;
|
||||
|
||||
private static AudioManager.OnAudioFocusChangeListener sAfChangeListener =
|
||||
new AudioManager.OnAudioFocusChangeListener() {
|
||||
public void onAudioFocusChange(int focusChange) {
|
||||
|
||||
Log.d(TAG, "onAudioFocusChange: " + focusChange + ", thread: " + Thread.currentThread().getName());
|
||||
|
||||
if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
|
||||
// Permanent loss of audio focus
|
||||
// Pause playback immediately
|
||||
Log.d(TAG, "Pause music by AUDIOFOCUS_LOSS");
|
||||
Cocos2dxHelper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnAudioFocusChange(AUDIOFOCUS_LOST);
|
||||
}
|
||||
});
|
||||
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
|
||||
// Pause playback
|
||||
Log.d(TAG, "Pause music by AUDIOFOCUS_LOSS_TRANSILENT");
|
||||
Cocos2dxHelper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnAudioFocusChange(AUDIOFOCUS_LOST_TRANSIENT);
|
||||
}
|
||||
});
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
|
||||
// Lower the volume, keep playing
|
||||
Log.d(TAG, "Lower the volume, keep playing by AUDIOFOCUS_LOSS_TRANSILENT_CAN_DUCK");
|
||||
Cocos2dxHelper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnAudioFocusChange(AUDIOFOCUS_LOST_TRANSIENT_CAN_DUCK);
|
||||
}
|
||||
});
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||
// Your app has been granted audio focus again
|
||||
// Raise volume to normal, restart playback if necessary
|
||||
Log.d(TAG, "Resume music by AUDIOFOCUS_GAIN");
|
||||
Cocos2dxHelper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnAudioFocusChange(AUDIOFOCUS_GAIN);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static boolean registerAudioFocusListener(Context context) {
|
||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
// Request audio focus for playback
|
||||
int result = am.requestAudioFocus(sAfChangeListener,
|
||||
// Use the music stream.
|
||||
AudioManager.STREAM_MUSIC,
|
||||
// Request permanent focus.
|
||||
AudioManager.AUDIOFOCUS_GAIN);
|
||||
|
||||
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||
Log.d(TAG, "requestAudioFocus succeed");
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.e(TAG, "requestAudioFocus failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
static void unregisterAudioFocusListener(Context context) {
|
||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
int result = am.abandonAudioFocus(sAfChangeListener);
|
||||
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||
Log.d(TAG, "abandonAudioFocus succeed!");
|
||||
} else {
|
||||
Log.e(TAG, "abandonAudioFocus failed!");
|
||||
}
|
||||
|
||||
Cocos2dxHelper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnAudioFocusChange(AUDIOFOCUS_GAIN);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static native void nativeOnAudioFocusChange(int focusChange);
|
||||
}
|
||||
Reference in New Issue
Block a user