Skip to content

Commit bcf5909

Browse files
committed
Lint suggestions
1 parent d079e22 commit bcf5909

30 files changed

+155
-174
lines changed

app/src/main/java/info/appdev/chartexample/AnotherBarActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
3939

4040
title = "AnotherBarActivity"
4141

42-
tvX = findViewById<TextView>(R.id.tvXMax)
43-
tvY = findViewById<TextView>(R.id.tvYMax)
42+
tvX = findViewById(R.id.tvXMax)
43+
tvY = findViewById(R.id.tvYMax)
4444

45-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
45+
seekBarX = findViewById(R.id.seekBarX)
4646
seekBarX!!.setOnSeekBarChangeListener(this)
4747

48-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
48+
seekBarY = findViewById(R.id.seekBarY)
4949
seekBarY!!.setOnSeekBarChangeListener(this)
5050

51-
chart = findViewById<BarChart>(R.id.chart1)
51+
chart = findViewById(R.id.chart1)
5252

5353
chart!!.description.isEnabled = false
5454

app/src/main/java/info/appdev/chartexample/BarChartActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
5353

5454
title = "BarChartActivity"
5555

56-
tvX = findViewById<TextView>(R.id.tvXMax)
57-
tvY = findViewById<TextView>(R.id.tvYMax)
56+
tvX = findViewById(R.id.tvXMax)
57+
tvY = findViewById(R.id.tvYMax)
5858

59-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
60-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
59+
seekBarX = findViewById(R.id.seekBarX)
60+
seekBarY = findViewById(R.id.seekBarY)
6161

6262
seekBarY!!.setOnSeekBarChangeListener(this)
6363
seekBarX!!.setOnSeekBarChangeListener(this)
6464

65-
chart = findViewById<BarChart>(R.id.chart1)
65+
chart = findViewById(R.id.chart1)
6666
chart!!.setOnChartValueSelectedListener(this)
6767
chart!!.setRoundedBarRadius(50f)
6868

@@ -173,7 +173,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
173173
val endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark)
174174
val endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark)
175175

176-
val gradientFills: MutableList<Fill?> = ArrayList<Fill?>()
176+
val gradientFills: MutableList<Fill?> = ArrayList()
177177
gradientFills.add(Fill(startColor1, endColor1))
178178
gradientFills.add(Fill(startColor2, endColor2))
179179
gradientFills.add(Fill(startColor3, endColor3))

app/src/main/java/info/appdev/chartexample/BarChartActivityMultiDataset.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
4747

4848
title = "BarChartActivityMultiDataset"
4949

50-
tvX = findViewById<TextView>(R.id.tvXMax)
50+
tvX = findViewById(R.id.tvXMax)
5151
tvX!!.textSize = 10f
52-
tvY = findViewById<TextView>(R.id.tvYMax)
52+
tvY = findViewById(R.id.tvYMax)
5353

54-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
54+
seekBarX = findViewById(R.id.seekBarX)
5555
seekBarX!!.max = 50
5656
seekBarX!!.setOnSeekBarChangeListener(this)
5757

58-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
58+
seekBarY = findViewById(R.id.seekBarY)
5959
seekBarY!!.setOnSeekBarChangeListener(this)
6060

61-
chart = findViewById<BarChart>(R.id.chart1)
61+
chart = findViewById(R.id.chart1)
6262
chart!!.setOnChartValueSelectedListener(this)
6363
chart!!.description.isEnabled = false
6464

app/src/main/java/info/appdev/chartexample/BarChartActivitySinus.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
4141

4242
data = FileUtils.loadBarEntriesFromAssets(assets, "othersine.txt")
4343

44-
tvX = findViewById<TextView>(R.id.tvValueCount)
44+
tvX = findViewById(R.id.tvValueCount)
4545

46-
seekBarX = findViewById<SeekBar>(R.id.seekbarValues)
46+
seekBarX = findViewById(R.id.seekbarValues)
4747

48-
chart = findViewById<BarChart>(R.id.chart1)
48+
chart = findViewById(R.id.chart1)
4949

5050
chart!!.setDrawBarShadow(false)
5151
chart!!.setDrawValueAboveBar(true)
@@ -105,7 +105,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
105105
val entries = ArrayList<BarEntry?>()
106106

