diff --git a/app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.java b/app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.java deleted file mode 100644 index 5161c53793..0000000000 --- a/app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.java +++ /dev/null @@ -1,52 +0,0 @@ - -package info.appdev.chartexample.custom; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.widget.TextView; - -import com.github.mikephil.charting.components.MarkerView; -import com.github.mikephil.charting.data.CandleEntry; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.MPPointF; -import com.github.mikephil.charting.utils.Utils; - -import info.appdev.chartexample.R; - -/** - * Custom implementation of the MarkerView. - * - * @author Philipp Jahoda - */ -@SuppressLint("ViewConstructor") -public class MyMarkerView extends MarkerView { - - private final TextView tvContent; - - public MyMarkerView(Context context, int layoutResource) { - super(context, layoutResource); - - tvContent = findViewById(R.id.tvContent); - } - - // runs every time the MarkerView is redrawn, can be used to update the - // content (user-interface) - @Override - public void refreshContent(Entry e, Highlight highlight) { - - if (e instanceof CandleEntry ce) { - tvContent.setText(Utils.formatNumber(ce.getHigh(), 0, true)); - } else { - - tvContent.setText(Utils.formatNumber(e.getY(), 0, true)); - } - - super.refreshContent(e, highlight); - } - - @Override - public MPPointF getOffset() { - return new MPPointF(-(getWidth() / 2), -getHeight()); - } -} diff --git a/app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.kt b/app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.kt new file mode 100644 index 0000000000..ffae0e0c7d --- /dev/null +++ b/app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.kt @@ -0,0 +1,36 @@ +package info.appdev.chartexample.custom + +import android.annotation.SuppressLint +import android.content.Context +import android.widget.TextView +import com.github.mikephil.charting.components.MarkerView +import com.github.mikephil.charting.data.CandleEntry +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.MPPointF +import com.github.mikephil.charting.utils.Utils +import info.appdev.chartexample.R + +/** + * Custom implementation of the MarkerView. + */ +@SuppressLint("ViewConstructor") +class MyMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, layoutResource) { + private val tvContent: TextView = findViewById(R.id.tvContent) + + // runs every time the MarkerView is redrawn, can be used to update the + // content (user-interface) + override fun refreshContent(e: Entry, highlight: Highlight?) { + if (e is CandleEntry) { + tvContent.text = Utils.formatNumber(e.high, 0, true) + } else { + tvContent.text = Utils.formatNumber(e.y, 0, true) + } + + super.refreshContent(e, highlight) + } + + override fun getOffset(): MPPointF { + return MPPointF(-(width / 2).toFloat(), -height.toFloat()) + } +} diff --git a/app/src/main/java/info/appdev/chartexample/custom/RadarMarkerView.java b/app/src/main/java/info/appdev/chartexample/custom/RadarMarkerView.java deleted file mode 100644 index 686634dad5..0000000000 --- a/app/src/main/java/info/appdev/chartexample/custom/RadarMarkerView.java +++ /dev/null @@ -1,49 +0,0 @@ - -package info.appdev.chartexample.custom; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Typeface; -import android.widget.TextView; - -import com.github.mikephil.charting.components.MarkerView; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.MPPointF; - -import java.text.DecimalFormat; - -import info.appdev.chartexample.R; - -/** - * Custom implementation of the MarkerView. - * - * @author Philipp Jahoda - */ -@SuppressLint("ViewConstructor") -public class RadarMarkerView extends MarkerView { - - private final TextView tvContent; - private final DecimalFormat format = new DecimalFormat("##0"); - - public RadarMarkerView(Context context, int layoutResource) { - super(context, layoutResource); - - tvContent = findViewById(R.id.tvContent); - tvContent.setTypeface(Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf")); - } - - // runs every time the MarkerView is redrawn, can be used to update the - // content (user-interface) - @Override - public void refreshContent(Entry e, Highlight highlight) { - tvContent.setText(String.format("%s %%", format.format(e.getY()))); - - super.refreshContent(e, highlight); - } - - @Override - public MPPointF getOffset() { - return new MPPointF(-(getWidth() / 2), -getHeight() - 10); - } -} diff --git a/app/src/main/java/info/appdev/chartexample/custom/RadarMarkerView.kt b/app/src/main/java/info/appdev/chartexample/custom/RadarMarkerView.kt new file mode 100644 index 0000000000..b45c472657 --- /dev/null +++ b/app/src/main/java/info/appdev/chartexample/custom/RadarMarkerView.kt @@ -0,0 +1,37 @@ +package info.appdev.chartexample.custom + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.Typeface +import android.widget.TextView +import com.github.mikephil.charting.components.MarkerView +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.MPPointF +import info.appdev.chartexample.R +import java.text.DecimalFormat + +/** + * Custom implementation of the MarkerView. + */ +@SuppressLint("ViewConstructor") +class RadarMarkerView(context: Context, layoutResource: Int) : MarkerView(context, layoutResource) { + private val tvContent: TextView = findViewById(R.id.tvContent) + private val format = DecimalFormat("##0") + + init { + tvContent.setTypeface(Typeface.createFromAsset(context.assets, "OpenSans-Light.ttf")) + } + + // runs every time the MarkerView is redrawn, can be used to update the + // content (user-interface) + override fun refreshContent(e: Entry, highlight: Highlight?) { + tvContent.text = String.format("%s %%", format.format(e.y.toDouble())) + + super.refreshContent(e, highlight) + } + + override fun getOffset(): MPPointF { + return MPPointF(-(width / 2).toFloat(), (-height - 10).toFloat()) + } +} diff --git a/app/src/main/java/info/appdev/chartexample/custom/StackedBarsMarkerView.java b/app/src/main/java/info/appdev/chartexample/custom/StackedBarsMarkerView.java deleted file mode 100644 index e56a8896a6..0000000000 --- a/app/src/main/java/info/appdev/chartexample/custom/StackedBarsMarkerView.java +++ /dev/null @@ -1,62 +0,0 @@ - -package info.appdev.chartexample.custom; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.widget.TextView; - -import com.github.mikephil.charting.components.MarkerView; -import com.github.mikephil.charting.data.BarEntry; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.MPPointF; -import com.github.mikephil.charting.utils.Utils; - -import info.appdev.chartexample.R; - -/** - * Custom implementation of the MarkerView. - * - * @author Philipp Jahoda - */ -@SuppressWarnings("unused") -@SuppressLint("ViewConstructor") -public class StackedBarsMarkerView extends MarkerView { - - private TextView tvContent; - - public StackedBarsMarkerView(Context context, int layoutResource) { - super(context, layoutResource); - - tvContent = findViewById(R.id.tvContent); - } - - // runs every time the MarkerView is redrawn, can be used to update the - // content (user-interface) - @Override - public void refreshContent(Entry e, Highlight highlight) { - - if (e instanceof BarEntry) { - - BarEntry be = (BarEntry) e; - - if(be.getYVals() != null) { - - // draw the stack value - tvContent.setText(Utils.formatNumber(be.getYVals()[highlight.getStackIndex()], 0, true)); - } else { - tvContent.setText(Utils.formatNumber(be.getY(), 0, true)); - } - } else { - - tvContent.setText(Utils.formatNumber(e.getY(), 0, true)); - } - - super.refreshContent(e, highlight); - } - - @Override - public MPPointF getOffset() { - return new MPPointF(-(getWidth() / 2), -getHeight()); - } -} diff --git a/app/src/main/java/info/appdev/chartexample/custom/StackedBarsMarkerView.kt b/app/src/main/java/info/appdev/chartexample/custom/StackedBarsMarkerView.kt new file mode 100644 index 0000000000..74bebe2a3c --- /dev/null +++ b/app/src/main/java/info/appdev/chartexample/custom/StackedBarsMarkerView.kt @@ -0,0 +1,43 @@ +package info.appdev.chartexample.custom + +import android.annotation.SuppressLint +import android.content.Context +import android.widget.TextView +import com.github.mikephil.charting.components.MarkerView +import com.github.mikephil.charting.data.BarEntry +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.MPPointF +import com.github.mikephil.charting.utils.Utils +import info.appdev.chartexample.R + +/** + * Custom implementation of the MarkerView. + */ +@Suppress("unused") +@SuppressLint("ViewConstructor") +class StackedBarsMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, layoutResource) { + private val tvContent: TextView = findViewById(R.id.tvContent) + + // runs every time the MarkerView is redrawn, can be used to update the + // content (user-interface) + override fun refreshContent(entry: Entry, highlight: Highlight) { + if (entry is BarEntry) { + + if (entry.yVals != null) { + // draw the stack value + tvContent.text = Utils.formatNumber(entry.yVals!![highlight.stackIndex], 0, true) + } else { + tvContent.text = Utils.formatNumber(entry.y, 0, true) + } + } else { + tvContent.text = Utils.formatNumber(entry.y, 0, true) + } + + super.refreshContent(entry, highlight) + } + + override fun getOffset(): MPPointF { + return MPPointF(-(width / 2).toFloat(), -height.toFloat()) + } +} diff --git a/app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.java b/app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.java deleted file mode 100644 index 7bebd17ded..0000000000 --- a/app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.java +++ /dev/null @@ -1,53 +0,0 @@ - -package info.appdev.chartexample.custom; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.widget.TextView; - -import com.github.mikephil.charting.components.MarkerView; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.formatter.IAxisValueFormatter; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.MPPointF; - -import java.text.DecimalFormat; - -import info.appdev.chartexample.R; - -/** - * Custom implementation of the MarkerView. - * - * @author Philipp Jahoda - */ -@SuppressLint("ViewConstructor") -public class XYMarkerView extends MarkerView { - - private final TextView tvContent; - private final IAxisValueFormatter xAxisValueFormatter; - - private final DecimalFormat format; - - public XYMarkerView(Context context, IAxisValueFormatter xAxisValueFormatter) { - super(context, R.layout.custom_marker_view); - - this.xAxisValueFormatter = xAxisValueFormatter; - tvContent = findViewById(R.id.tvContent); - format = new DecimalFormat("###.0"); - } - - // runs every time the MarkerView is redrawn, can be used to update the - // content (user-interface) - @Override - public void refreshContent(Entry e, Highlight highlight) { - - tvContent.setText(String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.getX(), null), format.format(e.getY()))); - - super.refreshContent(e, highlight); - } - - @Override - public MPPointF getOffset() { - return new MPPointF(-(getWidth() / 2), -getHeight()); - } -} diff --git a/app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.kt b/app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.kt new file mode 100644 index 0000000000..a64f768c29 --- /dev/null +++ b/app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.kt @@ -0,0 +1,33 @@ +package info.appdev.chartexample.custom + +import android.annotation.SuppressLint +import android.content.Context +import android.widget.TextView +import com.github.mikephil.charting.components.MarkerView +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.formatter.IAxisValueFormatter +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.MPPointF +import info.appdev.chartexample.R +import java.text.DecimalFormat + +/** + * Custom implementation of the MarkerView. + */ +@SuppressLint("ViewConstructor") +class XYMarkerView(context: Context?, private val xAxisValueFormatter: IAxisValueFormatter) : MarkerView(context, R.layout.custom_marker_view) { + private val tvContent: TextView = findViewById(R.id.tvContent) + + private val format: DecimalFormat = DecimalFormat("###.0") + + // runs every time the MarkerView is redrawn, can be used to update the content (user-interface) + override fun refreshContent(e: Entry, highlight: Highlight?) { + tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.x, null), format.format(e.y.toDouble())) + + super.refreshContent(e, highlight) + } + + override fun getOffset(): MPPointF { + return MPPointF(-(width / 2).toFloat(), -height.toFloat()) + } +}