下面列出了android.view.View#OnLayoutChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
};
}
/**
* 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();
}
};
}
/**
* 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();
}
};
}
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();
}
}
@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);
}
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);
}
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);
}
}
}
CleanupCallback(Map<View, View.OnLayoutChangeListener> listenerMap, ViewGroup parent) {
this.layoutChangeListenerMap = listenerMap;
this.parent = parent;
}
@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));
}