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.input;
//from   w w w  .ja  v a 2  s .  co  m
import com.uxxu.konashi.lib.Konashi;
import com.uxxu.konashi.lib.KonashiActivity;
import com.uxxu.konashi.lib.KonashiObserver;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends KonashiActivity {
    private static final String TAG = "KonashiSample";

    private LinearLayout mContainer;
    private Button mFindButton;
    private TextView mSwTextView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // ????????????
        mContainer = (LinearLayout)findViewById(R.id.container);
        mContainer.setVisibility(View.GONE);
        
        // ??????????????
        mSwTextView = (TextView)findViewById(R.id.sw_state);
        mSwTextView.setText(getString(R.string.off));
        
        // ?????????????????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();
                    
                    // disconnect??????find???????????????????
                    mFindButton.setText(getText(R.string.find_button));
                    mContainer.setVisibility(View.GONE);
                }
            }
        });
        
        // konashi???????????????????????????????????????
        getKonashiManager().addObserver(mKonashiObserver);
    }
    
    /**
     * 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?????????????S1?INPUT????????????INPUT??????????
            getKonashiManager().pinMode(Konashi.S1, Konashi.INPUT);
        }
        
        @Override
        public void onUpdatePioInput(byte value){
            Log.d(TAG, "onUpdatePioInput: " + value);
            
            // ??????????????????????????
            if(getKonashiManager().digitalRead(Konashi.S1)==Konashi.HIGH){
                mSwTextView.setText(getString(R.string.on));
            } else {
                mSwTextView.setText(getString(R.string.off));
            }
        }
    };
}




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