RxFile


Source link: https://github.com/pavlospt/RxFile

RxFile

Rx methods to get a File and Image or Video thumbnails from any DocumentProvider on Android (Drive, Dropbox, Photos etc)

How To Install

Available on jCenter() and mavenCentral()

compile 'com.github.pavlospt:rxfile:1.7' 

How To Use

It is really easy to use it, depending on your needs it returns the appropriate file or Bitmap. You can fetch a Bitmap when you are selecting an Image or a Video. The fetched Bitmap is a thumbnail of the selected Image or Video. When you choose to select a file from Dropbox or Drive, the file is being downloaded and copied to the Library's cache folder. It then returns the File object and you have complete access over it in case you need to upload it to a server or in a similar use case.

To enable logging:

RxFile.setLoggingEnabled(true);

To get a File, use: (need to change the name of the method)

Observable<File> createFileFromUri(final Context context, final Uri data);
 Observable<List<File>> createFileFromUri(final Context context, final ArrayList<Uri> uris);
 Observable<List<File>> createFilesFromClipData(final Context context, final ClipData clipData);

To get a thumbnail, use:

Observable<Bitmap> getThumbnail(Context context, Uri uri);
 Observable<Bitmap> getThumbnail(Context context, Uri uri, int requiredWidth, int requiredHeight);
 Observable<Bitmap> getThumbnail(Context context, Uri uri, int requiredWidth, int requiredHeight, int kind);

Get files from a ClipData object (applies to multiple file selection through intent):

RxFile.createFilesFromClipData(this,clipData)

  .subscribeOn(Schedulers.io())

  .observeOn(AndroidSchedulers.mainThread())

  .subscribe(new Subscriber<List<File>>() {

@Override

public void onCompleted() {

 Timber.e("onCompleted() for Files called");

}

 @Override

public void onError(Throwable e) {

 Timber.e("Error on files fetching:" + e.getMessage());

}

 @Override

public void onNext(List<File> files) {

 Timber.e("Files list size:" + files.size());

 for(File f : files){

  Timber.e("onNext() file called:" + f.getAbsolutePath());

 
}

}

  
}
);

Get file from single Uri:

RxFile.createFileFromUri(this,uri)

  .subscribeOn(Schedulers.io())

  .observeOn(AndroidSchedulers.mainThread())

  .subscribe(new Subscriber<File>() {

@Override

public void onCompleted() {

 Timber.e("onCompleted() for File called");

}

 @Override

public void onError(Throwable e) {

 Timber.e("Error on file fetching:" + e.getMessage());

}

 @Override

public void onNext(File file) {

 Timber.e("onNext() file called:" + file.getAbsolutePath());

}

  
}
);

Get Thumbnail from Uri (photo or video):

RxFile.getThumbnail(this,data)

  .subscribeOn(Schedulers.io())

  .observeOn(AndroidSchedulers.mainThread())

  .subscribe(new Subscriber<Bitmap>() {

@Override

public void onCompleted() {

 Timber.e("onCompleted() called");

}

 @Override

public void onError(Throwable e) {

 Timber.e("onError called with: " +  e.getMessage());

}

 @Override

public void onNext(Bitmap bitmap) {

 mBitmap.setImageBitmap(bitmap);

}

  
}
);

For more, check the Wiki

Credits

Author : Pavlos-Petros Tournaris ( [email protected])

Google+ : +Pavlos-Petros Tournaris

Facebook : Pavlos-Petros Tournaris

LinkedIn : Pavlos-Petros Tournaris

(In case you use this in your app let me know to make a list of apps that use it! )

License

Copyright 2015 Pavlos-Petros Tournaris  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

A simple and custom calendar view.

AnyMaps allows you to use the same API for different maps providers without the need to adjust existing Google Maps implementation (apart from changing the package name).

A simple ViewPager with parallax effect.

shapeletter is a simple view that displays a letter within circle or rectangle much like the gmail app.

ExVidPlayer is simple library that abstracts ExoPlayer.

Features:

  • Gesture controls.
  • Brightness controls with one single touch vertical scroll.
  • Volume controls with multitouch vertical scroll.
  • Forward on left swipe.
  • Reverse on right swipe.
  • Player controls

Data binding library for Android which is:

  • Lightweight
  • Doing one thing and doing it well
  • Easily extendable
  • Fully covered with unit tests
  • Working great with Jack, Retrolambda or Kotlin

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