org.videolan.libvlc.util.AndroidUtil Java Examples

The following examples show how to use org.videolan.libvlc.util.AndroidUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWindow.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
@MainThread
public void detachViews() {
    if (mSurfacesState.get() == SURFACE_STATE_INIT)
        return;

    mSurfacesState.set(SURFACE_STATE_INIT);
    mHandler.removeCallbacksAndMessages(null);
    synchronized (mNativeLock) {
        mOnNewVideoLayoutListener = null;
        mNativeLock.buffersGeometryAbort = true;
        mNativeLock.notifyAll();
    }
    for (int id = 0; id < ID_MAX; ++id) {
        final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
        if (surfaceHelper != null)
            surfaceHelper.release();
        mSurfaceHelpers[id] = null;
    }
    for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
        cb.onSurfacesDestroyed(this);
    if (mSurfaceCallback != null)
        mSurfaceCallback.onSurfacesDestroyed(this);
    if (AndroidUtil.isJellyBeanOrLater)
        mSurfaceTextureThread.release();
}
 
Example #2
Source File: Util.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean deleteFile (String path){
    boolean deleted = false;
    path = Uri.decode(Strings.removeFileProtocole(path));
    //Delete from Android Medialib, for consistency with device MTP storing and other apps listing content:// media
    if (AndroidUtil.isHoneycombOrLater()){
        ContentResolver cr = VLCApplication.getAppContext().getContentResolver();
        String[] selectionArgs = { path };
        deleted = cr.delete(MediaStore.Files.getContentUri("external"),
                MediaStore.Files.FileColumns.DATA + "=?", selectionArgs) > 0;
    }
    File file = new File(path);
    if (file.exists())
        deleted |= file.delete();
    return deleted;
}
 
Example #3
Source File: MainActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
/** Create menu from XML
 */
@TargetApi(Build.VERSION_CODES.FROYO)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mMenu = menu;
    /* Note: on Android 3.0+ with an action bar this method
     * is called while the view is created. This can happen
     * any time after onCreate.
     */
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.media_library, menu);

    if (AndroidUtil.isFroyoOrLater()) {
        SearchManager searchManager =
                (SearchManager) VLCApplication.getAppContext().getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setQueryHint(getString(R.string.search_hint));
        SearchSuggestionsAdapter searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, null);
        searchSuggestionsAdapter.setFilterQueryProvider(this);
        mSearchView.setSuggestionsAdapter(searchSuggestionsAdapter);
    } else
        menu.findItem(R.id.ml_menu_search).setVisible(false);
    return super.onCreateOptionsMenu(menu);
}
 
Example #4
Source File: BitmapUtil.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
static boolean canUseForInBitmap(
        Bitmap candidate, BitmapFactory.Options targetOptions) {

    if (candidate == null)
        return false;

    if (AndroidUtil.isKitKatOrLater()) {
        if (targetOptions.inSampleSize == 0)
            return false;
        // From Android 4.4 (KitKat) onward we can re-use if the byte size of
        // the new bitmap is smaller than the reusable bitmap candidate
        // allocation byte count.
        int width = targetOptions.outWidth / targetOptions.inSampleSize;
        int height = targetOptions.outHeight /  targetOptions.inSampleSize;
        int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
        return byteCount <= candidate.getAllocationByteCount();
    }

    // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
    return candidate.getWidth() == targetOptions.outWidth
            && candidate.getHeight() == targetOptions.outHeight
            && targetOptions.inSampleSize == 1;
}
 
Example #5
Source File: MediaLibrary.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
public ArrayList<AudioBrowserListAdapter.ListItem> getPlaylistDbItems() {
    ArrayList<AudioBrowserListAdapter.ListItem> playlistItems = new ArrayList<AudioBrowserListAdapter.ListItem>();
    AudioBrowserListAdapter.ListItem playList;
    MediaDatabase db = MediaDatabase.getInstance();
    String[] items, playlistNames = db.getPlaylists();
    for (String playlistName : playlistNames){
        items = db.playlistGetItems(playlistName);
        if (items == null)
            continue;
        playList = new AudioBrowserListAdapter.ListItem(playlistName, null, null, false);
        for (String track : items){
            playList.mMediaList.add(new MediaWrapper(AndroidUtil.LocationToUri(track)));
        }
        playlistItems.add(playList);
    }
    return playlistItems;
}
 
