Merge pull request #835 from WagicProject/android_tweaks

Android tweaks
This commit is contained in:
Rolzad73
2016-08-06 00:25:36 -04:00
committed by GitHub
10 changed files with 254 additions and 244 deletions

View File

@@ -77,6 +77,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0); return (result == 0);
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
int result;
__asm__ __volatile__(
"lock ; xchgl %0, (%1)\n"
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
return (result == 0);
#else #else
/* Need CPU instructions for spinlock here! */ /* Need CPU instructions for spinlock here! */
__need_spinlock_implementation__ __need_spinlock_implementation__

View File

@@ -1,3 +1,4 @@
/gen /gen
/bin /bin
/libs

View File

@@ -4,15 +4,13 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:debuggable="false" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:configChanges="keyboard|keyboardHidden|orientation" android:label="@string/app_name" android:name="org.libsdl.app.SDLActivity" android:screenOrientation="sensorLandscape"> <activity android:debuggable="false" android:configChanges="keyboard|keyboardHidden|orientation" android:label="@string/app_name" android:name="org.libsdl.app.SDLActivity" android:screenOrientation="sensorLandscape">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:configChanges="keyboard|keyboardHidden|orientation" android:name="com.google.ads.AdActivity" android:screenOrientation="sensorLandscape"/>
</application> </application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/> <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/>
</manifest> </manifest>

View File

@@ -1,6 +1,7 @@
APP_PROJECT_PATH := $(call my-dir)/.. APP_PROJECT_PATH := $(call my-dir)/..
APP_CPPFLAGS += -frtti -fexceptions APP_CPPFLAGS += -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a APP_ABI := armeabi armeabi-v7a
#APP_ABI := x86 # mainly for emulators
APP_STL := gnustl_static APP_STL := gnustl_static
APP_MODULES := libpng libjpeg main SDL APP_MODULES := libpng libjpeg main SDL

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -11,14 +11,13 @@ import android.util.Log;
public class DeckImporter public class DeckImporter
{ {
public static String importDeck( File f, String mypath, String activePath ) public static String importDeck( File f, String mypath, String activePath )
{ {
String message = ""; String message = "";
String deck = ""; String deck = "";
String deckname = ""; String deckname = "";
String prefix = "#SB:"; String prefix = "#SB:";
int cardcount = 0; int cardcount = 0;
if(f.exists() && !f.isDirectory()) if(f.exists() && !f.isDirectory())
{ {
deckname = f.getName(); deckname = f.getName();
@@ -36,91 +35,86 @@ public class DeckImporter
while (scanner.hasNext()) while (scanner.hasNext())
{ {
String line = scanner.nextLine(); String line = scanner.nextLine();
line = line.trim(); line = line.trim();
if (!line.equals("") && cardcount < 61) // don't write out blank lines if (!line.equals("") && cardcount < 61) // don't write out blank lines
{ {
String[] slines = line.split("\\s+"); String[] slines = line.split("\\s+");
String arranged = ""; String arranged = "";
for(int idx = 1; idx < slines.length; idx++) for (int idx = 1; idx < slines.length; idx++)
{ {
arranged += slines[idx] + " "; arranged += slines[idx] + " ";
} }
if ((isNumeric(slines[0])) && arranged != null) if ((isNumeric(slines[0])) && arranged != null)
{ {
if (slines[1] != null && slines[1].startsWith("[")) if (slines[1] != null && slines[1].startsWith("["))
{ {
arranged = arranged.substring(5); arranged = arranged.substring(5);
slines[1] = slines[1].replaceAll("\\[", "").replaceAll("\\]",""); slines[1] = slines[1].replaceAll("\\[", "").replaceAll("\\]", "");
deck += arranged + " (" + renameSet(slines[1]) + ") * " + slines[0] + "\n"; deck += arranged + " (" + renameSet(slines[1]) + ") * " + slines[0] + "\n";
} } else
else {
{ deck += arranged + "(*) * " + slines[0] + "\n";
deck += arranged + "(*) * " + slines[0] + "\n"; }
} cardcount += Integer.parseInt(slines[0]);
cardcount += Integer.parseInt(slines[0]); }
} }
} }
} File profile = new File(activePath + "/Res/settings/options.txt");
File profile = new File(activePath+"/Res/settings/options.txt"); if (profile.exists() && !profile.isDirectory())
if(profile.exists() && !profile.isDirectory()) {
{ String profileName = getActiveProfile(profile);
String profileName = getActiveProfile(profile); if (profileName != "Missing!")
if(profileName != "Missing!") {
{ File rootProfiles = new File(activePath + "/Res/profiles/" + profileName);
File rootProfiles = new File(activePath+"/Res/profiles/"+profileName); if (rootProfiles.exists() && rootProfiles.isDirectory())
if(rootProfiles.exists() && rootProfiles.isDirectory()) {
{ //save deck
//save deck int countdeck = 1;
int countdeck = 1; File[] files = rootProfiles.listFiles();
File[] files = rootProfiles.listFiles(); for (int i = 0; i < files.length; i++)
for (int i = 0; i < files.length; i++) {//check if there is available deck...
{//check if there is available deck... if (files[i].getName().startsWith("deck"))
if(files[i].getName().startsWith("deck")) countdeck++;
countdeck++; }
} File toSave = new File(rootProfiles + "/deck" + countdeck + ".txt");
File toSave = new File(rootProfiles+"/deck"+countdeck+".txt"); try
try {
{ FileOutputStream fop = new FileOutputStream(toSave);
FileOutputStream fop = new FileOutputStream(toSave);
// if file doesn't exists, then create it
// if file doesn't exists, then create it if (!toSave.exists())
if (!toSave.exists()) { {
toSave.createNewFile(); toSave.createNewFile();
} }
// get the content in bytes // get the content in bytes
byte[] contentInBytes = deck.getBytes(); byte[] contentInBytes = deck.getBytes();
fop.write(contentInBytes); fop.write(contentInBytes);
fop.flush(); fop.flush();
fop.close(); fop.close();
message = "Import Deck Success!\n"+cardcount+" total cards in this deck\n\n"+deck; message = "Import Deck Success!\n" + cardcount + " total cards in this deck\n\n" + deck;
} } catch (IOException e)
catch (IOException e) {
{ message = e.getMessage();
message = e.getMessage(); }
} } else
} {
else message = "Missing Folder!";
{ }
message = "Missing Folder!"; }
} } else
} {
} message = "Invalid Profile!";
else }
{ } else
message = "Invalid Profile!"; {
} message = "No errors, and file EMPTY";
} }
else } catch (IOException e)
{ {
message = "No errors, and file EMPTY"; message = e.getMessage();
} }
} }
catch(IOException e) return message;
{
message = e.getMessage();
}
}
return message;
} }
private static boolean isNumeric(String input) private static boolean isNumeric(String input)
@@ -135,7 +129,7 @@ public class DeckImporter
} }
return true; return true;
} }
private static String getActiveProfile(File mypath) private static String getActiveProfile(File mypath)
{ {
String name = ""; String name = "";
@@ -158,7 +152,7 @@ public class DeckImporter
} }
return name; return name;
} }
private static String renameSet(String set) private static String renameSet(String set)
{ {
if (set == "") if (set == "")
@@ -278,5 +272,4 @@ public class DeckImporter
else else
return set; return set;
} }
} }

