[text] чел

Viewer

  1. package com.example.horoscope
  2.  
  3. import android.app.DatePickerDialog
  4. import android.graphics.Color
  5. import androidx.appcompat.app.AppCompatActivity
  6. import android.os.Bundle
  7. import android.view.View
  8. import android.widget.DatePicker
  9. import android.widget.TextView
  10. import androidx.core.content.res.ResourcesCompat
  11. import androidx.core.graphics.alpha
  12. import androidx.core.graphics.drawable.DrawableCompat.inflate
  13. import com.example.horoscope.databinding.ActivityMainBinding
  14. import java.util.*
  15. import javax.xml.datatype.DatatypeConstants.MONTHS
  16.  
  17. class MainActivity : AppCompatActivity() {
  18.  
  19.     private lateinit var binding: ActivityMainBinding
  20.     val aries_desc = "Aries are spontaneous and courageous. They have a sense of adventure and love to explore. They're determined and bold, and are good at initiating new projects. They have high energy and can initiate quick actions."
  21.     val aries_day = listOf<String>()
  22.  
  23.     override fun onCreate(savedInstanceState: Bundle?) {
  24.         super.onCreate(savedInstanceState)
  25.         binding = ActivityMainBinding.inflate(layoutInflater)
  26.         val view = binding.root
  27.  
  28.  
  29.         setContentView(view)
  30.  
  31.         binding.openCalendar.setOnClickListener()
  32.         {
  33.         var datePickerFragment = DatePickerDialog(this)
  34.  
  35.         val onDateSetListener = object : DatePickerDialog.OnDateSetListener {
  36.         override fun onDateSet(p0: DatePicker?, p1: Int, p2: Int, p3: Int) {
  37.             var day = p0?.dayOfMonth.toString()
  38.             if (day.length==1){
  39.                 day = "0$day"
  40.             }
  41.             var month = (p0?.month?.plus(1)).toString()
  42.             if (month.length==1){
  43.                 month = "0$month"
  44.             }
  45.             var clickedType = "day"
  46.             var dayPrediction = ""
  47.             var weekPrediction = ""
  48.             var monthPrediction = ""
  49.  
  50.             //binding.openCalendar.text="${actionBar?.title}"
  51.            binding.openCalendar.text="${day}.${month}.${p0?.year}"
  52.             val zodiacName = zodiac(dataPicker = datePickerFragment.datePicker)
  53.             setTitle(zodiacName)
  54.             val onDayClickListener = object : View.OnClickListener{
  55.                 override fun onClick(p0: View?) {
  56.                     if (clickedType != "day"){
  57.                         binding.day.setBackgroundColor(resources.getColor(R.color.purple_500))
  58.                         if (clickedType=="week"){
  59.                             binding.week.setBackgroundColor(resources.getColor(R.color.purple_200))
  60.                         } else if (clickedType == "month"){
  61.                             binding.month.setBackgroundColor(resources.getColor(R.color.purple_200))
  62.                         }
  63.                         binding.prediction.text = dayPrediction
  64.                         clickedType="day"
  65.                     }
  66.                 }
  67.             }
  68.             val onWeekClickListener = object : View.OnClickListener{
  69.                 override fun onClick(p0: View?) {
  70.                     if (clickedType != "week"){
  71.                         binding.week.setBackgroundColor(resources.getColor(R.color.purple_500))
  72.                         binding.prediction.text = weekPrediction
  73.                         if (clickedType=="day"){
  74.                             binding.day.setBackgroundColor(resources.getColor(R.color.purple_200))
  75.                         } else if (clickedType == "month"){
  76.                             binding.month.setBackgroundColor(resources.getColor(R.color.purple_200))
  77.                         }
  78.                         clickedType="week"
  79.  
  80.                     }
  81.                 }
  82.             }
  83.             val onMonthClickListener = object : View.OnClickListener{
  84.                 override fun onClick(p0: View?) {
  85.                     if (clickedType != "month"){
  86.                         binding.month.setBackgroundColor(resources.getColor(R.color.purple_500))
  87.                         binding.prediction.text = monthPrediction
  88.                         if (clickedType=="week"){
  89.                             binding.week.setBackgroundColor(resources.getColor(R.color.purple_200))
  90.                         } else if (clickedType == "day"){
  91.                             binding.day.setBackgroundColor(resources.getColor(R.color.purple_200))
  92.                         }
  93.                         clickedType="month"
  94.                     }
  95.                 }
  96.             }
  97.             when(zodiacName){
  98.                 "aries"->{
  99.                     binding.description.text = resources.getText(R.string.aries_desc)
  100.                     dayPrediction = listOf<String>(resources.getString(R.string.aries_day_1), resources.getString(R.string.aries_day_2), resources.getString(R.string.aries_day_3), resources.getString(R.string.aries_day_4)).random()
  101.                     weekPrediction = listOf<String>(resources.getString(R.string.aries_week_1), resources.getString(R.string.aries_week_2), resources.getString(R.string.aries_week_3), resources.getString(R.string.aries_week_4)).random()
  102.                     monthPrediction = listOf<String>(resources.getString(R.string.aries_month_1), resources.getString(R.string.aries_month_2), resources.getString(R.string.aries_month_3), resources.getString(R.string.aries_month_4)).random()
  103.  
  104.                 }
  105.                 "taurus"->{
  106.                     binding.description.text = resources.getText(R.string.taurus_desc)
  107.                     dayPrediction = listOf<String>(resources.getString(R.string.taurus_day_1), resources.getString(R.string.taurus_day_2), resources.getString(R.string.taurus_day_3), resources.getString(R.string.taurus_day_4)).random()
  108.                     weekPrediction = listOf<String>(resources.getString(R.string.taurus_week_1), resources.getString(R.string.taurus_week_2), resources.getString(R.string.taurus_week_3), resources.getString(R.string.taurus_week_4)).random()
  109.                     monthPrediction = listOf<String>(resources.getString(R.string.taurus_month_1), resources.getString(R.string.taurus_month_2), resources.getString(R.string.taurus_month_3), resources.getString(R.string.taurus_month_4)).random()
  110.  
  111.                 }
  112.                 "gemini"->{
  113.                     binding.description.text = resources.getText(R.string.gemini_desc)
  114.                     dayPrediction = listOf<String>(resources.getString(R.string.gemini_day_1), resources.getString(R.string.gemini_day_2), resources.getString(R.string.gemini_day_3), resources.getString(R.string.gemini_day_4)).random()
  115.                     weekPrediction = listOf<String>(resources.getString(R.string.gemini_week_1), resources.getString(R.string.gemini_week_2), resources.getString(R.string.gemini_week_3), resources.getString(R.string.gemini_week_4)).random()
  116.                     dayPrediction = listOf<String>(resources.getString(R.string.gemini_month_1), resources.getString(R.string.gemini_month_2), resources.getString(R.string.gemini_month_3), resources.getString(R.string.gemini_month_4)).random()
  117.  
  118.                 }
  119.                 "cancer"->{
  120.                     binding.description.text = resources.getText(R.string.cancer_desc)
  121.  
  122.  
  123.                     dayPrediction = listOf<String>(resources.getString(R.string.cancer_day_1), resources.getString(R.string.cancer_day_2), resources.getString(R.string.cancer_day_3), resources.getString(R.string.cancer_day_4)).random()
  124.                     weekPrediction = listOf<String>(resources.getString(R.string.cancer_week_1), resources.getString(R.string.cancer_week_2), resources.getString(R.string.cancer_week_3), resources.getString(R.string.cancer_week_4)).random()
  125.                     monthPrediction = listOf<String>(resources.getString(R.string.cancer_month_1), resources.getString(R.string.cancer_month_2), resources.getString(R.string.cancer_month_3), resources.getString(R.string.cancer_month_4)).random()
  126.  
  127.  
  128.                 }
  129.                 "leo"->{
  130.                     binding.description.text = resources.getText(R.string.leo_desc)
  131.  
  132.  
  133.                     dayPrediction = listOf<String>(resources.getString(R.string.leo_day_1), resources.getString(R.string.leo_day_2), resources.getString(R.string.leo_day_3), resources.getString(R.string.leo_day_4)).random()
  134.                     weekPrediction = listOf<String>(resources.getString(R.string.leo_week_1), resources.getString(R.string.leo_week_2), resources.getString(R.string.leo_week_3), resources.getString(R.string.leo_week_4)).random()
  135.                     monthPrediction = listOf<String>(resources.getString(R.string.leo_month_1), resources.getString(R.string.leo_month_2), resources.getString(R.string.leo_month_3), resources.getString(R.string.leo_month_4)).random()
  136.  
  137.                 }
  138.                 "virgo"->{
  139.                     binding.description.text = resources.getText(R.string.virgo_desc)
  140.                     dayPrediction = listOf<String>(resources.getString(R.string.virgo_day_1), resources.getString(R.string.virgo_day_2), resources.getString(R.string.virgo_day_3), resources.getString(R.string.virgo_day_4)).random()
  141.                     weekPrediction = listOf<String>(resources.getString(R.string.virgo_week_1), resources.getString(R.string.virgo_week_2), resources.getString(R.string.virgo_week_3), resources.getString(R.string.virgo_week_4)).random()
  142.  
  143.                     monthPrediction = listOf<String>(resources.getString(R.string.virgo_month_1), resources.getString(R.string.virgo_month_2), resources.getString(R.string.virgo_month_3), resources.getString(R.string.virgo_month_4)).random()
  144.  
  145.                 }
  146.                 "libra"->{
  147.                     binding.description.text = resources.getText(R.string.libra_desc)
  148.                     dayPrediction = listOf<String>(resources.getString(R.string.libra_day_1), resources.getString(R.string.libra_day_2), resources.getString(R.string.libra_day_3), resources.getString(R.string.libra_day_4)).random()
  149.                     dayPrediction = listOf<String>(resources.getString(R.string.libra_week_1), resources.getString(R.string.libra_week_2), resources.getString(R.string.libra_week_3), resources.getString(R.string.libra_week_4)).random()
  150.  
  151.                     monthPrediction = listOf<String>(resources.getString(R.string.libra_month_1), resources.getString(R.string.libra_month_2), resources.getString(R.string.libra_month_3), resources.getString(R.string.libra_month_4)).random()
  152.  
  153.                 }
  154.                 "scorpio"->{
  155.                     binding.description.text = resources.getText(R.string.scorpio_desc)
  156.                     dayPrediction = listOf<String>(resources.getString(R.string.scorpio_day_1), resources.getString(R.string.scorpio_day_2), resources.getString(R.string.scorpio_day_3), resources.getString(R.string.scorpio_day_4)).random()
  157.                     weekPrediction = listOf<String>(resources.getString(R.string.scorpio_week_1), resources.getString(R.string.scorpio_week_2), resources.getString(R.string.scorpio_week_3), resources.getString(R.string.scorpio_week_4)).random()
  158.                     monthPrediction = listOf<String>(resources.getString(R.string.scorpio_month_1), resources.getString(R.string.scorpio_month_2), resources.getString(R.string.scorpio_month_3), resources.getString(R.string.scorpio_month_4)).random()
  159.  
  160.  
  161.                 }
  162.                 "saggitarius"->{
  163.                     binding.description.text = resources.getText(R.string.saggitarius_desc)
  164.                     dayPrediction = listOf<String>(resources.getString(R.string.saggitarius_day_1), resources.getString(R.string.saggitarius_day_2), resources.getString(R.string.saggitarius_day_3), resources.getString(R.string.saggitarius_day_4)).random()
  165.                     weekPrediction = listOf<String>(resources.getString(R.string.saggitarius_week_1), resources.getString(R.string.saggitarius_week_2), resources.getString(R.string.saggitarius_week_3), resources.getString(R.string.saggitarius_week_4)).random()
  166.                     monthPrediction = listOf<String>(resources.getString(R.string.saggitarius_month_1), resources.getString(R.string.saggitarius_month_2), resources.getString(R.string.saggitarius_month_3), resources.getString(R.string.saggitarius_month_4)).random()
  167.  
  168.  
  169.                 }
  170.                 "capricorn"->{
  171.                     binding.description.text = resources.getText(R.string.capricorn_desc)
  172.                     dayPrediction = listOf<String>(resources.getString(R.string.capricorn_day_1), resources.getString(R.string.capricorn_day_2), resources.getString(R.string.capricorn_day_3), resources.getString(R.string.capricorn_day_4)).random()
  173.                     weekPrediction = listOf<String>(resources.getString(R.string.capricorn_week_1), resources.getString(R.string.capricorn_week_2), resources.getString(R.string.capricorn_week_3), resources.getString(R.string.capricorn_week_4)).random()
  174.                     dayPrediction = listOf<String>(resources.getString(R.string.capricorn_month_1), resources.getString(R.string.capricorn_month_2), resources.getString(R.string.capricorn_month_3), resources.getString(R.string.capricorn_month_4)).random()
  175.  
  176.  
  177.                 }
  178.                 "aquarius"->{
  179.                     binding.description.text = resources.getText(R.string.aquarius_desc)
  180.                     dayPrediction = listOf<String>(resources.getString(R.string.aquarius_day_1), resources.getString(R.string.aquarius_day_2), resources.getString(R.string.aquarius_day_3), resources.getString(R.string.aquarius_day_4)).random()
  181.                     weekPrediction = listOf<String>(resources.getString(R.string.aquarius_week_1), resources.getString(R.string.aquarius_week_2), resources.getString(R.string.aquarius_week_3), resources.getString(R.string.aquarius_week_4)).random()
  182.                     monthPrediction = listOf<String>(resources.getString(R.string.aquarius_month_1), resources.getString(R.string.aquarius_month_2), resources.getString(R.string.aquarius_month_3), resources.getString(R.string.aquarius_month_4)).random()
  183.  
  184.  
  185.                 }
  186.                 "pisces"->{
  187.                     binding.description.text = resources.getText(R.string.pisces_desc)
  188.                     dayPrediction = listOf<String>(resources.getString(R.string.pisces_day_1), resources.getString(R.string.pisces_day_2), resources.getString(R.string.pisces_day_3), resources.getString(R.string.pisces_day_4)).random()
  189.                     weekPrediction = listOf<String>(resources.getString(R.string.pisces_week_1), resources.getString(R.string.pisces_week_2), resources.getString(R.string.pisces_week_3), resources.getString(R.string.pisces_week_4)).random()
  190.                     monthPrediction = listOf<String>(resources.getString(R.string.pisces_month_1), resources.getString(R.string.pisces_month_2), resources.getString(R.string.pisces_month_3), resources.getString(R.string.pisces_month_4)).random()
  191.  
  192.  
  193.                 }
  194.             }
  195.             if (binding.day.hasOnClickListeners()){
  196.                 binding.day.setOnClickListener(null)
  197.             }
  198.             binding.day.setOnClickListener(onDayClickListener)
  199.             if (binding.week.hasOnClickListeners()){
  200.                 binding.week.setOnClickListener(null)
  201.             }
  202.             binding.week.setOnClickListener(onWeekClickListener)
  203.             if (binding.month.hasOnClickListeners()){
  204.                 binding.month.setOnClickListener(null)
  205.             }
  206.             binding.month.setOnClickListener(onMonthClickListener)
  207.             binding.prediction.text = dayPrediction
  208.             binding.day.setBackgroundColor(resources.getColor(R.color.purple_500))
  209.             binding.week.setBackgroundColor(resources.getColor(R.color.purple_200))
  210.             binding.month.setBackgroundColor(resources.getColor(R.color.purple_200))
  211.         }
  212.  
  213.     }
  214.             datePickerFragment.setOnDateSetListener(onDateSetListener)
  215.     datePickerFragment.show()
  216.         }
  217.  
  218.     }
  219.  
  220. fun zodiac(dataPicker: DatePicker):String {
  221.     when (dataPicker.month) {
  222.         0 -> {
  223.             if (dataPicker.dayOfMonth < 20)
  224.                 return "capricorn"
  225.             else
  226.                 return "aquarius"
  227.         }
  228.         1 -> {
  229.             if (dataPicker.dayOfMonth < 19)
  230.                 return "aquarius"
  231.             else
  232.                 return "pisces"
  233.         }
  234.         2 -> {
  235.             if (dataPicker.dayOfMonth < 21)
  236.                 return "pisces"
  237.             else
  238.                 return "aries"
  239.         }
  240.         3 -> {
  241.             if (dataPicker.dayOfMonth < 20)
  242.                 return "aries"
  243.             else
  244.                 return "taurus"
  245.         }
  246.         4 -> {
  247.             if (dataPicker.dayOfMonth < 21)
  248.                 return "taurus"
  249.             else
  250.                 return "gemini"
  251.         }
  252.         5 -> {
  253.             if (dataPicker.dayOfMonth < 21)
  254.                 return "gemini"
  255.             else
  256.                 return "cancer"
  257.         }
  258.         6 -> {
  259.             if (dataPicker.dayOfMonth < 23)
  260.                 return "cancer"
  261.             else
  262.                 return "leo"
  263.         }
  264.         7 -> {
  265.             if (dataPicker.dayOfMonth < 23)
  266.                 return "leo"
  267.             else
  268.                 return "virgo"
  269.         }
  270.         8 -> {
  271.             if (dataPicker.dayOfMonth < 23)
  272.                 return "virgo"
  273.             else
  274.                 return "libra"
  275.         }
  276.         9 -> {
  277.             if (dataPicker.dayOfMonth < 23)
  278.                 return "libra"
  279.             else
  280.                 return "scorpio"
  281.         }
  282.         10 -> {
  283.             if (dataPicker.dayOfMonth < 22)
  284.                 return "scorpio"
  285.             else
  286.                 return "sagittarius"
  287.         }
  288.         11 -> {
  289.             if (dataPicker.dayOfMonth < 22)
  290.                 return "sagittarius"
  291.             else
  292.                 return "capricon"
  293.         }
  294.  
  295.     }
  296.     return "error"
  297. }
  298. }
  299.  

Editor

You can edit this paste and save as new:


File Description
  • чел
  • Paste Code
  • 24 Sep-2021
  • 17.53 Kb
You can Share it: