Skip to content

Commit 46dbba3

Browse files
authored
Merge pull request #438 from AppDevNext/FixDeprecations
Fix deprecations
2 parents 96dc4e5 + caefcc7 commit 46dbba3

37 files changed

+229
-359
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.content.pm.PackageManager
66
import android.os.Bundle
77
import android.view.Menu
88
import android.view.MenuItem
9-
import android.view.WindowManager
109
import android.widget.SeekBar
1110
import android.widget.SeekBar.OnSeekBarChangeListener
1211
import android.widget.TextView
@@ -31,24 +30,20 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
3130

3231
override fun onCreate(savedInstanceState: Bundle?) {
3332
super.onCreate(savedInstanceState)
34-
window.setFlags(
35-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
36-
WindowManager.LayoutParams.FLAG_FULLSCREEN
37-
)
3833
setContentView(R.layout.activity_barchart)
3934

4035
title = "AnotherBarActivity"
4136

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

45-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
40+
seekBarX = findViewById(R.id.seekBarX)
4641
seekBarX!!.setOnSeekBarChangeListener(this)
4742

48-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
43+
seekBarY = findViewById(R.id.seekBarY)
4944
seekBarY!!.setOnSeekBarChangeListener(this)
5045

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

5348
chart!!.description.isEnabled = false
5449

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import android.os.Bundle
88
import android.util.Log
99
import android.view.Menu
1010
import android.view.MenuItem
11-
import android.view.WindowManager
1211
import android.widget.SeekBar
1312
import android.widget.SeekBar.OnSeekBarChangeListener
1413
import android.widget.TextView
1514
import androidx.core.content.ContextCompat
15+
import androidx.core.content.res.ResourcesCompat
1616
import androidx.core.net.toUri
1717
import com.github.mikephil.charting.charts.BarChart
1818
import com.github.mikephil.charting.components.Legend
@@ -45,24 +45,20 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
4545

4646
override fun onCreate(savedInstanceState: Bundle?) {
4747
super.onCreate(savedInstanceState)
48-
window.setFlags(
49-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
50-
WindowManager.LayoutParams.FLAG_FULLSCREEN
51-
)
5248
setContentView(R.layout.activity_barchart)
5349

5450
title = "BarChartActivity"
5551

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

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

6258
seekBarY!!.setOnSeekBarChangeListener(this)
6359
seekBarX!!.setOnSeekBarChangeListener(this)
6460

65-
chart = findViewById<BarChart>(R.id.chart1)
61+
chart = findViewById(R.id.chart1)
6662
chart!!.setOnChartValueSelectedListener(this)
6763
chart!!.setRoundedBarRadius(50f)
6864

@@ -141,7 +137,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
141137
val `val` = (sampleValues[i]!!.toFloat() * (range + 1))
142138

143139
if (`val` * 100 < 25) {
144-
values.add(BarEntry(i.toFloat(), `val`, getResources().getDrawable(R.drawable.star)))
140+
values.add(BarEntry(i.toFloat(), `val`, ResourcesCompat.getDrawable(resources, R.drawable.star, null)))
145141
} else {
146142
values.add(BarEntry(i.toFloat(), `val`))
147143
}
@@ -173,7 +169,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
173169
val endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark)
174170
val endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark)
175171

176-
val gradientFills: MutableList<Fill?> = ArrayList<Fill?>()
172+
val gradientFills: MutableList<Fill?> = ArrayList()
177173
gradientFills.add(Fill(startColor1, endColor1))
178174
gradientFills.add(Fill(startColor2, endColor2))
179175
gradientFills.add(Fill(startColor3, endColor3))

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.os.Bundle
88
import android.util.Log
99
import android.view.Menu
1010
import android.view.MenuItem
11-
import android.view.WindowManager
1211
import android.widget.SeekBar
1312
import android.widget.SeekBar.OnSeekBarChangeListener
1413
import android.widget.TextView
@@ -39,26 +38,22 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
3938

