api-controller


Source link: https://github.com/AvinashSKaranth/api-controller

api-controller

Run GET,POST and DOWNLOAD API on Android. Library takes care of Cookie Management and http caching.

GRADLE LINK

compile 'in.nashapp.apicontroller:apicontroller:1.0.8'

ANDROID MANIFEST

<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
ApiController APIc = new ApiController(this);
//Calling Library  //GET : parmeters need to be only string String response  = APIc.GetRequest(String URL,HashMap<String,String> parameters);
  //POST : parmeters can be a string or a file, see example below String response  = APIc.PostRequest(String URL,HashMap<String,String> parameters);
  //DOWNLOAD BACKGROUND String destination  = APIc.DownloadFile(String URL,String AbsoluteDestination);
 //If you dont add the extension in AbsoluteDestination then extension will added based in MimeType of the downloaded file //return the downloaded path, creates the folder if does not exist.  //DOWNLOAD WITH NOTIFICATION String destination  = APIc.DownloadFileNotify(String URL,String AbsoluteDestination);
 //Shows progress in notification bar and then closes it on finishing //return the downloaded path, creates the folder if does not exist.

GET

ApiController APIc = new ApiController(this);
 new Thread( new Runnable() {

@Override
public void run() {

 //Network Operation

 HashMap<String,String> params = new HashMap<String, String>();

 params.put("get_request1", "1");

 params.put("get_request2", "2");

 params.put("get_request3", "3");

 final String result  = APIc.GetRequest("http://nashapp.in/request.php",params);

 new Handler(Looper.getMainLooper()).post(new Runnable() {

  @Override

  public void run() {

//UI Operation using network data

alertDialog("Result", result);

  
}

 
}
);

}
 
}
).start();

POST

You can post files and variables together. When posting files give the value as

"file://"+file.getAbsolutePath()

You cannot POST multiple files with the same key as described in http://php.net/manual/en/features.file-upload.multiple.php

ApiController APIc = new ApiController(this);
 new Thread( new Runnable() {

@Override
public void run() {

 //Network Operation

 HashMap<String,String> params = new HashMap<String, String>();

 params.put("post_message1", "1");

 params.put("post_message2", "2");

 params.put("post_message3", "3");

 params.put("post_file", "file:///storage/emulated/0/Pictures/Screenshots/Screenshot_2016-04-01-22-13-25.png");

 params.put("post_file1", "file:///storage/emulated/0/Pictures/Screenshots/Screenshot_2016-04-01-22-13-25.png");

 params.put("post_message4", "4");

 params.put("post_message5", "5");

 params.put("post_message6", "6");

 final String result  = APIc.PostRequest("http://nashapp.in/request.php",params);

 new Handler(Looper.getMainLooper()).post(new Runnable() {

  @Override

  public void run() {

//UI Operation using network data

alertDialog("Result", result);

  
}

 
}
);

}
 
}
).start();

DOWNLOAD BACKGROUND

ApiController APIc = new ApiController(this);
  new Thread( new Runnable() {

@Override
public void run() {

 final String result  = APIc.DownloadFile("http://nashapp.in/socialsignin.png", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/socialsignin.png");

 new Handler(Looper.getMainLooper()).post(new Runnable() {

  @Override

  public void run() {

  //UI Operation using network data

alertDialog("Result", result);

  
}

 
}
);

}
 
}
).start();

DOWNLOAD NOTIFY

ApiController APIc = new ApiController(this);
 new Thread( new Runnable() {

@Override
public void run() {

 final String result  = APIc.DownloadFileNotify("http://nashapp.in/test.txt", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/test.txt");

 new Handler(Looper.getMainLooper()).post(new Runnable() {

  @Override

  public void run() {

//UI Operation using network data

alertDialog("Result", result);

  
}

 
}
);

}
 
}
).start();

You can use http://nashapp.in/request.php to verify validity of the request variables.

ALERT DIALOG if you need to verify values before parsing

public void alertDialog(String title,String Message){

AlertDialog alertDialog = new AlertDialog.Builder(this).create();

alertDialog.setTitle(title);

alertDialog.setMessage(Message);

alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",

  new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

 dialog.dismiss();

}

  
}
);

alertDialog.show();

  
}

License

Copyright 2016 Avinash S Karanth

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

Gradle plugin to add unit testing to android plugin. Prepared for Robolectric.

Requirements:

  • Gradle 2.10 or superior.
  • Android's Gradle Plugin 0.14.0 or superior.
  • An Android app or library that builds with Gradle.

Android Studio (and Intellij 14) IDE support for Android Gradle unit tests.

This plugin will mark test directories and resolve testCompile dependencies. It also sets up the correct system properties so that Robolectric will work if you are using it.

This is an open source library which uses the scroll bar library. Clock widget was added inside the scroll bar panel which gives a Path 2.0 like effect and can be customized according to your needs.

2DScroller is a customized ListView implementation.

Simple tool to output per-package method counts in an Android DEX executable grouped by package, to aid in getting under the 65,536 referenced method limit.

Compile-time active record ORM for Android.

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