Android-scaex


Source link: https://github.com/petitviolet/android-scaex

Android-scaex

This library provides some expressions, IF, Match like Scala.
IF enables java if-statement to return a value as Scala if-expression.
Match also enables java to use pattern-match expression.

Setup

dependencies {

  compile 'net.petitviolet.android:scaex:<latest-version> 
}

Interface

IF

/** returns primitive value pattern **/ // if ~ else if ~ else String result = IF.<String>x(false).then("hoge")

.ElseIf(false).then("foo")

.Else("bar");
 assert result == "bar";  // if ~ else if ~ String result2 = IF.<String>x(true).then("hoge")

.ElseIf(false).then("foo")

.get();
 assert result2 == "hoge";  // not matched String result3 = IF.<String>x(false).then("hoge").get() assert result3 == null;
/** returns value the result of given method invoked **/ String result4 = IF.<String>x(false).then(new Action<String>() {

  @Override
  public String run() {

return "hoge";
  
}
 
}
).ElseIf(true).then(new Action<String>() {

  @Override
  public String run() {

return "foo";
  
}
 
}
).Else(new Action<String>() {

  @Override
  public String run() {

Log.d(TAG, "in else condition!");

return "bar";
  
}
 
}
);
  assert result4 == "foo";  // with lambda expression String result5 = IF.<String>x(false).then(() -> "hoge")
  .ElseIf(true).then(() -> "foo")
  .Else(() -> {

Log.d(TAG, "in else condition!");

return "bar";
  
}
);
  assert result5 == "foo";

Match

/** pattern match by value condition **/ int target = 100; String result1 = Match.<String, Integer>x(target)

.Case(target < 100).then("down")

.Case(target > 100).then("up")

.Case(target == 100).then("draw")

.eval();
 assert result1.equals("draw") == true;  /** pattern match by class **/ int result2 = Match.<Integer, Object>x(100)
.Case(String.class).then(1)
.Case(Boolean.class).then(2)
.Case(Integer.class).then(3)
.eval();
 assert result2 == 3;  /** lazy pattern-match using Function interface in Case **/ int result3 = Match.<Integer, Object>x(100)
.Case(String.class).then(1)
.Case(Boolean.class).then(2)
.Case(new Function.F1<Object, Boolean>() {

 @Override
 public Boolean apply(Object integer) {

  return integer == 100;
 
}

}
).then(3)
.Case(new Function.F1<Object, Boolean>() {

 @Override
 public Boolean apply(Object integer) {

  // not evaluate
  return integer == 999;
 
}

}
).then(4)
.Case(Integer.class).then(5)
.eval();
 assert result3 == 3;  /** with lambda expression **/ String result4 = Match.<String, String>x("hoge")

.Case(TextUtils::isEmpty).then("empty")

.Case((s) -> s.length() < 3).then("short")

.eval("long");
 assert result4 == "long";

For

// for(Integer i: inputs) {
 i -> action(i) 
}
 List<Integer> inputs = Arrays.asList(1, 2, 3);
 For.x(inputs).action(new Action.A1<Integer>() {

  @Override
  public void run(Integer integer) {

Log.i(Tag, s"result ->" + integer * 2);

  
}
 
}
);
  // for statement with returning value // result = for(String s: strings) {
 s -> function(s) 
}
 List<String> result = For.x(Arrays.asList("a", "b", "c")).apply(new Function.F1<String, String>() {

  @Override
  public String apply(String s) {

return "x" + s;
  
}
 
}
);
  // for(int i = 0; i <= 10; i++) {
 // 
}
 // `x(0).to(10).by(1)` List<Integer> result = For.x(0).to(10).by(1).apply(new Function.F1<Integer, Integer>() {

  @Override
  public Integer apply(Integer integer) {

return integer;
  
}
 
}
);
  // for(int i = 1; i < 10; i = i + 2 {
 // 
}
 // `x(1).until(10).by(2)` List<Integer> result = For.x(1).until(10).by(2).apply(new Function.F1<Integer, Integer>() {

  @Override
  public Integer apply(Integer integer) {

return integer;
  
}
 
}
);

// example using lambda // like foreach For.x(inputs).action(s -> Log.i(String.format("testFor: %s", input), s));
 // like map List<String> results = For.x(inputs).apply(s -> String.format("applied: %s: %s", input, s));

Lisence

This code is licensed under the Apache Software License 2.0.

Resources

droid-fu is a utility library for your daily Android needs.

NOTICE: This project has been discontinued. Developers are putting all efforts into ignition now, which is basically a rewritten but API breaking version of Droid-Fu that aims to have better project structure, better and less intrusive APIs, better documentation (we have samples now!) and proper release and issue management.

Custom Tabs with Material Design animations for pre-Lollipop devices.

RouteDrawer wraps Google Directions API using RxJava for Android so developers can download, parse and draw path on the map in very fast and flexible way.

The library contains two main parts:

  • RouteApi is responsible for sending request to Google's Direction API and handling the response
  • DrawerApi is responsible for drawing the path on the map

android-ripple-background is a beautiful ripple animation for your app. You can easily change its color, speed of wave, one ripple or multiple ripples.

This is fully-fledged the native BOINC client for Android and BOINC Manager (based on AndroBOINC) especially designed for working with this version of BOINC client.

Official Website

RapidJSON is a JSON parser and generator for C++. It was inspired by RapidXml.

Features:

  • Small but complete. It supports both SAX and DOM style API.
  • Fast. Its performance can be comparable to strlen().
  • Self-contained. It does not depend on external libraries.
  • Memory friendly. Each JSON value occupies exactly 16/20 bytes.
  • Unicode friendly.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes