From 814db2bc425cccd64225bde37ce114754f473309 Mon Sep 17 00:00:00 2001 From: pelya Date: Sat, 21 Aug 2010 14:20:45 +0300 Subject: [PATCH] Possibility to change user config --- project/src/Audio.java | 2 +- project/src/MainActivity.java | 23 ++++++++++++++++++++--- project/src/Settings.java | 30 ++++++++++-------------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/project/src/Audio.java b/project/src/Audio.java index 72136aa04..8e2da1863 100644 --- a/project/src/Audio.java +++ b/project/src/Audio.java @@ -50,7 +50,7 @@ class AudioThread { if( AudioTrack.getMinBufferSize( rate, channels, encoding ) > bufSize ) bufSize = AudioTrack.getMinBufferSize( rate, channels, encoding ); - bufSize = bufSize * ((Globals.AudioBufferConfig * 2.5f) + 1.0f); + bufSize = (int)((float)bufSize * (((float)Globals.AudioBufferConfig * 2.5f) + 1.0f)); mAudioBuffer = new byte[bufSize]; diff --git a/project/src/MainActivity.java b/project/src/MainActivity.java index 799ae1841..5321c2f10 100644 --- a/project/src/MainActivity.java +++ b/project/src/MainActivity.java @@ -25,11 +25,10 @@ public class MainActivity extends Activity { _tv = new TextView(this); _tv.setText("Initializing"); setContentView(_tv); - - Settings.Load(this); - mLoadLibraryStub = new LoadLibrary(); mAudioThread = new AudioThread(this); + + Settings.Load(this); } public void startDownloader() @@ -126,6 +125,24 @@ public class MainActivity extends Activity { mGLView.onTouchEvent(ev); return true; } + + public void setText(final String t) + { + class Callback implements Runnable + { + public TextView Status; + public String text; + public void run() + { + if(Status != null) + Status.setText(text); + } + } + Callback cb = new Callback(); + cb.text = new String(t); + cb.Status = _tv; + this.runOnUiThread(cb); + } private DemoGLSurfaceView mGLView = null; private LoadLibrary mLoadLibraryStub = null; diff --git a/project/src/Settings.java b/project/src/Settings.java index 7888d413d..c1f6b08db 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -58,7 +58,7 @@ class Settings Globals.TrackballDampening = settingsFile.readInt(); Globals.AudioBufferConfig = settingsFile.readInt(); - /* + AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle("Phone configuration"); builder.setPositiveButton("Change phone configuration", new DialogInterface.OnClickListener() @@ -70,6 +70,7 @@ class Settings showDownloadConfig(p); } }); + /* builder.setNegativeButton("Start", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) @@ -79,6 +80,7 @@ class Settings startDownloader(p); } }); + */ AlertDialog alert = builder.create(); alert.setOwnerActivity(p); changeConfigAlert = alert; @@ -89,33 +91,21 @@ class Settings Callback( MainActivity _p ) { p = _p; } public void run() { - System.out.println("Change phone config: sleeping 2 sec"); try { - Thread.sleep(5000); + Thread.sleep(1500); } catch( InterruptedException e ) {}; if( changeConfigAlert == null ) return; - class Callback2 implements Runnable - { - public void run() - { - System.out.println("Change phone config: launching..."); - changeConfigAlert.dismiss(); // Does not work, eh - //changeConfigAlert.getButton(AlertDialog.BUTTON_NEGATIVE).dispatchTouchEvent(MotionEvent.obtain(0l, 0l, MotionEvent.ACTION_DOWN, 0.0f, 0.0f, 0)); - //changeConfigAlert.getButton(AlertDialog.BUTTON_NEGATIVE).dispatchTouchEvent(MotionEvent.obtain(0l, 0l, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0)); - } - } - p.runOnUiThread(new Callback2()); + changeConfigAlert.dismiss(); + startDownloader(p); } }; changeConfigAlertThread = new Thread(new Callback(p)); - changeConfigAlertThread.run(); + changeConfigAlertThread.start(); alert.show(); - */ - startDownloader(p); return; } catch( FileNotFoundException e ) { @@ -142,9 +132,9 @@ class Settings c.navigation == Configuration.NAVIGATION_NONAV ? "None" : "Unknown" ) ); */ - - showDownloadConfig(p); - } + + showDownloadConfig(p); + } static void showDownloadConfig(final MainActivity p) {