Develop An Android Application To Make A LED Light Set in Which Single LED Light Blinks Randomly Out of Available 5 Lights. JAVA Code
Develop An Android Application To Make A LED Light Set in Which Single LED Light Blinks Randomly Out of Available 5 Lights. JAVA Code
Develop an android application to make a LED light set in which single LED light blinks randomly out
of available 5 lights.
JAVA code:
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Random;
Blink.setOnClickListener(new View.OnClickListener() {
@SuppressLint("WrongConstant")
@Override
public void onClick(View v) {
}
}, 2000);
break;
case 2: final ObjectAnimator animator2 = ObjectAnimator.ofInt(bulb2,
"backgroundColor", Color.YELLOW, Color.WHITE);
animator2.setDuration(500);
animator2.setEvaluator(new ArgbEvaluator());
animator2.setRepeatMode(Animation.REVERSE);
animator2.setRepeatCount(Animation.INFINITE);
animator2.start();
Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
@Override
public void run() {
animator2.removeAllListeners();
animator2.end();
animator2.cancel();
}
}, 2000);
break;
case 3: final ObjectAnimator animator3 = ObjectAnimator.ofInt(bulb3,
"backgroundColor", Color.YELLOW, Color.WHITE);
animator3.setDuration(500);
animator3.setEvaluator(new ArgbEvaluator());
animator3.setRepeatMode(Animation.REVERSE);
animator3.setRepeatCount(Animation.INFINITE);
animator3.start();
Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
@Override
public void run() {
animator3.removeAllListeners();
animator3.end();
animator3.cancel();
}
}, 2000);
break;
case 4: final ObjectAnimator animator4 = ObjectAnimator.ofInt(bulb4,
"backgroundColor", Color.YELLOW, Color.WHITE);
animator4.setDuration(500);
animator4.setEvaluator(new ArgbEvaluator());
animator4.setRepeatMode(Animation.REVERSE);
animator4.setRepeatCount(Animation.INFINITE);
animator4.start();
Handler handler2 = new Handler();
handler2.postDelayed(new Runnable() {
@Override
public void run() {
animator4.removeAllListeners();
animator4.end();
animator4.cancel();
}
}, 2000);
break;
case 5: final ObjectAnimator animator5 = ObjectAnimator.ofInt(bulb5,
"backgroundColor", Color.YELLOW, Color.WHITE);
animator5.setDuration(500);
animator5.setEvaluator(new ArgbEvaluator());
animator5.setRepeatMode(Animation.REVERSE);
animator5.setRepeatCount(Animation.INFINITE);
animator5.start();
Handler handler3 = new Handler();
handler3.postDelayed(new Runnable() {
@Override
public void run() {
animator5.removeAllListeners();
animator5.end();
animator5.cancel();
}
}, 2000);
break;
}
}
});
}
}
XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:padding="20dp"
tools:context=".MainActivity">
<Button
android:id="@+id/blink"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_height="wrap_content"
android:text="Blink"/>
<ImageView
android:id="@+id/bulb1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
</LinearLayout>