Back to project page konashi-android-sdk.
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.
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)); } } }; }