Example usage for android.media AudioManager getStreamMaxVolume

List of usage examples for android.media AudioManager getStreamMaxVolume

Introduction

In this page you can find the example usage for android.media AudioManager getStreamMaxVolume.

Prototype

public int getStreamMaxVolume(int streamType) 

Source Link

Document

Returns the maximum volume index for a particular stream.

Usage

From source file:io.puzzlebox.orbit.ui.OrbitFragment.java

public void playControl() {

    Log.d(TAG, "playControl()");

    // TODO Convert to service

    //      FragmentTabAdvanced fragmentAdvanced =
    //              (FragmentTabAdvanced) getActivity().getSupportFragmentManager().findFragmentByTag( getTabFragmentAdvanced() );
    ////from w w  w .  j  a va 2  s .c  o  m
    if (OrbitSingleton.getInstance().generateAudio) {

        /**
         * Generate signal on the fly
         */

        //         // Handle controlled descent thread if activated
        //         if ((fragmentAdvanced.orbitControlledDescentTask != null) &&
        //                 (fragmentAdvanced.orbitControlledDescentTask.keepDescending)) {
        //            fragmentAdvanced.orbitControlledDescentTask.callStopAudio = false;
        //            fragmentAdvanced.orbitControlledDescentTask.keepDescending = false;
        //         }

        //         if (audioHandler != null) {

        //            serviceBinder.ifFlip = fragmentAdvanced.checkBoxInvertControlSignal.isChecked(); // if checked then flip
        OrbitSingleton.getInstance().audioHandler.ifFlip = OrbitSingleton.getInstance().invertControlSignal; // if checked then flip

        int channel = 0; // default "A"

        //         if (fragmentAdvanced != null)
        //            channel = fragmentAdvanced.radioGroupChannel.getCheckedRadioButtonId();

        //            if (demoFlightMode)
        //               updateAudioHandlerLoopNumberWhileMindControl(200);
        //            else
        //               updateAudioHandlerLoopNumberWhileMindControl(4500);
        //
        //         updateAudioHandlerLoopNumberWhileMindControl(5000);

        updateAudioHandlerLoopNumberWhileMindControl(-1); // Loop infinite for easier user testing

        updateAudioHandlerChannel(channel);

        OrbitSingleton.getInstance().audioHandler.mutexNotify();

        //         }
        //
        //
    } else {

        /**
         * Play audio control file
         */

        /** Getting the user sound settings */
        AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
        //         float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        //         float volume = actualVolume / maxVolume;

        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) maxVolume, 0);
        /** Is the sound loaded already? */
        if (OrbitSingleton.getInstance().loaded) {
            //            soundPool.play(soundID, volume, volume, 1, 0, 1f);
            //            soundPool.setVolume(soundID, 1f, 1f);
            //            soundPool.play(soundID, maxVolume, maxVolume, 1, 0, 1f); // Fixes Samsung Galaxy S4 [SGH-M919]

            OrbitSingleton.getInstance().soundPool.play(OrbitSingleton.getInstance().soundID, 1f, 1f, 1, 0, 1f); // Fixes Samsung Galaxy S4 [SGH-M919]

            // TODO No visible effects of changing these variables on digital oscilloscope
            //            soundPool.play(soundID, 0.5f, 0.5f, 1, 0, 0.5f);
            //            if (DEBUG)
            Log.v(TAG, "Played sound");
        }

    }

}

From source file:org.freelectron.leobel.testlwa.models.AVSAudioPlayer.java

public AVSAudioPlayer(AudioManager audioManager, AVSController controller) {
    this.audioManager = audioManager;
    this.controller = controller;
    resLoader = Thread.currentThread().getContextClassLoader();
    timer = new AudioPlayerTimer();
    waitForPlaybackFinished = false;/*w  w w .  j av a  2  s  .c  o  m*/
    playQueue = new LinkedList<Stream>();
    speakQueue = new LinkedList<SpeakItem>();
    streamUrls = new HashSet<String>();
    attemptedUrls = new HashSet<String>();
    cachedAudioFiles = new HashMap<String, String>();
    setupAudioPlayer();

    currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    VOLUME_SCALAR = maxVolume / VOLUME_SCALAR;
    currentlyMuted = currentVolume == 0;

    audioPlayerStateMachine = new AudioPlayerStateMachine(this, controller);

    progressReporter = new AudioPlayerProgressReporter(
            new ProgressReportDelayEventRunnable(audioPlayerStateMachine),
            new ProgressReportIntervalEventRunnable(audioPlayerStateMachine), timer);

    listeners = new HashSet<>();
}

