Skip to content

Commit

Permalink
fix: change to raw file
Browse files Browse the repository at this point in the history
  • Loading branch information
SeptiawanAjiP committed Sep 22, 2023
1 parent 26442fe commit b368f44
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.dewakoding.androidchartjs

import android.content.Context
import android.net.Uri
import android.util.AttributeSet
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.widget.LinearLayout
import com.google.gson.Gson
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader


/**
Expand Down Expand Up @@ -36,7 +41,35 @@ class AndroidChartJSView @JvmOverloads constructor(
webSettings.javaScriptEnabled = true
webView.addJavascriptInterface(jsi!!, JavascriptInterface.TAG_HANDLER)
webView.setWebChromeClient(WebChromeClient())
webView.loadUrl("file:///android_asset/chart2023.html")

val rawResourceId = R.raw.chart2023
val inputStream = resources.openRawResource(rawResourceId)
val htmlData = convertStreamToString(inputStream)
val baseUrl = "file:///android_res/raw/"
val dataUri = Uri.parse(baseUrl + rawResourceId)

webView.loadDataWithBaseURL(baseUrl, htmlData, "text/html", "UTF-8", null)

addView(webView)
}

private fun convertStreamToString(inputStream: InputStream): String {
val reader = BufferedReader(InputStreamReader(inputStream))
val stringBuilder = StringBuilder()
var line: String?
try {
while (reader.readLine().also { line = it } != null) {
stringBuilder.append(line)
}
} catch (e: IOException) {
e.printStackTrace()
} finally {
try {
inputStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
return stringBuilder.toString()
}
}
10 changes: 0 additions & 10 deletions chartjs/src/main/res/layout/activity_chart.xml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<canvas id="myChart"></canvas>
</div>

<script src="js/chart.js"></script>
<script src="chart.js"></script>

<script>
const ctx = document.getElementById("myChart");
Expand Down

0 comments on commit b368f44

Please sign in to comment.