当前位置:操作系统 > 安卓/Android >>

友善之臂Mini6410之Android开发学习笔记(1)-LED Demo

[html] <span style="font-family:Arial;">git clone https://code.google.com/p/androiddemoformini6410/</span> 
<span style="font-family:Arial;">git clone https://code.google.com/p/androiddemoformini6410/</span>

 

 


LEDActivity.java


[java] package com.mini6410.LED; 
 
import com.friendlyarm.AndroidSDK.HardwareControler; 
import com.mini6410.R; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.CompoundButton; 
import android.widget.ToggleButton; 
 
/**
 * 
 * ClassName:LEDActivity
 * Reason:   LED Demo
 *
 * @author   snowdream
 * @version  
 * @since    Ver 1.1
 * @Date     2011   2012-03-11      16:07
 *
 * @see      
 */ 
public class LEDActivity extends Activity implements ToggleButton.OnCheckedChangeListener { 
 
    /*四个LED灯,编号ID依次为:LED 0,LED_1,LED_2,LED_3*/ 
    public static final int LED_0 = 0; 
    public static final int LED_1 = 1; 
    public static final int LED_2 = 2; 
    public static final int LED_3 = 3; 
 
    /*LED灯的状态: ON 表示点亮, OFF表示熄灭*/ 
    public static final int OFF = 0; 
    public static final int ON = 1; 
 
 
    private int mledID = LED_0;  
    private int mledState = OFF; 
 
 
    private boolean mStop = false; 
 
    /*LED编号数组*/ 
    private int[] mleds = new int[]{LED_0,LED_1,LED_2,LED_3}; 
 
    /*5个开关按钮*/ 
    private ToggleButton mToggleButton_led0 = null; 
    private ToggleButton mToggleButton_led1 = null; 
    private ToggleButton mToggleButton_led2 = null; 
    private ToggleButton mToggleButton_led3 = null; 
    private ToggleButton mToggleButton_ledrandom = null; 
 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.leddemo); 
 
        initUI(); 
    } 
 
    /**
     * 
     * initUI: 初始化UI
     *
     * @param   
     * @return     
     * @throws 
     */ 
    public void initUI(){ 
        mToggleButton_led0 = (ToggleButton)findViewById(R.id.button_led0); 
        mToggleButton_led1 = (ToggleButton)findViewById(R.id.button_led1); 
        mToggleButton_led2 = (ToggleButton)findViewById(R.id.button_led2); 
        mToggleButton_led3 =  (ToggleButton)findViewById(R.id.button_led3); 
        mToggleButton_ledrandom = (ToggleButton)findViewById(R.id.button_ledrandom); 
 
        mToggleButton_led0.setOnCheckedChangeListener(this); 
        mToggleButton_led1.setOnCheckedChangeListener(this); 
        mToggleButton_led2.setOnCheckedChangeListener(this); 
        mToggleButton_led3.setOnCheckedChangeListener(this); 
        mToggleButton_ledrandom.setOnCheckedChangeListener(this);        
    } 
 
    /**
     * 
     * onCheckedChanged: 开关按钮监听器
     *
     * @param   buttonView 当前被按下的按钮对象;isChecked表示该按钮的开关状态
     * @return     
     * @throws 
     */ 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
        ToggleButton mToggleButton = (ToggleButton)buttonView; 
 
        if(isChecked) 
            mledState = ON; 
        else 
            mledState = OFF; 
 
        switch (mToggleButton.getId()) { 
        case R.id.button_led0: 
            mledID = LED_0; 
            setLedState(mledID, mledState); 
            break; 
        case R.id.button_led1: 
            mledID = LED_1; 
            setLedState(mledID, mledState);      
            break; 
        case R.id.button_led2: 
            mledID = LED_2; 
            setLedState(mledID, mledState);              
            break; 
        case R.id.button_led3: 
            mledID = LED_3; 
            setLedState(mledID, mledState);              
            break;   
        case R.id.button_ledrandom: 
            if(isChecked){ 
                mStop = false; 
                RandomLight();&n

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,