4039
override fun onCreate(savedInstanceState: Bundle?) {
4140
super.onCreate(savedInstanceState)
42-
window.setFlags(
43-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
44-
WindowManager.LayoutParams.FLAG_FULLSCREEN
45-
)
4641
setContentView(R.layout.activity_barchart)
4742

4843
title = "BarChartActivityMultiDataset"
4944

50-
tvX = findViewById<TextView>(R.id.tvXMax)
45+
tvX = findViewById(R.id.tvXMax)
5146
tvX!!.textSize = 10f
52-
tvY = findViewById<TextView>(R.id.tvYMax)
47+
tvY = findViewById(R.id.tvYMax)
5348

54-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
49+
seekBarX = findViewById(R.id.seekBarX)
5550
seekBarX!!.max = 50
5651
seekBarX!!.setOnSeekBarChangeListener(this)
5752

58-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
53+
seekBarY = findViewById(R.id.seekBarY)
5954
seekBarY!!.setOnSeekBarChangeListener(this)
6055

61-
chart = findViewById<BarChart>(R.id.chart1)
56+
chart = findViewById(R.id.chart1)
6257
chart!!.setOnChartValueSelectedListener(this)
6358
chart!!.description.isEnabled = false
6459

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.graphics.Color
77
import android.os.Bundle
88
import android.view.Menu
99
import android.view.MenuItem
10-
import android.view.WindowManager
1110
import android.widget.SeekBar
1211
import android.widget.SeekBar.OnSeekBarChangeListener
1312
import android.widget.TextView
@@ -31,21 +30,17 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
3130

3231
override fun onCreate(savedInstanceState: Bundle?) {
3332
super.onCreate(savedInstanceState)
34-
window.setFlags(
35-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
36-
WindowManager.LayoutParams.FLAG_FULLSCREEN
37-
)
3833
setContentView(R.layout.activity_barchart_sinus)
3934

4035
title = "BarChartActivitySinus"
4136

4237
data = FileUtils.loadBarEntriesFromAssets(assets, "othersine.txt")
4338

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

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

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

5045
chart!!.setDrawBarShadow(false)
5146
chart!!.setDrawValueAboveBar(true)
@@ -105,7 +100,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
105100
val entries = ArrayList<BarEntry?>()
106101

107102
for (i in 0..<count) {
108-
entries.add(data!!.get(i))
103+
entries.add(data!![i])
109104
}
110105

111106
val set: BarDataSet

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.graphics.Color
55
import android.os.Bundle
66
import android.view.Menu
77
import android.view.MenuItem
8-
import android.view.WindowManager
98
import androidx.core.net.toUri
109
import com.github.mikephil.charting.charts.BarChart
1110
import com.github.mikephil.charting.components.AxisBase
@@ -27,15 +26,11 @@ class BarChartPositiveNegative : DemoBase() {
2726

2827
override fun onCreate(savedInstanceState: Bundle?) {
2928
super.onCreate(savedInstanceState)
30-
window.setFlags(
31-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
32-
WindowManager.LayoutParams.FLAG_FULLSCREEN
33-
)
3429
setContentView(R.layout.activity_barchart_noseekbar)
3530

3631
title = "BarChartPositiveNegative"
3732

38-
chart = findViewById<BarChart>(R.id.chart1)
33+
chart = findViewById(R.id.chart1)
3934
chart!!.setBackgroundColor(Color.WHITE)
4035
chart!!.extraTopOffset = -30f
4136
chart!!.extraBottomOffset = 10f
@@ -76,7 +71,7 @@ class BarChartPositiveNegative : DemoBase() {
7671
chart!!.legend.isEnabled = false
7772

7873
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
79-
val data: MutableList<Data> = ArrayList<Data>()
74+
val data: MutableList<Data> = ArrayList()
8075
data.add(Data(0f, -224.1f, "12-29"))
8176
data.add(Data(1f, 238.5f, "12-30"))
8277
data.add(Data(2f, 1280.1f, "12-31"))
@@ -85,7 +80,7 @@ class BarChartPositiveNegative : DemoBase() {
8580

8681
xAxis.valueFormatter = object : IAxisValueFormatter {
8782
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
88-
return data.get(min(max(value.toInt(), 0), data.size - 1)).xAxisValue
83+
return data[min(max(value.toInt(), 0), data.size - 1)].xAxisValue
8984
}
9085
}
9186

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

10297
for (i in dataList.indices) {
103-
val d = dataList.get(i)
98+
val d = dataList[i]
10499
val entry = BarEntry(d.xValue, d.yValue)
105100
values.add(entry)
106101

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

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

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

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import android.os.Bundle
88
import android.util.Log
99
import android.view.Menu
1010
import android.view.MenuItem
11-
import android.view.WindowManager
1211
import android.widget.SeekBar
1312
import android.widget.SeekBar.OnSeekBarChangeListener
1413
import android.widget.TextView
1514
import androidx.core.content.ContextCompat
15+
import androidx.core.content.res.ResourcesCompat
1616
import androidx.core.net.toUri
1717
import com.github.mikephil.charting.charts.BubbleChart
1818
import com.github.mikephil.charting.components.Legend
@@ -38,24 +38,20 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
3838

3939
override fun onCreate(savedInstanceState: Bundle?) {
4040
super.onCreate(savedInstanceState)
41-
window.setFlags(
42-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
43-
WindowManager.LayoutParams.FLAG_FULLSCREEN
44-
)
4541
setContentView(R.layout.activity_bubblechart)
4642

4743
title = "BubbleChartActivity"
4844

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

52-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
48+
seekBarX = findViewById(R.id.seekBarX)
5349
seekBarX!!.setOnSeekBarChangeListener(this)
5450

55-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
51+
seekBarY = findViewById(R.id.seekBarY)
5652
seekBarY!!.setOnSeekBarChangeListener(this)
5753

58-
chart = findViewById<BubbleChart>(R.id.chart1)
54+
chart = findViewById(R.id.chart1)
5955
chart!!.description.isEnabled = false
6056

6157
chart!!.setOnChartValueSelectedListener(this)
@@ -112,15 +108,15 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
112108
i.toFloat(),
113109
(sampleValues[i + 1]!! * range).toFloat(),
114110
(sampleValues[i]!!.toFloat() * range),
115-
getResources().getDrawable(R.drawable.star)
111+
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
116112
)
117113
)
118114
values2.add(
119115
BubbleEntry(
120116
i.toFloat(),
121117
(sampleValues[i + 2]!! * range).toFloat(),
122118
(sampleValues[i + 1]!!.toFloat() * range),
123-
getResources().getDrawable(R.drawable.star)
119+
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
124120
)
125121
)
126122
values3.add(BubbleEntry(i.toFloat(), (sampleValues[i]!! * range).toFloat(), (sampleValues[i + 2]!!.toFloat() * range)))

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import android.graphics.Paint
88
import android.os.Bundle
99
import android.view.Menu
1010
import android.view.MenuItem
11-
import android.view.WindowManager
1211
import android.widget.SeekBar
1312
import android.widget.SeekBar.OnSeekBarChangeListener
1413
import android.widget.TextView
1514
import androidx.core.content.ContextCompat
15+
import androidx.core.content.res.ResourcesCompat
1616
import com.github.mikephil.charting.charts.CandleStickChart
1717
import com.github.mikephil.charting.components.XAxis.XAxisPosition
1818
import com.github.mikephil.charting.components.YAxis.AxisDependency
@@ -32,24 +32,20 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
3232

3333
override fun onCreate(savedInstanceState: Bundle?) {
3434
super.onCreate(savedInstanceState)
35-
window.setFlags(
36-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
37-
WindowManager.LayoutParams.FLAG_FULLSCREEN
38-
)
3935
setContentView(R.layout.activity_candlechart)
4036

4137
title = "CandleStickChartActivity"
4238

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

46-
seekBarX = findViewById<SeekBar>(R.id.seekBarX)
42+
seekBarX = findViewById(R.id.seekBarX)
4743
seekBarX!!.setOnSeekBarChangeListener(this)
4844

49-
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
45+
seekBarY = findViewById(R.id.seekBarY)
5046
seekBarY!!.setOnSeekBarChangeListener(this)
5147

52-
chart = findViewById<CandleStickChart>(R.id.chart1)
48+
chart = findViewById(R.id.chart1)
5349
chart!!.setBackgroundColor(Color.WHITE)
5450

5551
chart!!.description.isEnabled = false
@@ -86,8 +82,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
8682
}
8783

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

9287
tvX!!.text = progress.toString()
9388
tvY!!.text = seekBarY!!.progress.toString()
@@ -115,7 +110,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
115110
`val` - low,
116111
if (even) `val` + open else `val` - open,
117112
if (even) `val` - close else `val` + close,
118-
getResources().getDrawable(R.drawable.star)
113+
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
119114
)
120115
)
121116
}

0 commit comments

Comments
 (0)