View File

@@ -14,6 +14,7 @@ import android.util.Log;
public class StorageOptions public class StorageOptions
{ {
private static final String TAG = StorageOptions.class.getCanonicalName();
private static ArrayList<String> mMounts = new ArrayList<String>(); private static ArrayList<String> mMounts = new ArrayList<String>();
private static ArrayList<String> mVold = new ArrayList<String>(); private static ArrayList<String> mVold = new ArrayList<String>();
@@ -77,11 +78,11 @@ public class StorageOptions
} catch (FileNotFoundException fnfex) } catch (FileNotFoundException fnfex)
{ {
// if proc/mount doesn't exist we just use // if proc/mount doesn't exist we just use
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point"); Log.i(TAG, fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} catch (Exception e) } catch (Exception e)
{ {
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file"); Log.e(TAG, e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} }
} }
@@ -111,11 +112,11 @@ public class StorageOptions
} catch (FileNotFoundException fnfex) } catch (FileNotFoundException fnfex)
{ {
// if proc/mount doesn't exist we just use // if proc/mount doesn't exist we just use
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point"); Log.i(TAG, fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} catch (Exception e) } catch (Exception e)
{ {
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file"); Log.e(TAG, e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} }
} }
@@ -144,11 +145,11 @@ public class StorageOptions
} catch (FileNotFoundException fnfex) } catch (FileNotFoundException fnfex)
{ {
// if vold.fstab doesn't exist we use the value gathered from the Environment // if vold.fstab doesn't exist we use the value gathered from the Environment
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point"); Log.i(TAG, fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} catch (Exception e) } catch (Exception e)
{ {
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file"); Log.e(TAG, e.getMessage() + ": unknown exception while reading vold.fstab file");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} }
} }
@@ -174,15 +175,18 @@ public class StorageOptions
{ {
/* /*
* Sometimes the two lists of mount points will be different. We only want those mount points that are in both list. * Sometimes the two lists of mount points will be different. We only want those mount points that are in both list.
* *
* Compare the two lists together and remove items that are not in both lists. * Compare the two lists together and remove items that are not in both lists.
*/ */
for (int i = 0; i < mMounts.size(); i++) if (mVold.size() > 0)
{ {
String mount = mMounts.get(i); for (int i = 0; i < mMounts.size(); i++)
if (!mVold.contains(mount)) {
mMounts.remove(i--); String mount = mMounts.get(i);
if (!mVold.contains(mount))
mMounts.remove(i--);
}
} }
// don't need this anymore, clear the vold list to reduce memory // don't need this anymore, clear the vold list to reduce memory
@@ -204,9 +208,10 @@ public class StorageOptions
if (!root.exists() || !root.isDirectory() || !root.canWrite()) if (!root.exists() || !root.isDirectory() || !root.canWrite())
mMounts.remove(i--); mMounts.remove(i--);
} }
if (t == 0 && Build.VERSION.SDK_INT >= 16 && findForcemount()) if (t == 0 && Build.VERSION.SDK_INT >= 16 && findForcemount())
{//if none is found lets force it for Jellybean and above... {
//if none is found lets force it for Jellybean and above...
if (System.getenv("EXTERNAL_STORAGE") != null) if (System.getenv("EXTERNAL_STORAGE") != null)
{ {
File root = new File(System.getenv("EXTERNAL_STORAGE")); File root = new File(System.getenv("EXTERNAL_STORAGE"));
@@ -224,7 +229,7 @@ public class StorageOptions
} }
} }
} }
if (System.getenv("SECONDARY_STORAGE") != null) if (System.getenv("SECONDARY_STORAGE") != null)
{ {
File root = new File(System.getenv("SECONDARY_STORAGE")); File root = new File(System.getenv("SECONDARY_STORAGE"));
@@ -247,6 +252,7 @@ public class StorageOptions
private static void setProperties() private static void setProperties()
{ {
Log.d(TAG, "setProperties()");
/* /*
* At this point all the paths in the list should be valid. Build the public properties. * At this point all the paths in the list should be valid. Build the public properties.
*/ */
@@ -268,7 +274,8 @@ public class StorageOptions
else else
{ {
for (String path : mMounts) for (String path : mMounts)
{ // TODO: /mnt/sdcard is assumed to always mean internal storage. Use this comparison until there is a better way to do this {
// TODO: /mnt/sdcard is assumed to always mean internal storage. Use this comparison until there is a better way to do this
if ("/mnt/sdcard".equalsIgnoreCase(path)) if ("/mnt/sdcard".equalsIgnoreCase(path))
mLabels.add("Built-in Storage"); mLabels.add("Built-in Storage");
else else
@@ -310,84 +317,97 @@ public class StorageOptions
* *
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise. * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/ */
public static boolean isRooted() { public static boolean isRooted()
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
try {
File file = new File("/system/app/Superuser/Superuser.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
//SuperSU
try {
File file = new File("/system/app/SuperSU.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
try {
File file = new File("/system/app/SuperSU/SuperSU.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
}
catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}
private static boolean findForcemount(){
try
{ {
File file = new File(System.getenv("EXTERNAL_STORAGE")+"/forcemount"); // get from build info
if (file.exists()) String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys"))
{ {
return true; return true;
} }
}
catch (Exception e1) // check if /system/app/Superuser.apk is present
try
{
File file = new File("/system/app/Superuser.apk");
if (file.exists())
{
return true;
}
} catch (Exception e1)
{
// ignore
}
try
{
File file = new File("/system/app/Superuser/Superuser.apk");
if (file.exists())
{
return true;
}
} catch (Exception e1)
{
// ignore
}
//SuperSU
try
{
File file = new File("/system/app/SuperSU.apk");
if (file.exists())
{
return true;
}
} catch (Exception e1)
{
// ignore
}
try
{
File file = new File("/system/app/SuperSU/SuperSU.apk");
if (file.exists())
{
return true;
}
} catch (Exception e1)
{
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command)
{ {
boolean executedSuccesfully;
try
{
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
} catch (Exception e)
{
executedSuccesfully = false;
}
return executedSuccesfully;
}
private static boolean findForcemount()
{
Log.d(TAG, "findForcemount()");
try
{
File file = new File(System.getenv("EXTERNAL_STORAGE") + "/forcemount");
if (file.exists())
{
return true;
}
} catch (Exception e)
{
Log.w(TAG, e.getMessage());
return false;
}
return false; return false;
} }
return false;
}
} }

View File

@@ -14,8 +14,6 @@ import java.net.URLConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext; import javax.microedition.khronos.egl.EGLContext;
@@ -68,12 +66,11 @@ import android.widget.FrameLayout.LayoutParams;
*/ */
public class SDLActivity extends Activity implements OnKeyListener public class SDLActivity extends Activity implements OnKeyListener
{ {
private static final String TAG = SDLActivity.class.getCanonicalName();
//import deck globals //import deck globals
public ArrayList<String> myresult = new ArrayList<String>(); public ArrayList<String> myresult = new ArrayList<String>();
public String myclickedItem = ""; public String myclickedItem = "";
// TAG used for debugging in DDMS
public static String TAG = Activity.class.getCanonicalName();
// Main components // Main components
private static SDLActivity mSingleton; private static SDLActivity mSingleton;
@@ -352,7 +349,7 @@ public class SDLActivity extends Activity implements OnKeyListener
updateStorageLocations(); updateStorageLocations();
} catch (Exception ioex) } catch (Exception ioex)
{ {
Log.e("SDL", "An error occurred in setting up the storage locations."); Log.e(TAG, "An error occurred in setting up the storage locations.");
} }
} }
@@ -497,14 +494,12 @@ public class SDLActivity extends Activity implements OnKeyListener
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
// Log.v("SDL", "onCreate()"); //Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// So we can call stuff from static callbacks // So we can call stuff from static callbacks
mSingleton = this; mSingleton = this;
mContext = this.getApplicationContext(); mContext = this.getApplicationContext();
// get the current version of the app to set the core filename
String versionCodeString = getApplicationCode();
RES_FILENAME = getResourceName(); RES_FILENAME = getResourceName();
StorageOptions.determineStorageOptions(); StorageOptions.determineStorageOptions();
@@ -532,7 +527,7 @@ public class SDLActivity extends Activity implements OnKeyListener
@Override @Override
protected void onPause() protected void onPause()
{ {
// Log.v("SDL", "onPause()"); // Log.d(TAG, "onPause()");
super.onPause(); super.onPause();
SDLActivity.nativePause(); SDLActivity.nativePause();
} }
@@ -540,7 +535,7 @@ public class SDLActivity extends Activity implements OnKeyListener
@Override @Override
protected void onResume() protected void onResume()
{ {
// Log.v("SDL", "onResume()"); // Log.d(TAG, "onResume()");
super.onResume(); super.onResume();
SDLActivity.nativeResume(); SDLActivity.nativeResume();
} }
@@ -548,8 +543,7 @@ public class SDLActivity extends Activity implements OnKeyListener
@Override @Override
public void onDestroy() public void onDestroy()
{ {
// Log.v("SDL", "onDestroy()"); // Log.d(TAG, "onDestroy()");
super.onDestroy(); super.onDestroy();
mSurface.onDestroy(); mSurface.onDestroy();
} }
@@ -660,7 +654,7 @@ public class SDLActivity extends Activity implements OnKeyListener
int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT;
int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1);
// Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); // Log.d(TAG, "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer");
// Let the user pick a larger buffer if they really want -- but ye // Let the user pick a larger buffer if they really want -- but ye
// gods they probably shouldn't, the minimums are horrifyingly high // gods they probably shouldn't, the minimums are horrifyingly high
@@ -671,7 +665,7 @@ public class SDLActivity extends Activity implements OnKeyListener
audioStartThread(); audioStartThread();
// Log.v("SDL", "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + ((float)mAudioTrack.getSampleRate() / 1000f) + // Log.d(TAG, "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + ((float)mAudioTrack.getSampleRate() / 1000f) +
// "kHz, " + desiredFrames + " frames buffer"); // "kHz, " + desiredFrames + " frames buffer");
if (is16Bit) if (is16Bit)
@@ -719,7 +713,7 @@ public class SDLActivity extends Activity implements OnKeyListener
} }
} else } else
{ {
Log.w("SDL", "SDL audio: error return from write(short)"); Log.w(TAG, "SDL audio: error return from write(short)");
return; return;
} }
} }
@@ -744,7 +738,7 @@ public class SDLActivity extends Activity implements OnKeyListener
} }
} else } else
{ {
Log.w("SDL", "SDL audio: error return from write(short)"); Log.w(TAG, "SDL audio: error return from write(short)");
return; return;
} }
} }
@@ -759,11 +753,11 @@ public class SDLActivity extends Activity implements OnKeyListener
mAudioThread.join(); mAudioThread.join();
} catch (Exception e) } catch (Exception e)
{ {
Log.v("SDL", "Problem stopping audio thread: " + e); Log.e(TAG, "Problem stopping audio thread: " + e);
} }
mAudioThread = null; mAudioThread = null;
// Log.v("SDL", "Finished waiting for audio thread"); // Log.d(TAG, "Finished waiting for audio thread");
} }
if (mAudioTrack != null) if (mAudioTrack != null)
@@ -775,7 +769,7 @@ public class SDLActivity extends Activity implements OnKeyListener
class DownloadFileAsync extends AsyncTask<String, Integer, Long> class DownloadFileAsync extends AsyncTask<String, Integer, Long>
{ {
final String TAG1 = DownloadFileAsync.class.getCanonicalName(); private final String TAG = DownloadFileAsync.class.getCanonicalName();
@Override @Override
protected void onPreExecute() protected void onPreExecute()
@@ -794,7 +788,6 @@ public class SDLActivity extends Activity implements OnKeyListener
try try
{ {
// //
// Prepare the sdcard folders in order to download the resource file // Prepare the sdcard folders in order to download the resource file
// //
@@ -815,7 +808,7 @@ public class SDLActivity extends Activity implements OnKeyListener
conexion.connect(); conexion.connect();
int lengthOfFile = conexion.getContentLength(); int lengthOfFile = conexion.getContentLength();
// Log.d("Wagic - " + TAG1, " Length of file: " + lengthOfFile); // Log.d(TAG, " Length of file: " + lengthOfFile);
input = new BufferedInputStream(url.openStream()); input = new BufferedInputStream(url.openStream());
// create a File object for the output file // create a File object for the output file
@@ -838,8 +831,8 @@ public class SDLActivity extends Activity implements OnKeyListener
{ {
String errorMessage = "An error happened while downloading the resources. It could be that our server is temporarily down, that your device is not connected to a network, or that we cannot write to " + mSingleton.getSystemStorageLocation() + ". Please check your phone settings and try again. For more help please go to http://wagic.net"; String errorMessage = "An error happened while downloading the resources. It could be that our server is temporarily down, that your device is not connected to a network, or that we cannot write to " + mSingleton.getSystemStorageLocation() + ". Please check your phone settings and try again. For more help please go to http://wagic.net";
mSingleton.downloadError(errorMessage); mSingleton.downloadError(errorMessage);
Log.e(TAG1, errorMessage); Log.e(TAG, errorMessage);
Log.e(TAG1, e.getMessage()); Log.e(TAG, e.getMessage());
} }
return Long.valueOf(totalBytes); return Long.valueOf(totalBytes);
@@ -849,7 +842,7 @@ public class SDLActivity extends Activity implements OnKeyListener
{ {
if (progress[0] != mProgressDialog.getProgress()) if (progress[0] != mProgressDialog.getProgress())
{ {
// Log.d("Wagic - " + TAG1, "current progress : " + progress[0]); // Log.d(TAG, "current progress : " + progress[0]);
mProgressDialog.setProgress(progress[0]); mProgressDialog.setProgress(progress[0]);
} }
} }
@@ -922,6 +915,7 @@ public class SDLActivity extends Activity implements OnKeyListener
*/ */
class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnKeyListener, View.OnTouchListener, SensorEventListener class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnKeyListener, View.OnTouchListener, SensorEventListener
{ {
private static final String TAG = SDLSurface.class.getCanonicalName();
// This is what SDL runs in. It invokes SDL_main(), eventually // This is what SDL runs in. It invokes SDL_main(), eventually
private Thread mSDLThread; private Thread mSDLThread;
@@ -961,7 +955,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
SDLActivity.nativeQuit(); SDLActivity.nativeQuit();
Log.v("SDL", "SDL thread terminated"); Log.d(TAG, "SDL thread terminated");
// On exit, tear everything down for a fresh restart next time. // On exit, tear everything down for a fresh restart next time.
System.exit(0); System.exit(0);
@@ -988,7 +982,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
// Called when we have a valid drawing surface // Called when we have a valid drawing surface
public void surfaceCreated(SurfaceHolder holder) public void surfaceCreated(SurfaceHolder holder)
{ {
Log.v("SDL", "surfaceCreated()"); //Log.d(TAG, "surfaceCreated()");
enableSensor(Sensor.TYPE_ACCELEROMETER, true); enableSensor(Sensor.TYPE_ACCELEROMETER, true);
} }
@@ -1008,18 +1002,18 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
mSDLThread.join(); mSDLThread.join();
} catch (Exception e) } catch (Exception e)
{ {
Log.v("SDL", "Problem stopping thread: " + e); Log.e(TAG, "Problem stopping thread: " + e);
} }
mSDLThread = null; mSDLThread = null;
// Log.v("SDL", "Finished waiting for SDL thread"); // Log.d(TAG, "Finished waiting for SDL thread");
} }
} }
// Called when we lose the surface // Called when we lose the surface
public void surfaceDestroyed(SurfaceHolder holder) public void surfaceDestroyed(SurfaceHolder holder)
{ {
Log.v("SDL", "surfaceDestroyed()"); Log.d(TAG, "surfaceDestroyed()");
synchronized (mSemSurface) synchronized (mSemSurface)
{ {
mSurfaceValid = false; mSurfaceValid = false;
@@ -1031,51 +1025,51 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
// Called when the surface is resized // Called when the surface is resized
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{ {
Log.d("SDL", "surfaceChanged()"); Log.d(TAG, "surfaceChanged()");
int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default
switch (format) switch (format)
{ {
case PixelFormat.A_8: case PixelFormat.A_8:
Log.d("SDL", "pixel format A_8"); Log.d("TAG", "pixel format A_8");
break; break;
case PixelFormat.LA_88: case PixelFormat.LA_88:
Log.d("SDL", "pixel format LA_88"); Log.d("TAG", "pixel format LA_88");
break; break;
case PixelFormat.L_8: case PixelFormat.L_8:
Log.d("SDL", "pixel format L_8"); Log.d("TAG", "pixel format L_8");
break; break;
case PixelFormat.RGBA_4444: case PixelFormat.RGBA_4444:
Log.d("SDL", "pixel format RGBA_4444"); Log.d("TAG", "pixel format RGBA_4444");
sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444 sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
break; break;
case PixelFormat.RGBA_5551: case PixelFormat.RGBA_5551:
Log.d("SDL", "pixel format RGBA_5551"); Log.d(TAG, "pixel format RGBA_5551");
sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551 sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
break; break;
case PixelFormat.RGBA_8888: case PixelFormat.RGBA_8888:
Log.d("SDL", "pixel format RGBA_8888"); Log.d(TAG, "pixel format RGBA_8888");
sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888
break; break;
case PixelFormat.RGBX_8888: case PixelFormat.RGBX_8888:
Log.d("SDL", "pixel format RGBX_8888"); Log.d(TAG, "pixel format RGBX_8888");
sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888 sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888
break; break;
case PixelFormat.RGB_332: case PixelFormat.RGB_332:
Log.d("SDL", "pixel format RGB_332"); Log.d(TAG, "pixel format RGB_332");
sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332 sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332
break; break;
case PixelFormat.RGB_565: case PixelFormat.RGB_565:
Log.d("SDL", "pixel format RGB_565"); Log.d(TAG, "pixel format RGB_565");
sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565
break; break;
case PixelFormat.RGB_888: case PixelFormat.RGB_888:
Log.d("SDL", "pixel format RGB_888"); Log.d(TAG, "pixel format RGB_888");
// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888 sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888
break; break;
default: default:
Log.d("SDL", "pixel format unknown " + format); Log.d(TAG, "pixel format unknown " + format);
break; break;
} }
SDLActivity.onNativeResize(width, height, sdlFormat); SDLActivity.onNativeResize(width, height, sdlFormat);
@@ -1092,11 +1086,10 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
// EGL functions // EGL functions
public boolean initEGL(int majorVersion, int minorVersion) public boolean initEGL(int majorVersion, int minorVersion)
{ {
Log.d("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion); Log.d(TAG, "Starting up OpenGL ES " + majorVersion + "." + minorVersion);
try try
{ {
EGL10 egl = (EGL10) EGLContext.getEGL(); EGL10 egl = (EGL10) EGLContext.getEGL();
EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
@@ -1122,7 +1115,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
int[] num_config = new int[1]; int[] num_config = new int[1];
if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0)
{ {
Log.e("SDL", "No EGL config available"); Log.e(TAG, "No EGL config available");
return false; return false;
} }
mEGLConfig = configs[0]; mEGLConfig = configs[0];
@@ -1130,7 +1123,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
EGLContext ctx = egl.eglCreateContext(dpy, mEGLConfig, EGL10.EGL_NO_CONTEXT, null); EGLContext ctx = egl.eglCreateContext(dpy, mEGLConfig, EGL10.EGL_NO_CONTEXT, null);
if (ctx == EGL10.EGL_NO_CONTEXT) if (ctx == EGL10.EGL_NO_CONTEXT)
{ {
Log.e("SDL", "Couldn't create context"); Log.e(TAG, "Couldn't create context");
return false; return false;
} }
@@ -1144,10 +1137,10 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
} catch (Exception e) } catch (Exception e)
{ {
Log.e("SDL", e + ""); Log.e(TAG, e + "");
for (StackTraceElement s : e.getStackTrace()) for (StackTraceElement s : e.getStackTrace())
{ {
Log.e("SDL", s.toString()); Log.e(TAG, s.toString());
} }
} }
@@ -1162,7 +1155,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
EGL10 egl = (EGL10) EGLContext.getEGL(); EGL10 egl = (EGL10) EGLContext.getEGL();
if (mEGLSurface != null) if (mEGLSurface != null)
{ {
/* /*
* Unbind and destroy the old EGL surface, if there is one. * Unbind and destroy the old EGL surface, if there is one.
*/ */
@@ -1176,7 +1168,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
mEGLSurface = egl.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, holder, null); mEGLSurface = egl.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, holder, null);
if (mEGLSurface == EGL10.EGL_NO_SURFACE) if (mEGLSurface == EGL10.EGL_NO_SURFACE)
{ {
Log.e("SDL", "Couldn't create surface"); Log.e(TAG, "Couldn't create surface");
return false; return false;
} }
@@ -1185,7 +1177,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
*/ */
if (!egl.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) if (!egl.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext))
{ {
Log.e("SDL", "Couldn't make context current"); Log.e(TAG, "Couldn't make context current");
return false; return false;
} }
@@ -1197,7 +1189,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
// EGL buffer flip // EGL buffer flip
public void flipEGL() public void flipEGL()
{ {
if (!mSurfaceValid) if (!mSurfaceValid)
{ {
createSurface(this.getHolder()); createSurface(this.getHolder());
@@ -1207,7 +1198,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
{ {
EGL10 egl = (EGL10) EGLContext.getEGL(); EGL10 egl = (EGL10) EGLContext.getEGL();
egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null); egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null);
// drawing here // drawing here
@@ -1217,13 +1208,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
} catch (Exception e) } catch (Exception e)
{ {
Log.e("SDL", "flipEGL(): " + e); Log.e(TAG, "flipEGL(): " + e);
for (StackTraceElement s : e.getStackTrace()) for (StackTraceElement s : e.getStackTrace())
{ {
Log.e("SDL", s.toString()); Log.e(TAG, s.toString());
} }
} }
} }
// Key events // Key events
@@ -1234,14 +1224,15 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
return false; return false;
if (event.getAction() == KeyEvent.ACTION_DOWN) if (event.getAction() == KeyEvent.ACTION_DOWN)
{ {
// Log.d("SDL", "key down: " + keyCode); // Log.d(TAG, "key down: " + keyCode);
SDLActivity.onNativeKeyDown(keyCode); SDLActivity.onNativeKeyDown(keyCode);
return true; return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) } else if (event.getAction() == KeyEvent.ACTION_UP)
{ {
// Log.d("SDL", "key up: " + keyCode); // Log.d(TAG, "key up: " + keyCode);
SDLActivity.onNativeKeyUp(keyCode); SDLActivity.onNativeKeyUp(keyCode);
return true; return true;
} }
@@ -1252,7 +1243,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnK
// Touch events // Touch events
public boolean onTouch(View v, MotionEvent event) public boolean onTouch(View v, MotionEvent event)
{ {
for (int index = 0; index < event.getPointerCount(); ++index) for (int index = 0; index < event.getPointerCount(); ++index)
{ {
int action = event.getActionMasked(); int action = event.getActionMasked();