Setting some env variables like app path and display physical size
This commit is contained in:
@@ -766,24 +766,32 @@ public class MainActivity extends Activity
|
||||
|
||||
// ----- VCMI hack -----
|
||||
try {
|
||||
//System.out.println("libSDL: Extracting VCMI server");
|
||||
//System.out.println("libSDL: Extracting binaries");
|
||||
|
||||
InputStream in = null;
|
||||
try
|
||||
{
|
||||
for( int i = 0; ; i++ )
|
||||
{
|
||||
InputStream in2 = getAssets().open("vcmiserver" + String.valueOf(i));
|
||||
InputStream in2 = getAssets().open("binaries.zip" + String.format("%02d", i));
|
||||
if( in == null )
|
||||
in = in2;
|
||||
else
|
||||
in = new SequenceInputStream( in, in2 );
|
||||
}
|
||||
}
|
||||
catch( IOException ee ) { }
|
||||
catch( IOException ee )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( in == null )
|
||||
in = getAssets().open("binaries.zip");
|
||||
}
|
||||
catch( IOException eee ) {}
|
||||
}
|
||||
|
||||
if( in == null )
|
||||
throw new RuntimeException("libSDL: Extracting VCMI server failed, the .apk file packaged incorrectly");
|
||||
throw new RuntimeException("libSDL: Extracting binaries failed, the .apk file packaged incorrectly");
|
||||
|
||||
ZipInputStream zip = new ZipInputStream(in);
|
||||
|
||||
@@ -803,7 +811,7 @@ public class MainActivity extends Activity
|
||||
*/
|
||||
if( entry == null )
|
||||
{
|
||||
System.out.println("Extracting libs finished");
|
||||
System.out.println("Extracting binaries finished");
|
||||
break;
|
||||
}
|
||||
if( entry.isDirectory() )
|
||||
|
||||
@@ -59,6 +59,7 @@ import android.text.SpannedString;
|
||||
import android.content.Intent;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.AlarmManager;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
// TODO: too much code here, split into multiple files, possibly auto-generated menus?
|
||||
class Settings
|
||||
@@ -2472,6 +2473,28 @@ class Settings
|
||||
nativeSetEnv( "LANG", lang );
|
||||
nativeSetEnv( "LANGUAGE", lang );
|
||||
// TODO: get current user name and set envvar USER, the API is not availalbe on Android 1.6 so I don't bother with this
|
||||
nativeSetEnv( "APPDIR", p.getFilesDir().getAbsolutePath() );
|
||||
nativeSetEnv( "SECURE_STORAGE_DIR", p.getFilesDir().getAbsolutePath() );
|
||||
nativeSetEnv( "DATADIR", Globals.DataDir );
|
||||
nativeSetEnv( "UNSECURE_STORAGE_DIR", Globals.DataDir );
|
||||
nativeSetEnv( "HOME", Globals.DataDir );
|
||||
try {
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
p.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
float xx = dm.widthPixels/dm.xdpi;
|
||||
float yy = dm.heightPixels/dm.ydpi;
|
||||
float x = Math.max(xx, yy);
|
||||
float y = Math.min(xx, yy);
|
||||
float displayInches = (float)Math.sqrt( x*x + y*y );
|
||||
nativeSetEnv( "DISPLAY_SIZE", String.valueOf(displayInches) );
|
||||
nativeSetEnv( "DISPLAY_SIZE_MM", String.valueOf((int)(displayInches*25.4f)) );
|
||||
nativeSetEnv( "DISPLAY_WIDTH", String.valueOf(x) );
|
||||
nativeSetEnv( "DISPLAY_HEIGHT", String.valueOf(y) );
|
||||
nativeSetEnv( "DISPLAY_WIDTH_MM", String.valueOf((int)(x*25.4f)) );
|
||||
nativeSetEnv( "DISPLAY_HEIGHT_MM", String.valueOf((int)(y*25.4f)) );
|
||||
nativeSetEnv( "DISPLAY_RESOLUTION_WIDTH", String.valueOf(Math.max(dm.widthPixels, dm.heightPixels)) );
|
||||
nativeSetEnv( "DISPLAY_RESOLUTION_HEIGHT", String.valueOf(Math.min(dm.widthPixels, dm.heightPixels)) );
|
||||
} catch (Exception eeeee) {}
|
||||
}
|
||||
|
||||
static byte [] loadRaw(Activity p, int res)
|
||||
|
||||
@@ -494,7 +494,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
// Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
|
||||
nativeInit( Globals.DataDir,
|
||||
Globals.CommandLine,
|
||||
( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacksVideo ) ? 1 : 0 );
|
||||
( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacksVideo ) ? 1 : 0,
|
||||
android.os.Debug.isDebuggerConnected() ? 1 : 0 );
|
||||
System.exit(0); // The main() returns here - I don't bother with deinit stuff, just terminate process
|
||||
}
|
||||
|
||||
@@ -649,7 +650,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
|
||||
|
||||
private native void nativeInitJavaCallbacks();
|
||||
private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo);
|
||||
private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo, int isDebuggerConnected);
|
||||
private native void nativeResize(int w, int h, int keepAspectRatio);
|
||||
private native void nativeDone();
|
||||
private native void nativeGlContextLost();
|
||||
|
||||
Reference in New Issue
Block a user