Description
Imagine EventBus that does not require subscribe/unsubscribe calls. Does not use reflection and no ProGuard rules - just delivers messages when you need it. Happy Coding!
Eventex alternatives and similar packages
Based on the "EventBus" category.
Alternatively, view Eventex alternatives based on common mentions on social networks and blogs.
-
RxJava
RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM. -
EventBus
Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality. -
AndroidEventBus
[DEPRECATED] A lightweight eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc. -
NetworkEvents
Android library listening network connection state and change of the Wifi signal strength -
LifecycleEvents
LifecycleEvents library is an event bus implementation, using lifecycle from android architecture components and kotlin language features.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Eventex or a related project?
README
Eventex, Android Express Events
Android library to send/post data to Fragments, Layouts, Activity. No need to create interfaces and pass listeners to multiple classes. There is also no need to subscribe/unsubscribe for events!
Try It Now
Make sure Java 8 (1.8) support is enabled in the gradle file
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Add EventEx to the project gradle file (Android*x* based projects)
implementation 'dev.uchitel:eventex:2.1.0'
Or for Android Support Library projects
implementation 'dev.uchitel:eventex-support:2.0.0'
Simple
To post message
new UIEvent("button.ok.click").post(view); // yes, this is it
To receive message. In any class that extends Fragment, ViewGroup, or Activity
public class CustomFragment extends Fragment implements UIEventListener {
// .....
@Override
public boolean onMessage(@NonNull UIEvent uiEvent) {
switch (uiEvent.what) {
case "button.ok.click":
Log.d(uiEvent.toString());
return true; // to stop message propagation
}
return false; // to let other objects to process message
}
}
No need to setOnItemClickListener in the RecyclerView.Adapter! Much less boilerplate code compare to classic solution Communicate with other fragments! Class CustomFragment extends Android class Fragment. It will also work well if the class extends Activity, ViewGroup, or any layout derived from ViewGroup (LinearLayout, FrameLayout, etc..)
Features
- Delivers messages between UI components of an Activity.
- Supports synchronous and asynchronous communication.
- No need to subscribe/unsubscribe to receive messages.
- Can deliver any data type.
- Completely decouples components.
- No reflection and no ProGuard rules.
- Tiny code size.
More Details
Message can be sent synchronously
new UIEvent(12345).send(viewGroup);
Message can carry additional integer, string value, and anything that can fit into Bundle:
new UIEvent(12345)
.setText("some text to pass with message")
.setNumber(9876) // some integer to pass with message
.putAll(bundle)
.post(viewGroup);
Next code will properly receive this message:
public class FragmentReceiver extends FrameLayout implements UIEventListener {
// .....
@Override
public boolean onMessage(@NonNull UIEvent uiEvent) {
switch (uiEvent.code) {
case 12345:
Log.d("FragmentReceiver", "text="+uiEvent.getText());
Log.d("FragmentReceiver", "number="+uiEvent.getNumber());
return true; // to stop message propagation
}
return false; // to let other components to process the message
}
}
Class UIEvent isn't 'final' and can be extended to carry any data. See sample CustomUIEvent.
Message can use integer ID, string ID, or both for more complex control scenarios:
new UIEvent(12345, "button.ok.click"))
.post(view);
The 'onMessage' for the above code:
public class FragmentReceiver extends Activity implements UIEventListener {
// .....
@Override
public boolean onMessage(@NonNull UIEvent uiEvent) {
switch (uiEvent.code) {
case 12345:
if(uiEvent.what.equals("button.ok.click")){
// ...
return true; // to stop message propagation
}
}
return false; // to let other components to process the message
}
}
When writing android library make sure to use 'namespace' to prevent collisions. Sending message inside library can look like:
new UIEvent("button.ok.click")
.setNamespace("lib_name.company_name.com")
.post(view);
Namespace "lib_name.company_name.com" is going to prevent ID collisions when the library is distributed to third party developers.
And to receive this message inside library module
public class FragmentReceiver extends Fragment implements UIEventListener {
// .....
@Override
public boolean onMessage(@NonNull UIEvent uiEvent) {
// return false if this is not library message
if (!uiEvent.getNamespace().equals("libname.company.com")) return false;
switch (uiEvent.what){
case "button.ok.click":
Log.d(uiEvent.getText());
return true; // to stop message propagation
}
return false; // to let other objects to process message
}
}
Requirements
- Android 4.1.0(API 16) or above.
- Java 8
R8 / ProGuard
No special requirements for R8 or ProGuard
Do you think it might be useful? Help devs to find it.
Alternative libraries
License
Copyright 2019 Alexander Uchitel
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*Note that all licence references and agreements mentioned in the Eventex README section above
are relevant to that project's source code only.