<gradient android:startColor = "#80F40303"
android:centerColor = "#8B055798"
android:endColor = "#8000FF0C"
android:angle = "90"
android:type = "linear"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/videoView"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Quizy"
android:textSize="40sp"
android:textStyle="bold"
android:fontFamily="cursive"
android:layout_marginTop="30sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Started"
android:id="@+id/start"
android:layout_centerInParent="true"/>
class MainActivity : AppCompatActivity() {
var videoPlay:VideoView?=null
var start: Button?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
videoPlay = findViewById(R.id.videoView)
start = findViewById(R.id.start)
var videoUri = Uri.parse("android.resource://"+packageName+"/"+R.raw.backgroundvideo)
videoPlay?.setVideoURI(videoUri)
videoPlay?.start()
start?.setOnClickListener {
var intent = Intent(this,quizy_app::class.java)
startActivity(intent)
}
}
}
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".quizy_app">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A6000000"/>
<TextView
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right Answer"
android:textSize="30sp"
android:id="@+id/txtRightAnswer"
android:textColor="@color/white"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtRightAnswer"
android:layout_above="@id/container">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:id="@+id/progresscircle"
android:max="15000"
android:progress="0"
android:layout_alignParentBottom="true"
android:progressDrawable="@drawable/circular"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/textprogress"/>
</RelativeLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/container"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Question"
android:textSize="20sp"
android:id="@+id/txtQuestion1"
android:padding="5dp"
android:background="#CC0A0A"
android:textColor="@color/white"/>
<TextView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtQuestion"
android:hint="Your Question is Here"
android:textColorHint="@color/white"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/white"
android:padding="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Answer"
android:textColorHint="@color/white"
android:textSize="20sp"
android:id="@+id/edtAnswer"
android:textColor="@color/white"
android:textAlignment="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:onClick="showAnswer"
android:text="SHOW" />
<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="nextQuestion"
android:text="NEXT" />
<Button
android:id="@+id/btnCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:onClick="checkAnswer"
android:text="CHECK" />
</RelativeLayout>
class quizy_app : AppCompatActivity() {
var Question = arrayOf("Web Development", "Android Development", "NetWorking",
"Graphic Desginer", "Programm Desginer")
var rightAnswer : TextView? = null
var txtQuestion : TextView? = null
var edtAnswer : EditText? = null
lateinit var random: Random
lateinit var question: String
var handler : Handler?=null
var view : View?=null
// CountDown Timer
var cTimer:CountDownTimer?=null
// Progress Bar
var progressbar : ProgressBar?=null
var txtProgress : TextView?=null
var milisecond : Long?= null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_quizy_app)
milisecond = 0
rightAnswer = findViewById(R.id.txtRightAnswer)
txtQuestion = findViewById(R.id.txtQuestion)
edtAnswer = findViewById(R.id.edtAnswer)
progressbar = findViewById(R.id.progresscircle)
txtProgress = findViewById(R.id.textprogress)
var i =5
StarQuizy()
handler = Handler()
do{
handler?.postDelayed({StarQuizy()},17000)
}while (i==5)
}
fun StarQuizy(){
random = Random
rightAnswer?.visibility = View.INVISIBLE
question = Question[random.nextInt(Question.size)]
txtQuestion?.text = mixLetter(question)
countDownTimer()
}
fun countDownTimer(){
cTimer = object :CountDownTimer(15000, 1000){
override fun onTick(millisUntilFinished: Long) {
milisecond = millisUntilFinished
rightAnswer?.setText(""+milisecond!!/1000)
}
override fun onFinish() {
}
}.start()
}
fun showAnswer(view: View){
rightAnswer?.visibility = View.VISIBLE
rightAnswer?.text = question
}
fun nextQuestion(view: View){
StarQuizy()
}
fun checkAnswer(view: View){
if(txtQuestion?.text.toString().equals(question, ignoreCase = true)){
RightAnswer()
Toast.makeText(this, "Correct Answer", Toast.LENGTH_LONG).show()
}else{
WrongAnswer()
Toast.makeText(this, "Incorrect Answer", Toast.LENGTH_LONG).show()
}
}
fun RightAnswer(){
rightAnswer?.visibility = View.VISIBLE
rightAnswer?.text = question
rightAnswer?.setBackgroundColor(Color.GREEN)
var handler = Handler()
handler?.postDelayed({
StarQuizy()
}, 3000)
}
fun WrongAnswer(){
rightAnswer?.visibility = View.VISIBLE
rightAnswer?.text = question
rightAnswer?.setBackgroundColor(Color.RED)
var handler = Handler()
handler?.postDelayed({
StarQuizy()
}, 3000)
}
fun mixLetter(word: String):String{
var character = word.toCharArray()
for(i in character.indices){
var randomIndex = (Math.random()*character.size).toInt()
var temp = character[i]
character[i] = character[randomIndex]
character[randomIndex] = temp
}
return String(character)
}
}