Example #6
Source File: BaseBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }
    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    setContextMenu(popupMenu.getMenuInflater(), popupMenu.getMenu(), position);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #7
Source File: AudioAlbumsSongsFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor, position);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #8
Source File: AudioAlbumFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor, position);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #9
Source File: AudioUtil.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void prepareCacheFolder(Context context) {
    try {
        if (AndroidUtil.isFroyoOrLater() && AndroidDevices.hasExternalStorage() && context.getExternalCacheDir() != null)
            CACHE_DIR = context.getExternalCacheDir().getPath();
        else
            CACHE_DIR = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
    } catch (Exception e) { // catch NPE thrown by getExternalCacheDir()
        CACHE_DIR = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
    }
    ART_DIR = CACHE_DIR + "/art/";
    COVER_DIR = CACHE_DIR + "/covers/";
    PLAYLIST_DIR = CACHE_DIR + "/playlists/";

    for(String path : Arrays.asList(ART_DIR, COVER_DIR)) {
        File file = new File(path);
        if (!file.exists())
            file.mkdirs();
    }
}
 
Example #10
Source File: AWindow.java    From vlc-example-streamplayer with GNU General Public License v3.0 6 votes vote down vote up
@Override
@MainThread
public void detachViews() {
    if (mSurfacesState.get() == SURFACE_STATE_INIT)
        return;

    mSurfacesState.set(SURFACE_STATE_INIT);
    mHandler.removeCallbacksAndMessages(null);
    synchronized (mNativeLock) {
        mOnNewVideoLayoutListener = null;
        mNativeLock.buffersGeometryAbort = true;
        mNativeLock.notifyAll();
    }
    for (int id = 0; id < ID_MAX; ++id) {
        final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
        if (surfaceHelper != null)
            surfaceHelper.release();
        mSurfaceHelpers[id] = null;
    }
    for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
        cb.onSurfacesDestroyed(this);
    if (mSurfaceCallback != null)
        mSurfaceCallback.onSurfacesDestroyed(this);
    if (AndroidUtil.isJellyBeanOrLater)
        mSurfaceTextureThread.release();
}
 
Example #11
Source File: AudioBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #12
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 6 votes vote down vote up
@Override
@MainThread
public void detachViews() {
    if (mSurfacesState.get() == SURFACE_STATE_INIT)
        return;

    mSurfacesState.set(SURFACE_STATE_INIT);
    mHandler.removeCallbacksAndMessages(null);
    synchronized (mNativeLock) {
        mOnNewVideoLayoutListener = null;
        mNativeLock.buffersGeometryAbort = true;
        mNativeLock.notifyAll();
    }
    for (int id = 0; id < ID_MAX; ++id) {
        final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
        if (surfaceHelper != null)
            surfaceHelper.release();
        mSurfaceHelpers[id] = null;
    }
    for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
        cb.onSurfacesDestroyed(this);
    if (mSurfaceCallback != null)
        mSurfaceCallback.onSurfacesDestroyed(this);
    if (AndroidUtil.isJellyBeanOrLater)
        mSurfaceTextureThread.release();
}
 
Example #13
Source File: VideoGridFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onContextPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    MediaWrapper media = mVideoAdapter.getItem(position);
    if (media == null)
        return;
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #14
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 6 votes vote down vote up
@Override
@MainThread
public void detachViews() {
    if (mSurfacesState.get() == SURFACE_STATE_INIT)
        return;

    mSurfacesState.set(SURFACE_STATE_INIT);
    mHandler.removeCallbacksAndMessages(null);
    synchronized (mNativeLock) {
        mOnNewVideoLayoutListener = null;
        mNativeLock.buffersGeometryAbort = true;
        mNativeLock.notifyAll();
    }
    for (int id = 0; id < ID_MAX; ++id) {
        final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
        if (surfaceHelper != null)
            surfaceHelper.release();
        mSurfaceHelpers[id] = null;
    }
    for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
        cb.onSurfacesDestroyed(this);
    if (mSurfaceCallback != null)
        mSurfaceCallback.onSurfacesDestroyed(this);
    if (AndroidUtil.isJellyBeanOrLater)
        mSurfaceTextureThread.release();
}
 
