Java Code Examples for android.view.View#OnLayoutChangeListener

The following examples show how to use android.view.View#OnLayoutChangeListener . These examples are extracted from open source projects. 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 Project: delion   File: SwipableOverlayView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a listener that is used only to animate the View coming onto the screen.
 * @return The SimpleOnGestureListener that will monitor the View.
 */
private View.OnLayoutChangeListener createLayoutChangeListener() {
    return new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            removeOnLayoutChangeListener(mLayoutChangeListener);

            // Animate the View coming in from the bottom of the screen.
            setTranslationY(mTotalHeight);
            mIsBeingDisplayedForFirstTime = true;
            createVerticalSnapAnimation(true);
            mCurrentAnimation.start();
        }
    };
}
 
Example 2
/**
 * Creates a listener that is used only to animate the View coming onto the screen.
 * @return The SimpleOnGestureListener that will monitor the View.
 */
private View.OnLayoutChangeListener createLayoutChangeListener() {
    return new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            removeOnLayoutChangeListener(mLayoutChangeListener);

            // Animate the View coming in from the bottom of the screen.
            setTranslationY(mTotalHeight);
            mIsBeingDisplayedForFirstTime = true;
            createVerticalSnapAnimation(true);
            mCurrentAnimation.start();
        }
    };
}
 
Example 3
Source Project: 365browser   File: SwipableOverlayView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a listener that is used only to animate the View coming onto the screen.
 * @return The SimpleOnGestureListener that will monitor the View.
 */
private View.OnLayoutChangeListener createLayoutChangeListener() {
    return new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            removeOnLayoutChangeListener(mLayoutChangeListener);

            // Animate the View coming in from the bottom of the screen.
            setTranslationY(mTotalHeight);
            mIsBeingDisplayedForFirstTime = true;
            createVerticalSnapAnimation(true);
            mCurrentAnimation.start();
        }
    };
}
 
Example 4
private void cleanup() {
    parent.getViewTreeObserver().removeOnPreDrawListener(this);
    parent.removeOnAttachStateChangeListener(this);
    int count = layoutChangeListenerMap.size();
    if (count > 0) {
        Collection<View> views = layoutChangeListenerMap.keySet();
        for (View view : views) {
            View.OnLayoutChangeListener listener = layoutChangeListenerMap.get(view);
            view.removeOnLayoutChangeListener(listener);
        }
        layoutChangeListenerMap.clear();
    }
}
 
Example 5
@Override
protected void onStart() {
    super.onStart();

    final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
    if (mVideoSurface != null) {
        vlcVout.setVideoView(mVideoSurface);
        if (mSubtitlesSurface != null)
            vlcVout.setSubtitlesView(mSubtitlesSurface);
    } else
        vlcVout.setVideoView(mVideoTexture);
    vlcVout.attachViews(this);

    Media media = new Media(mLibVLC, Uri.parse(SAMPLE_URL));
    mMediaPlayer.setMedia(media);
    media.release();
    mMediaPlayer.play();

    if (mOnLayoutChangeListener == null) {
        mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
            private final Runnable mRunnable = new Runnable() {
                @Override
                public void run() {
                    updateVideoSurfaces();
                }
            };

            @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) {
                    mHandler.removeCallbacks(mRunnable);
                    mHandler.post(mRunnable);
                }
            }
        };
    }
    mVideoSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
}
 
Example 6
void attachViews() {
    if (mVideoSurface == null && mVideoTexture == null) return;
    final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
    if (mVideoSurface != null) {
        vlcVout.setVideoView(mVideoSurface);
        if (mSubtitlesSurface != null)
            vlcVout.setSubtitlesView(mSubtitlesSurface);
    } else if (mVideoTexture != null)
        vlcVout.setVideoView(mVideoTexture);
    else return;
    vlcVout.attachViews(this);

    if (mOnLayoutChangeListener == null) {
        mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
            private final Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    if (mVideoSurfaceFrame != null && mOnLayoutChangeListener != null)
                        updateVideoSurfaces();
                }
            };

            @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) {
                    mHandler.removeCallbacks(runnable);
                    mHandler.post(runnable);
                }
            }
        };
    }
    mVideoSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
    mMediaPlayer.setVideoTrackEnabled(true);
}
 
Example 7
Source Project: Emojix   File: Emojix.java    License: Apache License 2.0 5 votes vote down vote up
public static void wrapView(View view) {
    if (view == null) return;

    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        if (textView.getTag(R.id.tag_emojix_watcher) == null) {
            EmojixTextWatcher watcher = new EmojixTextWatcher(textView);
            textView.addTextChangedListener(watcher);

            textView.setTag(R.id.tag_emojix_watcher, watcher);
        }

    } else if (view instanceof ViewGroup) {
        if (view.getTag(R.id.tag_layout_listener) == null) {
            View.OnLayoutChangeListener listener = new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                           int oldLeft, int oldTop, int oldRight, int oldBottom) {

                    ViewGroup parentView = (ViewGroup) v;
                    int len = parentView.getChildCount();
                    for (int i = 0; i < len; i ++) {
                        wrapView(parentView.getChildAt(i));
                    }
                }
            };
            view.addOnLayoutChangeListener(listener);

            view.setTag(R.id.tag_layout_listener, listener);
        }
    }
}
 
Example 8
CleanupCallback(Map<View, View.OnLayoutChangeListener> listenerMap, ViewGroup parent) {
    this.layoutChangeListenerMap = listenerMap;
    this.parent = parent;
}
 
Example 9
Source Project: VCL-Android   File: VideoPlayerActivity.java    License: 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));
}