~hokiegeek/qwingo-roller

6a77655ce0d243f1a13fa15449e55f654bdf353d — HokieGeek 5 months ago b8d0261 1.0.0
Adds the loader and finishes the whole shebang for v1 at least
M app/src/main/java/net/hokiegeek/qwingoroller/MainActivity.kt => app/src/main/java/net/hokiegeek/qwingoroller/MainActivity.kt +17 -29
@@ 6,10 6,13 @@ import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import kotlin.math.sqrt
import kotlin.random.Random



@@ 24,26 27,18 @@ class MainActivity : AppCompatActivity() {
    */
        private const val SHAKE_THRESHOLD_GRAVITY = 2.7f
        private const val SHAKE_SLOP_TIME_MS = 500
        // private const val SHAKE_COUNT_RESET_TIME_MS = 3000
    }

    private val logTag = "QWINGO"

    private var mSensorMgr: SensorManager? = null

    // blue coffee cup
    // green watermelon
    // pink tomato
    // purple ice cream cone
    // yellow banana
    // silver (on black) lighting

    private val dieColors = arrayOf(R.color.die_green, R.color.die_blue, R.color.die_pink, R.color.die_purple, R.color.die_yellow, R.color.black)

    private val dieFaces = arrayOf(R.drawable.watermelon, R.drawable.cup, R.drawable.tomato, R.drawable.cone, R.drawable.banana, R.drawable.lightning)

    private var mSensorMgr: SensorManager? = null

    private val mSensorListener = object : SensorEventListener {
        private var mShakeTimestamp: Long = 0
        // private var mShakeCount = 0
        override fun onSensorChanged(se: SensorEvent) {
            val gX = se.values[0] / SensorManager.GRAVITY_EARTH
            val gY = se.values[1] / SensorManager.GRAVITY_EARTH


@@ 57,16 52,10 @@ class MainActivity : AppCompatActivity() {
                    return
                }
                // reset the shake count after 3 seconds of no shakes
                /*
                if (mShakeTimestamp + SHAKE_COUNT_RESET_TIME_MS < now) {
                    mShakeCount = 0
                }
                */
                mShakeTimestamp = now
                // mShakeCount++
                Log.d(logTag, "ACTION: shake?")

                Log.d(logTag, "ACTION: shake")
                roll()
                // mListener!!.onShake(mShakeCount)
            }
        }



@@ 93,21 82,20 @@ class MainActivity : AppCompatActivity() {
    }

    override fun onPause() {
        mSensorMgr?.unregisterListener(mSensorListener);
        mSensorMgr?.unregisterListener(mSensorListener)
        super.onPause()
    }

    private fun roll() {
        Log.d(logTag, "roll!")

        val selection = Random.nextInt(dieFaces.size)
        findViewById<ImageView>(R.id.dieFace).setImageResource(dieFaces[selection]);
        findViewById<ConstraintLayout>(R.id.layout).setBackgroundResource(dieColors[selection])
    }

    /*
    (new Handler()).postDelayed(this::yourMethod, 5000);
        findViewById<ConstraintLayout>(R.id.layout).setBackgroundResource(R.color.loading_background)
        Glide.with(this).load(R.raw.hamster).into(findViewById(R.id.dieFace))

    Glide.with(this).load(R.raw.hamster).into(findViewById<ImageView>(R.id.loading));
     */
        Handler(Looper.getMainLooper()).postDelayed({
            val selection = Random.nextInt(dieFaces.size)
            findViewById<ImageView>(R.id.dieFace).setImageResource(dieFaces[selection])
            findViewById<ConstraintLayout>(R.id.layout).setBackgroundResource(dieColors[selection])
        }, Random.nextLong(1500) + 800L)
    }
}

M app/src/main/res/layout/activity_main.xml => app/src/main/res/layout/activity_main.xml +4 -4
@@ 13,10 13,10 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/dieFaceDescription"
        android:paddingBottom="20dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="20dp"
        android:paddingBottom="40dp"
        android:paddingEnd="40dp"
        android:paddingStart="40dp"
        android:paddingTop="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"

A app/src/main/res/raw/hamster.gif => app/src/main/res/raw/hamster.gif +0 -0
M app/src/main/res/values/colors.xml => app/src/main/res/values/colors.xml +3 -1
@@ 6,10 6,12 @@
    <color name="primary_pink">#CA1943</color>
    <color name="primary_orange">#FD8B49</color>

    <color name="loading_background">#36465D</color>

    <color name="die_pink">#DA0166</color>
    <color name="die_green">#4C8600</color>
    <color name="die_purple">#5C4F9F</color>
    <color name="die_yellow">#B08100</color>
    <color name="die_yellow">#E8AC07</color>
    <color name="die_blue">#2B97AE</color>
    <color name="die_silver">#868C93</color>
</resources>
\ No newline at end of file