diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2015-12-04 05:20:56 +0100 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2015-12-04 05:20:56 +0100 |
| commit | 4cff31bfd20d305a7858c28ac2eee5d8d5839b74 (patch) | |
| tree | c3b8bee744a00b5880f922b6f35a62aac994e4d0 /app/src | |
| parent | 3f06aee05ac73d849cef45cc5de49268763f82da (diff) | |
Full Preference API10 Support!
New TTS.Engine structure
Diffstat (limited to 'app/src')
5 files changed, 145 insertions, 70 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05ca590..573fb0e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,6 +26,9 @@ <activity android:name="com.softwarefools.nik.spiritlevel.AppPreferences" android:screenOrientation="portrait" android:theme="@android:style/Theme" /> + <activity android:name="com.softwarefools.nik.spiritlevel.AppPreferencesClassic" + android:screenOrientation="portrait" + android:theme="@android:style/Theme" /> </application> </manifest> diff --git a/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferences.java b/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferences.java index 30be89a..859239e 100644 --- a/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferences.java +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferences.java @@ -4,20 +4,25 @@ import com.example.spiritlevel.R; /** * Created by nick on 01.12.15. */ +//import android.app.Fragment; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; +//import android.support.v7.preference.*; +//import android.support.v4.app.*; + public class AppPreferences extends PreferenceActivity { - public static final String PREFS_NAME = "MyPrefsFile"; + //public static final String PREFS_NAME = "MyPrefsFile"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit(); - +//getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit(); //Initialize the "up" button // getActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferencesClassic.java b/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferencesClassic.java new file mode 100644 index 0000000..bd347fa --- /dev/null +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/AppPreferencesClassic.java @@ -0,0 +1,20 @@ +package com.softwarefools.nik.spiritlevel; + +import android.os.Bundle; +import android.preference.PreferenceActivity; + +import com.example.spiritlevel.R; + +/** + * Created by nick on 04.12.15. + */ +public class AppPreferencesClassic extends PreferenceActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.settings); + } +} + diff --git a/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelActivity.java b/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelActivity.java index 5b618d0..36afe67 100644 --- a/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelActivity.java +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelActivity.java @@ -50,6 +50,8 @@ import android.view.Surface; import android.view.View; import android.widget.TextView; import android.widget.Toast; +import android.speech.tts.TextToSpeech; +import android.speech.tts.TextToSpeech.OnInitListener; //Toast.makeText(getBaseContext(), "Sometext", Toast.LENGTH_SHORT).show(); // Toast Vorlage @@ -57,11 +59,12 @@ public class LevelActivity extends Activity implements MySensorListener{ public static DecimalFormat f = new DecimalFormat("#0.000"); - public static final String PREFS_NAME = "MyPrefsFile"; + private int MY_DATA_CHECK_CODE = 0; + //public static final String PREFS_NAME = "MyPrefsFile"; - private SensorManager mSensorManager; - private Sensor mySensor; - private Sensor aSensor,gSensor; +// private SensorManager mSensorManager; +// private Sensor mySensor; + //private Sensor aSensor,gSensor; private LevelView levelView; private AppPreferences myprefs; @@ -78,6 +81,7 @@ public class LevelActivity extends Activity implements MySensorListener{ SharedPreferences mySettings; + private TextToSpeech myTTS; TextToSpeech t1; @@ -97,30 +101,32 @@ public class LevelActivity extends Activity implements MySensorListener{ SharedPreferences.Editor editor = mySettings.edit(); editor.putBoolean("applicationRecording", false); editor.commit(); - //Fragments - //getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).commit(); - /*FragmentManager mFragmentManager = getFragmentManager(); - FragmentTransaction mFragmentTransaction = mFragmentManager - .beginTransaction(); - PrefsFragment mPrefsFragment = new PrefsFragment(); - mFragmentTransaction.replace(android.R.id.content, mPrefsFragment); - mFragmentTransaction.commit();*/ - r = new Random(); - /*mysupplangs = new ArrayList<String>(); - mysupplangs.add("de"); - mysupplangs.add("en"); - mysupplangs.add("es"); - mysupplangs.add("pl"); - mysupplangs.add("ru"); - mysupplangs.add("fr"); - mysupplangs.add("it");*/ - - t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { + + accelvector= new Vector<nikVector>(); + gravvector = new Vector<nikVector>(); + + //TTS Engine + Intent checkTTSIntent = new Intent(); + checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); + startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE); + + myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() { + @Override + public void onInit(int status) { + if (status == TextToSpeech.SUCCESS){ + myTTS.setLanguage(getResources().getConfiguration().locale); + }else if (status == TextToSpeech.ERROR) { + Toast.makeText(getBaseContext(), getApplicationContext().getString(R.string.action_lang_NA), Toast.LENGTH_LONG).show(); + } + } + }); + //Simple TTS + /*t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { - if(status != TextToSpeech.ERROR) { + if(status >=TextToSpeech.LANG_AVAILABLE) { String setlang = mySettings.getString("applicationLanguage","xxx"); String comp = getResources().getConfiguration().locale.getLanguage(); if (!setlang.contains(comp)){ @@ -139,40 +145,55 @@ public class LevelActivity extends Activity implements MySensorListener{ }} //t1.setLanguage(getResources().getConfiguration().locale); - accelvector= new Vector<nikVector>(); - gravvector = new Vector<nikVector>(); + } - } }); + } });*/ setupActionBar(); - - //setContentView(R.layout.activity_level); - - // !TfT -- Show the Up button in the action bar. - - - //accelField = (TextView) findViewById(R.id.TextView_accelerometer); - //gravityField = (TextView) findViewById(R.id.TextView_gravity); - + + //! } + + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == MY_DATA_CHECK_CODE) { + if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { + myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() { + @Override + public void onInit(int status) { + if (status == TextToSpeech.SUCCESS){ + myTTS.setLanguage(getResources().getConfiguration().locale); + }else if (status == TextToSpeech.ERROR) { + Toast.makeText(getBaseContext(), getApplicationContext().getString(R.string.action_lang_NA), Toast.LENGTH_LONG).show(); + } + } + }); + } + else { + Intent installTTSIntent = new Intent(); + installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); + startActivity(installTTSIntent); + } + } + } @Override public void onResume() { super.onResume(); - // Toast.makeText(getBaseContext(), "onResume Sensors Started", Toast.LENGTH_SHORT).show(); + //Toast.makeText(getBaseContext(), "On Resume", Toast.LENGTH_SHORT).show(); // Toast Vorlage + // Toast.makeText(getBaseContext(), "onResume Sensors Started", Toast.LENGTH_SHORT).show(); String setlang = mySettings.getString("applicationLanguage","none"); String comp = getResources().getConfiguration().locale.getLanguage(); if (setlang.contains(comp)){ - //Toast.makeText(getBaseContext(), "Language is local", Toast.LENGTH_SHORT).show(); // Toast Vorlage + // Toast.makeText(getBaseContext(), "Language is local", Toast.LENGTH_SHORT).show(); // Toast Vorlage } else if (setlang=="none" ) { SharedPreferences.Editor editor = mySettings.edit(); editor.putString("applicationLanguage", comp); editor.commit(); - t1.setLanguage(getResources().getConfiguration().locale); + //myTTS.setLanguage(getResources().getConfiguration().locale); //Toast.makeText(getBaseContext(), "Needet to Set Variable", Toast.LENGTH_SHORT).show(); // Toast Vorlage }else { //Toast.makeText(getBaseContext(), "Some Fuckup! Set:"+setlang+", current: "+comp, Toast.LENGTH_SHORT).show(); // Toast Vorlage @@ -191,7 +212,7 @@ public class LevelActivity extends Activity implements MySensorListener{ @Override public void onStop() { super.onStop(); - + // myTTS.stop(); //Check device supported Accelerometer senssor or not if (MySensorManager.isListening()) { @@ -207,7 +228,7 @@ public class LevelActivity extends Activity implements MySensorListener{ public void onDestroy() { super.onDestroy(); Log.i("Sensor", "Service distroy"); - + //myTTS.shutdown(); //Check device supported Accelerometer senssor or not if (MySensorManager.isListening()) { @@ -236,8 +257,16 @@ public class LevelActivity extends Activity implements MySensorListener{ case R.id.action_settings: beLoud(this.getString(R.string.action_settings)); //t1.speak(this.getString(R.string.action_settings), TextToSpeech.QUEUE_FLUSH, null); - Intent refresh = new Intent(this, AppPreferences.class); - startActivity(refresh); + /*Intent refresh = new Intent(this, AppPreferences.class); + startActivity(refresh);*/ + if (MySensorManager.isListening()) { + MySensorManager.stopListening(); + } + if (Build.VERSION.SDK_INT < 11) { + startActivity(new Intent(this,AppPreferencesClassic.class)); + } else { + startActivity(new Intent(this, AppPreferences.class)); + } return true; case R.id.action_record: @@ -245,14 +274,16 @@ public class LevelActivity extends Activity implements MySensorListener{ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); //Toast.makeText(getBaseContext(), "Setting on Recording:"+prefs.getBoolean("applicationRecording",true), Toast.LENGTH_SHORT).show(); if (!prefs.getBoolean("applicationRecording",true)) { - Boolean a= prefs.getBoolean("applicationRecording",false); + //Boolean a= prefs.getBoolean("applicationRecording",false); beLoud(this.getString(R.string.action_record_text)); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("applicationRecording",true); editor.commit(); } else { beLoud(this.getString(R.string.action_record_text_off)); - + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean("applicationRecording",false); + editor.commit(); Toast.makeText(getBaseContext(), "Vector:"+accelvector.size()+"\n"+printVect(accelvector), Toast.LENGTH_SHORT).show(); @@ -286,12 +317,8 @@ public class LevelActivity extends Activity implements MySensorListener{ }while(comp.contains(neus)); setLocale(neus); + //beLoud(this.getString(R.string.change_text)); - - - /* - - */ return true; default: return super.onOptionsItemSelected(item); @@ -420,43 +447,59 @@ public class LevelActivity extends Activity implements MySensorListener{ DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; + res.updateConfiguration(conf, dm); Intent refresh = new Intent(this, LevelActivity.class); + startActivity(refresh); + setupActionBar(); + + myTTS.setLanguage(conf.locale); + beLoud(this.getString(R.string.change_text)); + //myTTS.setLanguage(conf.locale); +/*setupActionBar(); t1.setLanguage(getResources().getConfiguration().locale); if(t1.isLanguageAvailable(getResources().getConfiguration().locale)<TextToSpeech.LANG_AVAILABLE) { Toast.makeText(getBaseContext(), this.getString(R.string.action_lang_NA), Toast.LENGTH_LONG).show(); - } - beLoud(this.getString(R.string.change_text)); + editor.putBoolean("applicationTalking", false); + editor.commit(); + }*/ + //t1.speak(this.getString(R.string.change_text), TextToSpeech.QUEUE_FLUSH, null); - setupActionBar(); + finish(); } public void beLoud(String whatsay,String whatwrite){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + /*t1.shutdown(); if(t1.isLanguageAvailable(getResources().getConfiguration().locale)>TextToSpeech.LANG_MISSING_DATA) { t1.setLanguage(getResources().getConfiguration().locale); if(prefs.getBoolean("applicationTalking",true))t1.speak(whatsay, TextToSpeech.QUEUE_FLUSH, null); - } - + }*/ + if(prefs.getBoolean("applicationTalking",true))myTTS.speak(whatsay, TextToSpeech.QUEUE_FLUSH, null); if (prefs.getBoolean("applicationWriting", true))Toast.makeText(getBaseContext(), whatwrite, Toast.LENGTH_LONG).show(); + while (myTTS.isSpeaking()){ + //system.Out.Println("Do something or nothing while speaking..") + } } public void beLoud(String what){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + //t1.stop(); + //if(t1.isLanguageAvailable(getResources().getConfiguration().locale)>TextToSpeech.LANG_MISSING_DATA) { - if(t1.isLanguageAvailable(getResources().getConfiguration().locale)>TextToSpeech.LANG_MISSING_DATA) { + //t1.setLanguage(getResources().getConfiguration().locale); - t1.setLanguage(getResources().getConfiguration().locale); - - if(prefs.getBoolean("applicationTalking",true))t1.speak(what, TextToSpeech.QUEUE_FLUSH, null); - - } + // if(prefs.getBoolean("applicationTalking",true))t1.speak(what, TextToSpeech.QUEUE_FLUSH, null); + //} + if(prefs.getBoolean("applicationTalking",true))myTTS.speak(what, TextToSpeech.QUEUE_FLUSH, null); if (prefs.getBoolean("applicationWriting", true))Toast.makeText(getBaseContext(), what, Toast.LENGTH_SHORT).show(); - + while (myTTS.isSpeaking()){ + //system.Out.Println("Do something or nothing while speaking..") + } } public String printVect(Vector<nikVector> v){ String str=""; @@ -478,13 +521,17 @@ public class LevelActivity extends Activity implements MySensorListener{ } public void exitAll(){ //if t1.isLanguageAvailable(getResources().getConfiguration().locale)==TextToSpeech.LANG_AVAILABLE) { - t1.setLanguage(getResources().getConfiguration().locale); - if(t1.isLanguageAvailable(getResources().getConfiguration().locale)>TextToSpeech.LANG_MISSING_DATA){ - t1.speak(this.getString(R.string.goodby), TextToSpeech.QUEUE_FLUSH, null); - } - while (t1.isSpeaking()){ + //t1.shutdown(); + //t1.setLanguage(getResources().getConfiguration().locale); + //if(t1.isLanguageAvailable(getResources().getConfiguration().locale)>TextToSpeech.LANG_MISSING_DATA){ + //t1.speak(this.getString(R.string.goodby), TextToSpeech.QUEUE_FLUSH, null); + //} + myTTS.speak(this.getString(R.string.goodby), TextToSpeech.QUEUE_FLUSH, null); + + while (myTTS.isSpeaking()){ //system.Out.Println("Do something or nothing while speaking..") } + myTTS.shutdown(); System.exit(0); } diff --git a/app/src/main/java/com/softwarefools/nik/spiritlevel/MySensorManager.java b/app/src/main/java/com/softwarefools/nik/spiritlevel/MySensorManager.java index aca416f..682ecad 100644 --- a/app/src/main/java/com/softwarefools/nik/spiritlevel/MySensorManager.java +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/MySensorManager.java @@ -282,7 +282,7 @@ public class MySensorManager { /*force = Math.abs(x + y + z - lastX - lastY - lastZ) / timeDiff; */ - force = Math.abs(x + y + z - lastX - lastY - lastZ); + force = Math.abs(x + y + z - lastX - lastY - lastZ)/timeDiff; if (Float.compare(force, threshold) >0 ) { //Toast.makeText(Accelerometer.getContext(), |
