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.lib; /*from ww w .j a v a2s .c o m*/ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * konashi????????KonashiObserver???????????? * * @author monakaz, YUKAI Engineering * http://konashi.ux-xu.com * ======================================================================== * Copyright 2014 Yukai Engineering Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ public class KonashiNotifier { /** * ???????????? */ private ArrayList<KonashiObserver> mObservers = null; private final Map<KonashiErrorReason, String> errorStrings = new HashMap<KonashiErrorReason, String>() {{ put(KonashiErrorReason.INVALID_PARAMETER, "INVALID_PARAMETER"); put(KonashiErrorReason.NOT_READY, "NOT_READY"); put(KonashiErrorReason.ALREADY_READY, "ALREADY_READY"); put(KonashiErrorReason.NOT_ENABLED_UART, "NOT_ENABLED_UART"); put(KonashiErrorReason.NOT_ENABLED_I2C, "NOT_ENABLED_I2C"); }}; /** * ??????? */ public KonashiNotifier() { mObservers = new ArrayList<KonashiObserver>(); } /** * ????????????? * @param observer ???????????? */ public void addObserver(KonashiObserver observer){ if(!mObservers.contains(observer)){ mObservers.add(observer); } } /** * ????????????? * @param observer ???????????? */ public void removeObserver(KonashiObserver observer){ if(mObservers.contains(observer)){ mObservers.remove(observer); } } /** * ?????????????????????? */ public void removeAllObservers(){ mObservers.clear(); } /** * ???????????????????? * @param event ???????(KonashiEvent???????? */ public void notifyKonashiEvent(final KonashiEvent event, final Object param0, final Object param1){ for(final KonashiObserver observer: mObservers){ if(observer.getActivity().isDestroyed()){ break; } observer.getActivity().runOnUiThread(new Runnable() { @Override public void run() { switch(event){ case PERIPHERAL_NOT_FOUND: observer.onNotFoundPeripheral(); break; case CONNECTED: observer.onConnected(); break; case DISCONNECTED: observer.onDisconncted(); break; case READY: observer.onReady(); break; case UPDATE_PIO_INPUT: observer.onUpdatePioInput(Byte.valueOf(param0.toString())); break; case UPDATE_ANALOG_VALUE: observer.onUpdateAnalogValue(Integer.valueOf(param0.toString()), Integer.valueOf(param1.toString())); break; case UPDATE_ANALOG_VALUE_AIO0: observer.onUpdateAnalogValueAio0(Integer.valueOf(param0.toString())); break; case UPDATE_ANALOG_VALUE_AIO1: observer.onUpdateAnalogValueAio1(Integer.valueOf(param0.toString())); break; case UPDATE_ANALOG_VALUE_AIO2: observer.onUpdateAnalogValueAio2(Integer.valueOf(param0.toString())); break; case UART_RX_COMPLETE: observer.onCompleteUartRx(Byte.valueOf(param0.toString())); break; case UPDATE_BATTERY_LEVEL: observer.onUpdateBatteryLevel(Integer.valueOf(param0.toString())); break; case UPDATE_SIGNAL_STRENGTH: observer.onUpdateSignalStrength(Integer.valueOf(param0.toString())); break; case CANCEL_SELECT_KONASHI: observer.onCancelSelectKonashi(); break; } } }); } } public void notifyKonashiError(final KonashiErrorReason errorReason){ // ??????????????????? final String cause = errorStrings.get(errorReason) + " on " + new Throwable().getStackTrace()[2].getMethodName() + "()"; for(final KonashiObserver observer: mObservers){ if(observer.getActivity().isDestroyed()){ break; } observer.getActivity().runOnUiThread(new Runnable() { @Override public void run() { observer.onError(errorReason, cause); } }); } } }