Example #15
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(android.os.Build.VERSION_CODES.FROYO)
private void initBrightnessTouch() {
    float brightnesstemp = 0.6f;
    // Initialize the layoutParams screen brightness
    try {
        if (AndroidUtil.isFroyoOrLater() &&
                Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
            mRestoreAutoBrightness = android.provider.Settings.System.getInt(getContentResolver(),
                    android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
        } else {
            brightnesstemp = android.provider.Settings.System.getInt(getContentResolver(),
                android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
        }
    } catch (SettingNotFoundException e) {
        e.printStackTrace();
    }
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.screenBrightness = brightnesstemp;
    getWindow().setAttributes(lp);
    mIsFirstBrightnessGesture = false;
}
 
Example #16
Source File: PlaybackService.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
/**
 * A function to control the Remote Control Client. It is needed for
 * compatibility with devices below Ice Cream Sandwich (4.0).
 *
 * @param state Playback state
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteControlClientPlaybackState(int state) {
    if (!AndroidUtil.isICSOrLater() || mRemoteControlClient == null)
        return;

    switch (state) {
        case MediaPlayer.Event.Playing:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            break;
        case MediaPlayer.Event.Paused:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
            break;
        case MediaPlayer.Event.Stopped:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
            break;
    }
}
 
Example #17
Source File: VideoGridFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void setContextMenuItems(Menu menu, MediaWrapper mediaWrapper) {
    long lastTime = mediaWrapper.getTime();
    if (lastTime > 0)
        menu.findItem(R.id.video_list_play_from_start).setVisible(true);

    boolean hasInfo = false;
    final Media media = new Media(VLCInstance.get(), mediaWrapper.getUri());
    media.parse();
    if (media.getMeta(Media.Meta.Title) != null)
        hasInfo = true;
    media.release();
    menu.findItem(R.id.video_list_info).setVisible(hasInfo);
    menu.findItem(R.id.video_list_delete).setVisible(!AndroidUtil.isLolliPopOrLater() ||
            mediaWrapper.getLocation().startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
}
 
Example #18
Source File: AudioUtil.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private static Bitmap readCoverBitmap(String path, int dipWidth) {
    Bitmap cover = null;
    BitmapFactory.Options options = new BitmapFactory.Options();
    int width = Util.convertDpToPx(dipWidth);

    /* Get the resolution of the bitmap without allocating the memory */
    options.inJustDecodeBounds = true;
    if (AndroidUtil.isHoneycombOrLater())
        options.inMutable = true;
    BitmapUtil.setInBitmap(options);
    BitmapFactory.decodeFile(path, options);

    if (options.outWidth > 0 && options.outHeight > 0) {
        options.inJustDecodeBounds = false;
        options.inSampleSize = 1;

        // Find the best decoding scale for the bitmap
        while( options.outWidth / options.inSampleSize > width)
            options.inSampleSize = options.inSampleSize * 2;

        // Decode the file (with memory allocation this time)
        BitmapUtil.setInBitmap(options);
        cover = BitmapFactory.decodeFile(path, options);
    }

    return cover;
}
 
Example #19
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (!AndroidUtil.isHoneycombOrLater())
        changeSurfaceLayout();
    super.onConfigurationChanged(newConfig);
    resetHudLayout();
}
 
Example #20
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Add or remove MediaRouter callbacks. This is provided for version targeting.
 *
 * @param add true to add, false to remove
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void mediaRouterAddCallback(boolean add) {
    if(!AndroidUtil.isJellyBeanMR1OrLater() || mMediaRouter == null) return;

    if(add)
        mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
    else
        mMediaRouter.removeCallback(mMediaRouterCallback);
}
 
Example #21
Source File: FileBrowserFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void browseRoot() {
    final Activity context = getActivity();
    mAdapter.updateMediaDirs();
    VLCApplication.runBackground(new Runnable() {
        @Override
        public void run() {
            String storages[] = AndroidDevices.getMediaDirectories();
            MediaWrapper directory;
            for (String mediaDirLocation : storages) {
                if (!(new File(mediaDirLocation).exists()))
                    continue;
                directory = new MediaWrapper(AndroidUtil.PathToUri(mediaDirLocation));
                directory.setType(MediaWrapper.TYPE_DIR);
                if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
                    directory.setTitle(getString(R.string.internal_memory));
                mAdapter.addItem(directory, false, false);
            }
            if (mReadyToDisplay) {
                context.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        updateEmptyView();
                        mAdapter.notifyDataSetChanged();
                        parseSubDirectories();
                    }
                });
            }
            mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
        }
    });
}
 
Example #22
Source File: MainActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    //Filter for LG devices, see https://code.google.com/p/android/issues/detail?id=78154
    if ((keyCode == KeyEvent.KEYCODE_MENU) &&
            (Build.VERSION.SDK_INT <= 16) &&
            (Build.MANUFACTURER.compareTo("LGE") == 0)) {
        openOptionsMenu();
        return true;
    }
    View v = getCurrentFocus();
    if (v == null)
        return super.onKeyUp(keyCode, event);
    if ((mActionBarIconId == -1) &&
        (v.getId() == -1)  &&
        (v.getNextFocusDownId() == -1) &&
        (v.getNextFocusUpId() == -1) &&
        (v.getNextFocusLeftId() == -1) &&
        (v.getNextFocusRightId() == -1)) {
        mActionBarIconId = Util.generateViewId();
        v.setId(mActionBarIconId);
        v.setNextFocusUpId(mActionBarIconId);
        v.setNextFocusDownId(mActionBarIconId);
        v.setNextFocusLeftId(mActionBarIconId);
        v.setNextFocusRightId(R.id.ml_menu_search);
        if (AndroidUtil.isHoneycombOrLater())
            v.setNextFocusForwardId(mActionBarIconId);
        if (findViewById(R.id.ml_menu_search) != null)
            findViewById(R.id.ml_menu_search).setNextFocusLeftId(mActionBarIconId);
    }
    return super.onKeyUp(keyCode, event);
}
 
Example #23
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Dim the status bar and/or navigation icons when needed on Android 3.x.
 * Hide it on Android 4.0 and later
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private void dimStatusBar(boolean dim) {
    if (!AndroidUtil.isHoneycombOrLater() || mIsNavMenu)
        return;
    int visibility = 0;
    int navbar = 0;

    if (!AndroidDevices.hasCombBar() && AndroidUtil.isJellyBeanOrLater()) {
        visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        navbar = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    }
    visibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    if (dim || mIsLocked) {
        navbar |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
        if (!AndroidDevices.hasCombBar()) {
            navbar |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            if (AndroidUtil.isKitKatOrLater())
                visibility |= View.SYSTEM_UI_FLAG_IMMERSIVE;
            visibility |= View.SYSTEM_UI_FLAG_FULLSCREEN;
        }
    }
    if (!dim) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        visibility |= View.SYSTEM_UI_FLAG_VISIBLE;
    }

    if (AndroidDevices.hasNavBar())
        visibility |= navbar;
    getWindow().getDecorView().setSystemUiVisibility(visibility);
}
 
Example #24
Source File: BitmapCache.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public static Bitmap getFromResource(Resources res, int resId) {
    BitmapCache cache = BitmapCache.getInstance();
    Bitmap bitmap = cache.getBitmapFromMemCache(resId);
    if (bitmap == null) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        BitmapUtil.setInBitmap(options);
        if (AndroidUtil.isHoneycombOrLater())
            options.inMutable = true;
        bitmap = BitmapFactory.decodeResource(res, resId, options);
        cache.addBitmapToMemCache(resId, bitmap);
    }
    return bitmap;
}
 
Example #25
Source File: BitmapCache.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private BitmapCache() {

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext().getSystemService(
            Context.ACTIVITY_SERVICE));
    final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass();

    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 5;

    Log.i(TAG, "LRUCache size set to " + cacheSize);

    mMemCache = new LruCache<String, CacheableBitmap>(cacheSize) {

        @Override
        protected int sizeOf(String key, CacheableBitmap value) {
            return value.getSize();
        }

        @Override
        protected void entryRemoved(boolean evicted, String key, CacheableBitmap oldValue, CacheableBitmap newValue) {
            if (evicted) {
                mCachedBitmaps.remove(oldValue.getReference());
                if (mReusableBitmaps != null && oldValue.get() != null && !TextUtils.equals(key, CONE_KEY) && !TextUtils.equals(key, CONE_O_KEY))
                    addReusableBitmapRef(oldValue.getReference());
            }
        }
    };

    if (AndroidUtil.isHoneycombOrLater())
        mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
        mCachedBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
}
 
Example #26
Source File: AWindow.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example #27
Source File: Util.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(android.os.Build.VERSION_CODES.GINGERBREAD)
public static void commitPreferences(SharedPreferences.Editor editor){
    if (AndroidUtil.isGingerbreadOrLater())
        editor.apply();
    else
        editor.commit();
}
 
Example #28
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example #29
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example #30
Source File: AWindow.java    From vlc-example-streamplayer with GNU General Public License v3.0 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}