Java Code Examples for org.videolan.libvlc.util.AndroidUtil#isHoneycombOrLater()

The following examples show how to use org.videolan.libvlc.util.AndroidUtil#isHoneycombOrLater() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: BitmapUtil.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setInBitmap(BitmapFactory.Options options){
    if (!AndroidUtil.isHoneycombOrLater())
        return;
    Bitmap inBitmap = BitmapCache.getInstance().getReusableBitmap(options);
    if (inBitmap != null) {
        options.inBitmap = inBitmap;
    }
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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 14
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void startPlayback() {
    /* start playback only when audio service and both surfaces are ready */
    if (mPlaybackStarted || mService == null)
        return;

    mPlaybackStarted = true;

    /* Dispatch ActionBar touch events to the Activity */
    mActionBarView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            onTouchEvent(event);
            return true;
        }
    });

    if (AndroidUtil.isICSOrLater())
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        if (visibility == mUiVisibility)
                            return;
                        if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing && !isFinishing()) {
                            showOverlay();
                        }
                        mUiVisibility = visibility;
                    }
                }
        );

    if (AndroidUtil.isHoneycombOrLater()) {
        if (mOnLayoutChangeListener == null) {
            mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
                private final Runnable mRunnable = new Runnable() {
                    @Override
                    public void run() {
                        changeSurfaceLayout();
                    }
                };
                @Override
                public void onLayoutChange(View v, int left, int top, int right,
                                           int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                        /* changeSurfaceLayout need to be called after the layout changed */
                        mHandler.removeCallbacks(mRunnable);
                        mHandler.post(mRunnable);
                    }
                }
            };
        }
        mSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
    }
    changeSurfaceLayout();

    /* Listen for changes to media routes. */
    if (mMediaRouter != null)
        mediaRouterAddCallback(true);

    LibVLC().setOnHardwareAccelerationError(this);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.detachViews();
    if (mPresentation == null) {
        vlcVout.setVideoView(mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mSubtitlesSurfaceView);
    } else {
        vlcVout.setVideoView(mPresentation.mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mPresentation.mSubtitlesSurfaceView);
    }
    mSurfacesAttached = true;
    vlcVout.addCallback(this);
    vlcVout.attachViews();
    mSurfaceView.setKeepScreenOn(true);

    loadMedia();

    // Add any selected subtitle file from the file picker
    if(mSubtitleSelectedFiles.size() > 0) {
        for(String file : mSubtitleSelectedFiles) {
            Log.i(TAG, "Adding user-selected subtitle " + file);
            mService.addSubtitleTrack(file);
        }
    }

    // Set user playback speed
    mService.setRate(mSettings.getFloat(PreferencesActivity.VIDEO_SPEED, 1));
}
 
Example 15
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void stopPlayback() {
    if (!mPlaybackStarted)
        return;

    if (mMute)
        mute(false);

    LibVLC().setOnHardwareAccelerationError(null);

    mPlaybackStarted = false;

    mService.removeCallback(this);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.removeCallback(this);
    if (mSurfacesAttached)
        vlcVout.detachViews();
    mSurfaceView.setKeepScreenOn(false);

    mHandler.removeCallbacksAndMessages(null);

    mDetector.setOnDoubleTapListener(null);

    /* Stop listening for changes to media routes. */
    if (mMediaRouter != null)
        mediaRouterAddCallback(false);

    if (AndroidUtil.isHoneycombOrLater() && mOnLayoutChangeListener != null)
        mSurfaceFrame.removeOnLayoutChangeListener(mOnLayoutChangeListener);

    if (AndroidUtil.isICSOrLater())
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(null);

    mActionBarView.setOnTouchListener(null);

    if(mSwitchingView && mService != null) {
        Log.d(TAG, "mLocation = \"" + mUri + "\"");
        mService.showWithoutParse(savedIndexPosition);
        return;
    }

    final boolean isPaused = !mService.isPlaying();
    long time = getTime();
    long length = mService.getLength();
    //remove saved position if in the last 5 seconds
    if (length - time < 5000)
        time = 0;
    else
        time -= 2000; // go back 2 seconds, to compensate loading time
    mService.stop();

    SharedPreferences.Editor editor = mSettings.edit();
    // Save position
    if (mService.isSeekable()) {
        if(MediaDatabase.getInstance().mediaItemExists(mUri)) {
            MediaDatabase.getInstance().updateMedia(
                    mUri,
                    MediaDatabase.INDEX_MEDIA_TIME,
                    time);
        } else {
            // Video file not in media library, store time just for onResume()
            editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, time);
        }
    }
    if(isPaused)
        Log.d(TAG, "Video paused - saving flag");
    editor.putBoolean(PreferencesActivity.VIDEO_PAUSED, isPaused);

    // Save selected subtitles
    String subtitleList_serialized = null;
    if(mSubtitleSelectedFiles.size() > 0) {
        Log.d(TAG, "Saving selected subtitle files");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(mSubtitleSelectedFiles);
            subtitleList_serialized = bos.toString();
        } catch(IOException e) {}
    }
    editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, subtitleList_serialized);

    if (mUri != null)
        editor.putString(PreferencesActivity.VIDEO_LAST, mUri.toString());

    // Save user playback speed and restore normal speed
    editor.putFloat(PreferencesActivity.VIDEO_SPEED, mService.getRate());
    mService.setRate(1.0f);

    Util.commitPreferences(editor);
}