Search in sources :

Example 1 with EqualizerBar

use of org.videolan.vlc.gui.view.EqualizerBar in project vlc-android by videolan.

the class EqualizerFragment method updateEqualizer.

private void updateEqualizer(int pos) {
    if (updateAlreadyHandled) {
        updateAlreadyHandled = false;
    } else {
        if (getEqualizerType(pos) == TYPE_PRESET) {
            mEqualizer = MediaPlayer.Equalizer.createFromPreset(pos);
            mState.update(pos, true);
        } else if (getEqualizerType(pos) == TYPE_CUSTOM) {
            mEqualizer = VLCOptions.getCustomSet(context, allSets.get(pos));
            mState.update(pos, true);
        } else if (getEqualizerType(pos) == TYPE_NEW) {
            mEqualizer = MediaPlayer.Equalizer.create();
            mState.update(pos, false);
        }
    }
    binding.equalizerPreamp.setProgress((int) mEqualizer.getPreAmp() + 20);
    for (int i = 0; i < BAND_COUNT; ++i) {
        EqualizerBar bar = (EqualizerBar) binding.equalizerBands.getChildAt(i);
        if (bar != null)
            bar.setValue(mEqualizer.getAmp(i));
    }
    if (binding.equalizerButton.isChecked())
        mService.setEqualizer(mEqualizer);
}
Also used : EqualizerBar(org.videolan.vlc.gui.view.EqualizerBar)

Example 2 with EqualizerBar

use of org.videolan.vlc.gui.view.EqualizerBar in project vlc-android by videolan.

the class EqualizerFragment method fillViews.

private void fillViews() {
    context = getActivity();
    if (context == null)
        return;
    allSets.clear();
    allSets = new ArrayList<>();
    allSets.addAll(Arrays.asList(getEqualizerPresets()));
    presetCount = allSets.size();
    for (Map.Entry<String, ?> entry : PreferenceManager.getDefaultSharedPreferences(context).getAll().entrySet()) {
        if (entry.getKey().startsWith("custom_equalizer_")) {
            allSets.add(entry.getKey().replace("custom_equalizer_", "").replace("_", " "));
            customCount++;
        }
    }
    allSets.add(newPresetName);
    mEqualizer = VLCOptions.getEqualizerSetFromSettings(context, true);
    // on/off
    binding.equalizerButton.setChecked(VLCOptions.getEqualizerEnabledState(context));
    binding.equalizerButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mService != null)
                if (isChecked)
                    mService.setEqualizer(mEqualizer);
                else
                    mService.setEqualizer(null);
        }
    });
    binding.equalizerSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            createSaveCustomSetDialog(binding.equalizerPresets.getSelectedItemPosition(), true, false);
        }
    });
    binding.equalizerDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            createDeleteCustomSetSnacker();
        }
    });
    binding.equalizerRevert.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            revertCustomSetChanges();
        }
    });
    // presets
    adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, allSets);
    binding.equalizerPresets.setAdapter(adapter);
    // Set the default selection asynchronously to prevent a layout initialization bug.
    binding.equalizerPresets.post(new Runnable() {

        @Override
        public void run() {
            binding.equalizerPresets.setOnItemSelectedListener(mSetListener);
            final int pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(context));
            mState.update(pos, VLCOptions.getEqualizerSavedState(context));
            updateAlreadyHandled = true;
            if (binding.equalizerButton.isChecked() || !mState.saved) {
                savePos = pos;
                revertPos = getEqualizerType(pos) == TYPE_CUSTOM ? pos : 0;
                binding.equalizerPresets.setSelection(pos);
            } else {
                updateEqualizer(0);
            }
        }
    });
    // preamp
    binding.equalizerPreamp.setMax(40);
    binding.equalizerPreamp.setProgress((int) mEqualizer.getPreAmp() + 20);
    binding.equalizerPreamp.setOnSeekBarChangeListener(mPreampListener);
    // bands
    for (int i = 0; i < BAND_COUNT; i++) {
        float band = MediaPlayer.Equalizer.getBandFrequency(i);
        EqualizerBar bar = new EqualizerBar(context, band);
        bar.setValue(mEqualizer.getAmp(i));
        bar.setListener(new BandListener(i));
        binding.equalizerBands.addView(bar);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1);
        bar.setLayoutParams(params);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) LayoutParams(android.view.ViewGroup.LayoutParams) View(android.view.View) AdapterView(android.widget.AdapterView) EqualizerBar(org.videolan.vlc.gui.view.EqualizerBar) Map(java.util.Map) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Example 3 with EqualizerBar

use of org.videolan.vlc.gui.view.EqualizerBar in project vlc-android by GeoffreyMetais.

the class EqualizerFragment method fillViews.

