Back to project page bluetooth-spp-terminal.
The source code is released under:
Apache License
If you think the Android project bluetooth-spp-terminal 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 ru.sash0k.bluetooth_terminal; /* ww w. j a va 2s . c o m*/ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.text.InputFilter; import android.text.Spanned; import android.util.Log; /** * ???????????????? ?????? * Created by sash0k on 29.01.14. */ public class Utils { /** * ????? ????? ?????? ?????????? ?????????? ? ??? */ public static void log(String message) { if (BuildConfig.DEBUG) { if (message != null) Log.i(Const.TAG, message); } } // ============================================================================ /** * ???????????? hex-?????? ? ??????? ???? ???????????? */ public static String printHex(String hex) { StringBuilder sb = new StringBuilder(); int len = hex.length(); try { for (int i = 0; i < len; i += 2) { sb.append("0x").append(hex.substring(i, i + 2)).append(" "); } } catch (NumberFormatException e) { log("printHex NumberFormatException: " + e.getMessage()); } catch (StringIndexOutOfBoundsException e) { log("printHex StringIndexOutOfBoundsException: " + e.getMessage()); } return sb.toString(); } // ============================================================================ /** * ??????? ????????? ASCII-?????? ? hex ????????. * @param hex - ??????? * @return - ???????? ???? ??????? */ public static byte[] toHex(String hex) { int len = hex.length(); byte[] result = new byte[len]; try { int index = 0; for (int i = 0; i < len; i += 2) { result[index] = (byte) Integer.parseInt(hex.substring(i, i + 2), 16); index++; } } catch (NumberFormatException e) { log("toHex NumberFormatException: " + e.getMessage()); } catch (StringIndexOutOfBoundsException e) { log("toHex StringIndexOutOfBoundsException: " + e.getMessage()); } return result; } // ============================================================================ /** * ????? ???????? ??? ????????? ? ???? */ public static byte[] concat(byte[] A, byte[] B) { byte[] C = new byte[A.length + B.length]; System.arraycopy(A, 0, C, 0, A.length); System.arraycopy(B, 0, C, A.length, B.length); return C; } // ============================================================================ /** * ????????? id ????????????? ? ??????? ????????? ?????? */ public static String getPrefence(Context context, String item) { final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); return settings.getString(item, Const.TAG); } // ============================================================================ /** * ????????? ????? ?? ????????? */ public static boolean getBooleanPrefence(Context context, String tag) { final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); return settings.getBoolean(tag, true); } // ============================================================================ /** * ???????-?????? ????? ????? */ // ============================================================================ public static class InputFilterHex implements InputFilter { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (!Character.isDigit(source.charAt(i)) && source.charAt(i) != 'A' && source.charAt(i) != 'D' && source.charAt(i) != 'B' && source.charAt(i) != 'E' && source.charAt(i) != 'C' && source.charAt(i) != 'F' ) { return ""; } } return null; } } // ============================================================================ }