From source file:org.drrickorang.loopback.LoopbackActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the layout for this activity. You can find it
    View view = getLayoutInflater().inflate(R.layout.main_activity, null);
    setContentView(view);//from w  w  w  . ja  va 2  s. c om

    mTextInfo = (TextView) findViewById(R.id.textInfo);
    mBarMasterLevel = (SeekBar) findViewById(R.id.BarMasterLevel);

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    mBarMasterLevel.setMax(maxVolume);

    mBarMasterLevel.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            am.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
            refreshState();
            log("Changed stream volume to: " + progress);
        }
    });
    mWavePlotView = (WavePlotView) findViewById(R.id.viewWavePlot);

    mTextViewCurrentLevel = (TextView) findViewById(R.id.textViewCurrentLevel);
    mTextViewCurrentLevel.setTextSize(15);

    mTextViewEstimatedLatency = (TextView) findViewById(R.id.textViewEstimatedLatency);
    refreshState();

    applyIntent(getIntent());
}

From source file:com.speedtong.example.ui.chatting.ChattingActivity.java

private void initToneGenerator() {
    AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (mToneGenerator == null) {
        try {/*www. j a  v a2  s. c om*/
            int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
            int streamMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
            int volume = (int) (TONE_RELATIVE_VOLUME * (streamVolume / streamMaxVolume));
            mToneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, volume);

        } catch (RuntimeException e) {
            LogUtil.d("Exception caught while creating local tone generator: " + e);
            mToneGenerator = null;
        }
    }
}

From source file:com.PPRZonDroid.MainActivity.java

/**
 * Play warning sound if airspeed goes below the selected value
 *
 * @param context// w w w.j  a va 2  s.  c  o m
 * @throws IllegalArgumentException
 * @throws SecurityException
 * @throws IllegalStateException
 * @throws IOException
 */
public void play_sound(Context context)
        throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDataSource(context, soundUri);
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    //Set volume max!!!
    audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM,
            audioManager.getStreamMaxVolume(audioManager.STREAM_SYSTEM), 0);

    if (audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) != 0) {
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_SYSTEM);
        mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    }
}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

/**
 * ?.//from  w w w.j ava2 s .co m
 * 
 * @param status 
 */
public void sendOnStatusChangeEvent(final String status) {

    if (onStatusChangeEventFlag) {
        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, MediaPlayerProfile.PROFILE_NAME,
                null, MediaPlayerProfile.ATTRIBUTE_ON_STATUS_CHANGE);

        AudioManager manager = (AudioManager) this.getContext().getSystemService(Context.AUDIO_SERVICE);

        double maxVolume = 1;
        double mVolume = 0;

        mVolume = manager.getStreamVolume(AudioManager.STREAM_MUSIC);
        maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

        double mVolumeValue = mVolume / maxVolume;

        for (int i = 0; i < events.size(); i++) {

            Event event = events.get(i);
            Intent intent = EventManager.createEventMessage(event);

            MediaPlayerProfile.setAttribute(intent, MediaPlayerProfile.ATTRIBUTE_ON_STATUS_CHANGE);
            Bundle mediaPlayer = new Bundle();
            MediaPlayerProfile.setStatus(mediaPlayer, status);
            MediaPlayerProfile.setMediaId(mediaPlayer, myCurrentFilePath);
            MediaPlayerProfile.setMIMEType(mediaPlayer, myCurrentFileMIMEType);
            MediaPlayerProfile.setPos(mediaPlayer, myCurrentMediaPosition);
            MediaPlayerProfile.setVolume(mediaPlayer, mVolumeValue);
            MediaPlayerProfile.setMediaPlayer(intent, mediaPlayer);
            getContext().sendBroadcast(intent);
        }
    }
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