107107
for (i in 0..<count) {
108-
entries.add(data!!.get(i))
108+
entries.add(data!![i])
109109
}
110110

111111
val set: BarDataSet

app/src/main/java/info/appdev/chartexample/BarChartPositiveNegative.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BarChartPositiveNegative : DemoBase() {
3535

3636
title = "BarChartPositiveNegative"
3737

38-
chart = findViewById<BarChart>(R.id.chart1)
38+
chart = findViewById(R.id.chart1)
3939
chart!!.setBackgroundColor(Color.WHITE)
4040
chart!!.extraTopOffset = -30f
4141
chart!!.extraBottomOffset = 10f
@@ -76,7 +76,7 @@ class BarChartPositiveNegative : DemoBase() {
7676
chart!!.legend.isEnabled = false
7777

7878
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
79-
val data: MutableList<Data> = ArrayList<Data>()
79+
val data: MutableList<Data> = ArrayList()
8080
data.add(Data(0f, -224.1f, "12-29"))
8181
data.add(Data(1f, 238.5f, "12-30"))
8282
data.add(Data(2f, 1280.1f, "12-31"))
@@ -85,7 +85,7 @@ class BarChartPositiveNegative : DemoBase() {
8585

8686
xAxis.valueFormatter = object : IAxisValueFormatter {
8787
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
88-
return data.get(min(max(value.toInt(), 0), data.size - 1)).xAxisValue
88+
return data[min(max(value.toInt(), 0), data.size - 1)].xAxisValue
8989
}
9090
}
9191

@@ -100,7 +100,7 @@ class BarChartPositiveNegative : DemoBase() {
100100
val red = Color.rgb(211, 74, 88)
101101

102102
for (i in dataList.indices) {
103-
val d = dataList.get(i)
103+
val d = dataList[i]
104104
val entry = BarEntry(d.xValue, d.yValue)
105105
values.add(entry)
106106

@@ -140,11 +140,7 @@ class BarChartPositiveNegative : DemoBase() {
140140
private class Data(val xValue: Float, val yValue: Float, val xAxisValue: String?)
141141

142142
private class ValueFormatter : IValueFormatter {
143-
private val mFormat: DecimalFormat
144-
145-
init {
146-
mFormat = DecimalFormat("######.0")
147-
}
143+
private val mFormat: DecimalFormat = DecimalFormat("######.0")
148144

149145
override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String {
150146
return mFormat.format(value.toDouble())

app/src/main/java/info/appdev/chartexample/BubbleChartActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
4646

4747
title = "BubbleChartActivity"
4848

49-
tvX = findViewById<TextView>(R.id.tvXMax)
50-
tvY = findViewById<TextView>(R.id.tvYMax)
49+
tvX = findViewById(R.id.tvXMax)
50+
tvY = findViewById(R.id.tvYMax)
5151

52-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
52+
seekBarX = findViewById(R.id.seekBarX)
5353
seekBarX!!.setOnSeekBarChangeListener(this)
5454

55-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
55+
seekBarY = findViewById(R.id.seekBarY)
5656
seekBarY!!.setOnSeekBarChangeListener(this)
5757

58-
chart = findViewById<BubbleChart>(R.id.chart1)
58+
chart = findViewById(R.id.chart1)
5959
chart!!.description.isEnabled = false
6060

6161
chart!!.setOnChartValueSelectedListener(this)

app/src/main/java/info/appdev/chartexample/CandleStickChartActivity.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
4040

4141
title = "CandleStickChartActivity"
4242

43-
tvX = findViewById<TextView>(R.id.tvXMax)
44-
tvY = findViewById<TextView>(R.id.tvYMax)
43+
tvX = findViewById(R.id.tvXMax)
44+
tvY = findViewById(R.id.tvYMax)
4545

46-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
46+
seekBarX = findViewById(R.id.seekBarX)
4747
seekBarX!!.setOnSeekBarChangeListener(this)
4848

49-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
49+
seekBarY = findViewById(R.id.seekBarY)
5050
seekBarY!!.setOnSeekBarChangeListener(this)
5151

52-
chart = findViewById<CandleStickChart>(R.id.chart1)
52+
chart = findViewById(R.id.chart1)
5353
chart!!.setBackgroundColor(Color.WHITE)
5454

5555
chart!!.description.isEnabled = false
@@ -86,8 +86,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
8686
}
8787

8888
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
89-
var progress: Int
90-
progress = (seekBarX!!.progress)
89+
val progress: Int = (seekBarX!!.progress)
9190

9291
tvX!!.text = progress.toString()
9392
tvY!!.text = seekBarY!!.progress.toString()

app/src/main/java/info/appdev/chartexample/CombinedChartActivity.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.github.mikephil.charting.utils.ColorTemplate
3232
import info.appdev.chartexample.DataTools.Companion.getValues
3333
import info.appdev.chartexample.notimportant.DemoBase
3434
import androidx.core.net.toUri
35+
import kotlin.math.roundToInt
3536

3637
class CombinedChartActivity : DemoBase() {
3738
private var chart: CombinedChart? = null
@@ -48,7 +49,7 @@ class CombinedChartActivity : DemoBase() {
4849

4950
title = "CombinedChartActivity"
5051

51-
chart = findViewById<CombinedChart>(R.id.chart1)
52+
chart = findViewById(R.id.chart1)
5253
chart!!.description.isEnabled = false
5354
chart!!.setBackgroundColor(Color.WHITE)
5455
chart!!.setDrawGridBackground(false)
@@ -57,7 +58,7 @@ class CombinedChartActivity : DemoBase() {
5758

5859
// draw bars behind lines
5960
chart!!.setDrawOrder(
60-
arrayOf<DrawOrder>(
61+
arrayOf(
6162
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
6263
)
6364
)
@@ -83,7 +84,7 @@ class CombinedChartActivity : DemoBase() {
8384
xAxis.setGranularity(1f)
8485
xAxis.valueFormatter = object : IAxisValueFormatter {
8586
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
86-
return months.get(value.toInt() % months.size)
87+
return months[value.toInt() % months.size]
8788
}
8889
}
8990

@@ -144,7 +145,7 @@ class CombinedChartActivity : DemoBase() {
144145
set1.axisDependency = YAxis.AxisDependency.LEFT
145146

146147
val set2 = BarDataSet(entries2, "")
147-
set2.stackLabels = arrayOf<String>("Stack 1", "Stack 2")
148+
set2.stackLabels = arrayOf("Stack 1", "Stack 2")
148149
set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255))
149150
set2.setValueTextColor(Color.rgb(61, 165, 255))
150151
set2.valueTextSize = 10f
@@ -171,7 +172,7 @@ class CombinedChartActivity : DemoBase() {
171172

172173
var index = 0f
173174
while (index < sampleCount) {
174-
entries.add(Entry(index + 0.25f, values[Math.round(index * 2)]!!.toFloat() * 10 + 55))
175+
entries.add(Entry(index + 0.25f, values[(index * 2).roundToInt()]!!.toFloat() * 10 + 55))
175176
index += 0.5f
176177
}
177178

app/src/main/java/info/appdev/chartexample/CubicLineChartActivity.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.annotation.SuppressLint
55
import android.content.Intent
66
import android.content.pm.PackageManager
77
import android.graphics.Color
8-
import android.net.Uri
98
import android.os.Bundle
109
import android.view.Menu
1110
import android.view.MenuItem
@@ -24,6 +23,7 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet
2423
import info.appdev.chartexample.DataTools.Companion.getMuchValues
2524
import info.appdev.chartexample.databinding.ActivityLinechartBinding
2625
import info.appdev.chartexample.notimportant.DemoBase
26+
import androidx.core.net.toUri
2727

2828
class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
2929
private var tvX: TextView? = null
@@ -50,7 +50,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
5050
binding.chart1.setBackgroundColor(Color.rgb(104, 241, 175))
5151

5252
// no description text
53-
binding.chart1.getDescription().isEnabled = false
53+
binding.chart1.description.isEnabled = false
5454

5555
// enable touch gestures
5656
binding.chart1.setTouchEnabled(true)
@@ -63,32 +63,32 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
6363
binding.chart1.setPinchZoom(false)
6464

6565
binding.chart1.setDrawGridBackground(false)
66-
binding.chart1.setMaxHighlightDistance(300f)
66+
binding.chart1.maxHighlightDistance = 300f
6767

68-
val x = binding.chart1.getXAxis()
68+
val x = binding.chart1.xAxis
6969
x.isEnabled = false
7070

71-
val y = binding.chart1.getAxisLeft()
71+
val y = binding.chart1.axisLeft
7272
y.typeface = tfLight
7373
y.setLabelCount(6, false)
7474
y.textColor = Color.WHITE
7575
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART)
7676
y.setDrawGridLines(false)
7777
y.axisLineColor = Color.WHITE
7878

79-
binding.chart1.getAxisRight().isEnabled = false
79+
binding.chart1.axisRight.isEnabled = false
8080

8181
// add data
8282
binding.seekBarY.setOnSeekBarChangeListener(this)
8383
binding.seekBarX.setOnSeekBarChangeListener(this)
8484

8585
// lower max, as cubic runs significantly slower than linear
86-
binding.seekBarX.setMax(700)
86+
binding.seekBarX.max = 700
8787

88-
binding.seekBarX.setProgress(45)
89-
binding.seekBarY.setProgress(100)
88+
binding.seekBarX.progress = 45
89+
binding.seekBarY.progress = 100
9090

91-
binding.chart1.getLegend().isEnabled = false
91+
binding.chart1.legend.isEnabled = false
9292

9393
binding.chart1.animateXY(2000, 2000)
9494

@@ -156,7 +156,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
156156
when (item.itemId) {
157157
R.id.viewGithub -> {
158158
val i = Intent(Intent.ACTION_VIEW)
159-
i.setData(Uri.parse("https://github.com/AppDevNext/AndroidChart/blob/master/app/src/main/java/info/appdev/chartexample/CubicLineChartActivity.kt"))
159+
i.data = "https://github.com/AppDevNext/AndroidChart/blob/master/app/src/main/java/info/appdev/chartexample/CubicLineChartActivity.kt".toUri()
160160
startActivity(i)
161161
}
162162

@@ -174,7 +174,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
174174
}
175175

176176
R.id.actionToggleFilled -> {
177-
val sets = binding.chart1.data!!.getDataSets()
177+
val sets = binding.chart1.data!!.dataSets
178178

179179
for (iSet in sets) {
180180
val set = iSet as LineDataSet
@@ -186,7 +186,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
186186
}
187187

188188
R.id.actionToggleCircles -> {
189-
val sets = binding.chart1.data!!.getDataSets()
189+
val sets = binding.chart1.data!!.dataSets
190190

191191
for (iSet in sets) {
192192
val set = iSet as LineDataSet
@@ -197,7 +197,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
197197
}
198198

199199
R.id.actionToggleCubic -> {
200-
val sets = binding.chart1.data!!.getDataSets()
200+
val sets = binding.chart1.data!!.dataSets
201201

202202
for (iSet in sets) {
203203
val set = iSet as LineDataSet
@@ -210,7 +210,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
210210
}
211211

212212
R.id.actionToggleStepped -> {
213-
val sets = binding.chart1.data!!.getDataSets()
213+
val sets = binding.chart1.data!!.dataSets
214214

215215
for (iSet in sets) {
216216
val set = iSet as LineDataSet
@@ -223,7 +223,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener {
223223
}
224224

225225
R.id.actionToggleHorizontalCubic -> {
226-
val sets = binding.chart1.data!!.getDataSets()
226+
val sets = binding.chart1.data!!.dataSets
227227

228228
for (iSet in sets) {
229229
val set = iSet as LineDataSet

app/src/main/java/info/appdev/chartexample/DynamicalAddingActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener {
3636

3737
title = "DynamicalAddingActivity"
3838

39-
chart = findViewById<LineChart>(R.id.chart1)
39+
chart = findViewById(R.id.chart1)
4040
chart!!.setOnChartValueSelectedListener(this)
4141
chart!!.setDrawGridBackground(false)
4242
chart!!.description.isEnabled = false
@@ -121,7 +121,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener {
121121
values.add(Entry(i.toFloat(), (sampleValues[cycleValue]!!.toFloat() * 50f) + 50f * count))
122122
}
123123

124-
val set = LineDataSet(values, "DataSet " + count)
124+
val set = LineDataSet(values, "DataSet $count")
125125
set.setLineWidth(2.5f)
126126
set.circleRadius = 4.5f
127127

0 commit comments

Comments
 (0)