Search in sources :

Example 1 with AnalogController

use of com.sdsmdg.harjot.MusicDNA.customviews.AnalogController in project MusicDNA by harjot-oberai.

the class EqualizerFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    backBtn = (ImageView) view.findViewById(R.id.equalizer_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    fragTitle = (TextView) view.findViewById(R.id.equalizer_fragment_title);
    if (SplashActivity.tf4 != null)
        fragTitle.setTypeface(SplashActivity.tf4);
    equalizerSwitch = (SwitchCompat) view.findViewById(R.id.equalizer_switch);
    equalizerSwitch.setChecked(HomeActivity.isEqualizerEnabled);
    equalizerSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mCallback.onCheckChanged(isChecked);
        }
    });
    spinnerDropDownIcon = (ImageView) view.findViewById(R.id.spinner_dropdown_icon);
    spinnerDropDownIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            presetSpinner.performClick();
        }
    });
    presetSpinner = (Spinner) view.findViewById(R.id.equalizer_preset_spinner);
    equalizerBlocker = (FrameLayout) view.findViewById(R.id.equalizerBlocker);
    if (HomeActivity.isEqualizerEnabled) {
        equalizerBlocker.setVisibility(View.GONE);
    } else {
        equalizerBlocker.setVisibility(View.VISIBLE);
    }
    chart = (LineChartView) view.findViewById(R.id.lineChart);
    paint = new Paint();
    dataset = new LineSet();
    bassController = (AnalogController) view.findViewById(R.id.controllerBass);
    reverbController = (AnalogController) view.findViewById(R.id.controller3D);
    bassController.setLabel("BASS");
    reverbController.setLabel("3D");
    bassController.circlePaint2.setColor(HomeActivity.themeColor);
    bassController.linePaint.setColor(HomeActivity.themeColor);
    bassController.invalidate();
    reverbController.circlePaint2.setColor(HomeActivity.themeColor);
    bassController.linePaint.setColor(HomeActivity.themeColor);
    reverbController.invalidate();
    if (!HomeActivity.isEqualizerReloaded) {
        int x = 0;
        if (PlayerFragment.bassBoost != null) {
            try {
                x = ((PlayerFragment.bassBoost.getRoundedStrength() * 19) / 1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (PlayerFragment.presetReverb != null) {
            try {
                y = (PlayerFragment.presetReverb.getPreset() * 19) / 6;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (x == 0) {
            bassController.setProgress(1);
        } else {
            bassController.setProgress(x);
        }
        if (y == 0) {
            reverbController.setProgress(1);
        } else {
            reverbController.setProgress(y);
        }
    } else {
        int x = ((HomeActivity.bassStrength * 19) / 1000);
        y = (HomeActivity.reverbPreset * 19) / 6;
        if (x == 0) {
            bassController.setProgress(1);
        } else {
            bassController.setProgress(x);
        }
        if (y == 0) {
            reverbController.setProgress(1);
        } else {
            reverbController.setProgress(y);
        }
    }
    bassController.setOnProgressChangedListener(new AnalogController.onProgressChangedListener() {

        @Override
        public void onProgressChanged(int progress) {
            HomeActivity.bassStrength = (short) (((float) 1000 / 19) * (progress));
            try {
                PlayerFragment.bassBoost.setStrength(HomeActivity.bassStrength);
                HomeActivity.equalizerModel.setBassStrength(HomeActivity.bassStrength);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    reverbController.setOnProgressChangedListener(new AnalogController.onProgressChangedListener() {

        @Override
        public void onProgressChanged(int progress) {
            HomeActivity.reverbPreset = (short) ((progress * 6) / 19);
            HomeActivity.equalizerModel.setReverbPreset(HomeActivity.reverbPreset);
            try {
                PlayerFragment.presetReverb.setPreset(HomeActivity.reverbPreset);
            } catch (Exception e) {
                e.printStackTrace();
            }
            y = progress;
        }
    });
    mLinearLayout = (LinearLayout) view.findViewById(R.id.equalizerContainer);
    TextView equalizerHeading = new TextView(getContext());
    equalizerHeading.setText("Equalizer");
    equalizerHeading.setTextSize(20);
    equalizerHeading.setGravity(Gravity.CENTER_HORIZONTAL);
    numberOfFrequencyBands = 5;
    points = new float[numberOfFrequencyBands];
    final short lowerEqualizerBandLevel = PlayerFragment.mEqualizer.getBandLevelRange()[0];
    final short upperEqualizerBandLevel = PlayerFragment.mEqualizer.getBandLevelRange()[1];
    for (short i = 0; i < numberOfFrequencyBands; i++) {
        final short equalizerBandIndex = i;
        final TextView frequencyHeaderTextView = new TextView(getContext());
        frequencyHeaderTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        frequencyHeaderTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frequencyHeaderTextView.setTextColor(Color.parseColor("#FFFFFF"));
        frequencyHeaderTextView.setText((PlayerFragment.mEqualizer.getCenterFreq(equalizerBandIndex) / 1000) + "Hz");
        LinearLayout seekBarRowLayout = new LinearLayout(getContext());
        seekBarRowLayout.setOrientation(LinearLayout.VERTICAL);
        TextView lowerEqualizerBandLevelTextView = new TextView(getContext());
        lowerEqualizerBandLevelTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        lowerEqualizerBandLevelTextView.setTextColor(Color.parseColor("#FFFFFF"));
        lowerEqualizerBandLevelTextView.setText((lowerEqualizerBandLevel / 100) + "dB");
        TextView upperEqualizerBandLevelTextView = new TextView(getContext());
        lowerEqualizerBandLevelTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        upperEqualizerBandLevelTextView.setTextColor(Color.parseColor("#FFFFFF"));
        upperEqualizerBandLevelTextView.setText((upperEqualizerBandLevel / 100) + "dB");
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.weight = 1;
        SeekBar seekBar = new SeekBar(getContext());
        TextView textView = new TextView(getContext());
        switch(i) {
            case 0:
                seekBar = (SeekBar) view.findViewById(R.id.seekBar1);
                textView = (TextView) view.findViewById(R.id.textView1);
                break;
            case 1:
                seekBar = (SeekBar) view.findViewById(R.id.seekBar2);
                textView = (TextView) view.findViewById(R.id.textView2);
                break;
            case 2:
                seekBar = (SeekBar) view.findViewById(R.id.seekBar3);
                textView = (TextView) view.findViewById(R.id.textView3);
                break;
            case 3:
                seekBar = (SeekBar) view.findViewById(R.id.seekBar4);
                textView = (TextView) view.findViewById(R.id.textView4);
                break;
            case 4:
                seekBar = (SeekBar) view.findViewById(R.id.seekBar5);
                textView = (TextView) view.findViewById(R.id.textView5);
                break;
        }
        seekBarFinal[i] = seekBar;
        seekBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(Color.DKGRAY, PorterDuff.Mode.SRC_IN));
        seekBar.getThumb().setColorFilter(new PorterDuffColorFilter(HomeActivity.themeColor, PorterDuff.Mode.SRC_IN));
        seekBar.setId(i);
        //            seekBar.setLayoutParams(layoutParams);
        seekBar.setMax(upperEqualizerBandLevel - lowerEqualizerBandLevel);
        textView.setText(frequencyHeaderTextView.getText());
        textView.setTextColor(Color.WHITE);
        textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        if (HomeActivity.isEqualizerReloaded) {
            points[i] = HomeActivity.seekbarpos[i] - lowerEqualizerBandLevel;
            dataset.addPoint(frequencyHeaderTextView.getText().toString(), points[i]);
            seekBar.setProgress(HomeActivity.seekbarpos[i] - lowerEqualizerBandLevel);
        } else {
            points[i] = PlayerFragment.mEqualizer.getBandLevel(equalizerBandIndex) - lowerEqualizerBandLevel;
            dataset.addPoint(frequencyHeaderTextView.getText().toString(), points[i]);
            seekBar.setProgress(PlayerFragment.mEqualizer.getBandLevel(equalizerBandIndex) - lowerEqualizerBandLevel);
            HomeActivity.seekbarpos[i] = PlayerFragment.mEqualizer.getBandLevel(equalizerBandIndex);
            HomeActivity.isEqualizerReloaded = true;
        }
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                PlayerFragment.mEqualizer.setBandLevel(equalizerBandIndex, (short) (progress + lowerEqualizerBandLevel));
                points[seekBar.getId()] = PlayerFragment.mEqualizer.getBandLevel(equalizerBandIndex) - lowerEqualizerBandLevel;
                HomeActivity.seekbarpos[seekBar.getId()] = (progress + lowerEqualizerBandLevel);
                HomeActivity.equalizerModel.getSeekbarpos()[seekBar.getId()] = (progress + lowerEqualizerBandLevel);
                dataset.updateValues(points);
                chart.notifyDataUpdate();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                presetSpinner.setSelection(0);
                HomeActivity.presetPos = 0;
                HomeActivity.equalizerModel.setPresetPos(0);
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
    }
    equalizeSound();
    paint.setColor(Color.parseColor("#555555"));
    paint.setStrokeWidth((float) (1.10 * HomeActivity.ratio));
    dataset.setColor(HomeActivity.themeColor);
    dataset.setSmooth(true);
    dataset.setThickness(5);
    chart.setXAxis(false);
    chart.setYAxis(false);
    chart.setYLabels(AxisRenderer.LabelPosition.NONE);
    chart.setXLabels(AxisRenderer.LabelPosition.NONE);
    chart.setGrid(ChartView.GridType.NONE, 7, 10, paint);
    chart.setAxisBorderValues(-300, 3300);
    chart.addData(dataset);
    chart.show();
    Button mEndButton = new Button(getContext());
    mEndButton.setBackgroundColor(HomeActivity.themeColor);
    mEndButton.setTextColor(Color.WHITE);
    showCase = new ShowcaseView.Builder(getActivity()).blockAllTouches().singleShot(4).setStyle(R.style.CustomShowcaseTheme).useDecorViewAsParent().replaceEndButton(mEndButton).setContentTitlePaint(HomeActivity.tp).setTarget(new ViewTarget(R.id.showcase_view_equalizer, getActivity())).setContentTitle("Presets").setContentText("Use one of the available presets").build();
    showCase.setButtonText("Next");
    showCase.setButtonPosition(HomeActivity.lps);
    showCase.overrideButtonClick(new View.OnClickListener() {

        int count1 = 0;

        @Override
        public void onClick(View v) {
            count1++;
            switch(count1) {
                case 1:
                    showCase.setTarget(new ViewTarget(R.id.equalizerContainer, getActivity()));
                    showCase.setContentTitle("Equalizer Controls");
                    showCase.setContentText("Use the seekbars to control the Individual frequencies");
                    showCase.setButtonPosition(HomeActivity.lps);
                    showCase.setButtonText("Next");
                    break;
                case 2:
                    showCase.setTarget(new ViewTarget(R.id.controllerBass, getActivity()));
                    showCase.setContentTitle("Bass and Reverb");
                    showCase.setContentText("Use these controls to control Bass and Reverb");
                    showCase.setButtonPosition(HomeActivity.lps);
                    showCase.setButtonText("Done");
                    break;
                case 3:
                    showCase.hide();
                    break;
            }
        }
    });
}
Also used : PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ViewTarget(com.github.amlcurran.showcaseview.targets.ViewTarget) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextView(android.widget.TextView) SeekBar(android.widget.SeekBar) ViewGroup(android.view.ViewGroup) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) ChartView(com.db.chart.view.ChartView) TextView(android.widget.TextView) LineChartView(com.db.chart.view.LineChartView) LineSet(com.db.chart.model.LineSet) Paint(android.graphics.Paint) AnalogController(com.sdsmdg.harjot.MusicDNA.customviews.AnalogController) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Aggregations

Paint (android.graphics.Paint)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 LineSet (com.db.chart.model.LineSet)1 ChartView (com.db.chart.view.ChartView)1 LineChartView (com.db.chart.view.LineChartView)1 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)1 ViewTarget (com.github.amlcurran.showcaseview.targets.ViewTarget)1 AnalogController (com.sdsmdg.harjot.MusicDNA.customviews.AnalogController)1