private void setDefaultPrefs(Map<String, String> DbPrefs) {
    String valueTmp = "";
    mVoltageAlarm = getDouble(mVoltageAlarm, DbPrefs.get("mVoltageAlarm"));
    mUsedCap = getDouble(mUsedCap, DbPrefs.get("mUsedCap"));
    mCurrentAlarm = getDouble(mCurrentAlarm, DbPrefs.get("mCurrentAlarm"));
    mPowerAlarm = getDouble(mPowerAlarm, DbPrefs.get("mPowerAlarm"));

    mSpeedAlarm = getInteger(mSpeedAlarm, DbPrefs.get("mSpeedAlarm"));
    mRpmAlarm = getInteger(mRpmAlarm, DbPrefs.get("mRpmAlarm"));
    mAltitudeAlarm = getInteger(mAltitudeAlarm, DbPrefs.get("mAltitudeAlarm"));
    mFuelAlarm = getInteger(mFuelAlarm, DbPrefs.get("mFuelAlarm"));
    voltage_hysteresis = getInteger(voltage_hysteresis, DbPrefs.get("voltage_hysteresis"));
    current_hysteresis = getInteger(current_hysteresis, DbPrefs.get("current_hysteresis"));
    rpm_hysteresis = getInteger(rpm_hysteresis, DbPrefs.get("rpm_hysteresis"));
    temperature_hysteresis = getInteger(temperature_hysteresis, DbPrefs.get("temperature_hysteresis"));
    power_hysteresis = getInteger(power_hysteresis, DbPrefs.get(""));
    mTemperatureAlarm = getInteger(mTemperatureAlarm, DbPrefs.get("power_hysteresis"));
    speech_volume = getInteger(speech_volume, DbPrefs.get("speech_volume"));
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int sb2value = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    sb2value = sb2value * speech_volume / 100;
    am.setStreamVolume(AudioManager.STREAM_MUSIC, sb2value, 0);
    vibrate_on = getBoolean(vibrate_on, DbPrefs.get("vibrate_on"));
    voltage_speech_ack = getBoolean(voltage_speech_ack, DbPrefs.get("voltage_speech_ack"));
    current_speech_ack = getBoolean(current_speech_ack, DbPrefs.get("current_speech_ack"));
    height_speech_ack = getBoolean(height_speech_ack, DbPrefs.get("height_speech_ack"));
    used_speech_ack = getBoolean(used_speech_ack, DbPrefs.get("used_speech_ack"));
    speed_speech_ack = getBoolean(speed_speech_ack, DbPrefs.get("speed_speech_ack"));
    rpm_speech_ack = getBoolean(rpm_speech_ack, DbPrefs.get("rpm_speech_ack"));
    temp_speech_ack = getBoolean(temp_speech_ack, DbPrefs.get("temp_speech_ack"));

    voltage_speech_label = DbPrefs.get("voltage_speech_label");
    voltage_speech_unit = DbPrefs.get("voltage_speech_unit");

    height_speech_label = DbPrefs.get("height_speech_label");
    height_speech_unit = DbPrefs.get("height_speech_unit");

    current_speech_label = DbPrefs.get("current_speech_label");
    current_speech_unit = DbPrefs.get("current_speech_unit");

    used_speech_label = DbPrefs.get("used_speech_label");
    used_speech_unit = DbPrefs.get("used_speech_unit");

    speed_speech_label = DbPrefs.get("speed_speech_label");
    speed_speech_unit = DbPrefs.get("speed_speech_unit");

    rpm_speech_label = DbPrefs.get("rpm_speech_label");
    rpm_speech_unit = DbPrefs.get("rpm_speech_unit");

    temp_speech_label = DbPrefs.get("temp_speech_label");
    temp_speech_unit = DbPrefs.get("temp_speech_unit");

    valueTmp = DbPrefs.get("log_file");
    if (valueTmp != "") {
        log_file = valueTmp;/*from w w w  .j ava  2s  .  co m*/
    }

    valueTmp = DbPrefs.get("bluetooth_device");
    if (valueTmp != "") {
        bluetooth_device = valueTmp;
    }
    mSound_on = getBoolean(mSound_on, DbPrefs.get("mSound_on"));
    speech_on = getBoolean(speech_on, DbPrefs.get("speech_on"));
    speech_intervall = DbPrefs.get("speech_intervall");
    mAlarm_on = getBoolean(mAlarm_on, DbPrefs.get("mAlarm_on"));
    mlog_file = getBoolean(mlog_file, DbPrefs.get("mlog_file"));
    alert_tone = DbPrefs.get("alert_tone");
    label_rpm1 = DbPrefs.get("label_rpm1");
    label_rpm2 = DbPrefs.get("label_rpm2");
    label_temp1 = DbPrefs.get("label_temp1");
    label_temp2 = DbPrefs.get("label_temp2");
    unit_rpm1 = DbPrefs.get("unit_rpm1");
    unit_rpm2 = DbPrefs.get("unit_rpm2");
    unit_temp1 = DbPrefs.get("unit_temp1");
    unit_temp2 = DbPrefs.get("unit_temp2");
    current_sensor_type = DbPrefs.get("current_sensor_type");
    alarm_voltage = getBoolean(alarm_voltage, DbPrefs.get("alarm_voltage"));
    alarm_used = getBoolean(alarm_used, DbPrefs.get("alarm_used"));
    alarm_current = getBoolean(alarm_current, DbPrefs.get("alarm_current"));
    alarm_speed = getBoolean(alarm_speed, DbPrefs.get("alarm_speed"));
    alarm_fuel = getBoolean(alarm_fuel, DbPrefs.get("alarm_fuel"));
    alarm_temperature = getBoolean(alarm_temperature, DbPrefs.get("alarm_temperature"));
    alarm_altitude = getBoolean(alarm_altitude, DbPrefs.get("alarm_altitude"));
    alarm_rpm = getBoolean(alarm_rpm, DbPrefs.get("alarm_rpm"));
    alarm_power = getBoolean(alarm_power, DbPrefs.get("alarm_power"));

    if (rpm1Label != null)
        rpm1Label.setText(label_rpm1);
    if (rpm2Label != null)
        rpm2Label.setText(label_rpm2);
    if (tempLabel != null)
        tempLabel.setText(label_temp1);
    if (temp2Label != null)
        temp2Label.setText(label_temp2);

    if (rpm1_unit != null)
        rpm1_unit.setText(unit_rpm1);
    if (rpm2_unit != null)
        rpm2_unit.setText(unit_rpm2);
    if (temp1_unit != null)
        temp1_unit.setText(unit_temp1);
    if (temp1_unit != null)
        temp1_unit.setText(unit_temp2);

    if (alert_tone.equals("")) {
        uri = null;
    } else {
        uri = Uri.parse(alert_tone);
    }

    if (mp != null) {
        mp.stop();
        mp.release();
        mp = null;
        if (uri != null && !uri.toString().equals("res/raw/alarm.mp3")) {
            mp = MediaPlayer.create(getApplicationContext(), uri);
        } else {
            mp = MediaPlayer.create(getApplicationContext(), R.raw.alarm);
        }
    }
}