private void fillViews() {
    context = getActivity();
    if (context == null)
        return;
    allSets.clear();
    allSets = new ArrayList<>();
    allSets.addAll(Arrays.asList(getEqualizerPresets()));
    presetCount = allSets.size();
    for (Map.Entry<String, ?> entry : PreferenceManager.getDefaultSharedPreferences(context).getAll().entrySet()) {
        if (entry.getKey().startsWith("custom_equalizer_")) {
            allSets.add(entry.getKey().replace("custom_equalizer_", "").replace("_", " "));
            customCount++;
        }
    }
    allSets.add(newPresetName);
    mEqualizer = VLCOptions.getEqualizerSetFromSettings(context, true);
    // on/off
    binding.equalizerButton.setChecked(VLCOptions.getEqualizerEnabledState(context));
    binding.equalizerButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mService != null)
                if (isChecked)
                    mService.setEqualizer(mEqualizer);
                else
                    mService.setEqualizer(null);
        }
    });
    binding.equalizerSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            createSaveCustomSetDialog(binding.equalizerPresets.getSelectedItemPosition(), true, false);
        }
    });
    binding.equalizerDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            createDeleteCustomSetSnacker();
        }
    });
    binding.equalizerRevert.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            revertCustomSetChanges();
        }
    });
    // presets
    adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, allSets);
    binding.equalizerPresets.setAdapter(adapter);
    // Set the default selection asynchronously to prevent a layout initialization bug.
    binding.equalizerPresets.post(new Runnable() {

        @Override
        public void run() {
            binding.equalizerPresets.setOnItemSelectedListener(mSetListener);
            final int pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(context));
            mState.update(pos, VLCOptions.getEqualizerSavedState(context));
            updateAlreadyHandled = true;
            if (binding.equalizerButton.isChecked() || !mState.saved) {
                savePos = pos;
                revertPos = getEqualizerType(pos) == TYPE_CUSTOM ? pos : 0;
                binding.equalizerPresets.setSelection(pos);
            } else {
                updateEqualizer(0);
            }
        }
    });
    // preamp
    binding.equalizerPreamp.setMax(40);
    binding.equalizerPreamp.setProgress((int) mEqualizer.getPreAmp() + 20);
    binding.equalizerPreamp.setOnSeekBarChangeListener(mPreampListener);
    // bands
    for (int i = 0; i < BAND_COUNT; i++) {
        float band = MediaPlayer.Equalizer.getBandFrequency(i);
        EqualizerBar bar = new EqualizerBar(context, band);
        bar.setValue(mEqualizer.getAmp(i));
        bar.setListener(new BandListener(i));
        binding.equalizerBands.addView(bar);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1);
        bar.setLayoutParams(params);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) LayoutParams(android.view.ViewGroup.LayoutParams) View(android.view.View) AdapterView(android.widget.AdapterView) EqualizerBar(org.videolan.vlc.gui.view.EqualizerBar) Map(java.util.Map) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Example 4 with EqualizerBar

use of org.videolan.vlc.gui.view.EqualizerBar in project vlc-android by GeoffreyMetais.

the class EqualizerFragment method updateEqualizer.

private void updateEqualizer(int pos) {
    if (updateAlreadyHandled) {
        updateAlreadyHandled = false;
    } else {
        if (getEqualizerType(pos) == TYPE_PRESET) {
            mEqualizer = MediaPlayer.Equalizer.createFromPreset(pos);
            mState.update(pos, true);
        } else if (getEqualizerType(pos) == TYPE_CUSTOM) {
            mEqualizer = VLCOptions.getCustomSet(context, allSets.get(pos));
            mState.update(pos, true);
        } else if (getEqualizerType(pos) == TYPE_NEW) {
            mEqualizer = MediaPlayer.Equalizer.create();
            mState.update(pos, false);
        }
    }
    binding.equalizerPreamp.setProgress((int) mEqualizer.getPreAmp() + 20);
    for (int i = 0; i < BAND_COUNT; ++i) {
        EqualizerBar bar = (EqualizerBar) binding.equalizerBands.getChildAt(i);
        if (bar != null)
            bar.setValue(mEqualizer.getAmp(i));
    }
    if (binding.equalizerButton.isChecked())
        mService.setEqualizer(mEqualizer);
}
Also used : EqualizerBar(org.videolan.vlc.gui.view.EqualizerBar)

Aggregations

EqualizerBar (org.videolan.vlc.gui.view.EqualizerBar)4 View (android.view.View)2 LayoutParams (android.view.ViewGroup.LayoutParams)2 AdapterView (android.widget.AdapterView)2 CompoundButton (android.widget.CompoundButton)2 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)2 LinearLayout (android.widget.LinearLayout)2 Map (java.util.Map)2