├── settings.gradle
├── wiseKit
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── drawable
│ │ │ ├── loading_bg.9.png
│ │ │ ├── search_box_bg.xml
│ │ │ ├── dialog_loading.xml
│ │ │ └── color_progressbar.xml
│ │ ├── mipmap-xxhdpi
│ │ │ ├── delete.png
│ │ │ ├── search.png
│ │ │ └── return_jiao.png
│ │ ├── mipmap
│ │ │ └── dialog_loading_img.png
│ │ └── layout
│ │ │ ├── activity_base.xml
│ │ │ ├── fragment_activity_base.xml
│ │ │ ├── fragment_base.xml
│ │ │ ├── activity_webview_base.xml
│ │ │ ├── dialog_loading.xml
│ │ │ └── base_top_view.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── wise
│ │ └── wisekit
│ │ ├── dialog
│ │ └── LoadingDialog.java
│ │ ├── widget
│ │ └── SearchEditText.java
│ │ ├── activity
│ │ ├── BaseFragmentActivity.java
│ │ └── BaseActivity.java
│ │ ├── fragment
│ │ └── BaseFragment.java
│ │ └── utils
│ │ ├── SPUtils.java
│ │ └── DateUtils.java
├── proguard-rules.pro
├── build.gradle
└── wiseKit.iml
├── app
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── ic_red.png
│ │ │ ├── ic_black.png
│ │ │ ├── ic_launcher.png
│ │ │ ├── button_background.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── mipmap-xxhdpi
│ │ │ ├── switch_on.png
│ │ │ └── switch_off.png
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ ├── activity_log.xml
│ │ │ ├── log_list_item.xml
│ │ │ ├── actionbar_indeterminate_progress.xml
│ │ │ ├── activity_set_password.xml
│ │ │ ├── list_item.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_set_button.xml
│ │ │ └── activity_serial_port.xml
│ │ ├── java
│ │ └── com
│ │ │ └── RRG
│ │ │ └── usbninja
│ │ │ ├── LogInfo.java
│ │ │ ├── app
│ │ │ └── MainApplication.java
│ │ │ ├── SetPasswordActivity.java
│ │ │ ├── ButtonModel.java
│ │ │ ├── config
│ │ │ └── ConfigInfo.java
│ │ │ ├── ble
│ │ │ ├── ConvertData.java
│ │ │ ├── BluetoothLe.java
│ │ │ └── HolloBluetooth.java
│ │ │ ├── LogActivity.java
│ │ │ ├── SetButtonActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── SerialPortActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── .idea
└── vcs.xml
├── README.txt
├── USBNinja.iml
├── gradlew.bat
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':wiseKit'
2 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WiseKit
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/app/src/main/res/drawable/ic_red.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/app/src/main/res/drawable/ic_black.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/app/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/wiseKit/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/switch_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/app/src/main/res/mipmap-xxhdpi/switch_on.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/switch_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/app/src/main/res/mipmap-xxhdpi/switch_off.png
--------------------------------------------------------------------------------
/wiseKit/src/main/res/drawable/loading_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/wiseKit/src/main/res/drawable/loading_bg.9.png
--------------------------------------------------------------------------------
/wiseKit/src/main/res/mipmap-xxhdpi/delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/wiseKit/src/main/res/mipmap-xxhdpi/delete.png
--------------------------------------------------------------------------------
/wiseKit/src/main/res/mipmap-xxhdpi/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/wiseKit/src/main/res/mipmap-xxhdpi/search.png
--------------------------------------------------------------------------------
/wiseKit/src/main/res/mipmap-xxhdpi/return_jiao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/wiseKit/src/main/res/mipmap-xxhdpi/return_jiao.png
--------------------------------------------------------------------------------
/wiseKit/src/main/res/mipmap/dialog_loading_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/USBNinjaRRG/USBNinja-android/HEAD/wiseKit/src/main/res/mipmap/dialog_loading_img.png
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16sp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/drawable/search_box_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #ff4081
6 |
7 | #123123
8 |
9 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 45dp
6 | 18sp
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_log.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/LogInfo.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | public class LogInfo {
4 |
5 | private String type;
6 | private String content;
7 |
8 | public String getType() {
9 | return type;
10 | }
11 |
12 | public void setType(String type) {
13 | this.type = type;
14 | }
15 |
16 | public String getContent() {
17 | return content;
18 | }
19 |
20 | public void setContent(String content) {
21 | this.content = content;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/layout/activity_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
10 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | USBNinja Bluetooth Android Remote Control Open Source Project
2 |
3 | The USBNinja is a USB Cable that embedded an BADUSB in it. It has 6KB Flash Memory in it to store your own payload.
4 | These payloads can be triggered by a Bluetooth Remote Control or this Application. The Cable can simulate itself to an
5 | HID-Keyboard or an HID-Mouse to Control your computer.
6 |
7 | For more information, please visit: https://usbninja.com
8 |
9 | This project can let the user control their Cable easily without their Remote Control Hardware. It`s very useful when the
10 | Hardware is lost or have no battery.
--------------------------------------------------------------------------------
/wiseKit/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #导航栏背景颜色
5 | #0d61e0
6 |
7 | #导航栏颜色
8 | #FFFFFF
9 |
10 | #背景颜色
11 | #e6e6e6
12 |
13 | #分割线颜色
14 | #bfbfbf
15 |
16 | #tab bar 选中字体颜色
17 | #ea9518
18 |
19 | #tab bar 未选中字体颜色
20 | #515151
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/drawable/dialog_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/layout/fragment_activity_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/layout/fragment_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/log_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/app/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja.app;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.RRG.usbninja.LogInfo;
7 |
8 | import java.util.ArrayList;
9 |
10 | public class MainApplication extends Application {
11 |
12 | private static final String TAG = MainApplication.class.getName();
13 |
14 | public static MainApplication instance;
15 |
16 | public ArrayList logList = new ArrayList<>();
17 |
18 | //get Application Context
19 | public static Context getAppContext() {
20 | return instance.getApplicationContext();
21 | }
22 |
23 | @Override
24 | public void onCreate() {
25 | super.onCreate();
26 |
27 | instance = this;
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/wiseKit/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/layout/activity_webview_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/USBNinja.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/wiseKit/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 18
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | buildToolsVersion '28.0.3'
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | }
35 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/drawable/color_progressbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 | -
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | USBNinja
3 | BLE is not supported
4 | Data:
5 | Device address:
6 | State:
7 | No data
8 | Connected
9 | Disconnected
10 | Bluetooth not supported.
11 | Wake Up
12 | Unknown device
13 | Unknown characteristic
14 | Unknown service
15 |
16 | Connect
17 | Disconnect
18 | Scan
19 | Stop
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/actionbar_indeterminate_progress.xml:
--------------------------------------------------------------------------------
1 |
16 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_set_password.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
16 |
20 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 | compileSdkVersion 28
6 | defaultConfig {
7 | applicationId "com.RRG.usbninja"
8 | minSdkVersion 18
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.1"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | debuggable false
19 | jniDebuggable false
20 | renderscriptDebuggable false
21 | pseudoLocalesEnabled true
22 | }
23 | }
24 | buildToolsVersion '28.0.3'
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(include: ['*.jar'], dir: 'libs')
29 | implementation project(':wiseKit')
30 | implementation 'com.android.support:appcompat-v7:28.0.0'
31 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35 | }
36 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/layout/dialog_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
28 |
29 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/SetPasswordActivity.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.widget.EditText;
7 | import android.widget.Toast;
8 |
9 | import com.RRG.usbninja.config.ConfigInfo;
10 | import com.wise.wisekit.activity.BaseActivity;
11 |
12 | public class SetPasswordActivity extends BaseActivity {
13 |
14 | private EditText mPasswordEditText;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | LayoutInflater.from(this).inflate(R.layout.activity_set_password, topContentView);
20 |
21 | initView();
22 |
23 | }
24 |
25 | private void initView() {
26 |
27 | topLeftBtn.setVisibility(View.VISIBLE);
28 | topRightBtn.setVisibility(View.VISIBLE);
29 |
30 | mPasswordEditText = findViewById(R.id.password);
31 |
32 | setTitle("Set Password");
33 | setRightText("Done");
34 |
35 | topRightBtn.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View view) {
38 |
39 | //Password
40 | if (mPasswordEditText.getText().toString().length() == 0) {
41 | Toast.makeText(SetPasswordActivity.this, "Please enter the password for the connection",Toast.LENGTH_SHORT).show();
42 | return;
43 | }
44 |
45 | ConfigInfo.getInstance().setPassword(mPasswordEditText.getText().toString());
46 |
47 | finish();
48 | }
49 | });
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
27 |
28 |
38 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
55 |
56 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
38 |
39 |
45 |
46 |
52 |
53 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/ButtonModel.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | import org.json.*;
4 | import java.util.*;
5 |
6 |
7 | public class ButtonModel{
8 |
9 | private String name = "";
10 | private String touchDown = "";
11 | private String touchUp = "";
12 |
13 | public void setName(String name){
14 | this.name = name;
15 | }
16 | public String getName(){
17 | return this.name;
18 | }
19 | public void setTouchDown(String touchDown){
20 | this.touchDown = touchDown;
21 | }
22 | public String getTouchDown(){
23 | return this.touchDown;
24 | }
25 | public void setTouchUp(String touchUp){
26 | this.touchUp = touchUp;
27 | }
28 | public String getTouchUp(){
29 | return this.touchUp;
30 | }
31 |
32 | /**
33 | * Instantiate the instance using the passed jsonObject to set the properties values
34 | */
35 | public ButtonModel(JSONObject jsonObject){
36 | if(jsonObject == null){
37 | return;
38 | }
39 | name = jsonObject.optString("name", "");
40 | touchDown = jsonObject.optString("touchDown", "");
41 | touchUp = jsonObject.optString("touchUp", "");
42 | }
43 |
44 | public ButtonModel(String jsonObjectStr){
45 | if(jsonObjectStr == null){
46 | return;
47 | }
48 |
49 | try {
50 | JSONObject jsonObject = new JSONObject(jsonObjectStr);
51 |
52 | if(jsonObject == null){
53 | return;
54 | }
55 | name = jsonObject.optString("name", "");
56 | touchDown = jsonObject.optString("touchDown", "");
57 | touchUp = jsonObject.optString("touchUp", "");
58 |
59 | } catch (JSONException e) {
60 | e.printStackTrace();
61 | return;
62 | }
63 |
64 | }
65 |
66 | /**
67 | * Returns all the available property values in the form of JSONObject instance where the key is the approperiate json key and the value is the value of the corresponding field
68 | */
69 | public JSONObject toJsonObject()
70 | {
71 | JSONObject jsonObject = new JSONObject();
72 |
73 | try {
74 | jsonObject.put("name", name);
75 | jsonObject.put("touchDown", touchDown);
76 | jsonObject.put("touchUp", touchUp);
77 | } catch (JSONException e) {
78 | // TODO Auto-generated catch block
79 | e.printStackTrace();
80 | }
81 | return jsonObject;
82 | }
83 |
84 | public String toJsonObjectStr() {
85 |
86 | return this.toJsonObject().toString();
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/config/ConfigInfo.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja.config;
2 |
3 | import com.RRG.usbninja.ButtonModel;
4 | import com.RRG.usbninja.app.MainApplication;
5 | import com.wise.wisekit.utils.SPUtils;
6 |
7 | public class ConfigInfo {
8 |
9 | private static String PASSWORD = "password";
10 |
11 | /**
12 | * 单例对象实例
13 | */
14 | private static ConfigInfo instance = null;
15 |
16 | public static ConfigInfo getInstance() {
17 | if (instance == null) {
18 | instance = new ConfigInfo();
19 | }
20 | return instance;
21 | }
22 |
23 | public String getPassword() {
24 | return (String) SPUtils.get(MainApplication.getAppContext(), PASSWORD, "8888");
25 | }
26 |
27 | public void setPassword(String password) {
28 | SPUtils.put(MainApplication.getAppContext(), PASSWORD, password);
29 | }
30 |
31 |
32 |
33 | public String getNum1() {
34 | return (String) SPUtils.get(MainApplication.getAppContext(), "num1","");
35 | }
36 |
37 | public void setNum1(String num1) {
38 | SPUtils.put(MainApplication.getAppContext(), "num1", num1);
39 | }
40 |
41 | public String getNum2() {
42 |
43 | return (String) SPUtils.get(MainApplication.getAppContext(), "num2", "");
44 | }
45 |
46 | public void setNum2(String num2) {
47 | SPUtils.put(MainApplication.getAppContext(), "num2", num2);
48 | }
49 |
50 | public String getNum3() {
51 | return (String) SPUtils.get(MainApplication.getAppContext(), "num3", "");
52 | }
53 |
54 | public void setNum3(String num3) {
55 | SPUtils.put(MainApplication.getAppContext(), "num3", num3);
56 | }
57 |
58 | public String getNum4() {
59 | return (String) SPUtils.get(MainApplication.getAppContext(), "num4", "");
60 | }
61 |
62 | public void setNum4(String num4) {
63 | SPUtils.put(MainApplication.getAppContext(), "num4", num4);
64 | }
65 |
66 | public String getNum5() {
67 | return (String) SPUtils.get(MainApplication.getAppContext(), "num5", "");
68 | }
69 |
70 | public void setNum5(String num5) {
71 | SPUtils.put(MainApplication.getAppContext(), "num5", num5);
72 | }
73 |
74 | public String getNum6() {
75 | return (String) SPUtils.get(MainApplication.getAppContext(), "num6", "");
76 | }
77 |
78 | public void setNum6(String num6) {
79 | SPUtils.put(MainApplication.getAppContext(), "num6", num6);
80 | }
81 |
82 | public String getNum7() {
83 | return (String) SPUtils.get(MainApplication.getAppContext(), "num7", "");
84 | }
85 |
86 | public void setNum7(String num7) {
87 | SPUtils.put(MainApplication.getAppContext(), "num7", num7);
88 | }
89 |
90 | public String getNum8() {
91 | return (String) SPUtils.get(MainApplication.getAppContext(), "num8", "");
92 | }
93 |
94 | public void setNum8(String num8) {
95 | SPUtils.put(MainApplication.getAppContext(), "num8", num8);
96 | }
97 |
98 | public String getNum9() {
99 | return (String) SPUtils.get(MainApplication.getAppContext(), "num9", "");
100 | }
101 |
102 | public void setNum9(String num9) {
103 | SPUtils.put(MainApplication.getAppContext(), "num9", num9);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/dialog/LoadingDialog.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.dialog;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import com.wise.wisekit.R;
11 |
12 | public class LoadingDialog extends Dialog{
13 |
14 |
15 | public LoadingDialog(Context context) {
16 | super(context);
17 | }
18 |
19 | public LoadingDialog(Context context, int themeResId) {
20 | super(context, themeResId);
21 | }
22 |
23 | public static class Builder{
24 |
25 | private Context context;
26 | private String message;
27 | private boolean isShowMessage=true;
28 | private boolean isCancelable=false;
29 | private boolean isCancelOutside=false;
30 | private OnCancelListener cancelListener;
31 |
32 |
33 | public Builder(Context context) {
34 | this.context = context;
35 | }
36 |
37 | /**
38 | * Set Hint Message
39 | * @param message
40 | * @return
41 | */
42 |
43 | public Builder setMessage(String message){
44 | this.message=message;
45 | return this;
46 | }
47 |
48 | /**
49 | * Set is Show Hint Message
50 | * @param isShowMessage
51 | * @return
52 | */
53 | public Builder setShowMessage(boolean isShowMessage){
54 | this.isShowMessage=isShowMessage;
55 | return this;
56 | }
57 |
58 | /**
59 | * Set Could canceled by Return Button
60 | * @param isCancelable
61 | * @return
62 | */
63 |
64 | public Builder setCancelable(boolean isCancelable){
65 | this.isCancelable=isCancelable;
66 | return this;
67 | }
68 |
69 | /**
70 | * Set Can Cancelled by click other place.
71 | * @param isCancelOutside
72 | * @return
73 | */
74 | public Builder setCancelOutside(boolean isCancelOutside){
75 | this.isCancelOutside=isCancelOutside;
76 | return this;
77 | }
78 |
79 | /**
80 | * Set OnCancel Listener
81 | * @param listener
82 | * @return
83 | */
84 | public Builder setOnCancelListener(OnCancelListener listener) {
85 | this.cancelListener = listener;
86 | return this;
87 | }
88 |
89 | public LoadingDialog create(){
90 |
91 | LayoutInflater inflater = LayoutInflater.from(context);
92 | View view=inflater.inflate(R.layout.dialog_loading,null);
93 | LoadingDialog loadingDailog=new LoadingDialog(context,R.style.LoadingDialogStyle);
94 | TextView msgText= (TextView) view.findViewById(R.id.tipTextView);
95 | if(isShowMessage){
96 | msgText.setText(message);
97 | }else{
98 | msgText.setVisibility(View.GONE);
99 | }
100 | loadingDailog.setContentView(view);
101 | loadingDailog.setCancelable(isCancelable);
102 | loadingDailog.setCanceledOnTouchOutside(isCancelOutside);
103 | loadingDailog.setOnCancelListener(cancelListener);
104 | return loadingDailog;
105 |
106 | }
107 |
108 |
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_set_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
17 |
18 |
26 |
27 |
28 |
29 |
30 |
31 |
37 |
38 |
43 |
44 |
56 |
57 |
62 |
63 |
74 |
75 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/wiseKit/src/main/res/layout/base_top_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
27 |
28 |
34 |
35 |
44 |
45 |
52 |
53 |
54 |
55 |
74 |
75 |
82 |
83 |
94 |
95 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/widget/SearchEditText.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.text.Editable;
6 | import android.text.TextWatcher;
7 | import android.util.AttributeSet;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.view.animation.Animation;
11 | import android.view.animation.CycleInterpolator;
12 | import android.view.animation.TranslateAnimation;
13 | import android.widget.EditText;
14 |
15 | import com.wise.wisekit.R;
16 |
17 | public class SearchEditText extends EditText implements
18 | View.OnFocusChangeListener, TextWatcher {
19 |
20 | public interface SearchWatcher {
21 | void searchTextChange(String searchText);
22 | }
23 |
24 | protected SearchWatcher searchWatcher = null;
25 |
26 | private Drawable clearWordsImage;
27 |
28 | public SearchEditText(Context context) {
29 | this(context, null);
30 | }
31 |
32 | public SearchEditText(Context context, AttributeSet attrs) {
33 | this(context, attrs, android.R.attr.editTextStyle);
34 | }
35 |
36 | public SearchEditText(Context context, AttributeSet attrs, int defStyle) {
37 | super(context, attrs, defStyle);
38 | init();
39 | }
40 |
41 |
42 | private void init() {
43 | clearWordsImage = getCompoundDrawables()[2];
44 | if (clearWordsImage == null) {
45 | clearWordsImage = getResources()
46 | .getDrawable(R.mipmap.delete);
47 | }
48 | clearWordsImage.setBounds(0, 0, clearWordsImage.getIntrinsicWidth(), clearWordsImage.getIntrinsicHeight());
49 | setClearIconVisible(false);
50 | setOnFocusChangeListener(this);
51 | addTextChangedListener(this);
52 | }
53 |
54 | @Override
55 | public boolean onTouchEvent(MotionEvent event) {
56 | if (getCompoundDrawables()[2] != null) {
57 | if (event.getAction() == MotionEvent.ACTION_UP) {
58 | boolean touchable = event.getX() > (getWidth()
59 | - getPaddingRight() - clearWordsImage.getIntrinsicWidth())
60 | && (event.getX() < ((getWidth() - getPaddingRight())));
61 | if (touchable) {
62 | this.setText("");
63 | }
64 | }
65 | }
66 |
67 | return super.onTouchEvent(event);
68 | }
69 |
70 | @Override
71 | public void onFocusChange(View v, boolean hasFocus) {
72 | if (hasFocus) {
73 | setClearIconVisible(getText().length() > 0);
74 | } else {
75 | setClearIconVisible(false);
76 | }
77 | }
78 |
79 | protected void setClearIconVisible(boolean visible) {
80 | Drawable right = visible ? clearWordsImage : null;
81 | setCompoundDrawables(getCompoundDrawables()[0],
82 | getCompoundDrawables()[1], right, getCompoundDrawables()[3]);
83 | }
84 |
85 | @Override
86 | public void onTextChanged(CharSequence s, int start, int count,
87 | int after) {
88 | setClearIconVisible(s.length() > 0);
89 |
90 | if (searchWatcher != null) {
91 | searchWatcher.searchTextChange(getText().toString());
92 | }
93 | }
94 |
95 | @Override
96 | public void beforeTextChanged(CharSequence s, int start, int count,
97 | int after) {
98 |
99 | }
100 |
101 | @Override
102 | public void afterTextChanged(Editable s) {
103 |
104 | }
105 |
106 | public void addWatcher(SearchWatcher watcher) {
107 | searchWatcher = watcher;
108 | }
109 |
110 | public void setShakeAnimation(){
111 | this.setAnimation(shakeAnimation(5));
112 | }
113 |
114 | public static Animation shakeAnimation(int counts){
115 | Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
116 | translateAnimation.setInterpolator(new CycleInterpolator(counts));
117 | translateAnimation.setDuration(1000);
118 | return translateAnimation;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/ble/ConvertData.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja.ble;
2 |
3 |
4 | import java.io.UnsupportedEncodingException;
5 |
6 | public class ConvertData
7 | {
8 | /**
9 | * byte[]->HEXString
10 | *
11 | * @param bytes byte[]
12 | * @param bSpace add Space Char between two Chars
13 | *
14 | * @return String hexstr
15 | */
16 | public static String bytesToHexString(byte[] bytes, boolean bSpace)
17 | {
18 | if(bytes == null || bytes.length <= 0)
19 | return null;
20 |
21 | StringBuffer stringBuffer = new StringBuffer(bytes.length);
22 | String sTemp;
23 |
24 | for (int i = 0; i < bytes.length; i++)
25 | {
26 | sTemp = Integer.toHexString(0xFF & bytes[i]);
27 |
28 | if (sTemp.length() < 2)
29 | stringBuffer.append(0);
30 |
31 | stringBuffer.append(sTemp);
32 |
33 | if(bSpace)
34 | stringBuffer.append(" ");
35 | }
36 | return stringBuffer.toString();
37 | }
38 |
39 | /**
40 | * HEXString->byte[]
41 | *
42 | * @param String hexstr
43 | *
44 | * @return byte[]
45 | */
46 | public static byte[] hexStringToBytes(String hexString)
47 | {
48 | if(hexString == null)
49 | return null;
50 |
51 | hexString = hexString.replace(" ", "");
52 | hexString = hexString.toUpperCase();
53 |
54 | int len = (hexString.length() / 2);
55 | if(len <= 0)
56 | return null;
57 |
58 | byte[] result = new byte[len];
59 | char[] achar = hexString.toCharArray();
60 | for (int i = 0; i < len; i++)
61 | {
62 | int pos = i * 2;
63 | result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
64 | }
65 |
66 | return result;
67 | }
68 |
69 | /**
70 | * byte[]->utf-8
71 | *
72 | * @param String src
73 | *
74 | * @return return byte[]
75 | */
76 | public static byte[] unicodeToBytes(String src)
77 | {
78 | if(src == null)
79 | return null;
80 |
81 | byte[] bytes = null;
82 | try {
83 | bytes = src.getBytes("UTF-8");
84 | } catch (UnsupportedEncodingException e) {
85 | e.printStackTrace();
86 | }
87 | return bytes;
88 | }
89 |
90 | public static String bytesToUnicode(byte[] bytes)
91 | {
92 | if(bytes == null)
93 | return null;
94 |
95 | String str = null;
96 | try {
97 | str = new String(bytes, "UTF-8");
98 | } catch (UnsupportedEncodingException e) {
99 | e.printStackTrace();
100 | }
101 |
102 | return str;
103 | }
104 |
105 | /**
106 | * Copy Byte[]
107 | *
108 | * @param dst
109 | * @param dstOffset
110 | * @param src
111 | * @param srcOffset
112 | * @param length
113 | *
114 | * @return Success=true,else=false;
115 | */
116 | public static boolean cpyBytes(byte[] dst, int dstOffset, byte[] src, int srcOffset, int length)
117 | {
118 | if(dst == null || src == null ||
119 | dstOffset > dst.length || srcOffset > src.length ||
120 | length > (dst.length-dstOffset) || length > (src.length-srcOffset))
121 | {
122 | return false;
123 | }
124 |
125 | for (int i = 0; i < length; i++)
126 | {
127 | dst[i+dstOffset] = src[i+srcOffset];
128 | }
129 |
130 | return true;
131 | }
132 |
133 | /**
134 | * Compare two []
135 | *
136 | * @param data1 []1
137 | * @param data2 []2
138 | *
139 | * @return Equal=true,else=false;
140 | */
141 | public static boolean cmpBytes(byte[] data1, byte[] data2)
142 | {
143 | if (data1 == null && data2 == null)
144 | {
145 | return true;
146 | }
147 | if (data1 == null || data2 == null)
148 | {
149 | return false;
150 | }
151 | if (data1 == data2)
152 | {
153 | return true;
154 | }
155 | if(data1.length != data2.length)
156 | {
157 | return false;
158 | }
159 |
160 | int len = data1.length;
161 | for (int i = 0; i < len; i++)
162 | {
163 | if(data1[i] != data2[i])
164 | return false;
165 | }
166 |
167 | return true;
168 | }
169 |
170 | private static int toByte(char c)
171 | {
172 | byte b = (byte) "0123456789ABCDEF".indexOf(c);
173 | return b;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/activity/BaseFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.activity;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 | import android.widget.ImageView;
12 | import android.widget.LinearLayout;
13 | import android.widget.TextView;
14 |
15 | import com.wise.wisekit.R;
16 |
17 | public class BaseFragmentActivity extends FragmentActivity {
18 |
19 | protected ImageView topLeftBtn;
20 | protected ImageView topRightBtn;
21 | protected TextView topTitleTxt;
22 | protected ImageView topTitelImage;
23 | protected TextView letTitleTxt;
24 | protected ViewGroup topBar;
25 | protected ViewGroup topContentView;
26 | protected LinearLayout baseRoot;
27 | protected LinearLayout topTitleLayout;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | requestWindowFeature(Window.FEATURE_NO_TITLE);
33 |
34 | if(Build.VERSION.SDK_INT >= 21) {
35 | Window window = getWindow();
36 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
37 | window.setStatusBarColor(getResources().getColor(R.color.colorNavBackground));
38 | }
39 |
40 | topContentView = (ViewGroup) LayoutInflater.from(this).inflate(
41 | R.layout.fragment_activity_base, null);
42 | topBar = (ViewGroup) topContentView.findViewById(R.id.topbar);
43 | topTitleTxt = (TextView) topContentView.findViewById(R.id.base_activity_title);
44 | topLeftBtn = (ImageView) topContentView.findViewById(R.id.left_btn);
45 | topRightBtn = (ImageView) topContentView.findViewById(R.id.right_btn);
46 | topTitelImage = (ImageView) topContentView.findViewById(R.id.title_image);
47 | letTitleTxt = (TextView) topContentView.findViewById(R.id.left_txt);
48 | baseRoot = (LinearLayout)topContentView.findViewById(R.id.act_base_root);
49 | topTitleLayout = (LinearLayout)topContentView.findViewById(R.id.base_activity_title_layout);
50 |
51 | topTitleTxt.setVisibility(View.GONE);
52 | topRightBtn.setVisibility(View.GONE);
53 | letTitleTxt.setVisibility(View.GONE);
54 | topLeftBtn.setVisibility(View.GONE);
55 | topTitelImage.setVisibility(View.GONE);
56 |
57 | topLeftBtn.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View view) {
60 | finish();
61 | }
62 | });
63 |
64 | setContentView(topContentView);
65 | }
66 |
67 | protected void setLeftText(String text) {
68 | if (null == text) {
69 | return;
70 | }
71 | letTitleTxt.setText(text);
72 | letTitleTxt.setVisibility(View.VISIBLE);
73 | }
74 |
75 | protected void setTitle(String title) {
76 | if (title == null) {
77 | return;
78 | }
79 | if (title.length() > 12) {
80 | title = title.substring(0, 11) + "...";
81 | }
82 | topTitleTxt.setText(title);
83 | topTitleTxt.setVisibility(View.VISIBLE);
84 | }
85 |
86 | @Override
87 | public void setTitle(int id) {
88 | String strTitle = getResources().getString(id);
89 | setTitle(strTitle);
90 | }
91 |
92 | public void setTitleImage(int resID) {
93 | if (resID <= 0) {
94 | return;
95 | }
96 |
97 | topTitelImage.setImageResource(resID);
98 | topTitelImage.setVisibility(View.VISIBLE);
99 | }
100 |
101 | protected void setLeftButton(int resID) {
102 | if (resID <= 0) {
103 | return;
104 | }
105 |
106 | topLeftBtn.setImageResource(resID);
107 | topLeftBtn.setVisibility(View.VISIBLE);
108 | }
109 |
110 | protected void setRightButton(int resID) {
111 | if (resID <= 0) {
112 | return;
113 | }
114 |
115 | topRightBtn.setImageResource(resID);
116 | topRightBtn.setVisibility(View.VISIBLE);
117 | }
118 |
119 | protected void setTopBar(int resID) {
120 | if (resID <= 0) {
121 | return;
122 | }
123 | topBar.setBackgroundResource(resID);
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/LogActivity.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 |
13 | import com.RRG.usbninja.app.MainApplication;
14 | import com.wise.wisekit.activity.BaseActivity;
15 |
16 | import java.util.ArrayList;
17 |
18 | public class LogActivity extends BaseActivity {
19 |
20 | ListView mListView;
21 | InfoListAdapter mInfoListAdapter;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | LayoutInflater.from(this).inflate(R.layout.activity_log, topContentView);
27 |
28 | initView();
29 |
30 | mInfoListAdapter.setInfoList(MainApplication.instance.logList);
31 | }
32 |
33 | void initView() {
34 |
35 | topLeftBtn.setVisibility(View.VISIBLE);
36 | setTitle("Log");
37 | topRightBtn.setVisibility(View.VISIBLE);
38 | setRightText("Clear");
39 |
40 | topRightBtn.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View view) {
43 | MainApplication.instance.logList.clear();
44 | mInfoListAdapter.setInfoList(MainApplication.instance.logList);
45 | }
46 | });
47 |
48 |
49 | mListView = findViewById(R.id.list);
50 |
51 | mInfoListAdapter = new InfoListAdapter(this);
52 | mListView.setAdapter(mInfoListAdapter);
53 |
54 | }
55 |
56 | // Adapter for holding devices found through scanning.
57 | private class InfoListAdapter extends BaseAdapter
58 | {
59 | private ArrayList mInfoList;
60 | private LayoutInflater mInflator;
61 |
62 | public InfoListAdapter(Context context) {
63 | super();
64 | mInfoList = new ArrayList();
65 | mInflator = LayoutInflater.from(context);
66 | }
67 |
68 | public void setInfoList(ArrayList infoList) {
69 |
70 | mInfoList = infoList;
71 | notifyDataSetChanged();
72 | }
73 |
74 | public void clear() {
75 | mInfoList.clear();
76 | }
77 |
78 | @Override
79 | public int getCount()
80 | {
81 | return mInfoList.size();
82 | }
83 |
84 | @Override
85 | public Object getItem(int i)
86 | {
87 | return mInfoList.get(i);
88 | }
89 |
90 | @Override
91 | public long getItemId(int i)
92 | {
93 | return i;
94 | }
95 |
96 | @Override
97 | public View getView(int i, View view, ViewGroup viewGroup)
98 | {
99 | ViewHolder viewHolder;
100 | // General ListView optimization code.
101 | if (view == null)
102 | {
103 | view = mInflator.inflate(R.layout.log_list_item, null);
104 | viewHolder = new ViewHolder();
105 | viewHolder.typeTextView = (TextView) view.findViewById(R.id.type);
106 | viewHolder.contentTextView = (TextView) view.findViewById(R.id.content);
107 | view.setTag(viewHolder);
108 | }
109 | else
110 | {
111 | viewHolder = (ViewHolder) view.getTag();
112 | }
113 |
114 |
115 | viewHolder.typeTextView.setText(mInfoList.get(i).getType());
116 | viewHolder.contentTextView.setText(mInfoList.get(i).getContent());
117 | if (mInfoList.get(i).getType().equals("send")) {
118 | viewHolder.typeTextView.setTextColor(Color.BLUE);
119 | }
120 | else if (mInfoList.get(i).getType().equals("receive")) {
121 | viewHolder.typeTextView.setTextColor(Color.rgb(255, 0, 255));
122 | }
123 | else if (mInfoList.get(i).getType().equals("error")) {
124 | viewHolder.typeTextView.setTextColor(Color.RED);
125 | }
126 | else {
127 | viewHolder.typeTextView.setTextColor(Color.BLACK);
128 | }
129 |
130 | return view;
131 | }
132 | }
133 |
134 | static class ViewHolder
135 | {
136 | TextView typeTextView;
137 | TextView contentTextView;
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 |
13 | import com.wise.wisekit.R;
14 |
15 | public class BaseFragment extends Fragment {
16 |
17 | public String TAG = this.getClass().getCanonicalName();
18 |
19 | protected ImageView topLeftBtn;
20 | protected ImageView topRightBtn;
21 | protected ImageView topTitelImage;
22 | protected TextView topTitleTxt;
23 | protected TextView leftTitleTxt;
24 | protected TextView rightTitleTxt;
25 | protected ViewGroup topBar;
26 | protected ViewGroup topContentView;
27 | protected LinearLayout baseRoot;
28 | protected View separateLineView;
29 |
30 | @Override
31 | public void onCreate(@Nullable Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 |
34 | topContentView = (ViewGroup) LayoutInflater.from(getActivity()).inflate(
35 | R.layout.fragment_base, null);
36 | topBar = (ViewGroup) topContentView.findViewById(R.id.topbar);
37 | topTitleTxt = (TextView) topContentView.findViewById(R.id.base_activity_title);
38 | topLeftBtn = (ImageView) topContentView.findViewById(R.id.left_btn);
39 | topRightBtn = (ImageView) topContentView.findViewById(R.id.right_btn);
40 | topTitelImage = (ImageView) topContentView.findViewById(R.id.title_image);
41 | leftTitleTxt = (TextView) topContentView.findViewById(R.id.left_txt);
42 | rightTitleTxt = (TextView) topContentView.findViewById(R.id.right_txt);
43 | baseRoot = (LinearLayout)topContentView.findViewById(R.id.act_base_root);
44 | separateLineView = topContentView.findViewById(R.id.separate_line);
45 |
46 | topTitleTxt.setVisibility(View.GONE);
47 | topRightBtn.setVisibility(View.GONE);
48 | leftTitleTxt.setVisibility(View.GONE);
49 | rightTitleTxt.setVisibility(View.GONE);
50 | topLeftBtn.setVisibility(View.GONE);
51 | topTitelImage.setVisibility(View.GONE);
52 |
53 | }
54 |
55 | @Nullable
56 | @Override
57 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
58 | if (null != topContentView) {
59 | ((ViewGroup) topContentView.getParent()).removeView(topContentView);
60 | return topContentView;
61 | }
62 | return topContentView;
63 | }
64 |
65 | public void willShowFragment(){
66 |
67 | }
68 |
69 | protected void setLeftText(String text) {
70 | if (null == text) {
71 | return;
72 | }
73 | leftTitleTxt.setText(text);
74 | leftTitleTxt.setVisibility(View.VISIBLE);
75 | }
76 |
77 | protected void setRightText(String text) {
78 | if (null == text) {
79 | return;
80 | }
81 | rightTitleTxt.setText(text);
82 | rightTitleTxt.setVisibility(View.VISIBLE);
83 | }
84 |
85 | protected void setTitle(String title) {
86 | if (title == null) {
87 | return;
88 | }
89 | if (title.length() > 12) {
90 | title = title.substring(0, 11) + "...";
91 | }
92 | topTitleTxt.setText(title);
93 | topTitleTxt.setVisibility(View.VISIBLE);
94 | }
95 |
96 | public void setTitle(int id) {
97 | String strTitle = getResources().getString(id);
98 | setTitle(strTitle);
99 | }
100 |
101 | public void setTitleImage(int resID) {
102 | if (resID <= 0) {
103 | return;
104 | }
105 |
106 | topTitelImage.setImageResource(resID);
107 | topTitelImage.setVisibility(View.VISIBLE);
108 | }
109 |
110 | protected void setLeftButton(int resID) {
111 | if (resID <= 0) {
112 | return;
113 | }
114 |
115 | topLeftBtn.setImageResource(resID);
116 | topLeftBtn.setVisibility(View.VISIBLE);
117 | }
118 |
119 | protected void setRightButton(int resID) {
120 | if (resID <= 0) {
121 | return;
122 | }
123 |
124 | topRightBtn.setImageResource(resID);
125 | topRightBtn.setVisibility(View.VISIBLE);
126 | }
127 |
128 | protected void setTopBar(int resID) {
129 | if (resID <= 0) {
130 | return;
131 | }
132 | topBar.setBackgroundResource(resID);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.activity;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.Window;
11 | import android.view.WindowManager;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 | import android.widget.TextView;
15 |
16 | import com.wise.wisekit.R;
17 | import com.wise.wisekit.widget.SearchEditText;
18 |
19 | public class BaseActivity extends Activity {
20 |
21 | public String TAG = this.getClass().getCanonicalName();
22 |
23 | protected ImageView topLeftBtn;
24 | protected ImageView topRightBtn;
25 | protected ImageView topTitelImage;
26 | protected TextView topTitleTxt;
27 | protected TextView leftTitleTxt;
28 | protected TextView rightTitleTxt;
29 | protected ViewGroup topBar;
30 | protected ViewGroup topContentView;
31 | protected LinearLayout baseRoot;
32 | protected LinearLayout topTitleLayout;
33 |
34 | protected SearchEditText searchEditText;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | requestWindowFeature(Window.FEATURE_NO_TITLE);
41 |
42 | if(Build.VERSION.SDK_INT >= 21) {
43 | Window window = getWindow();
44 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
45 | window.setStatusBarColor(getResources().getColor(R.color.colorNavBackground));
46 | }
47 |
48 |
49 | topContentView = (ViewGroup) LayoutInflater.from(this).inflate(
50 | R.layout.activity_base, null);
51 | topBar = (ViewGroup) topContentView.findViewById(R.id.topbar);
52 | topTitleTxt = (TextView) topContentView.findViewById(R.id.base_activity_title);
53 | topTitleLayout = (LinearLayout)topContentView.findViewById(R.id.base_activity_title_layout);
54 | topLeftBtn = (ImageView) topContentView.findViewById(R.id.left_btn);
55 | topRightBtn = (ImageView) topContentView.findViewById(R.id.right_btn);
56 | topTitelImage = (ImageView) topContentView.findViewById(R.id.title_image);
57 | leftTitleTxt = (TextView) topContentView.findViewById(R.id.left_txt);
58 | rightTitleTxt = (TextView) topContentView.findViewById(R.id.right_txt);
59 | baseRoot = (LinearLayout)topContentView.findViewById(R.id.act_base_root);
60 | searchEditText = (SearchEditText)topContentView.findViewById(R.id.title_search);
61 |
62 |
63 | topTitleTxt.setVisibility(View.GONE);
64 | topRightBtn.setVisibility(View.GONE);
65 | leftTitleTxt.setVisibility(View.GONE);
66 | rightTitleTxt.setVisibility(View.GONE);
67 | topLeftBtn.setVisibility(View.GONE);
68 | topTitelImage.setVisibility(View.GONE);
69 | searchEditText.setVisibility(View.GONE);
70 |
71 | setContentView(topContentView);
72 |
73 | setLeftButton(R.mipmap.return_jiao);
74 | topLeftBtn.setOnClickListener(new View.OnClickListener() {
75 | @Override
76 | public void onClick(View view) {
77 | finish();
78 | }
79 | });
80 | }
81 |
82 | protected void setLeftText(String text) {
83 | if (null == text) {
84 | return;
85 | }
86 | leftTitleTxt.setText(text);
87 | leftTitleTxt.setVisibility(View.VISIBLE);
88 | }
89 |
90 | protected void setRightText(String text) {
91 | if (null == text) {
92 | return;
93 | }
94 | rightTitleTxt.setText(text);
95 | rightTitleTxt.setVisibility(View.VISIBLE);
96 | }
97 |
98 | protected void setTitle(String title) {
99 | if (title == null) {
100 | return;
101 | }
102 | if (title.length() > 24) {
103 | title = title.substring(0, 23) + "...";
104 | }
105 | topTitleTxt.setText(title);
106 | topTitleTxt.setVisibility(View.VISIBLE);
107 | }
108 |
109 | @Override
110 | public void setTitle(int id) {
111 | String strTitle = getResources().getString(id);
112 | setTitle(strTitle);
113 | }
114 |
115 | public void setTitleImage(int resID) {
116 | if (resID <= 0) {
117 | return;
118 | }
119 |
120 | topTitelImage.setImageResource(resID);
121 | topTitelImage.setVisibility(View.VISIBLE);
122 | }
123 |
124 | protected void setLeftButton(int resID) {
125 | if (resID <= 0) {
126 | return;
127 | }
128 |
129 | topLeftBtn.setImageResource(resID);
130 | topLeftBtn.setVisibility(View.VISIBLE);
131 | }
132 |
133 | protected void setRightButton(int resID) {
134 | if (resID <= 0) {
135 | return;
136 | }
137 |
138 | topRightBtn.setImageResource(resID);
139 | topRightBtn.setVisibility(View.VISIBLE);
140 | }
141 |
142 | protected void setTopBar(int resID) {
143 | if (resID <= 0) {
144 | return;
145 | }
146 | topBar.setBackgroundResource(resID);
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/utils/SPUtils.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.utils;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 |
7 | import java.lang.reflect.InvocationTargetException;
8 | import java.lang.reflect.Method;
9 | import java.util.Map;
10 |
11 | public class SPUtils {
12 | /**
13 | * Config filename
14 | */
15 | public static final String FILE_NAME = "data";
16 |
17 | /**
18 | * Save Data
19 | *
20 | * @param context
21 | * @param key
22 | * @param object
23 | */
24 | public static void put(Context context, String key, Object object) {
25 |
26 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
27 | Context.MODE_PRIVATE);
28 | SharedPreferences.Editor editor = sp.edit();
29 |
30 | if (object instanceof String) {
31 | editor.putString(key, (String) object);
32 | } else if (object instanceof Integer) {
33 | editor.putInt(key, (Integer) object);
34 | } else if (object instanceof Boolean) {
35 | editor.putBoolean(key, (Boolean) object);
36 | } else if (object instanceof Float) {
37 | editor.putFloat(key, (Float) object);
38 | } else if (object instanceof Long) {
39 | editor.putLong(key, (Long) object);
40 | } else {
41 | editor.putString(key, object.toString());
42 | }
43 |
44 | SharedPreferencesCompat.apply(editor);
45 | }
46 | public static void putBool(Context context,String key,boolean data)
47 | {
48 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE);
49 | SharedPreferences.Editor editor = sp.edit();
50 | editor.putBoolean(key,data);
51 | editor.commit();
52 | SharedPreferencesCompat.apply(editor);
53 | }
54 | public static boolean getBool(Context context,String key)
55 | {
56 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE);
57 | return sp.getBoolean(key,false);
58 | }
59 | /**
60 | * Save Data
61 | *
62 | * @param context
63 | * @param key
64 | * @param defaultObject
65 | * @return
66 | */
67 | public static Object get(Context context, String key, Object defaultObject) {
68 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
69 | Context.MODE_PRIVATE);
70 |
71 | if (defaultObject instanceof String) {
72 | return sp.getString(key, (String) defaultObject);
73 | } else if (defaultObject instanceof Integer) {
74 | return sp.getInt(key, (Integer) defaultObject);
75 | } else if (defaultObject instanceof Boolean) {
76 | return sp.getBoolean(key, (Boolean) defaultObject);
77 | } else if (defaultObject instanceof Float) {
78 | return sp.getFloat(key, (Float) defaultObject);
79 | } else if (defaultObject instanceof Long) {
80 | return sp.getLong(key, (Long) defaultObject);
81 | }
82 |
83 | return null;
84 | }
85 |
86 | /**
87 | * Remove key`s value
88 | *
89 | * @param context
90 | * @param key
91 | */
92 | public static void remove(Context context, String key) {
93 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
94 | Context.MODE_PRIVATE);
95 | SharedPreferences.Editor editor = sp.edit();
96 | editor.remove(key);
97 | SharedPreferencesCompat.apply(editor);
98 | }
99 |
100 | /**
101 | * Clear All Datas.
102 | *
103 | * @param context
104 | */
105 | public static void clear(Context context) {
106 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
107 | Context.MODE_PRIVATE);
108 | SharedPreferences.Editor editor = sp.edit();
109 | editor.clear();
110 | SharedPreferencesCompat.apply(editor);
111 | }
112 |
113 | /**
114 | * Qurey is Key Exists
115 | *
116 | * @param context
117 | * @param key
118 | * @return
119 | */
120 | public static boolean contains(Context context, String key) {
121 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
122 | Context.MODE_PRIVATE);
123 | return sp.contains(key);
124 | }
125 |
126 | /**
127 | * Return All Keys
128 | *
129 | * @param context
130 | * @return
131 | */
132 | public static Map getAll(Context context) {
133 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
134 | Context.MODE_PRIVATE);
135 | return sp.getAll();
136 | }
137 |
138 | private static class SharedPreferencesCompat {
139 | private static final Method sApplyMethod = findApplyMethod();
140 | @SuppressWarnings({"unchecked", "rawtypes"})
141 | private static Method findApplyMethod() {
142 | try {
143 | Class clz = SharedPreferences.Editor.class;
144 | return clz.getMethod("apply");
145 | } catch (NoSuchMethodException e) {
146 | }
147 | return null;
148 | }
149 | public static void apply(SharedPreferences.Editor editor) {
150 | try {
151 | if (sApplyMethod != null) {
152 | sApplyMethod.invoke(editor);
153 | return;
154 | }
155 | } catch (IllegalArgumentException e) {
156 | } catch (IllegalAccessException e) {
157 | } catch (InvocationTargetException e) {
158 | }
159 | editor.commit();
160 | }
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/SetButtonActivity.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Bundle;
7 | import android.text.Editable;
8 | import android.text.method.DigitsKeyListener;
9 | import android.text.method.KeyListener;
10 | import android.view.KeyEvent;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.inputmethod.InputMethodManager;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.Toast;
17 |
18 | import com.RRG.usbninja.app.MainApplication;
19 | import com.RRG.usbninja.ble.ConvertData;
20 | import com.wise.wisekit.activity.BaseActivity;
21 | import com.wise.wisekit.utils.SPUtils;
22 |
23 | public class SetButtonActivity extends BaseActivity {
24 |
25 | public static final String EXTRAS_BUTTON_KEY = "button_key";
26 |
27 | private EditText mNameEditText;
28 | private EditText mTouchUpEditText;
29 | private EditText mTouchDownEditText;
30 |
31 | private String buttonKey;
32 | private ButtonModel btnModel;
33 | private Button mEditBtn;
34 |
35 | //is HEX Editing
36 | private boolean bHexEdit = true;
37 |
38 | KeyListener defaultKeyListener;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | LayoutInflater.from(this).inflate(R.layout.activity_set_button, topContentView);
44 |
45 | final Intent intent = getIntent();
46 | buttonKey = intent.getStringExtra(EXTRAS_BUTTON_KEY);
47 |
48 | String buttonStr = (String) SPUtils.get(MainApplication.getAppContext(), buttonKey, "");
49 | btnModel = new ButtonModel(buttonStr);
50 |
51 | initView();
52 |
53 | }
54 |
55 | private void initView() {
56 |
57 | topLeftBtn.setVisibility(View.VISIBLE);
58 | topRightBtn.setVisibility(View.VISIBLE);
59 |
60 | setTitle("Set");
61 | setRightText("Done");
62 |
63 | mNameEditText = findViewById(R.id.name_edit);
64 | mTouchDownEditText = findViewById(R.id.touch_down_edit);
65 | mTouchUpEditText = findViewById(R.id.touch_up_edit);
66 |
67 | mEditBtn = findViewById(R.id.edit);
68 |
69 | mNameEditText.setText(btnModel.getName());
70 | mTouchUpEditText.setText(btnModel.getTouchUp());
71 | mTouchDownEditText.setText(btnModel.getTouchDown());
72 |
73 | defaultKeyListener = mTouchUpEditText.getKeyListener();
74 |
75 | mTouchUpEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789abcdefABCDEF"));
76 | mTouchDownEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789abcdefABCDEF"));
77 |
78 | mEditBtn.setOnClickListener(new View.OnClickListener() {
79 | @Override
80 | public void onClick(View view) {
81 | bHexEdit = !bHexEdit;
82 |
83 | if (bHexEdit) {
84 | Drawable switchOn = getResources().getDrawable(R.mipmap.switch_on);
85 | switchOn.setBounds(0, 0, switchOn.getMinimumWidth(), switchOn.getMinimumHeight());
86 | mEditBtn.setCompoundDrawables(null, null, switchOn, null);
87 | mTouchUpEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789abcdefABCDEF"));
88 | mTouchDownEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789abcdefABCDEF"));
89 | mTouchDownEditText.setText("");
90 | mTouchUpEditText.setText("");
91 | }
92 | else {
93 | Drawable switchOff = getResources().getDrawable(R.mipmap.switch_off);
94 | switchOff.setBounds(0, 0, switchOff.getMinimumWidth(), switchOff.getMinimumHeight());
95 | mEditBtn.setCompoundDrawables(null, null, switchOff, null);
96 | mTouchUpEditText.setKeyListener(defaultKeyListener);
97 | mTouchDownEditText.setKeyListener(defaultKeyListener);
98 | }
99 |
100 | }
101 | });
102 |
103 | topRightBtn.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View view) {
106 |
107 | //could`t divied by 2
108 | if (bHexEdit && mTouchDownEditText.getText().toString().length()%2 != 0) {
109 | Toast.makeText(SetButtonActivity.this, "Press the command length to be an integer multiple of 2",Toast.LENGTH_SHORT).show();
110 | return;
111 | }
112 | //could`t divied by 2
113 | if (bHexEdit && mTouchUpEditText.getText().toString().length()%2 != 0) {
114 | Toast.makeText(SetButtonActivity.this, "The release command must be an integer multiple of 2",Toast.LENGTH_SHORT).show();
115 | return;
116 | }
117 |
118 | if (!mNameEditText.getText().toString().isEmpty()) {
119 | btnModel.setName(mNameEditText.getText().toString());
120 | }
121 |
122 | if (!mTouchDownEditText.getText().toString().isEmpty()) {
123 | if (bHexEdit) {
124 | btnModel.setTouchDown(mTouchDownEditText.getText().toString());
125 | }
126 | else {
127 | btnModel.setTouchDown(ConvertData.bytesToHexString(ConvertData.unicodeToBytes(mTouchDownEditText.getText().toString()),false));
128 | }
129 |
130 | }
131 |
132 | if (!mTouchUpEditText.getText().toString().isEmpty()) {
133 | if (bHexEdit) {
134 | btnModel.setTouchUp(mTouchUpEditText.getText().toString());
135 | }
136 | else {
137 | btnModel.setTouchUp(ConvertData.bytesToHexString(ConvertData.unicodeToBytes(mTouchUpEditText.getText().toString()),false));
138 | }
139 | }
140 |
141 | SPUtils.put(MainApplication.getAppContext(), buttonKey, btnModel.toJsonObjectStr());
142 |
143 | finish();
144 | }
145 | });
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/ble/BluetoothLe.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja.ble;
2 |
3 | import java.util.List;
4 | import java.util.UUID;
5 |
6 | import android.bluetooth.BluetoothAdapter;
7 | import android.bluetooth.BluetoothDevice;
8 | import android.bluetooth.BluetoothGatt;
9 | import android.bluetooth.BluetoothGattCallback;
10 | import android.bluetooth.BluetoothGattCharacteristic;
11 | import android.bluetooth.BluetoothGattDescriptor;
12 | import android.bluetooth.BluetoothGattService;
13 | import android.bluetooth.BluetoothManager;
14 | import android.content.Context;
15 | import android.content.pm.PackageManager;
16 | import android.util.Log;
17 |
18 | public class BluetoothLe
19 | {
20 | private final static String TAG = BluetoothLe.class.getSimpleName();
21 |
22 | private Context mContext;
23 |
24 | protected BluetoothManager mBluetoothManager;
25 | protected BluetoothAdapter mBluetoothAdapter;
26 | protected String mBluetoothDeviceAddress;
27 | protected BluetoothGatt mBluetoothGatt;
28 |
29 | private BluetoothAdapter.LeScanCallback mScanCallback;
30 |
31 | public final static UUID UUID_HEART_RATE_MEASUREMENT =
32 | UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb");
33 | public final static UUID UUID_CLIENT_CHARACTERISTIC_CONFIG =
34 | UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
35 |
36 | public BluetoothLe(Context context)
37 | {
38 | mContext = context;
39 | }
40 |
41 | public BluetoothGatt getGatt()
42 | {
43 | return mBluetoothGatt;
44 | }
45 |
46 | /**
47 | * Check Local Device Support BLE
48 | *
49 | * @param no
50 | *
51 | * @return Support=true,else=false
52 | *
53 | */
54 | public boolean isBleSupported()
55 | {
56 | if(!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
57 | return false;
58 |
59 | return true;
60 | }
61 |
62 | /**
63 | * Check Local Bluetooth is Opened
64 | *
65 | * @param no
66 | *
67 | * @return Open=true,else=false
68 | *
69 | */
70 | public boolean isOpened()
71 | {
72 | if(!mBluetoothAdapter.isEnabled())
73 | return false;
74 |
75 | return true;
76 | }
77 |
78 | /**
79 | * Set Search Result Callback Method
80 | *
81 | * @param scanCallback Method
82 | *
83 | * @return Success=true,else=false
84 | *
85 | */
86 | public boolean setScanCallBack(BluetoothAdapter.LeScanCallback scanCallback)
87 | {
88 | if(scanCallback == null)
89 | return false;
90 |
91 | mScanCallback = scanCallback;
92 | return true;
93 | }
94 |
95 | /**
96 | * Start Scan
97 | *
98 | * @param no
99 | *
100 | * @return Success=true,else=false
101 | *
102 | */
103 | public boolean startLeScan()
104 | {
105 | if(mScanCallback == null)
106 | return false;
107 |
108 | return mBluetoothAdapter.startLeScan(mScanCallback);
109 | }
110 |
111 | /**
112 | * Stop Scan
113 | *
114 | * @param no
115 | *
116 | * @return Success=true,else=false
117 | *
118 | */
119 | public boolean stopLeScan()
120 | {
121 | if(mScanCallback == null)
122 | return false;
123 |
124 | mBluetoothAdapter.stopLeScan(mScanCallback);
125 |
126 | return true;
127 | }
128 |
129 | /**
130 | * Connect Local Device
131 | *
132 | * @param no
133 | *
134 | * @return Success=true,else=false
135 | *
136 | */
137 | public boolean connectLocalDevice()
138 | {
139 | if (mBluetoothManager == null)
140 | {
141 | mBluetoothManager = (BluetoothManager)mContext.getSystemService(Context.BLUETOOTH_SERVICE);
142 | if (mBluetoothManager == null)
143 | {
144 | return false;
145 | }
146 | }
147 |
148 | mBluetoothAdapter = mBluetoothManager.getAdapter();
149 | if (mBluetoothAdapter == null)
150 | {
151 | return false;
152 | }
153 |
154 | return true;
155 | }
156 |
157 | /**
158 | * Close Local Device
159 | *
160 | * @param no
161 | *
162 | * @return Success=true,else=false
163 | *
164 | */
165 | public void disconnectLocalDevice()
166 | {
167 | if (mBluetoothGatt == null)
168 | {
169 | return;
170 | }
171 | mBluetoothGatt.close();
172 | mBluetoothGatt = null;
173 | }
174 |
175 | /**
176 | * Connect Remote Device by MAC
177 | *
178 | * @param address Remote Device`s MAC Address
179 | * @param gattCallback CallBack Method
180 | *
181 | * @return Success=true,else=false
182 | *
183 | */
184 | public boolean connectDevice(final String address, BluetoothGattCallback gattCallback)
185 | {
186 | if (mBluetoothAdapter == null || address == null)
187 | {
188 | return false;
189 | }
190 |
191 | final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
192 | if (device == null)
193 | {
194 | return false;
195 | }
196 | // We want to directly connect to the device, so we are setting the autoConnect
197 | // parameter to false.
198 | mBluetoothGatt = device.connectGatt(mContext, false, gattCallback);
199 | if(mBluetoothGatt == null)
200 | return false;
201 |
202 | mBluetoothDeviceAddress = address;
203 | return true;
204 | }
205 |
206 | /**
207 | * Close Remote Device
208 | *
209 | * @param no
210 | *
211 | * @return no
212 | *
213 | */
214 | public void disconnectDevice()
215 | {
216 | if (mBluetoothAdapter == null || mBluetoothGatt == null)
217 | {
218 | return ;
219 | }
220 | mBluetoothGatt.disconnect();
221 | Log.d(TAG, "Bluetooth disconnect");
222 | }
223 |
224 |
225 | public boolean readCharacteristic(BluetoothGattCharacteristic characteristic)
226 | {
227 | if (mBluetoothAdapter == null || mBluetoothGatt == null)
228 | {
229 | return false;
230 | }
231 | return mBluetoothGatt.readCharacteristic(characteristic);
232 | }
233 |
234 | public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic)
235 | {
236 | if (mBluetoothAdapter == null || mBluetoothGatt == null)
237 | {
238 | return false;
239 | }
240 | //characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
241 | return mBluetoothGatt.writeCharacteristic(characteristic);
242 | }
243 |
244 | public boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic,boolean enabled)
245 | {
246 | if (mBluetoothAdapter == null || mBluetoothGatt == null)
247 | {
248 | return false;
249 | }
250 | if(!mBluetoothGatt.setCharacteristicNotification(characteristic, enabled))
251 | return false;
252 |
253 | BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID_CLIENT_CHARACTERISTIC_CONFIG);
254 | if(descriptor == null)
255 | return false;
256 |
257 | byte[] data;
258 | if(enabled)
259 | data = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
260 | else
261 | data = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
262 |
263 | if(!descriptor.setValue(data))
264 | return false;
265 | return mBluetoothGatt.writeDescriptor(descriptor);
266 | }
267 |
268 | /**
269 | * Get Service List
270 | *
271 | * @param No
272 | *
273 | * @return Service List
274 | *
275 | */
276 | public List getSupportedGattServices()
277 | {
278 | if (mBluetoothGatt == null)
279 | return null;
280 |
281 | return mBluetoothGatt.getServices();
282 | }
283 | }
284 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/ble/HolloBluetooth.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja.ble;
2 |
3 | import java.util.UUID;
4 |
5 | import android.bluetooth.BluetoothGatt;
6 | import android.bluetooth.BluetoothGattCallback;
7 | import android.bluetooth.BluetoothGattCharacteristic;
8 | import android.bluetooth.BluetoothGattDescriptor;
9 | import android.bluetooth.BluetoothProfile;
10 | import android.content.Context;
11 | import android.util.Log;
12 |
13 |
14 | public class HolloBluetooth extends BluetoothLe
15 | {
16 | private final static String TAG = HolloBluetooth.class.getSimpleName();
17 |
18 | public final static int HOLLO_BLE_CONNECTED = 1; //BLE Connected
19 | public final static int HOLLO_BLE_SERVICE_DISCOVERY = 2; //BLE Discovery!
20 | public final static int HOLLO_BLE_DISCONNECTED = 3; //BLE Disconnected
21 |
22 | public final static UUID UUID_HOLLO_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb");
23 |
24 | public final static UUID UUID_HOLLO_DATA_RECEIVE = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb");
25 | public final static UUID UUID_HOLLO_DATA_SEND = UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb");
26 | public final static int RECV_TIME_OUT_SHORT = 2000; //short Receiving delay,ms
27 | public final static int RECV_TIME_OUT_MIDDLE = 5000; //middle Receiving delay,ms
28 | public final static int RECV_TIME_OUT_LONG = 10000; //long Receiving delay,ms
29 |
30 | public final static int BLE_SEND_DATA_LEN_MAX = 20;
31 |
32 |
33 | private WaitEvent connectEvent = new WaitEvent();
34 |
35 | private WaitEvent stateEvent = new WaitEvent();
36 |
37 | private WaitEvent sendEvent = new WaitEvent();
38 |
39 | private int mBleState = HOLLO_BLE_DISCONNECTED;
40 |
41 | private static HolloBluetooth mHolloBluetooth = null;
42 |
43 | private OnHolloBluetoothCallBack mBleCallBack = null;
44 |
45 | public interface OnHolloBluetoothCallBack
46 | {
47 | public void OnHolloBluetoothState(int state);
48 | public void OnReceiveData(byte[] recvData);
49 | }
50 |
51 | private HolloBluetooth(Context context)
52 | {
53 | super(context);
54 | }
55 | public static synchronized HolloBluetooth getInstance(Context context)
56 | {
57 | if (mHolloBluetooth == null)
58 | {
59 | if(context == null)
60 | return null;
61 |
62 | mHolloBluetooth = new HolloBluetooth(context);
63 | }
64 | return mHolloBluetooth;
65 | }
66 |
67 | /**
68 | * Connect Remote BLE Device
69 | *
70 | * @param address Remote MAC Address
71 | * @param bleCallBack Bluetooth CALLBACK, called when device disconnected unexpectedly.
72 | *
73 | * @return connect=true,else =false
74 | *
75 | */
76 | public boolean connectDevice(String address, OnHolloBluetoothCallBack bleCallBack)
77 | {
78 | mBleCallBack = bleCallBack;
79 |
80 | connectEvent.Init();
81 |
82 | if(!super.connectDevice(address, mGattCallback))
83 | return false;
84 |
85 | if(WaitEvent.SUCCESS != connectEvent.waitSignal(RECV_TIME_OUT_MIDDLE))
86 | {
87 | disconnectDevice();
88 | return false;
89 | }
90 |
91 | return true;
92 | }
93 |
94 | public void disconnectDevice()
95 | {
96 | mBleState = HOLLO_BLE_DISCONNECTED;
97 | mBleCallBack = null;
98 | super.disconnectDevice();
99 | }
100 |
101 | /**
102 | * Get is Connected
103 | *
104 | * @return Connected=true;else=false;
105 | *
106 | */
107 | public boolean isConnect()
108 | {
109 | return (mBleState == HOLLO_BLE_SERVICE_DISCOVERY);
110 | }
111 |
112 |
113 | /**
114 | * Wakeup Bluetooth, when errors occured, it will throw HolloBluetoothException
115 | *
116 | * @param no
117 | *
118 | * @return connected=true,else=false;
119 | *
120 | */
121 | public boolean wakeUpBle()
122 | {
123 | if(mBluetoothGatt == null)
124 | return false;
125 |
126 | BluetoothGattCharacteristic character;
127 |
128 | character = mBluetoothGatt.getService(UUID_HOLLO_SERVICE).getCharacteristic(UUID_HOLLO_DATA_RECEIVE);
129 |
130 | stateEvent.Init();
131 | if(!setCharacteristicNotification(character, true))
132 | return false;
133 |
134 | if(WaitEvent.SUCCESS != stateEvent.waitSignal(RECV_TIME_OUT_MIDDLE))
135 | return false;
136 |
137 | return true;
138 | }
139 |
140 | public boolean sendData(byte[] data)
141 | {
142 | if(mBluetoothGatt == null)
143 | return false;
144 |
145 | BluetoothGattCharacteristic character;
146 |
147 | character = mBluetoothGatt.getService(UUID_HOLLO_SERVICE).getCharacteristic(UUID_HOLLO_DATA_SEND);
148 |
149 | int nCount = data.length/BLE_SEND_DATA_LEN_MAX;
150 | if(data.length%BLE_SEND_DATA_LEN_MAX != 0)
151 | nCount++;
152 |
153 | byte[] temp;
154 | for (int i = 0; i < nCount; i++)
155 | {
156 | sendEvent.Init();
157 |
158 | if( (i+1) != nCount)
159 | {
160 | temp = new byte[BLE_SEND_DATA_LEN_MAX];
161 | }
162 | else
163 | {
164 | temp = new byte[data.length-BLE_SEND_DATA_LEN_MAX*i];
165 | }
166 |
167 | for (int j = 0; j < temp.length; j++)
168 | {
169 | temp[j] = data[i*(BLE_SEND_DATA_LEN_MAX)+j];
170 | }
171 |
172 | character.setValue(temp);
173 | // character.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
174 | if(!mBluetoothGatt.writeCharacteristic(character))
175 | return false;
176 |
177 | if(WaitEvent.SUCCESS != sendEvent.waitSignal(RECV_TIME_OUT_MIDDLE))
178 | return false;
179 | }
180 |
181 | return true;
182 | }
183 |
184 | // Implements callback methods for GATT events that the app cares about. For example,
185 | // connection change and services discovered.
186 | private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback()
187 | {
188 | @Override
189 | public void onConnectionStateChange(BluetoothGatt gatt, int status,
190 | int newState)
191 | {
192 | // String intentAction;
193 | if (newState == BluetoothProfile.STATE_CONNECTED)
194 | {
195 | mBleState = HOLLO_BLE_CONNECTED;
196 | mBluetoothGatt.discoverServices();
197 | Log.d(TAG, "Connect Successfully " + status);
198 | }
199 | else if (newState == BluetoothProfile.STATE_DISCONNECTED)
200 | {
201 | mBleState = HOLLO_BLE_DISCONNECTED;
202 | if(mBleCallBack != null)
203 | mBleCallBack.OnHolloBluetoothState(mBleState);
204 |
205 | Log.d(TAG, "Disconnected from GATT server "+mBleState);
206 | }
207 | }
208 |
209 | @Override
210 | public void onServicesDiscovered(BluetoothGatt gatt, int status)
211 | {
212 | if(status == BluetoothGatt.GATT_SUCCESS)
213 | mBleState = HOLLO_BLE_SERVICE_DISCOVERY;
214 | connectEvent.setSignal(status == BluetoothGatt.GATT_SUCCESS);
215 | }
216 |
217 | @Override
218 | public void onCharacteristicRead(BluetoothGatt gatt,
219 | BluetoothGattCharacteristic characteristic, int status)
220 | {
221 | if (status == BluetoothGatt.GATT_SUCCESS)
222 | {
223 | // broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
224 | // For all other profiles, writes the data formatted in HEX.
225 | final byte[] data = characteristic.getValue();
226 | if (data != null && data.length > 0)
227 | {
228 | }
229 | }
230 | }
231 |
232 | @Override
233 | public void onCharacteristicWrite(BluetoothGatt gatt,
234 | BluetoothGattCharacteristic characteristic, int status)
235 | {
236 | if (characteristic.getUuid().equals(UUID_HOLLO_DATA_SEND))
237 | {
238 | sendEvent.setSignal(status == BluetoothGatt.GATT_SUCCESS);
239 | }
240 | else
241 | {
242 | sendEvent.setSignal(false);
243 | }
244 | }
245 |
246 | @Override
247 | public void onCharacteristicChanged(BluetoothGatt gatt,
248 | BluetoothGattCharacteristic characteristic)
249 | {
250 | // broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
251 | final byte[] data = characteristic.getValue();
252 | if (data != null && data.length > 0)
253 | {
254 | if(mBleCallBack != null)
255 | mBleCallBack.OnReceiveData(data);
256 | }
257 | }
258 |
259 | @Override
260 | public void onDescriptorWrite(BluetoothGatt gatt,
261 | BluetoothGattDescriptor descriptor, int status)
262 | {
263 | if (status == BluetoothGatt.GATT_SUCCESS)
264 | {
265 | Log.d(TAG, "Descript success ");
266 | if(ConvertData.cmpBytes(descriptor.getValue(), BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE))
267 | {
268 | stateEvent.setSignal(true);
269 | }
270 | }
271 | else
272 | {
273 | stateEvent.setSignal(false);
274 | }
275 | }
276 | };
277 |
278 | private class WaitEvent
279 | {
280 | public final static int ERROR_OTHER = 2;
281 | public final static int ERROR_TIME_OUT = 1;
282 | public final static int SUCCESS = 0;
283 |
284 | private Object mSignal;
285 | private boolean mFlag;
286 | private int mResult;
287 |
288 | private MyThread myThread;
289 |
290 | public WaitEvent()
291 | {
292 | mSignal = new Object();
293 | mFlag = true;
294 | mResult = SUCCESS;
295 | }
296 | public void Init()
297 | {
298 | mFlag = true;
299 | mResult = SUCCESS;
300 | Log.d(TAG, "Init Event");
301 | }
302 | public int waitSignal(int millis)
303 | {
304 | myThread = new MyThread();
305 | myThread.startThread(millis);
306 | if(!mFlag)
307 | return mResult;
308 |
309 | synchronized (mSignal)
310 | {
311 | try
312 | {
313 | Log.d(TAG, "waitSignal ");
314 | mSignal.wait();
315 | Log.d(TAG, "waitSignal over");
316 | }
317 | catch (InterruptedException e)
318 | {
319 | e.printStackTrace();
320 | }
321 | }
322 |
323 | return mResult;
324 | }
325 |
326 | public void setSignal(boolean bSuccess)
327 | {
328 | synchronized (mSignal)
329 | {
330 | Log.d(TAG, "setSignal");
331 | mFlag = false;
332 | if(!bSuccess)
333 | mResult = ERROR_OTHER;
334 | if(myThread != null)
335 | myThread.stopThread();
336 | mSignal.notify();
337 | }
338 | }
339 |
340 | private void waitTimeOut()
341 | {
342 | Log.d(TAG, "waitTimeOut");
343 | mResult = ERROR_TIME_OUT;
344 | setSignal(true);
345 | }
346 |
347 | class MyThread extends Thread
348 | {
349 | boolean mThreadAlive = false;
350 | int mCount = 0;
351 | int mTotal = 0;
352 | public void startThread(int millis)
353 | {
354 | mTotal = millis/10;
355 | mCount = 0;
356 | mThreadAlive = true;
357 | start();
358 | Log.d(TAG, "runable start");
359 | }
360 |
361 | public void stopThread()
362 | {
363 | Log.d(TAG, "runable stop");
364 | mThreadAlive = false;
365 | }
366 |
367 | @Override
368 | public void run()
369 | {
370 | while(true)
371 | {
372 | //Log.d(TAG, "Thread Running");
373 | try
374 | {
375 | mCount++;
376 | Thread.sleep(10);
377 |
378 | if(!mThreadAlive)
379 | {
380 | return ;
381 | }
382 |
383 | if(mCount > mTotal) //Timeout
384 | {
385 | waitTimeOut();
386 | return ;
387 | }
388 | }
389 | catch (InterruptedException e)
390 | {
391 | e.printStackTrace();
392 | }
393 | }
394 | }
395 |
396 | }
397 | }
398 |
399 | }
400 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_serial_port.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
29 |
30 |
31 |
32 |
33 |
34 |
41 |
42 |
47 |
48 |
54 |
55 |
65 |
66 |
67 |
68 |
74 |
75 |
85 |
86 |
87 |
88 |
94 |
95 |
105 |
106 |
107 |
108 |
109 |
110 |
115 |
116 |
122 |
123 |
133 |
134 |
135 |
136 |
142 |
143 |
153 |
154 |
155 |
156 |
162 |
163 |
173 |
174 |
175 |
176 |
177 |
178 |
183 |
184 |
190 |
191 |
201 |
202 |
203 |
204 |
210 |
211 |
221 |
222 |
223 |
224 |
230 |
231 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
259 |
260 |
269 |
270 |
271 |
272 |
--------------------------------------------------------------------------------
/wiseKit/wiseKit.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/wiseKit/src/main/java/com/wise/wisekit/utils/DateUtils.java:
--------------------------------------------------------------------------------
1 | package com.wise.wisekit.utils;
2 |
3 | import android.text.TextUtils;
4 |
5 | import java.text.ParseException;
6 | import java.text.SimpleDateFormat;
7 | import java.util.Calendar;
8 | import java.util.Date;
9 |
10 | public class DateUtils {
11 |
12 | public static String DATE_PATTERN = "yyyy-MM-dd";
13 | public static String SHORT_DATE_PATTERN = "yy-MM-dd";
14 | public static String WEEK_PATTERN = "yyyy/MM/dd";
15 | public static String MONTH_PATTERN = "yyyy-MM";
16 | public static String TIME_PATTERN = "HH:mm:ss";
17 | public static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
18 | public static String METHOD_DATE_TIME_PATTERN = "yyyyMMddHHmmss";
19 | public static String NO_YEAR_DATE_TIME_PATTERN = "MM-dd HH:mm";
20 |
21 | public DateUtils() {
22 | }
23 |
24 | public static String getMethodDateTime() {
25 | Date currentTime = new Date();
26 | SimpleDateFormat formatter = new SimpleDateFormat(METHOD_DATE_TIME_PATTERN);
27 | String dateString = formatter.format(currentTime);
28 | return dateString;
29 | }
30 |
31 | public static String getNow() {
32 | Date currentTime = new Date();
33 | SimpleDateFormat formatter = new SimpleDateFormat(DATE_TIME_PATTERN);
34 | String dateString = formatter.format(currentTime);
35 | return dateString;
36 | }
37 |
38 | public static String getNowDate() {
39 | Date currentTime = new Date();
40 | SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN);
41 | String dateString = formatter.format(currentTime);
42 | return dateString;
43 | }
44 |
45 | public static String dateToString(Date date, String pattern) {
46 | SimpleDateFormat formatter = new SimpleDateFormat(pattern);
47 | String dateString = formatter.format(date);
48 | return dateString;
49 | }
50 |
51 | public static Date stringToDate(String strDate, String pattern) throws ParseException {
52 | SimpleDateFormat df = new SimpleDateFormat(pattern);
53 | return df.parse(strDate);
54 | }
55 |
56 | public static String getNowTime() {
57 | Date currentTime = new Date();
58 | SimpleDateFormat formatter = new SimpleDateFormat(TIME_PATTERN);
59 | String dateString = formatter.format(currentTime);
60 | return dateString;
61 | }
62 |
63 | public static boolean isGreaterToday(String date) {
64 | SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
65 | Date d = null;
66 |
67 | try {
68 | d = sdf.parse(date);
69 | } catch (ParseException var4) {
70 | var4.printStackTrace();
71 | return false;
72 | }
73 |
74 | return (new Date()).getTime() <= d.getTime();
75 | }
76 |
77 | public static boolean isGreaterMonth(String date) {
78 | SimpleDateFormat sdf = new SimpleDateFormat(MONTH_PATTERN);
79 | Date d = null;
80 |
81 | try {
82 | d = sdf.parse(date);
83 | } catch (ParseException var4) {
84 | var4.printStackTrace();
85 | return false;
86 | }
87 |
88 | return (new Date()).getTime() <= d.getTime();
89 | }
90 |
91 | public static boolean isGreaterWeek(String date) {
92 | String strWeek = date.substring(0, 10);
93 | SimpleDateFormat sdf = new SimpleDateFormat(WEEK_PATTERN);
94 | Date d = null;
95 |
96 | try {
97 | d = sdf.parse(strWeek);
98 | } catch (ParseException var10) {
99 | var10.printStackTrace();
100 | return false;
101 | }
102 |
103 | Date currentTime = new Date();
104 | SimpleDateFormat formatter = new SimpleDateFormat(WEEK_PATTERN);
105 | String dateString = formatter.format(currentTime);
106 |
107 | try {
108 | Date currentWeek = stringToDate(dateString, WEEK_PATTERN);
109 | return currentWeek.getTime() <= d.getTime();
110 | } catch (ParseException var9) {
111 | var9.printStackTrace();
112 | return false;
113 | }
114 | }
115 |
116 | public static String getBeforeDate(Date date) {
117 | Calendar ca = Calendar.getInstance();
118 | ca.setTime(date);
119 | ca.add(5, -1);
120 | Date beforeDate = ca.getTime();
121 | return dateToString(beforeDate, DATE_PATTERN);
122 | }
123 |
124 | public static String getBeforeDate(String date) throws ParseException {
125 | Calendar ca = Calendar.getInstance();
126 | ca.setTime(stringToDate(date, DATE_PATTERN));
127 | ca.add(5, -1);
128 | Date beforeDate = ca.getTime();
129 | return dateToString(beforeDate, DATE_PATTERN);
130 | }
131 |
132 | public static String getBeforeDate(String date, int days) throws ParseException {
133 | Calendar ca = Calendar.getInstance();
134 | ca.setTime(stringToDate(date, DATE_PATTERN));
135 | ca.add(5, -days);
136 | Date beforeDate = ca.getTime();
137 | return dateToString(beforeDate, DATE_PATTERN);
138 | }
139 |
140 | public static String getBeforeDate(Date date, int days) throws ParseException {
141 | Calendar ca = Calendar.getInstance();
142 | ca.setTime(date);
143 | ca.add(5, -days);
144 | Date beforeDate = ca.getTime();
145 | return dateToString(beforeDate, DATE_PATTERN);
146 | }
147 |
148 | public static String getAfterDate(Date date) {
149 | Calendar ca = Calendar.getInstance();
150 | ca.setTime(date);
151 | ca.add(5, 1);
152 | Date afterDate = ca.getTime();
153 | return dateToString(afterDate, DATE_PATTERN);
154 | }
155 |
156 | public static String getAfterDate(String date, int days) throws ParseException {
157 | Calendar ca = Calendar.getInstance();
158 | ca.setTime(stringToDate(date, DATE_PATTERN));
159 | ca.add(5, days);
160 | Date afterDate = ca.getTime();
161 | return dateToString(afterDate, DATE_PATTERN);
162 | }
163 |
164 | public static String getAfterDate(String date) throws ParseException {
165 | Calendar ca = Calendar.getInstance();
166 | ca.setTime(stringToDate(date, DATE_PATTERN));
167 | ca.add(5, 1);
168 | Date afterDate = ca.getTime();
169 | return dateToString(afterDate, DATE_PATTERN);
170 | }
171 |
172 | public static String getNowMonth() {
173 | Date currentTime = new Date();
174 | SimpleDateFormat formatter = new SimpleDateFormat(MONTH_PATTERN);
175 | String dateString = formatter.format(currentTime);
176 | return dateString;
177 | }
178 |
179 | public static String getBeforeMonth(String date) throws ParseException {
180 | Calendar ca = Calendar.getInstance();
181 | ca.setTime(stringToDate(date, MONTH_PATTERN));
182 | ca.add(2, -1);
183 | Date beforeDate = ca.getTime();
184 | return dateToString(beforeDate, MONTH_PATTERN);
185 | }
186 |
187 | public static String getAfterMonth(String date) throws ParseException {
188 | Calendar ca = Calendar.getInstance();
189 | ca.setTime(stringToDate(date, MONTH_PATTERN));
190 | ca.add(2, 1);
191 | Date afterDate = ca.getTime();
192 | return dateToString(afterDate, MONTH_PATTERN);
193 | }
194 |
195 | public static String getMonthBeginDate(String date) throws ParseException {
196 | return ChangeDatePattern(date, MONTH_PATTERN, DATE_PATTERN);
197 | }
198 |
199 | public static String getMonthEndDate(String date) throws ParseException {
200 | String strMonthBeginDate = ChangeDatePattern(date, MONTH_PATTERN, DATE_PATTERN);
201 | Calendar ca = Calendar.getInstance();
202 | ca.setTime(stringToDate(date, MONTH_PATTERN));
203 | ca.add(2, 1);
204 | ca.add(5, -1);
205 | Date MonthEndDate = ca.getTime();
206 | return dateToString(MonthEndDate, DATE_PATTERN);
207 | }
208 |
209 | public static String getNowWeek() {
210 | Calendar cal = Calendar.getInstance();
211 | SimpleDateFormat df = new SimpleDateFormat(WEEK_PATTERN);
212 | cal.set(7, 1);
213 | String strNowWeek = df.format(cal.getTime());
214 | cal.add(5, 6);
215 | strNowWeek = strNowWeek + "--" + df.format(cal.getTime());
216 | return strNowWeek;
217 | }
218 |
219 | public static String getBeforeWeek(String date) throws ParseException {
220 | Calendar cal = Calendar.getInstance();
221 | SimpleDateFormat df = new SimpleDateFormat(WEEK_PATTERN);
222 | cal.setTime(stringToDate(date, WEEK_PATTERN));
223 | cal.add(5, -7);
224 | String strBeforeWeek = df.format(cal.getTime());
225 | cal.add(5, 6);
226 | strBeforeWeek = strBeforeWeek + "--" + df.format(cal.getTime());
227 | return strBeforeWeek;
228 | }
229 |
230 | public static String getAfterWeek(String date) throws ParseException {
231 | Calendar cal = Calendar.getInstance();
232 | SimpleDateFormat df = new SimpleDateFormat(WEEK_PATTERN);
233 | cal.setTime(stringToDate(date, WEEK_PATTERN));
234 | cal.add(5, 7);
235 | String strAfterWeek = df.format(cal.getTime());
236 | cal.add(5, 6);
237 | strAfterWeek = strAfterWeek + "--" + df.format(cal.getTime());
238 | return strAfterWeek;
239 | }
240 |
241 | public static String ChangeDatePattern(String date, String pattern, String toPattern) {
242 | try {
243 | return dateToString(stringToDate(date, pattern), toPattern);
244 | } catch (ParseException var4) {
245 | var4.printStackTrace();
246 | return null;
247 | }
248 | }
249 |
250 | public static String formatTime(String time, String pattern) {
251 | if(TextUtils.isEmpty(time)) {
252 | return "1970-01-01";
253 | } else {
254 | String newTime = "";
255 |
256 | try {
257 | Date e = (new SimpleDateFormat(DATE_TIME_PATTERN)).parse(time);
258 | long timeMillis = e.getTime();
259 | newTime = (new SimpleDateFormat(pattern)).format(Long.valueOf(timeMillis));
260 | } catch (ParseException var6) {
261 | newTime = time;
262 | var6.printStackTrace();
263 | }
264 |
265 | return newTime;
266 | }
267 | }
268 |
269 | public static String formatTime(String time, String prePattern, String pattern) {
270 | if(TextUtils.isEmpty(time)) {
271 | return "1970-01-01";
272 | } else {
273 | String newTime = "";
274 |
275 | try {
276 | Date e = (new SimpleDateFormat(prePattern)).parse(time);
277 | long timeMillis = e.getTime();
278 | newTime = (new SimpleDateFormat(pattern)).format(Long.valueOf(timeMillis));
279 | } catch (ParseException var7) {
280 | newTime = time;
281 | var7.printStackTrace();
282 | }
283 |
284 | return newTime;
285 | }
286 | }
287 |
288 | public static int compareTime(String time1, String time2) {
289 | boolean status = true;
290 |
291 | byte status1;
292 | try {
293 | Date date1 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(time1);
294 | Date e = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(time2);
295 | long timeMillis1 = date1.getTime();
296 | long timeMillis2 = e.getTime();
297 | if(timeMillis1 == timeMillis2) {
298 | status1 = 0;
299 | } else if(timeMillis1 > timeMillis2) {
300 | status1 = 1;
301 | } else {
302 | status1 = -1;
303 | }
304 | } catch (ParseException var9) {
305 | var9.printStackTrace();
306 | status1 = -1;
307 | }
308 |
309 | return status1;
310 | }
311 |
312 | public static long getTimeMillis(String time, String pattern) {
313 | Date date = null;
314 |
315 | try {
316 | date = (new SimpleDateFormat(pattern)).parse(time);
317 | } catch (ParseException var4) {
318 | var4.printStackTrace();
319 | return 0L;
320 | }
321 |
322 | return date.getTime();
323 | }
324 |
325 | public static int getCurrentYear() {
326 | Calendar calendar = Calendar.getInstance();
327 | int currentYear = calendar.get(1);
328 | return currentYear;
329 | }
330 |
331 | public static int getCurrentMonth() {
332 | Calendar calendar = Calendar.getInstance();
333 | int currentMonth = calendar.get(2) + 1;
334 | return currentMonth;
335 | }
336 | }
337 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.app.AlertDialog;
6 | import android.bluetooth.BluetoothAdapter;
7 | import android.bluetooth.BluetoothDevice;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.content.Intent;
11 | import android.content.pm.PackageManager;
12 | import android.os.Build;
13 | import android.os.Bundle;
14 | import android.os.Handler;
15 | import android.support.v4.app.ActivityCompat;
16 | import android.support.v4.content.ContextCompat;
17 | import android.util.Log;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.widget.AdapterView;
22 | import android.widget.BaseAdapter;
23 | import android.widget.Button;
24 | import android.widget.ListView;
25 | import android.widget.ProgressBar;
26 | import android.widget.TextView;
27 | import android.widget.Toast;
28 |
29 | import com.RRG.usbninja.app.MainApplication;
30 | import com.RRG.usbninja.ble.ConvertData;
31 | import com.RRG.usbninja.ble.HolloBluetooth;
32 | import com.RRG.usbninja.config.ConfigInfo;
33 | import com.wise.wisekit.activity.BaseActivity;
34 | import com.wise.wisekit.utils.SPUtils;
35 |
36 | import java.util.ArrayList;
37 |
38 | public class MainActivity extends BaseActivity {
39 |
40 | private HolloBluetooth mble;
41 | private static final int REQUEST_ENABLE_BT = 1;
42 | private static final int REQUEST_CODE_ACCESS_COARSE_LOCATION = 100;
43 | private Handler mHandler=new Handler();
44 | private boolean mScanning=true;
45 | // Stops scanning after 10 seconds.
46 | private static final long SCAN_PERIOD = 5000;
47 | ListView mListView;
48 | ProgressBar mProgressBar;
49 |
50 | private LeDeviceListAdapter mLeDeviceListAdapter;
51 |
52 | private Button mScanBt;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | InitParam();
58 | LayoutInflater.from(this).inflate(R.layout.activity_main,topContentView);
59 | initView();
60 |
61 | mListView = findViewById(R.id.list);
62 |
63 | checkPermissions();
64 |
65 | //Get Bluetooth Context
66 | mble = HolloBluetooth.getInstance(getApplicationContext());
67 | //Check is support BLE
68 | if(!mble.isBleSupported() || !mble.connectLocalDevice())
69 | {
70 | Toast.makeText(this, "BLE is not supported on the device",Toast.LENGTH_SHORT).show();
71 | finish();
72 | return ;
73 | }
74 |
75 | mScanBt = (Button)findViewById(R.id.scanBt);
76 | mProgressBar = findViewById(R.id.progressBar1);
77 | findViewById(R.id.scan_layout).setOnClickListener(new View.OnClickListener()
78 | {
79 | @Override
80 | public void onClick(View v)
81 | {
82 | if(mScanning)
83 | {
84 | scanLeDevice(false);
85 | mScanBt.setText("Start scanning");
86 | mProgressBar.setVisibility(View.GONE);
87 | }
88 | else
89 | {
90 | mLeDeviceListAdapter.clear();
91 | mLeDeviceListAdapter.notifyDataSetChanged();
92 | scanLeDevice(true);
93 | mScanBt.setText("Stop scanning");
94 | mProgressBar.setVisibility(View.VISIBLE);
95 | }
96 |
97 | }
98 | });
99 |
100 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
101 | @Override
102 | public void onItemClick(AdapterView> adapterView, View view, int position, long l) {
103 |
104 | final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
105 | if (device == null) return;
106 |
107 | final Intent intent = new Intent(MainActivity.this, SerialPortActivity.class);
108 | intent.putExtra(SerialPortActivity.EXTRAS_DEVICE_NAME, device.getName());
109 | intent.putExtra(SerialPortActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
110 | if (mScanning)
111 | {
112 | mble.stopLeScan();
113 | mScanning = false;
114 | }
115 |
116 | startActivity(intent);
117 |
118 | }
119 | });
120 | }
121 |
122 | private void InitParam()
123 | {
124 | if(!SPUtils.getBool(this,"first_run")) {
125 | String BUTTON_KEY = "button_key";
126 | ButtonModel btnModel= new ButtonModel(BUTTON_KEY);
127 | btnModel.setTouchDown("423d4c0d0a");
128 | btnModel.setTouchUp("423d480d0a");
129 | btnModel.setName("ButtonB");
130 | SPUtils.put(MainApplication.getAppContext(), "num2", btnModel.toJsonObjectStr());
131 | btnModel.setTouchDown("413d4c0d0a");
132 | btnModel.setTouchUp("413d480d0a");
133 | btnModel.setName("ButtonA");
134 | SPUtils.put(MainApplication.getAppContext(), "num1", btnModel.toJsonObjectStr());
135 | SPUtils.putBool(this,"first_run",true);
136 | }
137 | }
138 | private void checkPermissions() {
139 |
140 | //if sdk version > 23 Ask Permission
141 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
142 | if (ContextCompat.checkSelfPermission(this,
143 | Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
144 | //Set Permission Description to Show to User.
145 | if (ActivityCompat.shouldShowRequestPermissionRationale(this,
146 | Manifest.permission.ACCESS_COARSE_LOCATION)) {
147 | Toast.makeText(this, "After Android 6.0 You need Open Location Permission to Search Device!", Toast.LENGTH_SHORT).show();
148 | }
149 | //Request Permission
150 | ActivityCompat.requestPermissions(this,
151 | new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
152 | REQUEST_CODE_ACCESS_COARSE_LOCATION);
153 | } else {
154 |
155 | }
156 | }
157 | }
158 |
159 | private void initView() {
160 |
161 | topLeftBtn.setVisibility(View.GONE);
162 | topRightBtn.setVisibility(View.VISIBLE);
163 | setTitle("Main Page");
164 | setRightText("Password");
165 |
166 | topRightBtn.setOnClickListener(new View.OnClickListener() {
167 | @Override
168 | public void onClick(View view) {
169 | final Intent intent = new Intent(MainActivity.this, SetPasswordActivity.class);
170 | startActivity(intent);
171 | }
172 | });
173 | }
174 |
175 | @Override
176 | protected void onResume()
177 | {
178 | super.onResume();
179 |
180 | //Check is BLE Opened
181 | if(!mble.isOpened())
182 | {
183 | Intent openIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
184 | startActivityForResult(openIntent, REQUEST_ENABLE_BT);
185 | }
186 |
187 | //Set Bluetooth Scan CALLBACK func.
188 | mble.setScanCallBack(mLeScanCallback);
189 | // Initializes list view adapter.
190 | mLeDeviceListAdapter = new LeDeviceListAdapter(this);
191 | mListView.setAdapter(mLeDeviceListAdapter);
192 | scanLeDevice(true); //Start Scan
193 | mScanBt.setText("Stop scanning");
194 | mProgressBar.setVisibility(View.VISIBLE);
195 | }
196 |
197 |
198 | @Override
199 | protected void onDestroy()
200 | {
201 | super.onDestroy();
202 | }
203 |
204 |
205 | @Override
206 | protected void onPause()
207 | {
208 | super.onPause();
209 | scanLeDevice(false); //Stop Scan
210 | mLeDeviceListAdapter.clear(); //Clear list
211 | }
212 |
213 | @Override
214 | protected void onActivityResult(int requestCode, int resultCode, Intent data)
215 | {
216 | //result of opening bluetooth
217 | if(resultCode == REQUEST_ENABLE_BT || resultCode == Activity.RESULT_CANCELED)
218 | {
219 | Toast.makeText(this,"Bluetooth Open Cancelled.",Toast.LENGTH_LONG).show();
220 | finish();
221 | return ;
222 | }
223 | super.onActivityResult(requestCode, resultCode, data);
224 | }
225 |
226 |
227 | Runnable cancelScan = new Runnable()
228 | {
229 | @Override
230 | public void run()
231 | {
232 | mble.stopLeScan();
233 | try {
234 | Thread.sleep(500);
235 | } catch (InterruptedException e) {
236 | e.printStackTrace();
237 | }
238 | mble.startLeScan();
239 | mHandler.postDelayed(cancelScan,SCAN_PERIOD);
240 | invalidateOptionsMenu();
241 | }
242 | };
243 |
244 | //enable = true shows that scan was running.
245 | private void scanLeDevice(final boolean enable)
246 | {
247 | if (enable)
248 | {
249 | // SCAN_PERIOD times later, stop Scan.
250 | mHandler.postDelayed(cancelScan,SCAN_PERIOD);
251 |
252 | mScanning = true;
253 | mble.startLeScan(); //Start BLE Scan.
254 | }
255 | else
256 | {
257 | //Cancel Stop Scan`s Thread.
258 | mHandler.removeCallbacks(cancelScan);
259 | mScanning = false;
260 | mble.stopLeScan(); //Stop Scan.
261 | }
262 | invalidateOptionsMenu();
263 | }
264 |
265 | // Scan Result
266 | private BluetoothAdapter.LeScanCallback mLeScanCallback =
267 | new BluetoothAdapter.LeScanCallback()
268 | {
269 | @Override
270 | public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord)
271 | {
272 | runOnUiThread(new Runnable()
273 | {
274 | @Override
275 | public void run()
276 | {
277 | String deviceName = "H01";//device.getName();
278 |
279 | if(deviceName == null || deviceName.length() <= 0)
280 | deviceName = "unknow device";
281 | Log.d(TAG, deviceName);
282 | Log.d(TAG, device.getAddress());
283 | //Log.d(TAG,"BroadCast:"+ConvertData.bytesToHexString(scanRecord, false));
284 | //02010603035869
285 | if(scanRecord.length < 7 || scanRecord[0] != 0x02 || scanRecord[1] != 0x01 ||
286 | scanRecord[2] != 0x06 || scanRecord[3] != 0x03 || scanRecord[4] != 0x03 ||
287 | scanRecord[5] != 0x58 || scanRecord[6] != 0x69) {
288 |
289 |
290 | if (scanRecord.length < 9 || scanRecord[0] != 0x02 || scanRecord[1] != 0x01 ||
291 | scanRecord[2] != 0x06 || scanRecord[3] != 0x05 || scanRecord[4] != 0x03 ||
292 | scanRecord[5] != 0x58 || scanRecord[6] != 0x69 || scanRecord[7] != (byte)0xE7 ||
293 | scanRecord[8] != (byte)0xFE) {
294 |
295 | if (scanRecord.length < 2 || scanRecord[0] != 0x1A || scanRecord[1] != (byte)0xFF) {
296 |
297 | if (scanRecord.length < 7 || scanRecord[0] != 0x02 || scanRecord[1] != 0x01 ||
298 | scanRecord[2] != 0x06 || scanRecord[3] != 0x03 || scanRecord[4] != 0x03 ||
299 | scanRecord[5] != (byte)0xE7 || scanRecord[6] != (byte)0xFE) {
300 |
301 | return;
302 | }
303 | }
304 |
305 | }
306 | }
307 |
308 |
309 | byte[] temp =scanRecord;
310 | Log.d(TAG, ConvertData.bytesToHexString(temp, false));
311 | mLeDeviceListAdapter.addDevice(device,Integer.valueOf(rssi), ConvertData.bytesToHexString(temp, false));
312 | mLeDeviceListAdapter.notifyDataSetChanged();
313 | }
314 | });
315 | }
316 | };
317 |
318 | // Adapter for holding devices found through scanning.
319 | private class LeDeviceListAdapter extends BaseAdapter
320 | {
321 | private ArrayList mLeDevices;
322 | private ArrayList mLeRssi;
323 | private ArrayList mLeRecord;
324 | private LayoutInflater mInflator;
325 |
326 | public LeDeviceListAdapter(Context context)
327 | {
328 | super();
329 | mLeDevices = new ArrayList();
330 | mLeRssi = new ArrayList();
331 | mLeRecord = new ArrayList();
332 | mInflator = LayoutInflater.from(context);//MainActivity.this.getLayoutInflater();
333 | }
334 |
335 | public void addDevice(BluetoothDevice device, Integer rssi, String record)
336 | {
337 | if(!mLeDevices.contains(device))
338 | {
339 | mLeDevices.add(device);
340 | mLeRssi.add(rssi);
341 | mLeRecord.add(record);
342 | }
343 | else {
344 | int pos = mLeDevices.indexOf(device);
345 | mLeRecord.remove(pos);
346 | mLeRecord.add(pos, record);
347 | mLeRssi.remove(pos);
348 | mLeRssi.add(pos, rssi);
349 | }
350 | }
351 |
352 | public BluetoothDevice getDevice(int position)
353 | {
354 | return mLeDevices.get(position);
355 | }
356 |
357 | public void clear() {
358 | mLeDevices.clear();
359 | mLeRecord.clear();
360 | mLeRssi.clear();
361 | }
362 |
363 | @Override
364 | public int getCount()
365 | {
366 | return mLeDevices.size();
367 | }
368 |
369 | @Override
370 | public Object getItem(int i)
371 | {
372 | return mLeDevices.get(i);
373 | }
374 |
375 | @Override
376 | public long getItemId(int i)
377 | {
378 | return i;
379 | }
380 |
381 | @Override
382 | public View getView(int i, View view, ViewGroup viewGroup)
383 | {
384 | ViewHolder viewHolder;
385 | // General ListView optimization code.
386 | if (view == null)
387 | {
388 | // view = mInflator.inflate(R.layout.activity_main, null);
389 | view = mInflator.inflate(R.layout.list_item, null);
390 | viewHolder = new ViewHolder();
391 | viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
392 | viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
393 | viewHolder.deviceRecord = (TextView)view.findViewById(R.id.device_record);
394 | viewHolder.deviceTime = (TextView)view.findViewById(R.id.device_time);
395 | view.setTag(viewHolder);
396 | }
397 | else
398 | {
399 | viewHolder = (ViewHolder) view.getTag();
400 | }
401 |
402 | BluetoothDevice device = mLeDevices.get(i);
403 | Integer rssi = mLeRssi.get(i);
404 | String record = mLeRecord.get(i);
405 | final String deviceName = device.getName();
406 | if (deviceName != null && deviceName.length() > 0)
407 | viewHolder.deviceName.setText(deviceName);
408 | else
409 | viewHolder.deviceName.setText(R.string.unknown_device);
410 |
411 | viewHolder.deviceAddress.setText("address:"+device.getAddress() + " RSSI:"+rssi+"dB");
412 | viewHolder.deviceRecord.setText("broadcast:"+record);
413 | // String timeStr = "time: " + time.year + "-" + time.month + "-" + time.monthDay + " " +
414 | // time.hour + ":" + time.minute + ":" + time.second;
415 | // viewHolder.deviceTime.setText(timeStr);
416 |
417 | return view;
418 | }
419 | }
420 |
421 | static class ViewHolder
422 | {
423 | TextView deviceName;
424 | TextView deviceAddress;
425 | TextView deviceRecord;
426 | TextView deviceTime;
427 | }
428 | }
429 |
--------------------------------------------------------------------------------
/app/src/main/java/com/RRG/usbninja/SerialPortActivity.java:
--------------------------------------------------------------------------------
1 | package com.RRG.usbninja;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.ImageView;
13 | import android.widget.ProgressBar;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.RRG.usbninja.app.MainApplication;
18 | import com.RRG.usbninja.ble.ConvertData;
19 | import com.RRG.usbninja.ble.HolloBluetooth;
20 | import com.RRG.usbninja.config.ConfigInfo;
21 | import com.wise.wisekit.activity.BaseActivity;
22 | import com.wise.wisekit.dialog.LoadingDialog;
23 |
24 | import java.util.HashMap;
25 | import java.util.Map;
26 |
27 | public class SerialPortActivity extends BaseActivity {
28 |
29 | public static final String EXTRAS_DEVICE_NAME = "DEVICE_NAME";
30 | public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";
31 |
32 | private HolloBluetooth mble;
33 |
34 | private String mDeviceName;
35 | private String mDeviceAddress;
36 |
37 | private TextView mNum1Btn;
38 | private TextView mNum2Btn;
39 | private TextView mNum3Btn;
40 | private TextView mNum4Btn;
41 | private TextView mNum5Btn;
42 | private TextView mNum6Btn;
43 | private TextView mNum7Btn;
44 | private TextView mNum8Btn;
45 | private TextView mNum9Btn;
46 |
47 | private Button mEditBtn;
48 |
49 | private ButtonModel mNum1Info;
50 | private ButtonModel mNum2Info;
51 | private ButtonModel mNum3Info;
52 | private ButtonModel mNum4Info;
53 | private ButtonModel mNum5Info;
54 | private ButtonModel mNum6Info;
55 | private ButtonModel mNum7Info;
56 | private ButtonModel mNum8Info;
57 | private ButtonModel mNum9Info;
58 | private ImageView a;
59 | private LoadingDialog loadingDialog = null;
60 |
61 | //is Editing
62 | private boolean bEdit = false;
63 |
64 | @Override
65 | protected void onCreate(Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 | LayoutInflater.from(this).inflate(R.layout.activity_serial_port, topContentView);
68 |
69 | initView();
70 |
71 | final Intent intent = getIntent();
72 | mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
73 | mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
74 |
75 | mble = HolloBluetooth.getInstance(getApplicationContext()); //get BLEContext
76 |
77 | enableButton(false);
78 |
79 | connectBle();
80 |
81 | }
82 |
83 | @Override
84 | protected void onResume() {
85 | super.onResume();
86 |
87 | updateButton();
88 | }
89 |
90 | private void initView() {
91 | a=findViewById(R.id.imgproc);
92 | topLeftBtn.setVisibility(View.VISIBLE);
93 | setTitle("BLE Control Panel");
94 | topRightBtn.setVisibility(View.VISIBLE);
95 | setRightText("Log");
96 |
97 | topRightBtn.setOnClickListener(new View.OnClickListener() {
98 | @Override
99 | public void onClick(View view) {
100 | final Intent intent = new Intent(SerialPortActivity.this, LogActivity.class);
101 | startActivity(intent);
102 | }
103 | });
104 |
105 | LoadingDialog.Builder loadBuilder=new LoadingDialog.Builder(this)
106 | .setCancelable(true)
107 | .setShowMessage(false)
108 | .setCancelOutside(false)
109 | .setOnCancelListener(new DialogInterface.OnCancelListener() {
110 | @Override
111 | public void onCancel(DialogInterface dialogInterface) {
112 | SerialPortActivity.this.finish();
113 | }
114 | });
115 | loadingDialog = loadBuilder.create();
116 |
117 | initButtons();
118 |
119 | initButtonListener();
120 | }
121 |
122 | //初始化按钮
123 | void initButtons() {
124 |
125 | mEditBtn = findViewById(R.id.edit);
126 |
127 | mNum1Btn = findViewById(R.id.num1);
128 | mNum2Btn = findViewById(R.id.num2);
129 | mNum3Btn = findViewById(R.id.num3);
130 | mNum4Btn = findViewById(R.id.num4);
131 | mNum5Btn = findViewById(R.id.num5);
132 | mNum6Btn = findViewById(R.id.num6);
133 | mNum7Btn = findViewById(R.id.num7);
134 | mNum8Btn = findViewById(R.id.num8);
135 | mNum9Btn = findViewById(R.id.num9);
136 |
137 | // updateButton();
138 | }
139 |
140 | void updateButton() {
141 |
142 | mNum1Info = new ButtonModel(ConfigInfo.getInstance().getNum1());
143 | mNum2Info = new ButtonModel(ConfigInfo.getInstance().getNum2());
144 | mNum3Info = new ButtonModel(ConfigInfo.getInstance().getNum3());
145 | mNum4Info = new ButtonModel(ConfigInfo.getInstance().getNum4());
146 | mNum5Info = new ButtonModel(ConfigInfo.getInstance().getNum5());
147 | mNum6Info = new ButtonModel(ConfigInfo.getInstance().getNum6());
148 | mNum7Info = new ButtonModel(ConfigInfo.getInstance().getNum7());
149 | mNum8Info = new ButtonModel(ConfigInfo.getInstance().getNum8());
150 | mNum9Info = new ButtonModel(ConfigInfo.getInstance().getNum9());
151 |
152 | mNum1Btn.setText(mNum1Info.getName());
153 | mNum2Btn.setText(mNum2Info.getName());
154 | mNum3Btn.setText(mNum3Info.getName());
155 | mNum4Btn.setText(mNum4Info.getName());
156 | mNum5Btn.setText(mNum5Info.getName());
157 | mNum6Btn.setText(mNum6Info.getName());
158 | mNum7Btn.setText(mNum7Info.getName());
159 | mNum8Btn.setText(mNum8Info.getName());
160 | mNum9Btn.setText(mNum9Info.getName());
161 |
162 | }
163 |
164 | void initButtonListener() {
165 |
166 | mEditBtn.setOnClickListener(new View.OnClickListener() {
167 | @Override
168 | public void onClick(View view) {
169 | bEdit = !bEdit;
170 | if (bEdit) {
171 | Drawable switchOn = getResources().getDrawable(R.mipmap.switch_on);
172 | switchOn.setBounds(0, 0, switchOn.getMinimumWidth(), switchOn.getMinimumHeight());
173 | mEditBtn.setCompoundDrawables(null, null, switchOn, null);
174 | }
175 | else {
176 | Drawable switchOff = getResources().getDrawable(R.mipmap.switch_off);
177 | switchOff.setBounds(0, 0, switchOff.getMinimumWidth(), switchOff.getMinimumHeight());
178 | mEditBtn.setCompoundDrawables(null, null, switchOff, null);
179 | }
180 | }
181 | });
182 |
183 | mNum1Btn.setOnClickListener(new View.OnClickListener() {
184 | @Override
185 | public void onClick(View view) {
186 | if (bEdit) {
187 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
188 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num1");
189 | startActivity(intent);
190 | }
191 | }
192 | });
193 |
194 | mNum1Btn.setOnTouchListener(new View.OnTouchListener() {
195 | @Override
196 | public boolean onTouch(View view, MotionEvent motionEvent) {
197 | if (bEdit) return false;
198 |
199 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
200 | sendInfo(mNum1Info, true);
201 |
202 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
203 | sendInfo(mNum1Info, false);
204 | }
205 |
206 | return false;
207 | }
208 | });
209 |
210 | mNum2Btn.setOnClickListener(new View.OnClickListener() {
211 | @Override
212 | public void onClick(View view) {
213 | if (bEdit) {
214 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
215 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num2");
216 | startActivity(intent);
217 | }
218 | }
219 | });
220 |
221 | mNum2Btn.setOnTouchListener(new View.OnTouchListener() {
222 | @Override
223 | public boolean onTouch(View view, MotionEvent motionEvent) {
224 |
225 | if (bEdit) return false;
226 |
227 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
228 | sendInfo(mNum2Info, true);
229 |
230 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
231 | sendInfo(mNum2Info, false);
232 | }
233 |
234 | return false;
235 | }
236 | });
237 |
238 | mNum3Btn.setOnClickListener(new View.OnClickListener() {
239 | @Override
240 | public void onClick(View view) {
241 | if (bEdit) {
242 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
243 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num3");
244 | startActivity(intent);
245 | }
246 | }
247 | });
248 |
249 | mNum3Btn.setOnTouchListener(new View.OnTouchListener() {
250 | @Override
251 | public boolean onTouch(View view, MotionEvent motionEvent) {
252 |
253 | if (bEdit) return false;
254 |
255 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
256 | sendInfo(mNum3Info, true);
257 |
258 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
259 | sendInfo(mNum3Info, false);
260 | }
261 |
262 | return false;
263 | }
264 | });
265 |
266 | mNum4Btn.setOnClickListener(new View.OnClickListener() {
267 | @Override
268 | public void onClick(View view) {
269 | if (bEdit) {
270 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
271 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num4");
272 | startActivity(intent);
273 | }
274 | }
275 | });
276 |
277 | mNum4Btn.setOnTouchListener(new View.OnTouchListener() {
278 | @Override
279 | public boolean onTouch(View view, MotionEvent motionEvent) {
280 |
281 | if (bEdit) return false;
282 |
283 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
284 | sendInfo(mNum4Info, true);
285 |
286 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
287 | sendInfo(mNum4Info, false);
288 | }
289 |
290 | return false;
291 | }
292 | });
293 |
294 | mNum5Btn.setOnClickListener(new View.OnClickListener() {
295 | @Override
296 | public void onClick(View view) {
297 | if (bEdit) {
298 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
299 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num5");
300 | startActivity(intent);
301 | }
302 | }
303 | });
304 |
305 | mNum5Btn.setOnTouchListener(new View.OnTouchListener() {
306 | @Override
307 | public boolean onTouch(View view, MotionEvent motionEvent) {
308 |
309 | if (bEdit) return false;
310 |
311 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
312 | sendInfo(mNum5Info, true);
313 |
314 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
315 | sendInfo(mNum5Info, false);
316 | }
317 |
318 | return false;
319 | }
320 | });
321 |
322 | mNum6Btn.setOnClickListener(new View.OnClickListener() {
323 | @Override
324 | public void onClick(View view) {
325 | if (bEdit) {
326 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
327 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num6");
328 | startActivity(intent);
329 | }
330 | }
331 | });
332 |
333 | mNum6Btn.setOnTouchListener(new View.OnTouchListener() {
334 | @Override
335 | public boolean onTouch(View view, MotionEvent motionEvent) {
336 |
337 | if (bEdit) return false;
338 |
339 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
340 | sendInfo(mNum6Info, true);
341 |
342 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
343 | sendInfo(mNum6Info, false);
344 | }
345 |
346 | return false;
347 | }
348 | });
349 |
350 | mNum7Btn.setOnClickListener(new View.OnClickListener() {
351 | @Override
352 | public void onClick(View view) {
353 | if (bEdit) {
354 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
355 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num7");
356 | startActivity(intent);
357 | }
358 | }
359 | });
360 |
361 | mNum7Btn.setOnTouchListener(new View.OnTouchListener() {
362 | @Override
363 | public boolean onTouch(View view, MotionEvent motionEvent) {
364 |
365 | if (bEdit) return false;
366 |
367 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
368 | sendInfo(mNum7Info, true);
369 |
370 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
371 | sendInfo(mNum7Info, false);
372 | }
373 |
374 | return false;
375 | }
376 | });
377 |
378 | mNum8Btn.setOnClickListener(new View.OnClickListener() {
379 | @Override
380 | public void onClick(View view) {
381 | if (bEdit) {
382 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
383 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num8");
384 | startActivity(intent);
385 | }
386 | }
387 | });
388 |
389 | mNum8Btn.setOnTouchListener(new View.OnTouchListener() {
390 | @Override
391 | public boolean onTouch(View view, MotionEvent motionEvent) {
392 |
393 | if (bEdit) return false;
394 |
395 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
396 | sendInfo(mNum8Info, true);
397 |
398 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
399 | sendInfo(mNum8Info, false);
400 | }
401 |
402 | return false;
403 | }
404 | });
405 |
406 | mNum9Btn.setOnClickListener(new View.OnClickListener() {
407 | @Override
408 | public void onClick(View view) {
409 | if (bEdit) {
410 | final Intent intent = new Intent(SerialPortActivity.this, SetButtonActivity.class);
411 | intent.putExtra(SetButtonActivity.EXTRAS_BUTTON_KEY, "num9");
412 | startActivity(intent);
413 | }
414 | }
415 | });
416 |
417 | mNum9Btn.setOnTouchListener(new View.OnTouchListener() {
418 | @Override
419 | public boolean onTouch(View view, MotionEvent motionEvent) {
420 |
421 | if (bEdit) return false;
422 |
423 | if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
424 | sendInfo(mNum9Info, true);
425 |
426 | }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
427 | sendInfo(mNum9Info, false);
428 | }
429 |
430 | return false;
431 | }
432 | });
433 | }
434 |
435 | /*
436 | * Send Message,
437 | * btnModel Button Information
438 | * bDown is Pushed
439 | * */
440 | void sendInfo(ButtonModel btnModel, boolean bDown) {
441 |
442 | byte[] tempData = null;
443 | if (bDown && !btnModel.getTouchDown().isEmpty()) {
444 | tempData = ConvertData.hexStringToBytes(btnModel.getTouchDown());
445 | }
446 | else if (!bDown && !btnModel.getTouchUp().isEmpty()) {
447 | tempData = ConvertData.hexStringToBytes(btnModel.getTouchUp());
448 | }
449 |
450 | if (tempData == null) return;
451 |
452 |
453 | final byte[] sendData = tempData;
454 | new Thread(new Runnable()
455 | {
456 | @Override
457 | public void run() {
458 | sendBleData(sendData);
459 |
460 | }
461 | }).start();
462 |
463 | }
464 |
465 | synchronized void sendBleData(byte[] data) {
466 |
467 | if(!mble.sendData(data)) {
468 | runOnUiThread(new Runnable() {
469 | @Override
470 | public void run() {
471 | Toast.makeText(SerialPortActivity.this, "Send Failed!", Toast.LENGTH_SHORT).show();
472 | LogInfo info = new LogInfo();
473 | info.setType("error");
474 | info.setContent("Send Failed");
475 | MainApplication.instance.logList.add(info);
476 | }
477 | });
478 |
479 | }
480 |
481 | LogInfo info = new LogInfo();
482 | info.setType("send");
483 | info.setContent(ConvertData.bytesToHexString(data, false));
484 | MainApplication.instance.logList.add(info);
485 | runOnUiThread(new Runnable() {
486 | @Override
487 | public void run() {
488 |
489 | }
490 | });
491 | }
492 |
493 |
494 | //Enable Buttons
495 | void enableButton(boolean enable) {
496 |
497 | mEditBtn.setEnabled(enable);
498 |
499 | mNum1Btn.setEnabled(enable);
500 | mNum2Btn.setEnabled(enable);
501 | mNum3Btn.setEnabled(enable);
502 | mNum4Btn.setEnabled(enable);
503 | mNum5Btn.setEnabled(enable);
504 | mNum6Btn.setEnabled(enable);
505 | mNum7Btn.setEnabled(enable);
506 | mNum8Btn.setEnabled(enable);
507 | mNum9Btn.setEnabled(enable);
508 |
509 | }
510 |
511 | //Connect Bluetooth
512 | void connectBle() {
513 |
514 |
515 | loadingDialog.show();
516 |
517 | new Thread(new Runnable()
518 | {
519 | @Override
520 | public void run()
521 | {
522 | int i;
523 | for (i = 0; i < 5; i++)
524 | {
525 | if(mble.connectDevice(mDeviceAddress,bleCallBack)) //Connect Bluetooth Device
526 | break;
527 | }
528 | if(i == 5)
529 | {
530 | runOnUiThread(new Runnable() {
531 | @Override
532 | public void run() {
533 | loadingDialog.hide();
534 | Toast.makeText(SerialPortActivity.this,"The connection fails", Toast.LENGTH_SHORT).show();
535 | LogInfo info = new LogInfo();
536 | info.setType("error");
537 | info.setContent("The connection fails");
538 | MainApplication.instance.logList.add(info);
539 | }
540 | });
541 |
542 | return ;
543 | }
544 |
545 | try {
546 | Thread.sleep(200,0);//200ms
547 | }
548 | catch (Exception e){
549 |
550 | }
551 |
552 |
553 | if(!mble.wakeUpBle())
554 | {
555 | runOnUiThread(new Runnable() {
556 | @Override
557 | public void run() {
558 | loadingDialog.hide();
559 | Toast.makeText(SerialPortActivity.this,"The connection fails",Toast.LENGTH_SHORT).show();
560 | LogInfo info = new LogInfo();
561 | info.setType("error");
562 | info.setContent("Failure to open notification");
563 | MainApplication.instance.logList.add(info);
564 | }
565 | });
566 | }
567 | else {
568 |
569 | runOnUiThread(new Runnable() {
570 | @Override
571 | public void run() {
572 |
573 | LogInfo info = new LogInfo();
574 | info.setType("");
575 | info.setContent("Successful bluetooth connection");
576 | MainApplication.instance.logList.add(info);
577 | }
578 | });
579 |
580 | String password = ConfigInfo.getInstance().getPassword();
581 | if (password != null && password.length() != 0) {
582 |
583 | LogInfo info = new LogInfo();
584 | info.setType("");
585 | info.setContent("Sending the password");
586 | MainApplication.instance.logList.add(info);
587 | sendBleData(ConvertData.unicodeToBytes(password));
588 |
589 | }
590 |
591 | runOnUiThread(new Runnable() {
592 | @Override
593 | public void run() {
594 |
595 | loadingDialog.hide();
596 | enableButton(true);
597 | }
598 | });
599 |
600 | }
601 |
602 | }
603 | }).start();
604 | }
605 |
606 | HolloBluetooth.OnHolloBluetoothCallBack bleCallBack = new HolloBluetooth.OnHolloBluetoothCallBack()
607 | {
608 |
609 | @Override
610 | public void OnHolloBluetoothState(int state)
611 | {
612 | if(state == HolloBluetooth.HOLLO_BLE_DISCONNECTED)
613 | {
614 | runOnUiThread(new Runnable() {
615 | public void run() {
616 | Toast.makeText(SerialPortActivity.this, "Bluetooth disconnected", Toast.LENGTH_SHORT).show();
617 | LogInfo info = new LogInfo();
618 | info.setType("");
619 | info.setContent("Bluetooth disconnected");
620 | MainApplication.instance.logList.add(info);
621 | finish();
622 | }
623 | });
624 | }
625 | }
626 |
627 | @Override
628 | public void OnReceiveData(byte[] recvData)
629 | {
630 | final int sleep_time=100;
631 | LogInfo info = new LogInfo();
632 | info.setType("receive");
633 | info.setContent(ConvertData.bytesToHexString(recvData, false));
634 | MainApplication.instance.logList.add(info);
635 | runOnUiThread(new Runnable() {
636 | @Override
637 | public void run() {
638 | a.setImageResource(R.drawable.ic_red);
639 | }
640 | });
641 | try {
642 | Thread.sleep(sleep_time);
643 | } catch (InterruptedException e) {
644 | e.printStackTrace();
645 | }
646 | runOnUiThread(new Runnable() {
647 | @Override
648 | public void run() {
649 | a.setImageResource(R.drawable.ic_black);
650 | }
651 | });
652 | try {
653 | Thread.sleep(sleep_time);
654 | } catch (InterruptedException e) {
655 | e.printStackTrace();
656 | }
657 | }
658 | };
659 |
660 | @Override
661 | protected void onDestroy()
662 | {
663 | super.onDestroy();
664 | mble.disconnectDevice();
665 | Log.d(TAG, "destroy");
666 | mble.disconnectLocalDevice();
667 | }
668 | }
--------------------------------------------------------------------------------