Skip to content

Commit ddee945

Browse files
committed
Kotlin fragments
1 parent 6a7500e commit ddee945

13 files changed

+503
-557
lines changed

app/src/main/java/info/appdev/chartexample/fragments/BarChartFrag.java

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package info.appdev.chartexample.fragments
2+
3+
import android.graphics.Typeface
4+
import android.os.Bundle
5+
import android.util.Log
6+
import android.view.LayoutInflater
7+
import android.view.MotionEvent
8+
import android.view.View
9+
import android.view.ViewGroup
10+
import android.widget.FrameLayout
11+
import androidx.fragment.app.Fragment
12+
import com.github.mikephil.charting.charts.BarChart
13+
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture
14+
import com.github.mikephil.charting.listener.OnChartGestureListener
15+
import info.appdev.chartexample.R
16+
import info.appdev.chartexample.custom.MyMarkerView
17+
18+
class BarChartFrag : SimpleFragment(), OnChartGestureListener {
19+
private var chart: BarChart? = null
20+
21+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
22+
val v = inflater.inflate(R.layout.frag_simple_bar, container, false)
23+
24+
// create a new chart object
25+
chart = BarChart(requireActivity())
26+
chart!!.description.isEnabled = false
27+
chart!!.onChartGestureListener = this
28+
29+
val mv = MyMarkerView(activity, R.layout.custom_marker_view)
30+
mv.chartView = chart // For bounds control
31+
chart!!.setMarker(mv)
32+
33+
chart!!.setDrawGridBackground(false)
34+
chart!!.setDrawBarShadow(false)
35+
36+
val tf = Typeface.createFromAsset(requireContext().assets, "OpenSans-Light.ttf")
37+
38+
chart!!.setData(generateBarData(1, 20000f))
39+
40+
val l = chart!!.legend
41+
l.typeface = tf
42+
43+
val leftAxis = chart!!.axisLeft
44+
leftAxis.typeface = tf
45+
leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true)
46+
47+
chart!!.axisRight.isEnabled = false
48+
49+
val xAxis = chart!!.xAxis
50+
xAxis.isEnabled = false
51+
52+
// programmatically add the chart
53+
val parent = v.findViewById<FrameLayout>(R.id.parentLayout)
54+
parent.addView(chart)
55+
56+
return v
57+
}
58+
59+
override fun onChartGestureStart(me: MotionEvent?, lastPerformedGesture: ChartGesture?) {
60+
Log.i("Gesture", "START")
61+
}
62+
63+
override fun onChartGestureEnd(me: MotionEvent?, lastPerformedGesture: ChartGesture?) {
64+
Log.i("Gesture", "END")
65+
chart!!.highlightValues(null)
66+
}
67+
68+
override fun onChartLongPressed(me: MotionEvent?) {
69+
Log.i("LongPress", "Chart long pressed.")
70+
}
71+
72+
override fun onChartDoubleTapped(me: MotionEvent?) {
73+
Log.i("DoubleTap", "Chart double-tapped.")
74+
}
75+
76+
override fun onChartSingleTapped(me: MotionEvent?) {
77+
Log.i("SingleTap", "Chart single-tapped.")
78+
}
79+
80+
override fun onChartFling(me1: MotionEvent?, me2: MotionEvent?, velocityX: Float, velocityY: Float) {
81+
Log.i("Fling", "Chart fling. VelocityX: $velocityX, VelocityY: $velocityY")
82+
}
83+
84+
override fun onChartScale(me: MotionEvent?, scaleX: Float, scaleY: Float) {
85+
Log.i("Scale / Zoom", "ScaleX: $scaleX, ScaleY: $scaleY")
86+
}
87+
88+
override fun onChartTranslate(me: MotionEvent?, dX: Float, dY: Float) {
89+
Log.i("Translate / Move", "dX: $dX, dY: $dY")
90+
}
91+
92+
companion object {
93+
fun newInstance(): Fragment {
94+
return BarChartFrag()
95+
}
96+
}
97+
}

app/src/main/java/info/appdev/chartexample/fragments/ComplexityFragment.java

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package info.appdev.chartexample.fragments
2+
3+
import android.graphics.Typeface
4+
import android.os.Bundle
5+
import android.view.LayoutInflater
6+
import android.view.View
7+
import android.view.ViewGroup
8+
import androidx.fragment.app.Fragment
9+
import com.github.mikephil.charting.charts.LineChart
10+
import info.appdev.chartexample.R
11+
12+
class ComplexityFragment : SimpleFragment() {
13+
private var chart: LineChart? = null
14+
15+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
16+
val v = inflater.inflate(R.layout.frag_simple_line, container, false)
17+
18+
chart = v.findViewById(R.id.lineChart1)
19+
20+
chart!!.description.isEnabled = false
21+
22+
chart!!.setDrawGridBackground(false)
23+
24+
chart!!.setData(complexity)
25+
chart!!.animateX(3000)
26+
27+
val tf = Typeface.createFromAsset(requireContext().assets, "OpenSans-Light.ttf")
28+
29+
val l = chart!!.legend
30+
l.typeface = tf
31+
32+
val leftAxis = chart!!.axisLeft
33+
leftAxis.typeface = tf
34+
35+
chart!!.axisRight.isEnabled = false
36+
37+
val xAxis = chart!!.xAxis
38+
xAxis.isEnabled = false
39+
40+
return v
41+
}
42+
43+
companion object {
44+
fun newInstance(): Fragment {
45+
return ComplexityFragment()
46+
}
47+
}
48+
}

app/src/main/java/info/appdev/chartexample/fragments/PieChartFrag.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)