MediaFacade


Source link: https://github.com/Drivemode/MediaFacade

MediaFacade

Facade modules for dealing with complicated MediaStore in a simple way.

Usage

Audio

Audio in MediaStore has several tables like Media, Artists, Albums, Playlists and Genres. MediaFacade provides easy accesses to those tables.

Albums

public class SampleActivity extends Activity {

private AudioFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor albums = null;
  try {

 albums = facade.album().fetchAlbum();

 // do whatever you like with the album metadata
  
}
 finally {

 if (albums != null)

albums.close();

  
}

}
 
}

Artists

public class SampleActivity extends Activity {

private AudioFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor artists = null;
  try {

 artists = facade.artist().fetchArtists();

 // do whatever you like with the album metadata
  
}
 finally {

 if (artists != null)

artists.close();

  
}

}
 
}

Genres

public class SampleActivity extends Activity {

private AudioFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor genres = null;
  try {

 genres = facade.genre().fetchGenres();

 // do whatever you like with the album metadata
  
}
 finally {

 if (genres != null)

genres.close();

  
}

}
 
}

Playlists

public class SampleActivity extends Activity {

private AudioFacade facade;
private EditText playlistName;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor playlists = null;
  try {

 playlists = facade.playlist().fetchGenres();

 // do whatever you like with the album metadata
  
}
 finally {

 if (playlists != null)

playlists.close();

  
}

}

 public void onNewPlaylistButtonClick(View v) {

  String name = playlistName.getText().toString();

  Uri uri = facade.playlist().createNew(name);

  // you can add music tracks with this uri

}
 
}

Image and Video

Image and Video have similar structure in their tables. One noteworthy concept is Bucket, which is kind of Album for images and/or videos. Image and Video have 2 columns ( BUCKET_ID and BUCKET_DISPLAY_NAME) for describing which bucket the image belongs to.

Bucket

Since there's no specific table that manages each buckets so you need to group by bucket when you query images/videos in SQL. ImageFacade and VideoFacade do grouping for you.

public class SampleActivity extends Activity {

private ImageFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = ImageFacade.getInstance(this);

  Cursor imageBuckets = null;
  try {

 imageBuckets = facade.bucket().fetch();

 if (imageBuckets == null)

return;

 while (imageBuckets.moveToNext()) {

long bucketId = imageBuckets.getLong(imageBuckets.getColumnIndex(MediaStore.Image.Media.BUCKET_ID));

// you can query images in the specific bucket with this bucketId

Cursor imagesInBucket = facade.image().fetchByBucket(bucketId);

// ...

 
}

  
}
 finally {

 if (imageBuckets != null)

imageBuckets.close();

  
}

}
 
}

Cursors

MediaFacade provides customized yet fully Android compatible Cursors for developers to access fields by just calling corresponding methods.

public class SampleActivity extends Activity {

private ImageFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = ImageFacade.getInstance(this);

  ImageCursor imageBuckets = null;
  try {

 imageBuckets = facade.bucket().fetch();

 if (imageBuckets == null)

return;

 while (imageBuckets.moveToNext()) {

long bucketId = imageBuckets.id();

// you can query images in the specific bucket with this bucketId

ImageCursor imagesInBucket = facade.image().fetchByBucket(bucketId);

// ...

 
}

  
}
 finally {

 if (imageBuckets != null)

imageBuckets.close();

  
}

}
 
}

We have following customized classes of Cursors.

  • MediaItemCursor
  • AlbumCursor
  • AlbumItemCursor
  • GenreCursor
  • GenreItemCursor
  • ArtistCursor
  • ArtistItemCursor
  • PlaylistCurosr
  • PlaylistItemCurosr
  • ImageCursor
  • VideoCursor

These Cursors are subclasses of Cursor so that you can use them with CursorAdapter and various Cursor API.

Download

Gradle:

compile 'com.drivemode:mediafacade-audio:0.1.0@aar' compile 'com.drivemode:mediafacade-image:0.1.0@aar' compile 'com.drivemode:mediafacade-video:0.1.0@aar' 

License

Apache v2

Copyright (C) 2016 Drivemode, Inc. All rights reserved.  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

Simple events bus (publish–subscribe) implementation based on regular Android BroadcastReceivers mechanism.

The recommended pattern for Android's equivalent to cron jobs and Windows scheduled tasks is to use AlarmManager. This works well when coupled with an IntentService, as the service will do its work on a background thread and shut down when there is no more work to do.

There's one small problem: IntentService does nothing to keep the device awake. If the alarm was a WAKEUP variant, the phone will only stay awake on its own while the BroadcastReceiver handling the alarm is in its onReceive() method. Otherwise, the phone may fall back asleep.

WakefulIntentService attempts to combat this by combining the ease of IntentService with a partial WakeLock.

ViewPager with custom aspect ratio.

Design template library for LG QCircle SDK.

Tooleap is an Android SDK which brings your app to the forefront of a user's device screen with a floating (always-on-top) UI, thus creating a unique multitasking experience and increasing your app's availability and usability.

Sample Of All Samples

With your help we can build a sample app that touches most components of the Android framework, helpful for beginners and experienced.

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