diff --git a/app/build.gradle b/app/build.gradle index a715648..6bb0de9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "spider65.ebike.tsdz2_esp32" minSdkVersion 23 targetSdkVersion 28 - versionCode 11 - versionName "2.1.4" + versionCode 12 + versionName "2.1.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -39,11 +39,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation "com.google.android.material:material:1.1.0" + implementation "com.google.android.material:material:1.2.1" implementation group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1' implementation 'com.github.hedzr:android-file-chooser:v1.2.0-final' implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' diff --git a/app/src/main/java/spider65/ebike/tsdz2_esp32/MainActivity.java b/app/src/main/java/spider65/ebike/tsdz2_esp32/MainActivity.java index b08687b..4289358 100644 --- a/app/src/main/java/spider65/ebike/tsdz2_esp32/MainActivity.java +++ b/app/src/main/java/spider65/ebike/tsdz2_esp32/MainActivity.java @@ -153,7 +153,6 @@ public boolean onSwipe(Direction direction) { mTitle = toolbar.findViewById(R.id.toolbar_title); mTitle.setText(R.string.status); - modeLevelTV = findViewById(R.id.modeLevelTV); statusTV = findViewById(R.id.statusTV); statusTV.setOnClickListener(v -> { int val; @@ -197,6 +196,8 @@ public boolean onSwipe(Direction direction) { } }); brakeIV = findViewById(R.id.brakeIV); + modeLevelTV = findViewById(R.id.modeLevelTV); + registerForContextMenu(modeLevelTV); streetModeIV = findViewById(R.id.streetModeIV); registerForContextMenu(streetModeIV); @@ -233,54 +234,6 @@ public boolean onSwipe(Direction direction) { checkBT(); } - @Override - public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - if (v.getId() != R.id.streetModeIV) - return; - TSDZBTService service = TSDZBTService.getBluetoothService(); - if (service == null || service.getConnectionStatus() != TSDZBTService.ConnectionState.CONNECTED) - return; - - // create context menu for Street Mode Icon long press - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.menu_street_mode, menu); - menu.setHeaderTitle(getResources().getString(R.string.street_mode)); - } - - @Override - public boolean onContextItemSelected(MenuItem item){ - // manage Street Mode icon context menu selection - TSDZBTService service = TSDZBTService.getBluetoothService(); - if (service == null || service.getConnectionStatus() != TSDZBTService.ConnectionState.CONNECTED) - return false; - - switch (item.getItemId()) { - case R.id.lcd_master: - service.writeCommand(new byte[] {TSDZConst.CMD_STREET_MODE, TSDZConst.STREET_MODE_LCD_MASTER}); - break; - case R.id.force_off: - service.writeCommand(new byte[] {TSDZConst.CMD_STREET_MODE, TSDZConst.STREET_MODE_FORCE_OFF}); - break; - case R.id.force_on: - service.writeCommand(new byte[] {TSDZConst.CMD_STREET_MODE, TSDZConst.STREET_MODE_FORCE_ON}); - break; - default: - return false; - } - return true; - } - - private boolean checkDevice() { - String mac = MyApp.getPreferences().getString(KEY_DEVICE_MAC, null); - if (mac != null) { - final BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); - final BluetoothAdapter btAdapter = btManager.getAdapter(); - BluetoothDevice selectedDevice = btAdapter.getRemoteDevice(mac); - return selectedDevice.getBondState() == BluetoothDevice.BOND_BONDED; - } - return false; - } - @Override protected void onResume() { super.onResume(); @@ -367,6 +320,68 @@ public boolean onOptionsItemSelected(MenuItem item) { } } + @Override + public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + TSDZBTService service = TSDZBTService.getBluetoothService(); + if (service == null || service.getConnectionStatus() != TSDZBTService.ConnectionState.CONNECTED) + return; + + MenuInflater inflater; + switch (v.getId()) { + case R.id.streetModeIV: + // create context menu for Street Mode Icon long press + inflater = getMenuInflater(); + inflater.inflate(R.menu.menu_street_mode, menu); + menu.setHeaderTitle(getResources().getString(R.string.street_mode)); + break; + case R.id.modeLevelTV: + // create context menu for Assist Mode Icon long press + inflater = getMenuInflater(); + inflater.inflate(R.menu.menu_assist_mode, menu); + menu.setHeaderTitle(getResources().getString(R.string.assist_mode)); + break; + } + } + + @Override + public boolean onContextItemSelected(MenuItem item){ + TSDZBTService service = TSDZBTService.getBluetoothService(); + if (service == null || service.getConnectionStatus() != TSDZBTService.ConnectionState.CONNECTED) + return false; + + switch (item.getItemId()) { + // manage Street Mode context menu selection + case R.id.street_lcd_master: + service.writeCommand(new byte[] {TSDZConst.CMD_STREET_MODE, TSDZConst.STREET_MODE_LCD_MASTER}); + break; + case R.id.street_force_off: + service.writeCommand(new byte[] {TSDZConst.CMD_STREET_MODE, TSDZConst.STREET_MODE_FORCE_OFF}); + break; + case R.id.street_force_on: + service.writeCommand(new byte[] {TSDZConst.CMD_STREET_MODE, TSDZConst.STREET_MODE_FORCE_ON}); + break; + // manage Assist Mode context menu selection + case R.id.assist_lcd_master: + service.writeCommand(new byte[] {TSDZConst.CMD_ASSIST_MODE, TSDZConst.ASSIST_MODE_LCD_MASTER}); + break; + case R.id.assist_power: + service.writeCommand(new byte[] {TSDZConst.CMD_ASSIST_MODE, TSDZConst.ASSIST_MODE_FORCE_POWER}); + break; + case R.id.assist_emtb: + service.writeCommand(new byte[] {TSDZConst.CMD_ASSIST_MODE, TSDZConst.ASSIST_MODE_FORCE_EMTB}); + break; + case R.id.assist_torque: + service.writeCommand(new byte[] {TSDZConst.CMD_ASSIST_MODE, TSDZConst.ASSIST_MODE_FORCE_TORQUE}); + break; + case R.id.assist_cadence: + service.writeCommand(new byte[] {TSDZConst.CMD_ASSIST_MODE, TSDZConst.ASSIST_MODE_FORCE_CADENCE}); + break; + default: + return false; + } + return true; + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode,resultCode,data); @@ -397,6 +412,17 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } } + private boolean checkDevice() { + String mac = MyApp.getPreferences().getString(KEY_DEVICE_MAC, null); + if (mac != null) { + final BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); + final BluetoothAdapter btAdapter = btManager.getAdapter(); + BluetoothDevice selectedDevice = btAdapter.getRemoteDevice(mac); + return selectedDevice.getBondState() == BluetoothDevice.BOND_BONDED; + } + return false; + } + private void refreshView() { if (status.brake) brakeIV.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/spider65/ebike/tsdz2_esp32/TSDZConst.java b/app/src/main/java/spider65/ebike/tsdz2_esp32/TSDZConst.java index d0c50ca..bf327fa 100644 --- a/app/src/main/java/spider65/ebike/tsdz2_esp32/TSDZConst.java +++ b/app/src/main/java/spider65/ebike/tsdz2_esp32/TSDZConst.java @@ -24,11 +24,18 @@ public interface TSDZConst { byte CMD_STM8_OTA_STATUS = 0x06; byte CMD_ESP32_CONFIG = 0x08; byte CMD_STREET_MODE = 0x09; + byte CMD_ASSIST_MODE = 0x0A; byte STREET_MODE_LCD_MASTER = 0; byte STREET_MODE_FORCE_OFF = 1; byte STREET_MODE_FORCE_ON = 2; + byte ASSIST_MODE_LCD_MASTER = 0; + byte ASSIST_MODE_FORCE_POWER = 1; + byte ASSIST_MODE_FORCE_EMTB = 2; + byte ASSIST_MODE_FORCE_TORQUE = 3; + byte ASSIST_MODE_FORCE_CADENCE = 4; + // sub commands of CMD_ESP32_CONFIG byte CONFIG_GET = 0; byte CONFIG_SET = 1; diff --git a/app/src/main/res/menu/menu_assist_mode.xml b/app/src/main/res/menu/menu_assist_mode.xml new file mode 100644 index 0000000..ea41ed3 --- /dev/null +++ b/app/src/main/res/menu/menu_assist_mode.xml @@ -0,0 +1,13 @@ + +
\ No newline at end of file diff --git a/app/src/main/res/menu/menu_street_mode.xml b/app/src/main/res/menu/menu_street_mode.xml index 75311e5..d41a00b 100644 --- a/app/src/main/res/menu/menu_street_mode.xml +++ b/app/src/main/res/menu/menu_street_mode.xml @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cb7d7f4..f3d0bbe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -211,6 +211,9 @@