From source file:usbong.android.likha_collection_1.UsbongDecisionTreeEngineActivity.java

public void init() {
    //if return is null, then currScreen=0
    //        currScreen=Integer.parseInt(getIntent().getStringExtra("currScreen")); 
    //modified by JPT, May 25, 2015
    if (getIntent().getStringExtra("currScreen") != null) {
        currScreen = Integer.parseInt(getIntent().getStringExtra("currScreen"));
    }/*from  www. java  2 s  . c o m*/

    //updated by Mike, 20160608
    /*        
            currLanguageBeingUsed=UsbongUtils.LANGUAGE_ENGLISH;
          UsbongUtils.setCurrLanguage("English"); //added by Mike, 22 Sept. 2015
    */
    //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example
    //; last accessed: 9 June 2015
    //answer by Elenasys
    //added by Mike, 9 June 2015
    SharedPreferences prefs = getSharedPreferences(UsbongConstants.MY_SAVED_LANGUAGE_SETTING, MODE_PRIVATE);
    if (prefs != null) {
        //@todo: remove this id thing, immediately use the String; otherwise it'll be cumbersome to keep on adding language ids
        currLanguageBeingUsed = prefs.getInt("preferredLanguage",
                UsbongUtils.getLanguageID(UsbongUtils.getCurrLanguage())); //default is Filipino
        /* //commented out by Mike, 20160608
         * //default language will be set based on the default language set in the .xml of the .utree file
         *         UsbongUtils.setDefaultLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed));
         */
        UsbongUtils.setCurrLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed));//prefs.getInt("preferredLanguage", 0))); //updated by Mike, 20160612
    } else {
        //default..
        currLanguageBeingUsed = UsbongUtils.getLanguageID(UsbongUtils.getCurrLanguage());
        //UsbongUtils.setCurrLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //updated by Mike, 20160612
    }

    /*       //commented out by Mike, 20160618
     *       //why? the index numbers used by currSelectedItemForSetLanguage does not always match with currLanguageBeingUsed
     *        //added by Mike, 20160608
     *        currSelectedItemForSetLanguage = currLanguageBeingUsed;
     */
    //==================================================================
    //text-to-speech stuff
    /*//comment out, not needed in DAHON, 
     * commented out by Mike, 20160613
            Intent checkIntent = new Intent();
            checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
            startActivityForResult(checkIntent, UsbongUtils.MY_DATA_CHECK_CODE);
    */
    mTts = new TextToSpeech(this, this);
    mTts.setLanguage(new Locale("en", "US"));//default
    //==================================================================

    myMediaPlayer = new MediaPlayer();
    myMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); //added by Mike, 22 July 2015
    myMediaPlayer.setVolume(1.0f, 1.0f);

    //added by Mike, 25 Sept. 2015
    myBGMediaPlayer = new MediaPlayer();
    myBGMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    myBGMediaPlayer.setVolume(0.5f, 0.5f);

    //added by Mike, 22 July 2015
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);

    usbongNodeContainer = new Vector<String>();
    classificationContainer = new Vector<String>();
    radioButtonsContainer = new Vector<String>();
    usbongAnswerContainer = new Vector<String>();
    checkBoxesContainer = new Vector<String>();
    decisionTrackerContainer = new Vector<String>();

    usedBackButton = false;
    currAnswer = "";

    try {
        //commented out by Mike, 4 Oct. 2015
        UsbongUtils.createUsbongFileStructure();

        //added by Mike, 20160417
        UsbongUtils.initUsbongConfigFile();

        //create the usbong_demo_tree and store it in sdcard/usbong/usbong_trees
        //          UsbongUtils.storeAssetsFileIntoSDCard(this,"usbong_demo_tree.xml");
        //          UsbongUtils.storeAssetsFileIntoSDCard(this,UsbongUtils.DEFAULT_UTREE_TO_LOAD+".utree");

        //edited by Mike, 20161111
        UsbongUtils.storeAssetsFileIntoSDCard(this, "pagtsing.utree");
        UsbongUtils.storeAssetsFileIntoSDCard(this, "gamugamo.utree");
        UsbongUtils.storeAssetsFileIntoSDCard(this, "juant.utree");

        UsbongUtils.storeAssetsFileIntoSDCard(this, "pagtsing_icon.png");
        UsbongUtils.storeAssetsFileIntoSDCard(this, "gamugamo_icon.png");
        UsbongUtils.storeAssetsFileIntoSDCard(this, "juant_icon.png");
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    //Reference: http://stackoverflow.com/questions/2793004/java-lista-addalllistb-fires-nullpointerexception
    //Last accessed: 14 March 2012
    attachmentFilePaths = new ArrayList<String>();
    //      attachmentFilePaths.clear();
    //      System.out.println(">>>>>>>>> attachmentFilePaths.clear!");
    currAudioRecorder = null;

    myQRCodeContent = "";
    hasReturnedFromAnotherActivity = false; //camera, paint, email, etc

    //added by Mike, March 4, 2013
    usbongAnswerContainerCounter = 0;
    /*              
           ArrayList<String> skuList = new ArrayList<String> ();
           skuList.add(UsbongConstants.ALL_LOCAL_LANGUAGES_PRODUCT_ID);
           skuList.add(UsbongConstants.ALL_FOREIGN_LANGUAGES_PRODUCT_ID);
           Bundle querySkus = new Bundle();
           querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
    */

    new AsyncTask<String, Integer, Boolean>() {
        @Override
        protected void onPostExecute(Boolean result) {
            //added by Mike, 20160421
            //init purchase languages list
            purchaseLanguagesListDialog = new AlertDialog.Builder(getInstance());
            myPurchaseLanguageBundleListAdapter = new PurchaseLanguageBundleListAdapter(getInstance(),
                    UsbongUtils.getInAppOwnedItems(), UsbongUtils.getInAppMService());
            purchaseLanguagesListDialog.setTitle("Purchase");
            purchaseLanguagesListDialog.setSingleChoiceItems(myPurchaseLanguageBundleListAdapter, 0,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            //                         Log.i("Selected Item : ", (String) myPurchaseLanguageBundleListAdapter.getItem(which));
                            dialog.dismiss(); //edited by Mike, 20160508                  
                            //                        purchaseLanguagesListDialogInterface = dialog;
                        }
                    });
            purchaseLanguagesListDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        }

        @Override
        protected Boolean doInBackground(String... params) {
            try {
                UsbongUtils.initInAppBillingService(getInstance());
                UsbongUtils.initInAppBillingService(getInstance()); //need to call this twice to get the updated languageBundleList
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
    }.execute();

    //reference: Labeeb P's answer from stackoverflow;
    //http://stackoverflow.com/questions/4275797/view-setpadding-accepts-only-in-px-is-there-anyway-to-setpadding-in-dp;
    //last accessed: 23 May 2013
    final float scale = getResources().getDisplayMetrics().density;
    padding_in_px = (int) (padding_in_dp * scale + 0.5f);

    //added by Mike, 25 June 2013
    UsbongUtils.setDebugMode(UsbongUtils.isInDebugMode());

    //added by Mike, 25 Feb. 2014
    //        UsbongUtils.setStoreOutput(UsbongUtils.checkIfStoreOutput());
    UsbongUtils.setStoreOutput(false); //don't store output, added by Mike, 27 Sept. 2015

    myUsbongScreenProcessor = new UsbongScreenProcessor(UsbongDecisionTreeEngineActivity.getInstance());
    myUsbongVariableMemory = new HashMap<String, String>();

    //added by Mike, March 26, 2014
    try {
        Log.d(">>>>", "" + UsbongUtils.STORE_OUTPUT);
        if (UsbongUtils.STORE_OUTPUT) { //added by Mike, 27 Sept. 2015
            UsbongUtils.createNewOutputFolderStructure();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*//commented out by Mike, 20161110      
          //added by Mike, 30 April 2015
          isInTreeLoader=false;      
          myTree = UsbongUtils.DEFAULT_UTREE_TO_LOAD; //edited by Mike, 20160418
          UsbongUtils.clearTempFolder();
    */
    initTreeLoader();
}

From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java

private void initToneGenerator() {
    AudioManager mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    if (mToneGenerator == null) {
        try {//from w w  w .j a v  a 2 s.  co m
            int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
            int streamMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
            int volume = (int) (TONE_RELATIVE_VOLUME * (streamVolume / streamMaxVolume));
            mToneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, volume);

        } catch (RuntimeException e) {
            LogUtil.d("Exception caught while creating local tone generator: " + e);
            mToneGenerator = null;
        }
    }
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

public void readPrefs() {
    String valueTmp = "";
    try {//from  w ww.  j a  v a  2  s.  c om
        voltage_speech_alert = mPrefs.getString("voltage_speech_alert", voltage_speech_alert);
        height_speech_alert = mPrefs.getString("height_speech_alert", height_speech_alert);
        current_speech_alert = mPrefs.getString("current_speech_alert", current_speech_alert);
        used_speech_alert = mPrefs.getString("used_speech_alert", used_speech_alert);
        temp_speech_alert = mPrefs.getString("temp_speech_alert", temp_speech_alert);
        rpm_speech_alert = mPrefs.getString("rpm_speech_alert", rpm_speech_alert);
        speed_speech_alert = mPrefs.getString("speed_speech_alert", speed_speech_alert);
        mVoltageAlarm = getDouble("voltage", mVoltageAlarm);
        mUsedCap = getDouble("used_cap", mUsedCap);
        mCurrentAlarm = getDouble("current", mCurrentAlarm);
        mPowerAlarm = getDouble("power", mPowerAlarm);
        mSpeedAlarm = tools.getInteger("speed", mSpeedAlarm, mPrefs);
        // mSpeedAlarm = getInteger("speed", mSpeedAlarm);
        mRpmAlarm = getInteger("rpm", mRpmAlarm);
        mAltitudeAlarm = getInteger("altitude", mAltitudeAlarm);
        mFuelAlarm = getInteger("fuel", mFuelAlarm);
        voltage_hysteresis = getInteger("voltage_hysteresis", voltage_hysteresis);
        current_hysteresis = getInteger("current_hysteresis", current_hysteresis);
        rpm_hysteresis = getInteger("rpm_hysteresis", rpm_hysteresis);
        temperature_hysteresis = getInteger("temperature_hysteresis", temperature_hysteresis);

        power_hysteresis = getInteger("power_hysteresis", power_hysteresis);
        mTemperatureAlarm = getInteger("temperature", mTemperatureAlarm);
        speech_volume = getInteger("speech_volume", speech_volume);
        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        int sb2value = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        sb2value = sb2value * speech_volume / 100;
        am.setStreamVolume(AudioManager.STREAM_MUSIC, sb2value, 0);
        vibrate_on = mPrefs.getBoolean("vibrate_on", vibrate_on);
        metric = mPrefs.getBoolean("metric", metric);
        mpxData = mPrefs.getBoolean("mpx_data", mpxData);
        displayAlwaysOn = mPrefs.getBoolean("displayAlwaysOn", displayAlwaysOn);
        voltage_speech_ack = mPrefs.getBoolean("voltage_speech_ack", voltage_speech_ack);
        valueTmp = voltage_speech_label + ";" + voltage_speech_unit;
        valueTmp = mPrefs.getString("voltage_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            voltage_speech_label = tokens.nextToken().trim();
            voltage_speech_unit = tokens.nextToken().trim();
        }

        height_speech_ack = mPrefs.getBoolean("height_speech_ack", height_speech_ack);
        auto_connect = mPrefs.getBoolean("auto_connect", auto_connect);
        mpxData = mPrefs.getBoolean("mpx_data", mpxData);
        valueTmp = height_speech_label + ";" + height_speech_unit;
        valueTmp = mPrefs.getString("height_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            height_speech_label = tokens.nextToken().trim();
            height_speech_unit = tokens.nextToken().trim();
        }
        current_speech_ack = mPrefs.getBoolean("current_speech_ack", current_speech_ack);
        valueTmp = current_speech_label + ";" + current_speech_unit;
        valueTmp = mPrefs.getString("current_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            current_speech_label = tokens.nextToken().trim();
            current_speech_unit = tokens.nextToken().trim();
        }
        used_speech_ack = mPrefs.getBoolean("used_speech_ack", used_speech_ack);
        valueTmp = used_speech_label + ";" + used_speech_unit;
        valueTmp = mPrefs.getString("used_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            used_speech_label = tokens.nextToken().trim();
            used_speech_unit = tokens.nextToken().trim();
        }
        speed_speech_ack = mPrefs.getBoolean("speed_speech_ack", speed_speech_ack);
        valueTmp = speed_speech_label + ";" + speed_speech_unit;
        valueTmp = mPrefs.getString("speed_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            speed_speech_label = tokens.nextToken().trim();
            speed_speech_unit = tokens.nextToken().trim();
        }
        vario_delay = mPrefs.getString("vario_delay", vario_delay);
        rpm_speech_ack = mPrefs.getBoolean("rpm_speech_ack", rpm_speech_ack);
        valueTmp = rpm_speech_label + ";" + rpm_speech_unit;
        valueTmp = mPrefs.getString("rpm_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            rpm_speech_label = tokens.nextToken().trim();
            rpm_speech_unit = tokens.nextToken().trim();
        }

        temp_speech_ack = mPrefs.getBoolean("temp_speech_ack", temp_speech_ack);
        valueTmp = temp_speech_label + ";" + temp_speech_unit;
        valueTmp = mPrefs.getString("temp_speech_text", valueTmp);
        if (!valueTmp.equals("") && valueTmp.contains(";")) {
            StringTokenizer tokens = new StringTokenizer(valueTmp, ";");
            temp_speech_label = tokens.nextToken().trim();
            temp_speech_unit = tokens.nextToken().trim();
        }

    } catch (Exception e) {
    }
    valueTmp = mPrefs.getString("log_file", log_file);
    if (valueTmp != "") {
        log_file = valueTmp;
    }
    valueTmp = mPrefs.getString("bluetooth_device", bluetooth_device);
    if (valueTmp != "") {
        bluetooth_device = valueTmp;
    }
    mSound_on = mPrefs.getBoolean("sound_on", mSound_on);
    speech_on = mPrefs.getBoolean("speech_on", speech_on);
    speech_intervall = mPrefs.getString("speech_intervall", speech_intervall);

    speech_alert_intervall = mPrefs.getString("speech_alert_intervall", speech_alert_intervall);
    mAlarm_on = mPrefs.getBoolean("alarm_on", mAlarm_on);
    mSpeak_on = mPrefs.getBoolean("speak_on", mSpeak_on);
    mlog_file = mPrefs.getBoolean("logging_on", mlog_file);
    alert_tone = mPrefs.getString("ringtone", alert_tone);
    label_rpm1 = mPrefs.getString("label_rpm1", label_rpm1);
    label_rpm2 = mPrefs.getString("label_rpm2", label_rpm2);
    label_temp1 = mPrefs.getString("label_temp1", label_temp1);
    label_temp2 = mPrefs.getString("label_temp2", label_temp2);
    unit_rpm1 = mPrefs.getString("unit_rpm1", unit_rpm1);
    unit_rpm2 = mPrefs.getString("unit_rpm2", unit_rpm2);
    unit_temp1 = mPrefs.getString("unit_temp1", unit_temp1);
    unit_temp2 = mPrefs.getString("unit_temp2", unit_temp2);
    current_sensor_type = mPrefs.getString("current_sensor_type", current_sensor_type);
    vario_delay = mPrefs.getString("vario_delay", vario_delay);

    alarm_voltage = mPrefs.getBoolean("alarm_voltage", alarm_voltage);
    alarm_used = mPrefs.getBoolean("alarm_used", alarm_used);
    alarm_current = mPrefs.getBoolean("alarm_current", alarm_current);
    alarm_speed = mPrefs.getBoolean("alarm_speed", alarm_speed);
    alarm_fuel = mPrefs.getBoolean("alarm_fuel", alarm_fuel);
    alarm_temperature = mPrefs.getBoolean("alarm_temperature", alarm_temperature);
    alarm_altitude = mPrefs.getBoolean("alarm_altitude", alarm_altitude);
    alarm_rpm = mPrefs.getBoolean("alarm_rpm", alarm_rpm);
    alarm_power = mPrefs.getBoolean("alarm_power", alarm_power);
    speak_voltage = mPrefs.getBoolean("speak_voltage", speak_voltage);
    speak_used = mPrefs.getBoolean("speak_used", speak_used);
    speak_current = mPrefs.getBoolean("speak_current", speak_current);
    speak_speed = mPrefs.getBoolean("speak_speed", speak_speed);
    speak_fuel = mPrefs.getBoolean("speak_fuel", speak_fuel);
    speak_temperature = mPrefs.getBoolean("speak_temperature", speak_temperature);
    speak_altitude = mPrefs.getBoolean("speak_altitude", speak_altitude);
    speak_rpm = mPrefs.getBoolean("speak_rpm", speak_rpm);
    speak_power = mPrefs.getBoolean("speak_power", speak_power);
    if (rpm1Label != null)
        rpm1Label.setText(label_rpm1);
    if (rpm2Label != null)
        rpm2Label.setText(label_rpm2);
    if (tempLabel != null)
        tempLabel.setText(label_temp1);
    if (temp2Label != null)
        temp2Label.setText(label_temp2);
    if (rpm1_unit != null)
        rpm1_unit.setText(unit_rpm1);
    if (rpm2_unit != null)
        rpm2_unit.setText(unit_rpm2);
    if (temp1_unit != null)
        temp1_unit.setText(unit_temp1);
    if (temp1_unit != null)
        temp1_unit.setText(unit_temp2);
    if (alert_tone.equals("")) {
        uri = null;
    } else {
        uri = Uri.parse(alert_tone);
    }
    if (mp != null) {
        mp.stop();
        mp.release();
        mp = null;
        if (uri != null && !uri.toString().equals("res/raw/alarm.mp3")) {

            mp = MediaPlayer.create(getApplicationContext(), uri);
        } else {
            mp = MediaPlayer.create(getApplicationContext(), R.raw.alarm);
        }
    }
}