From 5a39746b2a2876357e24dcbf4eec93a80339e26f Mon Sep 17 00:00:00 2001 From: pelya Date: Wed, 20 Oct 2010 17:04:00 +0300 Subject: [PATCH] Added support for showing publisher logo at startup screen (we have to show button "Change phone config" there anyway). Guys from Korean market asked to show game rating (an image with text "18+" and some more korean text) in startup screen, so I've added more-less generic solution. --- project/jni/Application.mk | 4 +- project/jni/application/Android.mk | 3 + project/jni/sdl_mixer/Android.mk | 15 +++- project/res/drawable/publisherlogo.png | Bin 0 -> 2922 bytes project/src/AssetExtract.java | 105 ------------------------- project/src/MainActivity.java | 105 +++++++++++++++++++++++-- project/src/Settings.java | 80 +++---------------- 7 files changed, 129 insertions(+), 183 deletions(-) create mode 100644 project/res/drawable/publisherlogo.png delete mode 100644 project/src/AssetExtract.java diff --git a/project/jni/Application.mk b/project/jni/Application.mk index d6f8e8666..ad90e0480 100644 --- a/project/jni/Application.mk +++ b/project/jni/Application.mk @@ -1,8 +1,8 @@ APP_PROJECT_PATH := $(call my-dir)/.. -# Available libraries: mad sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx intl xml2 lua jpeg png tremor freetype xerces +# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces -APP_MODULES := application sdl-1.2 sdl_main stlport tremor png jpeg freetype xerces sdl_mixer sdl_image sdl_ttf intl lua png xerces +APP_MODULES := application sdl-1.2 sdl_main stlport ogg flac tremor vorbis png jpeg freetype xerces sdl_mixer sdl_image sdl_ttf intl lua png xerces # To filter out static libs from all libs in makefile APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces diff --git a/project/jni/application/Android.mk b/project/jni/application/Android.mk index f1be9f8f2..8d3af1e3b 100644 --- a/project/jni/application/Android.mk +++ b/project/jni/application/Android.mk @@ -35,6 +35,9 @@ LOCAL_CFLAGS += \ -I$(LOCAL_PATH)/../xml2/include \ -I$(LOCAL_PATH)/../xerces/src \ -I$(LOCAL_PATH)/../lua/src \ + -I$(LOCAL_PATH)/../flac/include \ + -I$(LOCAL_PATH)/../ogg/include \ + -I$(LOCAL_PATH)/../vorbis/include \ -I$(LOCAL_PATH)/.. LOCAL_CFLAGS += $(APPLICATION_ADDITIONAL_CFLAGS) diff --git a/project/jni/sdl_mixer/Android.mk b/project/jni/sdl_mixer/Android.mk index 1c52c0d2c..308c65da6 100644 --- a/project/jni/sdl_mixer/Android.mk +++ b/project/jni/sdl_mixer/Android.mk @@ -4,15 +4,24 @@ include $(CLEAR_VARS) LOCAL_MODULE := sdl_mixer -LOCAL_CFLAGS := -I$(LOCAL_PATH) -I$(LOCAL_PATH)/.. -I$(LOCAL_PATH)/../sdl-$(SDL_VERSION)/include -I$(LOCAL_PATH)/../mad \ - -DWAV_MUSIC -DOGG_USE_TREMOR -DOGG_MUSIC +LOCAL_CFLAGS := -I$(LOCAL_PATH) -I$(LOCAL_PATH)/.. -I$(LOCAL_PATH)/../sdl-$(SDL_VERSION)/include \ + -I$(LOCAL_PATH)/../mad -I$(LOCAL_PATH)/../flac/include -I$(LOCAL_PATH)/../ogg/include -I$(LOCAL_PATH)/../vorbis/include \ + -DWAV_MUSIC -DOGG_USE_TREMOR -DOGG_MUSIC -DFLAC_MUSIC LOCAL_CPP_EXTENSION := .cpp LOCAL_SRC_FILES := $(notdir $(wildcard $(LOCAL_PATH)/*.c)) LOCAL_SHARED_LIBRARIES := sdl-$(SDL_VERSION) -LOCAL_STATIC_LIBRARIES := tremor +LOCAL_STATIC_LIBRARIES := flac + +ifeq "$(TARGET_ARCH_ABI)" "armeabi" +LOCAL_CFLAGS += -DOGG_USE_TREMOR +LOCAL_STATIC_LIBRARIES += tremor +else +LOCAL_STATIC_LIBRARIES += vorbis +endif +LOCAL_STATIC_LIBRARIES += ogg ifneq ($(SDL_MIXER_USE_LIBMAD),) LOCAL_CFLAGS += -DMP3_MAD_MUSIC diff --git a/project/res/drawable/publisherlogo.png b/project/res/drawable/publisherlogo.png new file mode 100644 index 0000000000000000000000000000000000000000..706617815a625b997e165e919966eec08d2ad58a GIT binary patch literal 2922 zcmeAS@N?(olHy`uVBq!ia0y~yVANq?U^v0S#=yW3bpK8$0|NtNage(c!@6@aFBupZ z*pj^6T^PXNr}OT51_lPs0*}aI1_o|n5N2eUHAjMhfq}im)7O>#7MBPgvyjCGCq@Pa z2FViFh!W@g+}zZ>5(ej@)Wnk16ovB4k_-iRPv3y>Mm}){2Ck!?E{-7;x8B}~&4^BA zX#Z#)J$b{tFUH6S`eyFsdl9*TA}snj z`fR%+&2L@xYCU9ie8M4}?Cj@D;xF*4c}4ZAt@K`9zh3CtvX|#P`!;Sq&tEio?w(EZk57smo|$Wq=q+UB*GC81<7Lrz)b= z*Oxyo{r^>J!~RGX?TwGiEA%TGxcNMcUG1mV3`8+Bj;=-v@ zr`po@m)(nZbZoS;vJ&BI|9V`$e#Pq5-b2>{k>l%sbm%u7^r`?{CWDu z)vHs5IvyYISKn@3{q2pc^P`UyCC|>x+;Y3Ow|C`+4F;+2xW)Bu?2Fm{`QJ6^{JcEB z?{|v*!w#M*xwG~B%}8(cQ&ayntf~hUJ9$JtBdlmJ^lPM zBrtH{%a@s+m)PZNCWLMgk+_^4dhm*B}NDl%GK`1Vcyx@+fNTC8KuuB?olG-dkq z>EFJ_tq-5HWzU{B8VZ$_m742Mr`eh7bIz}Nwem@^s;cUwB_1l1YVE9XT9#s^JkLNE*sA|@;ysiTl-{u?7FzUTAo#pI@LGX z@zwwTTmI?vnfk|*3_ivmxqUuoe%-H^b7F*Ufz$li(()?LiWe6aZm}0yyH{n+%9W8@ zV{>zJ!yc!7lKa1QYq3>d_Vku%shLShPLoVbOqT50WfeJX>7PF}SFc>j$jCVHtv14L zzCXYHpAAyd(wFbGPd!_+lP4@betuSVc537_rpAUoS?g&LIAr>3T!e6M(E?Zml-Z`W*`3yrqr@w?ic6lJYSJf@|d+@vFG zS7TARbM}v-J!{wM{*=_y*Pnj058!lNEKRdJPx@ukL#^UNjZolu}ygBn@F7NjLG4tMiYkqvZ ze|gU3yLb0Kl)5Q-{hZY8Sa0?8{dsG5Prfas7r$>#*}BHY#wYq2s;a8LUM`;>wC(4o z)B3@6K1D|Bqz@Jqzn#?4%^%|h z5jx9u?zF7^dNsW2^I7xjdkwGj{wxw)^Y{1n*LQXnbG14}#l>Cw@@31t`u~5Y=m+&0 zS`|EKu(Gx`wYOhiVY4nmXW7P$hPB^rrgO11Z~ONDAiMmPoyE_$Y}hbikIk0f|G2oh zuim@2?&wihS0%yH^77Xc-Q^;;u08%Z(A&G)Y2k#r|9{Kp+SOXU?d|b9wsrHdvg?;# zKHVk#`rVVwkH7!EdgaQJi4z5Nb#*nxx-(N!T=Mt-E%OSItA1nn_1iZssa`D^zSWBt zJNMiDTA}iCdVJl^r#ASm z+P(XBNLZNE{`>h|U0r7`E_OfbE?=9{WBBaP&(G0CzBZkgb#i<=|I7Byoj>E_eVN%? z+uGWEQd5_99)BF2=WB78$!z8G`Stg{eE&YXz#`|-#~m|g%`#fMcI~oVyQ;j8bs6h0 z%t>TqILPF%fuSLR`V55#28hYjWk6bY4jZ7YJ8ChIn~OPN{~7AJ1hxeKR$Risz`)?? L>gTe~DWM4fpjRq# literal 0 HcmV?d00001 diff --git a/project/src/AssetExtract.java b/project/src/AssetExtract.java deleted file mode 100644 index 91623c035..000000000 --- a/project/src/AssetExtract.java +++ /dev/null @@ -1,105 +0,0 @@ -// This string is autogenerated by ChangeAppSettings.sh, do not change -// spaces amount -package org.enigmagame.enigma; - -import java.util.zip.*; -import java.io.*; -import android.util.Log; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; - -import android.content.res.AssetManager; - -class AssetExtract { - - private AssetManager mAssetManager = null; - - AssetExtract(AssetManager am) { - mAssetManager = am; - } - - - public boolean extract(String asset, String target) { - - byte buf[] = new byte[1024 * 1024]; - - InputStream assetStream = null; - - try { - assetStream = mAssetManager.open(asset, AssetManager.ACCESS_RANDOM); - } catch (IOException e) { - // TODO: Report error. - return false; - } - - ZipInputStream zip = new ZipInputStream(assetStream); - - while (true) { - ZipEntry entry = null; - - try { - entry = zip.getNextEntry(); - } catch ( java.io.IOException e ) { - // Todo: Error out. - return false; - } - - if ( entry == null ) { - break; - } - - Log.i("AssetExtract", "Extracting " + entry.getName()); - - if (entry.isDirectory()) { - - try { - new File(target +"/" + entry.getName()).mkdirs(); - } catch ( SecurityException e ) { }; - - continue; - } - - OutputStream out = null; - - String path = target + "/" + entry.getName(); - - try { - out = new FileOutputStream( path ); - } catch ( FileNotFoundException e ) { - } catch ( SecurityException e ) { }; - if ( out == null ) { - // TODO: Error. - return false; - } - - try { - while (true) { - int len = zip.read(buf); - - if (len == -1) { - break; - } - - out.write(buf, 0, len); - } - - out.flush(); - out.close(); - } catch ( java.io.IOException e ) { - // TODO: Deal w/ error. - return false; - } - } - - try { - zip.close(); - assetStream.close(); - } catch (IOException e) { - // pass - } - - return true; - } -} diff --git a/project/src/MainActivity.java b/project/src/MainActivity.java index 4a372cd7c..7288b45f7 100644 --- a/project/src/MainActivity.java +++ b/project/src/MainActivity.java @@ -8,7 +8,12 @@ import android.view.MotionEvent; import android.view.KeyEvent; import android.view.Window; import android.view.WindowManager; +import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; import android.content.res.Configuration; @@ -25,27 +30,110 @@ public class MainActivity extends Activity { getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - _tv = new TextView(this); - _tv.setText(R.string.init); - setContentView(_tv); + System.out.println("libSDL: Creating startup screen"); + _layout = new LinearLayout(this); + _layout.setOrientation(LinearLayout.VERTICAL); + _layout.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); + _layout2 = new LinearLayout(this); + _layout2.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + + _btn = new Button(this); + _btn.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + _btn.setText(getResources().getString(R.string.device_change_cfg)); + class onClickListener implements View.OnClickListener + { + public MainActivity p; + onClickListener( MainActivity _p ) { p = _p; } + public void onClick(View v) + { + System.out.println("libSDL: User clicked change phone config button"); + Settings.showConfig(p); + } + }; + _btn.setOnClickListener(new onClickListener(this)); + + _layout2.addView(_btn); + + _layout.addView(_layout2); + + ImageView img = new ImageView(this); + + img.setScaleType(ImageView.ScaleType.FIT_CENTER /* FIT_XY */ ); + img.setImageResource(R.drawable.publisherlogo); + img.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); + _layout.addView(img); + + setContentView(_layout); + if(mAudioThread == null) // Starting from background (should not happen) { + System.out.println("libSDL: Loading libraries"); mLoadLibraryStub = new LoadLibrary(); mAudioThread = new AudioThread(this); + System.out.println("libSDL: Loading settings"); Settings.Load(this); } + + if( !Settings.settingsChanged ) + { + System.out.println("libSDL: 3-second timeout in startup screen"); + class Callback implements Runnable + { + MainActivity p; + Callback( MainActivity _p ) { p = _p; } + public void run() + { + try { + Thread.sleep(3000); + } catch( InterruptedException e ) {}; + if( Settings.settingsChanged ) + return; + System.out.println("libSDL: Timeout reached in startup screen, process with downloader"); + p.startDownloader(); + } + }; + Thread changeConfigAlertThread = null; + changeConfigAlertThread = new Thread(new Callback(this)); + changeConfigAlertThread.start(); + } } - + public void startDownloader() { - if( downloader == null ) - downloader = new DataDownloader(this, _tv); + System.out.println("libSDL: Starting data downloader"); + class Callback implements Runnable + { + public MainActivity Parent; + public void run() + { + System.out.println("libSDL: Removing button from startup screen and adding status text"); + if( Parent._btn != null ) + { + Parent._layout2.removeView(Parent._btn); + Parent._btn = null; + } + if( Parent._tv == null ) + { + Parent._tv = new TextView(Parent); + Parent._tv.setText(R.string.init); + Parent._layout2.addView(Parent._tv); + } + + System.out.println("libSDL: Starting downloader"); + if( Parent.downloader == null ) + Parent.downloader = new DataDownloader(Parent, Parent._tv); + } + } + Callback cb = new Callback(); + cb.Parent = this; + this.runOnUiThread(cb); } public void initSDL() { if(sdlInited) return; + System.out.println("libSDL: Initializing video and SDL application"); sdlInited = true; if(Globals.UseAccelerometerAsArrowKeys) getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, @@ -126,6 +214,8 @@ public class MainActivity extends Activity { public boolean dispatchTouchEvent(final MotionEvent ev) { if(mGLView != null) mGLView.onTouchEvent(ev); + else if( _btn != null ) + return _btn.dispatchTouchEvent(ev); return true; } @@ -158,6 +248,9 @@ public class MainActivity extends Activity { private static AudioThread mAudioThread = null; private static DataDownloader downloader = null; private TextView _tv = null; + private Button _btn = null; + private LinearLayout _layout = null; + private LinearLayout _layout2 = null; private boolean sdlInited = false; } diff --git a/project/src/Settings.java b/project/src/Settings.java index 60278019f..9bff5d278 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -28,9 +28,8 @@ class Settings { static String SettingsFileName = "libsdl-settings.cfg"; - static AlertDialog changeConfigAlert = null; - static Thread changeConfigAlertThread = null; static boolean settingsLoaded = false; + static boolean settingsChanged = false; static void Save(final MainActivity p) { @@ -43,6 +42,7 @@ class Settings out.writeBoolean(Globals.UseTouchscreenKeyboard); out.writeInt(Globals.TouchscreenKeyboardSize); out.writeInt(Globals.AccelerometerSensitivity); + out.writeInt(Globals.AccelerometerCenterPos); out.writeInt(Globals.TrackballDampening); out.writeInt(Globals.AudioBufferConfig); out.writeInt(Globals.OptionalDataDownload.length); @@ -61,9 +61,9 @@ class Settings { if(settingsLoaded) // Prevent starting twice { - startDownloader(p); return; } + System.out.println("libSDL: Settings.Load(): enter"); try { ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName )); Globals.DownloadToSdcard = settingsFile.readBoolean(); @@ -73,6 +73,7 @@ class Settings Globals.UseTouchscreenKeyboard = settingsFile.readBoolean(); Globals.TouchscreenKeyboardSize = settingsFile.readInt(); Globals.AccelerometerSensitivity = settingsFile.readInt(); + Globals.AccelerometerCenterPos = settingsFile.readInt(); Globals.TrackballDampening = settingsFile.readInt(); Globals.AudioBufferConfig = settingsFile.readInt(); Globals.OptionalDataDownload = new boolean[settingsFile.readInt()]; @@ -81,54 +82,9 @@ class Settings Globals.TouchscreenKeyboardTheme = settingsFile.readInt(); settingsLoaded = true; + + System.out.println("libSDL: Settings.Load(): loaded settings successfully"); - AlertDialog.Builder builder = new AlertDialog.Builder(p); - builder.setTitle(p.getResources().getString(R.string.device_config)); - builder.setPositiveButton(p.getResources().getString(R.string.device_change_cfg), - new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int item) - { - changeConfigAlert = null; - dialog.dismiss(); - showDownloadConfig(p); - } - }); - /* - builder.setNegativeButton("Start", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int item) - { - changeConfigAlert = null; - dialog.dismiss(); - startDownloader(p); - } - }); - */ - AlertDialog alert = builder.create(); - alert.setOwnerActivity(p); - changeConfigAlert = alert; - - class Callback implements Runnable - { - MainActivity p; - Callback( MainActivity _p ) { p = _p; } - public void run() - { - try { - Thread.sleep(2000); - } catch( InterruptedException e ) {}; - if( changeConfigAlert == null ) - return; - changeConfigAlert.dismiss(); - startDownloader(p); - } - }; - changeConfigAlertThread = new Thread(new Callback(p)); - changeConfigAlertThread.start(); - - alert.show(); - return; } catch( FileNotFoundException e ) { @@ -156,6 +112,12 @@ class Settings "Unknown" ) ); */ + System.out.println("libSDL: Settings.Load(): loading settings failed, running config dialog"); + showConfig(p); + } + + public static void showConfig(final MainActivity p) { + settingsChanged = true; showDownloadConfig(p); } @@ -478,7 +440,7 @@ class Settings Globals.AudioBufferConfig = item; dialog.dismiss(); Save(p); - startDownloader(p); + p.startDownloader(); } }); AlertDialog alert = builder.create(); @@ -546,22 +508,6 @@ class Settings } } - static void startDownloader(MainActivity p) - { - class Callback implements Runnable - { - public MainActivity Parent; - public void run() - { - Parent.startDownloader(); - } - } - Callback cb = new Callback(); - cb.Parent = p; - p.runOnUiThread(cb); - }; - - private static native void nativeIsSdcardUsed(int flag); private static native void nativeSetTrackballUsed(); private static native void nativeSetTrackballDampening(int value);