Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RxBleConnectionState compile time constant, e.g. an enum. Otherwise I get "Constant expression required". #42

Closed
farmazon3000 opened this issue Jul 4, 2016 · 4 comments

Comments

@farmazon3000
Copy link

RxBleConnectionState can't be used in the switch-case statement because they are not compile time constant, see http://stackoverflow.com/questions/3827393/java-switch-statement-constant-expression-required-but-it-is-constant. Maybe make RxBleConnectionState an enum?

For example this is illegal:

import static com.polidea.rxandroidble.RxBleConnection.RxBleConnectionState.CONNECTED;

switch(connectionState){
    case CONNECTED:
        break;
    default:
        break;
}

because Android Studio complaints Constant expression required.

@farmazon3000 farmazon3000 changed the title Make RxBleConnectionState compile time constant, e.g. an enum. Otherwise I get "constant expression required". Make RxBleConnectionState compile time constant, e.g. an enum. Otherwise I get "Constant expression required". Jul 4, 2016
@dariuszseweryn
Copy link
Owner

Hello,
Basically using enums in Android development is discouraged because #perfmatters -> https://www.youtube.com/watch?v=Hzs6OBcvNQE
I was thinking if using @IntDef would solve the problem you have and it would kind of do but passing ints without any context is not very informative and cumbersome to get a human-readable meaningful value.

@farmazon3000
Copy link
Author

OK, enum was just an idea, you can also go Google style like https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#GATT_SUCCESS.

@dariuszseweryn dariuszseweryn modified the milestone: 1.1.0 Jul 27, 2016
@literator literator removed this from the 2.0.0 milestone Feb 2, 2017
dariuszseweryn added a commit that referenced this issue May 16, 2017


Reviewers: michal.zielinski, pawel.urban

Reviewed By: pawel.urban

Differential Revision: https://phabricator.polidea.com/D2350
@dariuszseweryn
Copy link
Owner

Finally done.

@RobLewis
Copy link

I've used switch( connectionState.toString() ). Not the safest, but it works this week, anyway :-)

BharathMG added a commit to hammerheadnav/RxAndroidBle that referenced this issue Jun 3, 2017
* upstream/master: (35 commits)
  Updated Changelog and Readmes. Release 1.2.3.
  Added changelog for `1.3.0-SNAPSHOT`
  Bumped Butterknife library to 8.6.0
  Updated `RxJava` to 1.3.0
  Added extracting of 32-bit UUIDs by UUIDUtil. dariuszseweryn#207
  Extracted Radio Release Interface. Align to library usage to Observable contract.
  Issue template update.
  Added indication of `RxBleAdapterStateObservable` under `Helpers` section of the Readme page. dariuszseweryn#201
  Checkstyle fix.
  Added annotations on `RxBleConnection` for lint checks and ease of use.
  Moving towards 1.2.3.
  Fixed readme code snippets indentation (now using 4 spaces instead of tabs everywhere)
  Fixed indenting in readme.
  Gradle bump.
  Added better description of UUID filtering for `.scanBleDevices(UUID…)`.
  Added `Observable behaviour` to Readme. dariuszseweryn#187
  Extracted `NotificationAndIndicationManager`. Fixed tests running from the IDE.
  Changed `RxBleConnectionState` from a class to enum for convenience. dariuszseweryn#42
  Refactored `RxBleDeviceServices` for much less memory pressure when using `RxBleConnection` `UUID`’s functions.
  Moving towards 1.3.0.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants