use of org.videolan.vlc.extensions.ExtensionListing in project vlc-android by videolan.
the class PreferencesExtensions method createCheckboxes.
private void createCheckboxes() {
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
for (int i = 0; i < mExtensions.size(); ++i) {
ExtensionListing extension = mExtensions.get(i);
ClickableSwitchPreference switchPreference = new ClickableSwitchPreference(preferenceScreen.getContext());
switchPreference.setTitle(extension.title());
switchPreference.setSummary(extension.description());
final String key = ExtensionsManager.EXTENSION_PREFIX + "_" + extension.componentName().getPackageName();
switchPreference.setKey(key);
int iconRes = extension.menuIcon();
Drawable extensionIcon = null;
if (iconRes != 0) {
try {
Resources res = pm.getResourcesForApplication(extension.componentName().getPackageName());
extensionIcon = res.getDrawable(extension.menuIcon());
} catch (PackageManager.NameNotFoundException e) {
}
}
if (extensionIcon != null)
switchPreference.setIcon(extensionIcon);
else
try {
switchPreference.setIcon(pm.getApplicationIcon(mExtensions.get(i).componentName().getPackageName()));
} catch (PackageManager.NameNotFoundException e) {
switchPreference.setIcon(R.drawable.icon);
}
final boolean checked = mSettings.getBoolean(key, false);
switchPreference.setChecked(checked);
preferenceScreen.addPreference(switchPreference);
switchPreference.setOnSwitchClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (((SwitchCompat) view).isChecked())
mSettings.edit().putBoolean(key, true).apply();
else
for (Map.Entry<String, ?> entry : mSettings.getAll().entrySet()) if (entry.getKey().startsWith(ExtensionsManager.EXTENSION_PREFIX + "_"))
mSettings.edit().putBoolean(entry.getKey(), false).apply();
}
});
count++;
}
if (count == 0) {
PreferenceCategory emptyCategory = new PreferenceCategory(preferenceScreen.getContext());
emptyCategory.setTitle(R.string.extensions_empty);
preferenceScreen.addPreference(emptyCategory);
}
}
use of org.videolan.vlc.extensions.ExtensionListing in project vlc-android by GeoffreyMetais.
the class BrowserProvider method browse.
@WorkerThread
public static List<MediaBrowserCompat.MediaItem> browse(String parentId) {
List<MediaBrowserCompat.MediaItem> results = new ArrayList<>();
MediaLibraryItem[] list = null;
boolean limitSize = false;
Resources res = VLCApplication.getAppResources();
// Extensions
if (parentId.startsWith(ExtensionsManager.EXTENSION_PREFIX)) {
if (sExtensionServiceConnection == null) {
createExtensionServiceConnection();
try {
extensionLock.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (sExtensionServiceConnection == null)
return null;
String[] data = parentId.split("_");
int index = Integer.valueOf(data[1]);
extensionItems.clear();
if (data.length == 2) {
// case extension root
sExtensionManagerService.connectService(index);
} else {
// case sub-directory
String stringId = parentId.replace(ExtensionsManager.EXTENSION_PREFIX + "_" + String.valueOf(index) + "_", "");
sExtensionManagerService.browse(stringId);
}
try {
extensionLock.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
results = extensionItems;
} else {
switch(parentId) {
case ID_ROOT:
MediaDescriptionCompat.Builder item = new MediaDescriptionCompat.Builder();
// List of Extensions
List<ExtensionListing> extensions = ExtensionsManager.getInstance().getExtensions(VLCApplication.getAppContext(), true);
for (int i = 0; i < extensions.size(); i++) {
ExtensionListing extension = extensions.get(i);
if (extension.androidAutoEnabled() && PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean(ExtensionsManager.EXTENSION_PREFIX + "_" + extension.componentName().getPackageName() + "_" + ExtensionsManager.ANDROID_AUTO_SUFFIX, false)) {
item.setMediaId(ExtensionsManager.EXTENSION_PREFIX + "_" + String.valueOf(i)).setTitle(extension.title());
int iconRes = extension.menuIcon();
Bitmap b = null;
Resources extensionRes;
if (iconRes != 0) {
try {
extensionRes = VLCApplication.getAppContext().getPackageManager().getResourcesForApplication(extension.componentName().getPackageName());
b = BitmapFactory.decodeResource(extensionRes, iconRes);
} catch (PackageManager.NameNotFoundException e) {
}
}
if (b != null)
item.setIconBitmap(b);
else
try {
b = ((BitmapDrawable) VLCApplication.getAppContext().getPackageManager().getApplicationIcon(extension.componentName().getPackageName())).getBitmap();
item.setIconBitmap(b);
} catch (PackageManager.NameNotFoundException e) {
b = BitmapFactory.decodeResource(res, R.drawable.icon);
item.setIconBitmap(b);
}
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
}
}
// Last added
item = new MediaDescriptionCompat.Builder().setMediaId(ID_LAST_ADDED).setTitle(res.getString(R.string.last_added_media)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_history_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
// History
item = new MediaDescriptionCompat.Builder().setMediaId(ID_HISTORY).setTitle(res.getString(R.string.history)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_history_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
// Playlists
item.setMediaId(ID_PLAYLISTS).setTitle(res.getString(R.string.playlists)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_playlist_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
// Artists
item.setMediaId(ID_ARTISTS).setTitle(res.getString(R.string.artists)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_artist_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
// Albums
item.setMediaId(ID_ALBUMS).setTitle(res.getString(R.string.albums)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_album_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
// Songs
item.setMediaId(ID_SONGS).setTitle(res.getString(R.string.songs)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_audio_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
// Genres
item.setMediaId(ID_GENRES).setTitle(res.getString(R.string.genres)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_genre_normal"));
results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
return results;
case ID_LAST_ADDED:
limitSize = true;
list = VLCApplication.getMLInstance().getRecentAudio();
break;
case ID_HISTORY:
limitSize = true;
list = VLCApplication.getMLInstance().lastMediaPlayed();
break;
case ID_ARTISTS:
list = VLCApplication.getMLInstance().getArtists(VLCApplication.getSettings().getBoolean(Constants.KEY_ARTISTS_SHOW_ALL, false));
break;
case ID_ALBUMS:
list = VLCApplication.getMLInstance().getAlbums();
break;
case ID_GENRES:
list = VLCApplication.getMLInstance().getGenres();
break;
case ID_PLAYLISTS:
list = VLCApplication.getMLInstance().getPlaylists();
break;
case ID_SONGS:
list = VLCApplication.getMLInstance().getAudio();
break;
default:
String[] idSections = parentId.split("_");
Medialibrary ml = VLCApplication.getMLInstance();
long id = Long.parseLong(idSections[1]);
switch(idSections[0]) {
case ARTIST_PREFIX:
list = ml.getArtist(id).getAlbums();
break;
case GENRE_PREFIX:
list = ml.getGenre(id).getAlbums();
break;
}
}
if (list != null) {
MediaDescriptionCompat.Builder item = new MediaDescriptionCompat.Builder();
for (MediaLibraryItem libraryItem : list) {
if (libraryItem == null || (libraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA && ((MediaWrapper) libraryItem).getType() != MediaWrapper.TYPE_AUDIO))
continue;
Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(libraryItem.getArtworkMrl()), 256);
if (cover == null)
cover = DEFAULT_AUDIO_COVER;
item.setTitle(libraryItem.getTitle()).setMediaId(generateMediaId(libraryItem));
item.setIconBitmap(cover);
if (libraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
item.setMediaUri(((MediaWrapper) libraryItem).getUri()).setSubtitle(MediaUtils.getMediaSubtitle((MediaWrapper) libraryItem));
} else
item.setSubtitle(libraryItem.getDescription());
boolean playable = libraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA || libraryItem.getItemType() == MediaLibraryItem.TYPE_ALBUM || libraryItem.getItemType() == MediaLibraryItem.TYPE_PLAYLIST;
results.add(new MediaBrowserCompat.MediaItem(item.build(), playable ? MediaBrowserCompat.MediaItem.FLAG_PLAYABLE : MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
if (limitSize && results.size() == MAX_HISTORY_SIZE)
break;
}
}
}
if (results.isEmpty()) {
MediaDescriptionCompat.Builder mediaItem = new MediaDescriptionCompat.Builder();
mediaItem.setMediaId(DUMMY);
mediaItem.setTitle(VLCApplication.getAppContext().getString(R.string.search_no_result));
results.add(new MediaBrowserCompat.MediaItem(mediaItem.build(), 0));
}
return results;
}
use of org.videolan.vlc.extensions.ExtensionListing in project vlc-android by GeoffreyMetais.
the class ExtensionBrowser method onClick.
@Override
public void onClick(View v) {
if (v.getId() == mAddDirectoryFAB.getId()) {
ExtensionListing extension = mExtensionManagerService.getCurrentExtension();
if (extension == null)
return;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(extension.settingsActivity());
startActivity(intent);
}
}
Aggregations