Android Open Source - DoomPlay Equalizer Bands Fragment






From Project

Back to project page DoomPlay.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project DoomPlay 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

package com.perm.DoomPlay;
//w  w w .j a  v a  2s. c om
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;

public class EqualizerBandsFragment extends Fragment implements SeekBar.OnSeekBarChangeListener
{
    SeekBar seek0;
    SeekBar seek1;
    SeekBar seek2;
    SeekBar seek3;
    SeekBar seek4;
    SeekBar seek5;
    SeekBar seek6;
    SeekBar seek7;
    SeekBar seek8;
    SeekBar seek9;

    TextView text0;
    TextView text1;
    TextView text2;
    TextView text3;
    TextView text4;
    TextView text5;
    TextView text6;
    TextView text7;
    TextView text8;
    TextView text9;


    public static int[] getSavedBounds()
    {
        int[] bound = new int[10];
        SharedPreferences preferences = MyApplication.getInstance().getSharedPreferences("bounds",Activity.MODE_PRIVATE);
        for(int i = 0 ; i < 10; i++)
        {
            bound[i] = preferences.getInt("equal"+String.valueOf(i),50);
        }
        return bound;
    }

    @Override
    public void onResume()
    {
        super.onResume();
        int[] bounds = getSavedBounds();
        for(int i = 0;i < bounds.length; i++)
        {
            try
            {
                SeekBar seekBar =(SeekBar)this.getClass().getDeclaredField("seek" + String.valueOf(i)).get(this);
                seekBar.setProgress(bounds[i]);

                TextView textView = (TextView)this.getClass().getDeclaredField("text"+String.valueOf(i)).get(this);
                textView.setText(String.format("%.1f db", EqualizerBandsFragment.convertProgressToGain(bounds[i])));

            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.equalizer_bands,container,false);

        seek0 = (SeekBar)view.findViewById(R.id.seekEqual0);
        seek1 = (SeekBar)view.findViewById(R.id.seekEqual1);
        seek2 = (SeekBar)view.findViewById(R.id.seekEqual2);
        seek3 = (SeekBar)view.findViewById(R.id.seekEqual3);
        seek4 = (SeekBar)view.findViewById(R.id.seekEqual4);
        seek5 = (SeekBar)view.findViewById(R.id.seekEqual5);
        seek6 = (SeekBar)view.findViewById(R.id.seekEqual6);
        seek7 = (SeekBar)view.findViewById(R.id.seekEqual7);
        seek8 = (SeekBar)view.findViewById(R.id.seekEqual8);
        seek9 = (SeekBar)view.findViewById(R.id.seekEqual9);

        text0 = (TextView)view.findViewById(R.id.textDb0);
        text1 = (TextView)view.findViewById(R.id.textDb1);
        text2 = (TextView)view.findViewById(R.id.textDb2);
        text3 = (TextView)view.findViewById(R.id.textDb3);
        text4 = (TextView)view.findViewById(R.id.textDb4);
        text5 = (TextView)view.findViewById(R.id.textDb5);
        text6 = (TextView)view.findViewById(R.id.textDb6);
        text7 = (TextView)view.findViewById(R.id.textDb7);
        text8 = (TextView)view.findViewById(R.id.textDb8);
        text9 = (TextView)view.findViewById(R.id.textDb9);

        seek0.setOnSeekBarChangeListener(this);
        seek1.setOnSeekBarChangeListener(this);
        seek2.setOnSeekBarChangeListener(this);
        seek3.setOnSeekBarChangeListener(this);
        seek4.setOnSeekBarChangeListener(this);
        seek5.setOnSeekBarChangeListener(this);
        seek6.setOnSeekBarChangeListener(this);
        seek7.setOnSeekBarChangeListener(this);
        seek8.setOnSeekBarChangeListener(this);
        seek9.setOnSeekBarChangeListener(this);
        return view;
    }
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
    {
        if(fromUser)
        {
            //for  java.lang.ClassCastException
            Object tag = seekBar.getTag();
            int n;
            if(tag instanceof Integer)
                n = (Integer)tag;
            else if(tag instanceof String)
                n = Integer.parseInt((String)tag);
            else
                throw new IllegalArgumentException("wtf exception");

            TextView textView ;
            try {
                textView = (TextView)this.getClass().getDeclaredField("text"+String.valueOf(n)).get(this);
                textView.setText(String.format("%.0f db", EqualizerBandsFragment.convertProgressToGain(progress)));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }


            saveBound(progress,n);
            BassPlayer.updateFX(progress, n);
        }
    }

    private void saveBound(int progress, int n)
    {
        SharedPreferences preferences =getActivity().getSharedPreferences("bounds", Activity.MODE_PRIVATE);

        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("equal" + String.valueOf(n), progress);
        editor.commit();
        editor.apply();
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {}
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {}

    public static float convertProgressToGain(int progress)
    {
        float x = (( progress * 3f )/ 10f) - 15f;
        return x;
    }
}




Java Source Code List

com.api.Account.java
com.api.Api.java
com.api.AudioAlbum.java
com.api.Auth.java
com.api.Group.java
com.api.IdsPair.java
com.api.KException.java
com.api.Media.java
com.api.Params.java
com.api.PhotoTag.java
com.api.Photo.java
com.api.SearchDialogItem.java
com.api.User.java
com.api.Utils.java
com.api.VkStatus.java
com.api.WrongResponseCodeException.java
com.perm.DoomPlay.AbstractControls.java
com.perm.DoomPlay.AbstractList.java
com.perm.DoomPlay.AbstractReceiver.java
com.perm.DoomPlay.AbstractVkItems.java
com.perm.DoomPlay.AddListDialog.java
com.perm.DoomPlay.AddTrackFromPlaybackDialog.java
com.perm.DoomPlay.AddTrackToAlbumDialog.java
com.perm.DoomPlay.AlbumArtGetter.java
com.perm.DoomPlay.AlbumArtistActivity.java
com.perm.DoomPlay.Audio.java
com.perm.DoomPlay.BassPlayer.java
com.perm.DoomPlay.BigWidget.java
com.perm.DoomPlay.CustomViewPager.java
com.perm.DoomPlay.DirectoryChooserActivity.java
com.perm.DoomPlay.DownloadNotifBuilder.java
com.perm.DoomPlay.Download.java
com.perm.DoomPlay.DownloadingService.java
com.perm.DoomPlay.EqualizerActivity.java
com.perm.DoomPlay.EqualizerBandsFragment.java
com.perm.DoomPlay.EqualizerEffectsFragment.java
com.perm.DoomPlay.ExceptionLog.java
com.perm.DoomPlay.FileSystemActivity.java
com.perm.DoomPlay.FullPlaybackActivity.java
com.perm.DoomPlay.ListTracksActivity.java
com.perm.DoomPlay.ListVkActivity.java
com.perm.DoomPlay.ListsAdapter.java
com.perm.DoomPlay.LoginActivity.java
com.perm.DoomPlay.LyricsDialog.java
com.perm.DoomPlay.MainLocalFragment.java
com.perm.DoomPlay.MainScreenActivity.java
com.perm.DoomPlay.MainVkFragment.java
com.perm.DoomPlay.MediaButtonReceiver.java
com.perm.DoomPlay.MyApplication.java
com.perm.DoomPlay.PageFragment.java
com.perm.DoomPlay.PlayingService.java
com.perm.DoomPlay.PlaylistActivity.java
com.perm.DoomPlay.PlaylistDB.java
com.perm.DoomPlay.PlaylistParser.java
com.perm.DoomPlay.ReportDialog.java
com.perm.DoomPlay.SearchActivity.java
com.perm.DoomPlay.SearchVkActivity.java
com.perm.DoomPlay.Serializator.java
com.perm.DoomPlay.SettingActivity.java
com.perm.DoomPlay.SleepDialog.java
com.perm.DoomPlay.SmallWidget.java
com.perm.DoomPlay.TracksHolder.java
com.perm.DoomPlay.Utils.java
com.perm.DoomPlay.VerticalSeekBar.java
com.perm.DoomPlay.VkAlbumsActivity.java
com.perm.DoomPlay.VkFrActivity.java
com.perm.DoomPlay.VkGrActivity.java
com.perm.DoomPlay.VkPopularActivity.java
com.un4seen.bass.BASSFLAC.java
com.un4seen.bass.BASSMIDI.java
com.un4seen.bass.BASSOPUS.java
com.un4seen.bass.BASSWV.java
com.un4seen.bass.BASS_AAC.java
com.un4seen.bass.BASS_ALAC.java
com.un4seen.bass.BASS_APE.java
com.un4seen.bass.BASS_MPC.java
com.un4seen.bass.BASS.java