Android Open Source - Flight-Computer-Android-Flightradar24 Beep Thread






From Project

Back to project page Flight-Computer-Android-Flightradar24.

License

The source code is released under:

GNU General Public License

If you think the Android project Flight-Computer-Android-Flightradar24 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* Copyright (C) T?rkay Biliyor 
   turkaybiliyor@hotmail.com *///  w  w w . j a v a 2 s .c  o  m

package com.flightcomputer.utilities;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import com.flightcomputer.R;
public class BeepThread implements Runnable, SoundPool.OnLoadCompleteListener {
    private boolean running;
    private double base = 1000.0;
    private double increment = 100.0;
    private SoundPool soundPool;
    private int numSounds = 2;
    private int soundsLoaded = 0;
    private int tone;
    private int sink;
    private int tone_stream;
    private int sink_stream;
    private int temp;
    private Thread thread;
    private boolean beepOn=false;
    private double avgvario,sinkalarm;
    private double sinkBase = 500.0;
    private double sinkIncrement = 100.0;
    private PiecewiseLinearFunction cadenceFunction;
   
    public BeepThread(Context context) {  
      cadenceFunction = new PiecewiseLinearFunction(new Point2d(0, 0.4763));
        cadenceFunction.addNewPoint(new Point2d(0.135, 0.4755));
        cadenceFunction.addNewPoint(new Point2d(0.441, 0.3619));
        cadenceFunction.addNewPoint(new Point2d(1.029, 0.2238));
        cadenceFunction.addNewPoint(new Point2d(1.559, 0.1565));
        cadenceFunction.addNewPoint(new Point2d(2.471, 0.0985));
        cadenceFunction.addNewPoint(new Point2d(3.571, 0.0741));       
        running = true;
        soundPool = new SoundPool(numSounds, AudioManager.STREAM_MUSIC, 0);
        soundPool.setOnLoadCompleteListener(this);   
    }
    public void stop() {
        this.beepOn=false;       
    }
    public void start(Context context,int soundtype,double newsinkalarm) { 
      try {
        sinkalarm=newsinkalarm;
      if(soundtype==1)
          temp=R.raw.tone_600mhz;
        else if (soundtype==2)
          temp=R.raw.tone_750mhz;
        else if (soundtype==3)
          temp=R.raw.tone_1000mhz;
        tone = soundPool.load(context, temp, 1);
        sink = soundPool.load(context, R.raw.sink_tone500mhz, 1);
        this.beepOn=true;  
        } catch (Exception e) {}
    }
    public void setAvgVario(double newavgvario) {
      this.avgvario = newavgvario;      
    }     
    public void run() {
        while (running) {
            try {
                while (beepOn) {                   
                  if(avgvario>0.2)
                  {
                     tone_stream = soundPool.play(tone, 1.0f, 1.0f, 0, -1, getRateFromTone1000(avgvario));//need to set rate to something other than 1.0f to start with for Android 4.1 based Nexus 7. Perhaps a bug?
                         Thread.sleep((int) (cadenceFunction.getValue(avgvario) * 1250));
                         soundPool.setVolume(tone_stream, 0.0f, 0.0f);
                         Thread.sleep((int) (cadenceFunction.getValue(avgvario) * 1000));
                  }else if(avgvario<=-1*sinkalarm)
                  {
                    sink_stream = soundPool.play(sink, 1.0f, 1.0f, 0, -1, 0);
                    Thread.sleep((int) (600));
                    soundPool.setVolume(sink_stream, 0.0f, 0.0f);
                    Thread.sleep((int) (200));
                  }
                }
            } catch (Exception e) {                
            }            
        }
        soundPool.stop(tone_stream);
        soundPool.stop(sink_stream);
        soundPool.release();
        soundPool = null;
    }

    public synchronized void setRunning(boolean running) {
        this.running = running;    
        this.beepOn=false;
    }   
    public float getRateFromTone1000(double var) {
        double hZ = base + increment * var;
        float rate = (float) hZ / 1000.0f;
        if (rate < 0.5f) {
            rate = 0.5f;
        } else if (rate > 2.0f) {
            rate = 2.0f;
        } else if (rate == 1.0f) {
            rate = 1.0f + Float.MIN_VALUE;
        }
        return rate;
    }
    public float getRateFromTone500(double var) {
        double hZ = sinkBase + sinkIncrement * var;

        float rate = (float) hZ / 500.0f;
        if (rate < 0.5f) {
            rate = 0.5f;
        } else if (rate > 2.0f) {
            rate = 2.0f;
        } else if (rate == 1.0f) {
            rate = 1.0f + Float.MIN_VALUE;
        }
        return rate;


    }
    public void onLoadComplete(SoundPool soundPool, int i, int i1) {
        soundsLoaded++;
        if (soundsLoaded == numSounds) {
            thread = new Thread(this);
            thread.setPriority(Thread.MAX_PRIORITY);
            thread.start();
        }
    }
    public synchronized void setBase(double base) {
        this.base = base;
    }

    public synchronized void setIncrement(double increment) {
        this.increment = increment;
    }

    public void onDestroy() {
      try{
        this.setRunning(false);           
        thread.stop();
        thread = null;
      }catch(Exception e){};
    }
    

}




Java Source Code List

com.flightcomputer.Circle.java
com.flightcomputer.DownloadActivity.java
com.flightcomputer.EditPreferences.java
com.flightcomputer.FCActivity.java
com.flightcomputer.GpsSkyActivity.java
com.flightcomputer.IgcLoad.java
com.flightcomputer.LeonardoLiveWriter.java
com.flightcomputer.MapEventListener.java
com.flightcomputer.PositionWriter.java
com.flightcomputer.PressureAltimeterActivity.java
com.flightcomputer.RouteLine.java
com.flightcomputer.Task.java
com.flightcomputer.TrckLine.java
com.flightcomputer.filefilter.FilterByFileExtension.java
com.flightcomputer.filefilter.ValidFileFilter.java
com.flightcomputer.filefilter.ValidMapFile.java
com.flightcomputer.filefilter.ValidRenderTheme.java
com.flightcomputer.filepicker.FilePickerIconAdapter.java
com.flightcomputer.filepicker.FilePicker.java
com.flightcomputer.utilities.BaroService.java
com.flightcomputer.utilities.BeepThread.java
com.flightcomputer.utilities.GpsSkyView.java
com.flightcomputer.utilities.KalmanFilter.java
com.flightcomputer.utilities.PiecewiseLinearFunction.java
com.flightcomputer.utilities.Point2d.java
com.flightcomputer.utilities.VerticalProgressBar_Reverse.java
com.flightcomputer.utilities.VerticalProgressBar.java
com.flightcomputer.openGlUtils.java
com.nutiteq.advancedmap.mapquest.SearchQueryResults.java
com.nutiteq.advancedmap.mapquest.SearchSuggestionProvider.java
com.nutiteq.services.geocode.MapQuestGeocoder.java
com.nutiteq.utils.MapsforgeMapLayer.java
com.nutiteq.utils.MbTilesDatabaseHelper.java
com.nutiteq.utils.MyLocationCircle.java
com.nutiteq.utils.NetUtils.java
com.nutiteq.utils.UiUtils.java
com.nutiteq.utils.UtfGridHelper.java
com.nutiteq.utils.UtfGridLayerInterface.java