Android Open Source - konashi-android-sdk Main Activity






From Project

Back to project page konashi-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project konashi-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.uxxu.konashi.sample.basic;
/*from   ww  w  . j  av  a2  s  .c om*/
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uxxu.konashi.lib.*;

public class MainActivity extends KonashiActivity {
    private static final String TAG = "KonashiSample";
    
    private LinearLayout mContainer;
    private Button mFindButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // ????????????
        mContainer = (LinearLayout)findViewById(R.id.container);
        mContainer.setVisibility(View.GONE);
        
        // ?????????????????konashi???????????????????????????
        mFindButton = (Button)findViewById(R.id.find_button);
        mFindButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!getKonashiManager().isReady()){
                    // konashi???????????konashi?????????????????????
                    getKonashiManager().find(MainActivity.this);
                    
                    // konashi????????????????????????????????????? 
                    //mKonashiManager.findWithName(MainActivity.this, "konashi#4-0452");           
                } else {
                    // konashi??????
                    getKonashiManager().disconnect();
                    
                    mFindButton.setText(getText(R.string.find_button));
                    mContainer.setVisibility(View.GONE);
                }
            }
        });
        
        // ???????????
        setButtonAction(R.id.led2_button, Konashi.LED2);
        setButtonAction(R.id.led3_button, Konashi.LED3);
        setButtonAction(R.id.led4_button, Konashi.LED4);
        setButtonAction(R.id.led5_button, Konashi.LED5);
        
        // konashi???????????????????????????????????????
        getKonashiManager().addObserver(mKonashiObserver);
    }
    
    /**
     * ???????????????????????????LED???ON, ??????????????LED???OFF
     * @param resId Resource ID
     * @param pin ???????????????????????????
     */
    private void setButtonAction(int resId, final int pin){
        Button button = (Button)findViewById(resId);
        button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {                
                switch(event.getAction()){
                case MotionEvent.ACTION_DOWN:
                    // ????????
                    getKonashiManager().digitalWrite(pin, Konashi.HIGH);  // HIGH???LED???????
                    break;
                    
                case MotionEvent.ACTION_UP:
                    // ????????
                    getKonashiManager().digitalWrite(pin, Konashi.LOW);  // LOW???LED???????
                    break;
                }
                return false;
            }
        });
    }

    /**
     * konashi????????????
     */
    private final KonashiObserver mKonashiObserver = new KonashiObserver(MainActivity.this) {
        @Override
        public void onReady(){
            Log.d(TAG, "onKonashiReady");
            
            // find???????????disconnect???
            mFindButton.setText(getText(R.string.disconnect_button));
            // ??????????
            mContainer.setVisibility(View.VISIBLE);

            // konashi?????????????LED2?5?????????
            getKonashiManager().pinMode(Konashi.LED2, Konashi.OUTPUT);
            getKonashiManager().pinMode(Konashi.LED3, Konashi.OUTPUT);
            getKonashiManager().pinMode(Konashi.LED4, Konashi.OUTPUT);
            getKonashiManager().pinMode(Konashi.LED5, Konashi.OUTPUT);
        }
    };
}




Java Source Code List

com.uxxu.konashi.lib.BleDeviceListAdapter.java
com.uxxu.konashi.lib.BleDeviceSelectionDialog.java
com.uxxu.konashi.lib.KonashiActivity.java
com.uxxu.konashi.lib.KonashiApiInterface.java
com.uxxu.konashi.lib.KonashiBaseManager.java
com.uxxu.konashi.lib.KonashiErrorReason.java
com.uxxu.konashi.lib.KonashiEvent.java
com.uxxu.konashi.lib.KonashiManager.java
com.uxxu.konashi.lib.KonashiNotifier.java
com.uxxu.konashi.lib.KonashiObserver.java
com.uxxu.konashi.lib.KonashiUUID.java
com.uxxu.konashi.lib.KonashiUtils.java
com.uxxu.konashi.lib.Konashi.java
com.uxxu.konashi.sample.basic.MainActivity.java
com.uxxu.konashi.sample.input.MainActivity.java
com.uxxu.konashi.sample.multi_activity.ControllerActivity.java
com.uxxu.konashi.sample.multi_activity.MainActivity.java