Android Question 3 Color Led

Philip Prins

Active Member
Licensed User
Longtime User
Hello ,

On my Android device i have a LED that can disply 3 colors.

The manufacturar send me this sample code:
B4X:
package com.example.threecolorlightsdemo;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ThreeColorLights extends Activity implements OnClickListener {
    private Button mBtnRedColor;
    private Button mBtnGreenColor;
    private Button mBtnBuleColor;
    private NotificationManager manager;
    private static final int NOTIFICATION_ID = 20160322;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.three_color_lights);

        mBtnRedColor = (Button) findViewById(R.id.red_lights_id);
        mBtnGreenColor = (Button) findViewById(R.id.green_lights_id);
        mBtnBuleColor = (Button) findViewById(R.id.bule_lights_id);

        mBtnRedColor.setOnClickListener(this);
        mBtnGreenColor.setOnClickListener(this);
        mBtnBuleColor.setOnClickListener(this);

        manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    }

    @Override
    protected void onPause() {
        super.onPause();

        manager.cancel(NOTIFICATION_ID);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.red_lights_id:
            toNotify(Color.RED);
            break;
        case R.id.green_lights_id:
            toNotify(Color.GREEN);
            break;
        case R.id.bule_lights_id:
            toNotify(Color.BLUE);
            break;
        }
    }

    private void toNotify(int color) {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle("FactoryMode").setContentText("LedLightsTest")
                .setLights(color, 1, 0);

        // Notification notification = new Notification();

        // notification.ledARGB = color;

        // notification.ledOnMS = 1;
        // notification.ledOffMS = 0;

        // notification.flags = Notification.FLAG_SHOW_LIGHTS;
        manager.notify(NOTIFICATION_ID, mBuilder.build());
    }
}

How can i do this in B4A?

Regards,
Philip
 
Top