大阪市中央区 システムソフトウェア開発会社

営業時間:平日09:15〜18:15
MENU

Kotlinで作るAndroidアプリ・・アナログ時計の背景画像変え

著者:川上洋
公開日:2019/08/03
最終更新日:2019/08/03
カテゴリー:雑記

こんにちは。川上です。

時計針の回転処理ができたので、Swift版のアナログ時計同様に、しっかり蛇足しとかなあかんよね。

と、いう事で、Pi、Pi、Pi、Poooo です。

    
   // --- PiPiPoo管理用
    private var pipoo_idx = 0

// ---- Now時刻の表示
    fun updateTimeClock() {
        val textclock = findViewById(R.id.textTimer) as TextView
        textclock.text =  getToday() 

        val dateTime: DateTime = DateTime.now()
        val year: Int = dateTime.year
        val day: Int = dateTime.day
        val hour:Int = dateTime.hour
        val mint:Int = dateTime.minute
        val second:Int = dateTime.second
        println("--- year =$year day=$day")
        println("--- hour =$hour mint=$mint,mint=$second")

        //--- 短針の表示
        updateHoure(hour,mint)
        //--- 長針の表示
        updateMinur(mint)
        //--- 秒針の表示
        updateSecond(second)

        //--- justUp_non
        justUp_non(mint,second)
    }

    // --- just Make Up_non
    fun justUp_non(mint :Int,sec:Int) {
        println("--- justUp_non mint =$mint sec=$sec")

        if (sec == 54  ) {
            println(" --- On -- justClock_Non --")
            baseVwChgImg()
        }
        else if (pipoo_idx > 0  ) {
            println(" --- Update -- justClock_Non --")
            baseVwChgImg()
        }
        else if (pipoo_idx == 0) {
            var pipngVw : ImageView? = findViewById(R.id.pi)
            var poopngVw : ImageView? = findViewById(R.id.poo)
            pipngVw!!.setVisibility(View.INVISIBLE)
            poopngVw!!.setVisibility(View.INVISIBLE)
        }
    }

    fun baseVwChgImg(){
        println("--- baseVwChgImg pipoo_idx =$pipoo_idx ")

        var basepngVw : ImageView? = findViewById(R.id.base_png)
        var pipngVw : ImageView? = findViewById(R.id.pi)
        var poopngVw : ImageView? = findViewById(R.id.poo)

        // --- PiPiPoo画像ID
        val imgarry = arrayOf(R.drawable.non_1,
                                        R.drawable.non_2,
                                        R.drawable.non_1,
                                        R.drawable.non_2,
                                        R.drawable.non_1,
                                        R.drawable.non_2,
            R.drawable.non_3,R.drawable.non_3,
            R.drawable.non_3,R.drawable.non_3,R.drawable.non_3
            )

        val bitmap1 = BitmapFactory.decodeResource(
            resources,
            imgarry[pipoo_idx]
        )
        basepngVw!!.setImageBitmap(bitmap1)

        // ---- Pi,Pooの表示OnOff
        if (pipoo_idx == 0 || pipoo_idx == 2 || pipoo_idx == 4) {
            pipngVw!!.setVisibility(VISIBLE)
        }
        else if (pipoo_idx >= 6) {
            poopngVw!!.setVisibility(VISIBLE)

        }
        else {
            pipngVw!!.setVisibility(View.INVISIBLE)
            poopngVw!!.setVisibility(View.INVISIBLE)
        }

            pipoo_idx ++

        // -- PiPiPoo 完了
        if (pipoo_idx == imgarry.count()) {
            val bitmap2 = BitmapFactory.decodeResource(
                resources,
                R.drawable.base_tokei
            )
            basepngVw.setImageBitmap(bitmap2)

            pipngVw!!.setVisibility(View.INVISIBLE)
            poopngVw!!.setVisibility(View.INVISIBLE)

            pipoo_idx = 0
        }
    }

残っているアナログ時計の処理は、曜日と日付の表示ですwね。

でもって、iPhoneXRでのアナログ時計動作はコチラで、Swift版同様のKotlin版アナログ時計はこちらです。

ではでは。

    上に戻る