GgaREST


Source link: https://github.com/greengrowapps/ggarest

GgaREST

Introduction

This library makes it easy to work with http connections on Android, but you can also make it work on Java vanilla by modifying only a couple of classes. It's especially designed to work with JSON, as it uses a JSON de/serializer by default. Its strongest points are the following :

  • When you make a request (get, post, put, delete) and you register the listeners, your listener code will be code in the main thread. This design allows the modification of UI components directly in the listener code.
  • You can specify the object that you are expecting and it will be deserialized using the Jackson library. If it's a list, you also can use the list listener to deserialize it as an object list.

Usage

To use the GgaRest class you only have to call the init method when your application start. Here is an example by adding default headers like an Api key.

GgaRest.init(this);
 GgaRest.addDefaulteader("Accept","application/json");

This example gets the content of the url given and deserializes the content as an OriginAndUrl object:

GgaRest.ws().get("http://httpbin.org/get")

.onSuccess(OriginAndUrl.class, new OnObjResponseListener<OriginAndUrl>() {

 @Override

 public void onResponse(int code, OriginAndUrl object, Response fullResponse) {

  txtUrl.setText(object.url);

  txtIp.setText(object.origin);

 
}

}
)

.onOther(new OnResponseListener() {

 @Override

 public void onResponse(int code, Response fullResponse, Exception exception) {

  Toast.makeText(MainActivity.this, "Get failed", Toast.LENGTH_SHORT).show();

 
}

}
)

.execute();

Or here we use basic auth to retrieve the commits of this repository:

 GgaRest.useBasicAuth(GITHUB_USERNAME,PASSWORD);

GgaRest.ws()

 .get("https://api.github.com/repos/greengrowapps/ggarest/commits")

 .onSuccess(Commit.class, new OnListResponseListener<Commit>() {

  @Override

  public void onResponse(int code, List<Commit> object, Response fullResponse) {

populateCommits(object);

  
}

 
}
)

 .onResponse(401, new OnResponseListener() {

  @Override

  public void onResponse(int code, Response fullResponse, Exception exception) {

Toast.makeText(MainActivity.this, "Unauthorized", Toast.LENGTH_SHORT).show();

  
}

 
}
)

 .execute();

It's possible to mock some calls for test prouposes:


  GgaRest.ws().mockGet("http://mysite/someendpoint/")

  .responseCode(200)

  .responseContent("{
\"text\":\"hello\"
}
")

  .save();

   

Integration

1) Add as a dependency to your build.gradle:

dependencies {

  compile 'com.greengrowapps:ggarest:0.8' 
}

2) Avoid duplicate files copied in APK adding this inside the android tag in your build.gradle:

 packagingOptions {

exclude 'META-INF/ASL2.0'

exclude 'META-INF/LICENSE'

exclude 'META-INF/MANIFEST.MF'

exclude 'META-INF/NOTICE'

exclude 'META-INF/LICENSE.txt'

exclude 'META-INF/NOTICE.txt'
  
}

3) Initialize the object in one of your activities' onCreate to start using it:

GgaRest.init(this);

Things to develop

This version is still not 1.0, which means api changes could happen. It needs some test and development.

If you want to collaborate, here is a checklist of planned features you can help working on:

  • More authentication methods like OAuth, OAuth2
  • Response stream to string using the headers encoding
  • Request cache
  • More tests

License


Apache License Version 2.0, January 2004
  Copyright 2015 Green Grow Apps SC
  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.  

Resources

An Android Parallax ListView item (this effect inspired by sound cloud android app).

Android comes with a few "wrapper" classes, like CursorWrapper, that make it relatively easy for you to add just a bit of functionality to an existing object. The wrapper delegates all behaviors to the wrapped object; you just override the specific behaviors you need. This works well in cases where there are many possible underlying implementations, so you could not robustly accomplish these ends by subclassing.

Android lacks such a wrapper for ListAdapter, though. There is a WrappedListAdapter entry in the SDK, but it is an interface, not an implementation.

So, CWAC offers an AdapterWrapper to fill this void.

Sometimes, you want your users to pick a color. A simple approach is to give the user a fixed roster of a handful of colors -- easy, but limited. A fancy approach is to use some form of color wheel, but these can be difficult to use on a touchscreen and perhaps impossible without a touchscreen.

ColorMixer is a widget that provides a simple set of SeekBars to let the user mix red, green, and blue to pick an arbitrary color. It is not very big, so it is easy to fit on a form, and it is still fairly finger-friendly.

It is also packaged as a dialog (ColorMixerDialog), a dialog-themed activity (ColorMixerActivity), and a preference (ColorPreference).

This project has a handful of Android containers (ViewGroup implementations) designed to handle specific scenarios:

  • AspectLockedFrameLayout that resizes itself, and its children, to fit within a specific aspect ratio
  • MirroringFrameLayout and an associated Mirror that duplicates and scales the contents of the MirroringFrameLayout onto the Mirror

Android BounceProgressBar Widget.

Library for handling Kiosk Mode in your Android Application. It restricts device to be using only one activity without possibility to switch to other app.

Features:

  • Run activity of you choice in kiosk mode
  • Blocks every application from going into foreground with activity manager
  • Handles home button by being a Launcher App

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