diff options
Diffstat (limited to 'app')
5 files changed, 182 insertions, 57 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98406bc..25ba337 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.softwarefools.spiritlevel" android:versionCode="2" - android:versionName="1.0.1" > + android:versionName="1.0.2" > <uses-sdk android:minSdkVersion="10" 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 ab332b0..14746d4 100644 --- a/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelActivity.java +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelActivity.java @@ -1,9 +1,12 @@ package com.softwarefools.nik.spiritlevel; +import java.io.FileOutputStream; import java.sql.Array; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.Locale; @@ -16,8 +19,10 @@ import java.util.Locale; import java.util.Map; import java.util.Random; import java.util.Set; +import java.util.TimeZone; import java.util.Vector; +import android.os.AsyncTask; import android.os.Bundle; import android.app.Activity; import android.content.Intent; @@ -61,7 +66,7 @@ import android.speech.tts.TextToSpeech.OnInitListener; public class LevelActivity extends Activity implements MySensorListener{ public static DecimalFormat f = new DecimalFormat("#0.000"); - + private static final String TAG = "SpiritLevel"; private int MY_DATA_CHECK_CODE = 0; //public static final String PREFS_NAME = "MyPrefsFile"; @@ -73,7 +78,7 @@ public class LevelActivity extends Activity implements MySensorListener{ private Vector<nikVector> accelvector; private Vector<nikVector> gravvector; - + private Vector<nikVector> magvector; //private TextView accelField; //private TextView gravityField; @@ -96,10 +101,11 @@ public class LevelActivity extends Activity implements MySensorListener{ super.onCreate(savedInstanceState); levelView = new LevelView(this); myprefs = new AppPreferences(); + Log.i(TAG,"LevelActivity.onCreate()"); setContentView(levelView); - System.out.println("LevelActivity.onCreate()"); + mySettings = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = mySettings.edit(); @@ -110,6 +116,7 @@ public class LevelActivity extends Activity implements MySensorListener{ accelvector= new Vector<>(); gravvector = new Vector<>(); + magvector = new Vector<>(); //TTS Engine Intent checkTTSIntent = new Intent(); @@ -123,6 +130,7 @@ public class LevelActivity extends Activity implements MySensorListener{ myTTS.setLanguage(getResources().getConfiguration().locale); funkSpeech(myTTS,false); }else if (status == TextToSpeech.ERROR) { + Log.i(TAG,getApplicationContext().getString(R.string.action_lang_NA)); Toast.makeText(getBaseContext(), getApplicationContext().getString(R.string.action_lang_NA), Toast.LENGTH_LONG).show(); } } @@ -134,6 +142,7 @@ public class LevelActivity extends Activity implements MySensorListener{ } protected void onActivityResult(int requestCode, int resultCode, Intent data) { + Log.i(TAG,"onActivityResult() RequestCode"+requestCode+" resultCode"+resultCode); if (requestCode == MY_DATA_CHECK_CODE) { if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @@ -158,7 +167,7 @@ public class LevelActivity extends Activity implements MySensorListener{ @Override public void onResume() { super.onResume(); - System.out.println("LevelActivity.onResume()"); + Log.i(TAG,"LevelActivity.onResume()"); restartTTS(); //Toast.makeText(getBaseContext(), "On Resume", Toast.LENGTH_SHORT).show(); // Toast Vorlage @@ -171,20 +180,21 @@ public class LevelActivity extends Activity implements MySensorListener{ //Start Accelerometer Listening MySensorManager.startListening(this); + Log.i(TAG,"SensorManager-Start Listening"); } } @Override public void onStop() { super.onStop(); - System.out.println("LevelActivity.onStop()"); + Log.i(TAG,"LevelActivity.onStop()"); // myTTS.stop(); //Check device supported Accelerometer senssor or not if (MySensorManager.isListening()) { //Start Accelerometer Listening MySensorManager.stopListening(); - + Log.i(TAG,"SensorManager-Stop Listening"); //Toast.makeText(getBaseContext(), "onStop Sensors Stoped",Toast.LENGTH_SHORT).show(); } @@ -193,19 +203,33 @@ public class LevelActivity extends Activity implements MySensorListener{ @Override public void onDestroy() { super.onDestroy(); - System.out.println("LevelActivity.onDestroy()"); + Log.i(TAG,"LevelActivity.onDestroy()"); //myTTS.shutdown(); //Check device supported Accelerometer senssor or not if (MySensorManager.isListening()) { //Start Accelerometer Listening MySensorManager.stopListening(); - + Log.i(TAG,"SensorManager-Stop Listening"); //Toast.makeText(getBaseContext(), "onDestroy Sensors Stoped", Toast.LENGTH_SHORT).show(); } } - + @Override + public void onPause() { + super.onPause(); + Log.i(TAG,"LevelActivity.onPause()"); + //myTTS.shutdown(); + //Check device supported Accelerometer senssor or not + if (MySensorManager.isListening()) { + + //Start Accelerometer Listening + MySensorManager.stopListening(); + Log.i(TAG,"SensorManager-Stop Listening"); + //Toast.makeText(getBaseContext(), "onDestroy Sensors Stoped", Toast.LENGTH_SHORT).show(); + } + + } @Override @@ -213,6 +237,7 @@ public class LevelActivity extends Activity implements MySensorListener{ //menu.clear(); // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.level, menu); + Log.i(TAG,"LevelActivity.onCreateOptionsMenu()"); return true; } @@ -220,7 +245,7 @@ public class LevelActivity extends Activity implements MySensorListener{ public boolean onPrepareOptionsMenu(Menu menu) { menu.clear(); // Clear the menu first - + Log.i(TAG,"LevelActivity.onPrepareOptionsMenu()"); /* Add the menu items */ getMenuInflater().inflate(R.menu.level, menu); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -240,6 +265,7 @@ public class LevelActivity extends Activity implements MySensorListener{ switch (item.getItemId()) { case R.id.action_settings: beLoud(this.getString(R.string.action_settings)); + Log.i(TAG,"LevelActivity.onOptionsItemSelected() "+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);*/ @@ -248,17 +274,17 @@ public class LevelActivity extends Activity implements MySensorListener{ } if (Build.VERSION.SDK_INT < 11) { startActivity(new Intent(this,AppPreferencesClassic.class)); - System.out.println("Starting Oldschool Settings"); + Log.i(TAG,"Starting Oldschool Settings"); } else { startActivity(new Intent(this, AppPreferences.class)); - System.out.println("Starting Settings"); + Log.i(TAG,"Starting Settings"); } return true; case R.id.action_record: - - System.out.println("Start Recording"); + Log.i(TAG,"LevelActivity.onOptionsItemSelected() "+this.getString(R.string.action_record)); + //System.out.println("Start Recording"); beLoud(this.getString(R.string.action_record_text)); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("applicationRecording",true); @@ -267,39 +293,47 @@ public class LevelActivity extends Activity implements MySensorListener{ case R.id.action_record_off: //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - System.out.println("Stop Recording"); + Log.i(TAG,"LevelActivity.onOptionsItemSelected() "+this.getString(R.string.action_record_off)); + //System.out.println("Stop Recording"); beLoud(this.getString(R.string.action_record_text_off)); SharedPreferences.Editor editor2 = prefs.edit(); editor2.putBoolean("applicationRecording",false); editor2.commit(); - Toast.makeText(getBaseContext(), "Vector:"+accelvector.size()+"\n"+printVect(accelvector), Toast.LENGTH_LONG).show(); + //Toast.makeText(getBaseContext(), "Vector:"+accelvector.size()+"\n"+printVect(accelvector), Toast.LENGTH_LONG).show(); // Save The DATA + Log.d(TAG,"AccelerationVect Size:"+accelvector.size()); + Log.d(TAG,"GravityVect Size:"+gravvector.size()); + Log.d(TAG,"MagneticVect Size:"+magvector.size()); + //new ProcessData().execute(gravvector,accelvector,magvector); + new ProcessData().execute(accelvector); - //dump the vectors + //dump the vectors accelvector.clear(); gravvector.clear(); - + magvector.clear(); return true; case R.id.action_exit: //t1.speak(this.getString(R.string.goodby), TextToSpeech.QUEUE_FLUSH, null); - + Log.i(TAG,"LevelActivity.onOptionsItemSelected() "+this.getString(R.string.action_exit)); exitAll(); return true; case R.id.action_changelang: //t1.speak(this.getString(R.string.change_text), TextToSpeech.QUEUE_FLUSH, null); - System.out.println("Change Language"); + //System.out.println("Change Language"); + Log.i(TAG,"LevelActivity.onOptionsItemSelected() "+this.getString(R.string.action_lang)); String[] sf=getResources().getStringArray(R.array.langValues); String comp=getResources().getConfiguration().locale.getLanguage(); String neus; do { int neur = r.nextInt(sf.length); neus = sf[neur]; + Log.v(TAG,"Current:"+comp+" New:"+neus); }while(comp.contains(neus)); funkSpeech(myTTS,true); setLocale(neus); @@ -315,7 +349,7 @@ public class LevelActivity extends Activity implements MySensorListener{ @Override public void onGravityChanged(float x, float y, float z) { // TODO Auto-generated method stub - System.out.println("Noticed Gravity Change"); + Log.v(TAG,"Gravity Changed - x:"+x+" y:"+y+" z:"+z); float sq= (float)x*x+y*y+z*z; float sum=(float)Math.sqrt(sq); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -331,7 +365,7 @@ public class LevelActivity extends Activity implements MySensorListener{ @Override public void onAccelerationChanged(float x, float y, float z) { // TODO Auto-generated method stub - System.out.println("Noticed Acceleration Change"); + Log.v(TAG,"Acceleration Changed - x:"+x+" y:"+y+" z:"+z); float sq= (float)x*x+y*y+z*z; float sum=(float)Math.sqrt(sq); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -345,14 +379,14 @@ public class LevelActivity extends Activity implements MySensorListener{ @Override public void onMagneticFieldChanged(float x, float y, float z) { // TODO Auto-generated method stub - System.out.println("Noticed Magnetic Field Change"); + Log.v(TAG,"Magnetic Field Changed - x:"+x+" y:"+y+" z:"+z); float sq= (float)x*x+y*y+z*z; float sum=(float)Math.sqrt(sq); - //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - //nikVector temp=new nikVector(); - //temp.setVector(getTime(),x/sum,y/sum,z/sum); - //if(prefs.getBoolean("applicationRecording",true))accelvector.add(temp); + nikVector temp=new nikVector(); + temp.setVector(getTime(),x,y,z); + if(prefs.getBoolean("applicationRecording",true))magvector.add(temp); levelView.updateMagneticData(x, y, z); } @@ -361,8 +395,8 @@ public class LevelActivity extends Activity implements MySensorListener{ // TODO Auto-generated method stub SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - float force=((float)prefs.getInt("deviceweight",0))*forceacc/1000; - System.out.println("Force Detected: "+force); + float force=((float)prefs.getInt("deviceweight",0)/1000)*forceacc; + Log.v(TAG,"Force Detected: "+force); beLoud(this.getString(R.string.alert)+(int)force+this.getString(R.string.newton),this.getString(R.string.toast_force)+force+this.getString(R.string.newton_short)); /* String maketext= this.getString(R.string.alert)+(int)force+this.getString(R.string.newton); @@ -383,11 +417,12 @@ public class LevelActivity extends Activity implements MySensorListener{ } @Override public void onBackPressed() { + Log.i(TAG,"LevelActivity.onBackPressed() "); new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle("Closing Activity") - .setMessage("Are you sure you want to close this activity?") - .setPositiveButton("Yes", new DialogInterface.OnClickListener() + .setTitle(getApplicationContext().getString(R.string.dialogue_exit_title)) + .setMessage(getApplicationContext().getString(R.string.dialogue_exit_text)) + .setPositiveButton(getApplicationContext().getString(R.string.dialogue_yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -397,10 +432,11 @@ public class LevelActivity extends Activity implements MySensorListener{ } }) - .setNegativeButton("No", null) + .setNegativeButton(getApplicationContext().getString(R.string.dialogue_no), null) .show(); } private void restartTTS(){ + Log.v(TAG,"restartTTS()"); myTTS.shutdown(); myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override @@ -501,7 +537,7 @@ private void restartTTS(){ return orientation; } public void setLocale(String lang) { - System.out.println("Changing Language to "+lang); + Log.i(TAG, "LevelActivity.setLocale() "+lang); SharedPreferences.Editor editor = mySettings.edit(); editor.putString("applicationLanguage", lang); editor.commit(); @@ -554,17 +590,11 @@ private void restartTTS(){ } sp.setPitch((float)pitch); sp.setSpeechRate((float)rate); - System.out.println("Pitch: "+pitch+" Rate: "+rate); + Log.i(TAG, "Pitch: "+pitch+" Rate: "+rate); } 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); - }*/ - System.out.println("Systemoutput"); + Log.i(TAG,"LevelActivity.beLoud()"+whatsay+"|"+whatwrite); if (prefs.getBoolean("applicationWriting", true))Toast.makeText(getBaseContext(), whatwrite, Toast.LENGTH_LONG).show(); if(prefs.getBoolean("applicationTalking",true))myTTS.speak(whatsay, TextToSpeech.QUEUE_FLUSH, null); @@ -574,15 +604,7 @@ private void restartTTS(){ } public void beLoud(String what){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - //t1.stop(); - //if(t1.isLanguageAvailable(getResources().getConfiguration().locale)>TextToSpeech.LANG_MISSING_DATA) { - - //t1.setLanguage(getResources().getConfiguration().locale); - - // if(prefs.getBoolean("applicationTalking",true))t1.speak(what, TextToSpeech.QUEUE_FLUSH, null); - - //} - System.out.println("Systemoutput"); + Log.i(TAG,"LevelActivity.beLoud()"+what); if (prefs.getBoolean("applicationWriting", true))Toast.makeText(getBaseContext(), what, Toast.LENGTH_SHORT).show(); if(prefs.getBoolean("applicationTalking",true))myTTS.speak(what, TextToSpeech.QUEUE_FLUSH, null); @@ -616,13 +638,91 @@ private void restartTTS(){ //t1.speak(this.getString(R.string.goodby), TextToSpeech.QUEUE_FLUSH, null); //} myTTS.speak(this.getString(R.string.goodby), TextToSpeech.QUEUE_FLUSH, null); - System.out.println("Shutting Down"); + Log.i(TAG,"Shutting Down"); while (myTTS.isSpeaking()){ //system.Out.Println("Do something or nothing while speaking..") } myTTS.shutdown(); System.exit(0); } + public String getDateCurrentTimeZone(long timestamp) { + try{ + Calendar calendar = Calendar.getInstance(); + TimeZone tz = TimeZone.getDefault(); + calendar.setTimeInMillis(timestamp * 1000); + calendar.add(Calendar.MILLISECOND, tz.getOffset(calendar.getTimeInMillis())); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd__HH-mm-ss"); + Date currenTimeZone = (Date) calendar.getTime(); + return sdf.format(currenTimeZone); + }catch (Exception e) { + Log.e(TAG,"Unable to get TimeZone",e); + } + return ""; + } + + private class ProcessData extends AsyncTask<Vector<nikVector>, Float, Integer> { + + @Override + protected Integer doInBackground(Vector<nikVector>... vects) { + + String printout=""; + String filename="newfile"; + FileOutputStream outputStream; + + int count = vects.length; + int totalSize = 0; + Log.i(TAG,"LevelActivity.AsyncTask.ProcessData() for "+count+"Vectors"); + filename=getDateCurrentTimeZone(getTime())+".csv"; + for (int i = 0; i < count; i++) { + totalSize += vects[i].size(); + publishProgress((float) ((i / (float) count))); // 0.2 + + // Escape early if cancel() is called + if (isCancelled()) break; + String timeline=""; + String xline=""; + String yline=""; + String zline=""; + + for(int j=0;j<vects[i].size();j++){ + timeline+=vects[i].get(j).getT()+","; + xline+=vects[i].get(j).getX()+","; + yline+=vects[i].get(j).getY()+","; + zline+=vects[i].get(j).getZ()+","; + } + printout+=timeline+"\n"+xline+"\n"+yline+"\n"+zline+"\n\n"; + + try { + outputStream = openFileOutput(filename, getApplicationContext().MODE_WORLD_WRITEABLE); + outputStream.write(printout.getBytes()); + outputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + Log.i(TAG,"LevelActivity.AsyncTask.ProcessData() of "+totalSize+"Totalsize"); + return totalSize; + //return "Executed"; + } + + @Override + protected void onPostExecute(Integer result) { + //TextView txt = (TextView) findViewById(R.id.output); + //txt.setText("Executed"); // txt.setText(result); + // might want to change "executed" for the returned string passed + // into onPostExecute() but that is upto you + //beLoud(getBaseContext().getString(R.string.action_savedata)); + Toast.makeText(getBaseContext(), getBaseContext().getString(R.string.action_savedata), Toast.LENGTH_LONG).show(); + + } + + @Override + protected void onPreExecute() {} + + @Override + protected void onProgressUpdate(Float... values) {} + } + } diff --git a/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelView.java b/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelView.java index e379552..351d113 100644 --- a/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelView.java +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/LevelView.java @@ -499,7 +499,7 @@ public class LevelView extends View{ public double getAngle(float x, float y){ double div = (double)x/y; float theta = (float) Math.toDegrees(Math.atan(div)); - System.out.println(theta); // 53.130104 + //System.out.println(theta); // 53.130104 return theta; } public double getAlpha(float x,float y){ @@ -535,6 +535,7 @@ public class LevelView extends View{ invalidate(); } public void updateAccelData(float x,float y,float z,int orientation) { + if (getLength(x_accSense_max,y_accSense_max,z_accSense_max)<getLength(x-x_gravSense,y-y_gravSense,z-z_gravSense)){ this.x_accSense_max=x-x_gravSense; this.y_accSense_max=y-y_gravSense; @@ -547,6 +548,11 @@ public class LevelView extends View{ } float sq= (float)x*x+y*y+z*z; float sum=(float)Math.sqrt(sq); + if(sum<sum_gravSense) { + x = x / sum * sum_gravSense; + y = y / sum * sum_gravSense; + z = z / sum * sum_gravSense; + } this.x_accSense = x; this.y_accSense = y; this.z_accSense = z; @@ -625,7 +631,7 @@ public class LevelView extends View{ double acc= getLength(x_accSense-x_gravSense,y_accSense-y_gravSense,z_accSense-z_gravSense); - if (acc<0.01){ + if (acc<0.05){ paintVector2.setColor(Color.GREEN); paintVector2Help.setColor(Color.GREEN); }else if (acc<=0.694){ diff --git a/app/src/main/java/com/softwarefools/nik/spiritlevel/nikVector.java b/app/src/main/java/com/softwarefools/nik/spiritlevel/nikVector.java index e4a3e2f..a95e7f9 100644 --- a/app/src/main/java/com/softwarefools/nik/spiritlevel/nikVector.java +++ b/app/src/main/java/com/softwarefools/nik/spiritlevel/nikVector.java @@ -32,8 +32,20 @@ public class nikVector { this.z=c; } + public long getT(){ + return this.t; + } + public double getX(){ + return this.x; + } + public double getY(){ + return this.y; + } + public double getZ(){ + return this.z; + } public String getString(){ - String str=t+" : "+x+";"+y+";"+z ; + String str=t+","+x+","+y+","+z+","; return str; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b856001..b77228c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -43,7 +43,10 @@ <string translatable="false" name="setting_dialog_message">Dialog Slider shit</string> <string translatable="false" name="setting_unit">Units</string> - + <string translatable="false" name="dialogue_exit_title">Quit SpiritLevel</string> + <string translatable="false" name="dialogue_exit_text">Are you sure you want to close SpiritLevel?</string> + <string translatable="false" name="dialogue_yes">Yes</string> + <string translatable="false" name="dialogue_no">No</string> <string name="action_settings">Settings</string> <string name="action_record">Record</string> @@ -57,4 +60,8 @@ <string name="change_text">Changing Language to English</string> <string name="goodby">Thank You for using Software Fools Software! Which never fooled anybody</string> <string name="toast_force">Accelleration detected \n Force:</string> + + + <string name="action_savedata">Data Saved Successfully</string> + </resources> |
