Search in sources :

Example 1 with LineSet

use of com.db.chart.model.LineSet in project WilliamChart by diogobernardino.

the class LineChartView method onDrawChart.

/**
	 * Method responsible to draw a line with the parsed screen points.
	 *
	 * @param canvas The canvas to draw on.
	 */
@Override
public void onDrawChart(Canvas canvas, ArrayList<ChartSet> data) {
    LineSet lineSet;
    Path linePath;
    for (ChartSet set : data) {
        lineSet = (LineSet) set;
        if (lineSet.isVisible()) {
            mStyle.mLinePaint.setColor(lineSet.getColor());
            mStyle.mLinePaint.setStrokeWidth(lineSet.getThickness());
            applyShadow(mStyle.mLinePaint, lineSet.getAlpha(), lineSet.getShadowDx(), lineSet.getShadowDy(), lineSet.getShadowRadius(), lineSet.getShadowColor());
            if (lineSet.isDashed())
                mStyle.mLinePaint.setPathEffect(new DashPathEffect(lineSet.getDashedIntervals(), lineSet.getDashedPhase()));
            else
                mStyle.mLinePaint.setPathEffect(null);
            if (!lineSet.isSmooth())
                linePath = createLinePath(lineSet);
            else
                linePath = createSmoothLinePath(lineSet);
            //Draw background
            if (lineSet.hasFill() || lineSet.hasGradientFill())
                canvas.drawPath(createBackgroundPath(new Path(linePath), lineSet), mStyle.mFillPaint);
            //Draw line
            canvas.drawPath(linePath, mStyle.mLinePaint);
            //Draw points
            drawPoints(canvas, lineSet);
        }
    }
}
Also used : Path(android.graphics.Path) DashPathEffect(android.graphics.DashPathEffect) LineSet(com.db.chart.model.LineSet) ChartSet(com.db.chart.model.ChartSet)

Example 2 with LineSet

use of com.db.chart.model.LineSet 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)

Example 3 with LineSet

use of com.db.chart.model.LineSet in project WilliamChart by diogobernardino.

the class SandboxFragment method buildLineChart.

private static ChartView buildLineChart(LineChartView chart) {
    chart.reset();
    LineSet dataset = new LineSet(mLabels, mValues);
    if (mIsLineDashed)
        dataset.setDashed(mLineDashType);
    dataset.setSmooth(mIsLineSmooth).setThickness(Tools.fromDpToPx(mLineThickness)).setColor(mLineColorId);
    if (mPointsSizeId != -1)
        dataset.setDotsRadius(Tools.fromDpToPx(mPointsSize)).setDotsColor(mPointColorId);
    chart.addData(dataset);
    return chart;
}
Also used : LineSet(com.db.chart.model.LineSet)

Example 4 with LineSet

use of com.db.chart.model.LineSet in project WilliamChart by diogobernardino.

the class DashAnimation method nextUpdate.

@Override
public void nextUpdate(ChartSet set) {
    LineSet line = (LineSet) set;
    line.setDashedPhase(line.getDashedPhase() - 4);
}
Also used : LineSet(com.db.chart.model.LineSet)

Example 5 with LineSet

use of com.db.chart.model.LineSet in project WilliamChart by diogobernardino.

the class LineCardOne method show.

@Override
public void show(Runnable action) {
    super.show(action);
    // Tooltip
    mTip = new Tooltip(mContext, R.layout.linechart_three_tooltip, R.id.value);
    ((TextView) mTip.findViewById(R.id.value)).setTypeface(Typeface.createFromAsset(mContext.getAssets(), "OpenSans-Semibold.ttf"));
    mTip.setVerticalAlignment(Tooltip.Alignment.BOTTOM_TOP);
    mTip.setDimensions((int) Tools.fromDpToPx(58), (int) Tools.fromDpToPx(25));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mTip.setEnterAnimation(PropertyValuesHolder.ofFloat(View.ALPHA, 1), PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f), PropertyValuesHolder.ofFloat(View.SCALE_X, 1f)).setDuration(200);
        mTip.setExitAnimation(PropertyValuesHolder.ofFloat(View.ALPHA, 0), PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f), PropertyValuesHolder.ofFloat(View.SCALE_X, 0f)).setDuration(200);
        mTip.setPivotX(Tools.fromDpToPx(65) / 2);
        mTip.setPivotY(Tools.fromDpToPx(25));
    }
    mChart.setTooltips(mTip);
    // Data
    LineSet dataset = new LineSet(mLabels, mValues[0]);
    dataset.setColor(Color.parseColor("#758cbb")).setFill(Color.parseColor("#2d374c")).setDotsColor(Color.parseColor("#758cbb")).setThickness(4).setDashed(new float[] { 10f, 10f }).beginAt(5);
    mChart.addData(dataset);
    dataset = new LineSet(mLabels, mValues[0]);
    dataset.setColor(Color.parseColor("#b3b5bb")).setFill(Color.parseColor("#2d374c")).setDotsColor(Color.parseColor("#ffc755")).setThickness(4).endAt(6);
    mChart.addData(dataset);
    // Chart
    mChart.setBorderSpacing(Tools.fromDpToPx(15)).setAxisBorderValues(0, 20).setYLabels(AxisRenderer.LabelPosition.NONE).setLabelsColor(Color.parseColor("#6a84c3")).setXAxis(false).setYAxis(false);
    mBaseAction = action;
    Runnable chartAction = new Runnable() {

        @Override
        public void run() {
            mBaseAction.run();
            mTip.prepare(mChart.getEntriesArea(0).get(3), mValues[0][3]);
            mChart.showTooltip(mTip, true);
        }
    };
    Animation anim = new Animation().setEasing(new BounceInterpolator()).setEndAction(chartAction);
    mChart.show(anim);
}
Also used : BounceInterpolator(android.view.animation.BounceInterpolator) Tooltip(com.db.chart.tooltip.Tooltip) Animation(com.db.chart.animation.Animation) TextView(android.widget.TextView) LineSet(com.db.chart.model.LineSet)

Aggregations

LineSet (com.db.chart.model.LineSet)8 Animation (com.db.chart.animation.Animation)4 DashPathEffect (android.graphics.DashPathEffect)3 Paint (android.graphics.Paint)3 View (android.view.View)2 TextView (android.widget.TextView)2 Point (com.db.chart.model.Point)2 ChartView (com.db.chart.view.ChartView)2 LineChartView (com.db.chart.view.LineChartView)2 Path (android.graphics.Path)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 ViewGroup (android.view.ViewGroup)1 BounceInterpolator (android.view.animation.BounceInterpolator)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 ChartSet (com.db.chart.model.ChartSet)1