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

A small library which creates iPad-style ActionSheet for Android apps.

Generates public.xml for Android libraries, which allows resources to be hidden from clients. More info

A simple, minimalistic and beautiful dialog color picker for Android 4.1+ devices. This color picker is easy-to-use and easy-to-integrate in your application to let users of your app choose color in a simple way.

Features:

  • Get Hex and (A)RGB color codes
  • Set color using (A)RGB values and get HEX codes
  • Set color using HEX value
  • Separate UI for portrait and landscape devices
  • Support for pre-lollipop devices

ExpandingCollection is a card peek/pop controller.

A simple stock charting library for Android, supporting time-line, k-line, macd, kdj, rsi, boll index, and interactive gesture operation, including left and right sliding to refresh, scaling, highlighting.

Easily build big and bigger forms with minimal effort.

This library aids in building bigger forms on-the-fly. Forms with large number of elements can easily be added programmatically within a few minutes.

Features:

  • Easily build big and bigger forms with minimal effort
  • Fast color change as needed

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