Skip to content

Commit

Permalink
Code update
Browse files Browse the repository at this point in the history
  • Loading branch information
antoxa2584x committed Dec 20, 2018
1 parent 17c121f commit 54a704b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import devs.goldenpie.com.tvnoiseview.TvNoiseView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(TvNoiseView(this))
setContentView(R.layout.main_activity)
}
}
Binary file added app/src/main/res/drawable-nodpi/tv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions app/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<devs.goldenpie.com.tvnoiseview.TvNoiseView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="@+id/tv"
app:layout_constraintEnd_toEndOf="@+id/tv"
app:layout_constraintStart_toStartOf="@id/tv"
app:layout_constraintTop_toTopOf="@+id/tv" />

<android.support.v7.widget.AppCompatImageView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tv"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Binary file added preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,53 @@ class TvNoiseView : View {

private var time = 0

private var height8: Int = 0
private var width8: Int = 0
private var height2: Int = 0
private var width2: Int = 0
private var width8: Int = 0

lateinit var pixels: IntArray

init {
Timer("", false).schedule(50, 20) {
Timer("", false).schedule(0, 50) {
invalidate()
}
}

override fun onDraw(canvas: Canvas?) {
val compare = Bitmap.createBitmap(width8, height8, Bitmap.Config.RGB_565)
val bitmap = Bitmap.createBitmap(width8, height2, Bitmap.Config.RGB_565)

for (y in 0 until height8) {
for (x in 0 until width8) {
val pix = ((40.0 * Math.random() * (7 + Math.sin(((x / 50000 + time / 7).toDouble())))).toInt())
compare.setPixel(x, y, Color.argb(255, pix, pix, pix))
}
for (i in 0 until (height2 * width8)) {
val pix = ((40.0 * Math.random() * (7 + Math.sin(((x / 50000 + time / 7).toDouble())))).toInt())
pixels[i] = Color.argb(255, pix, pix, pix)
}

val scaledBitmap = Bitmap.createScaledBitmap(compare, width2, height2, false)
bitmap.setPixels(pixels, 0, width8, 0, 0, width8, height2)

canvas?.let {
it.drawBitmap(scaledBitmap, 0f, 0f, null)
it.drawBitmap(scaledBitmap, width2.toFloat(), 0f, null)
it.drawBitmap(scaledBitmap, 0f, height2.toFloat(), null)
it.drawBitmap(scaledBitmap, width2.toFloat(), height2.toFloat(), null)
}
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, width / DIVIDER, height, false)

val width4 = width / DIVIDER

time = (time + 1) % compare.height
for (multiplier in 0 until DIVIDER)
canvas?.drawBitmap(scaledBitmap, (width4 * multiplier).toFloat(), 0f, null)

scaledBitmap.recycle()
compare.recycle()

time = (time + 1) % scaledBitmap.height

// scaledBitmap.recycled()
bitmap.recycle()

super.onDraw(canvas)
}

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
height2 = height / 2
width8 = width / (DIVIDER * 2)

height8 = height / 8
width8 = width / 8
pixels = IntArray(width8 * (height2))
}

height2 = height / 2
width2 = width / 2
companion object {
const val DIVIDER = 4
}


Expand Down

0 comments on commit 54a704b

Please sign in to comment.