List of usage examples for android.view ViewTreeObserver addOnGlobalLayoutListener
public void addOnGlobalLayoutListener(OnGlobalLayoutListener listener)
From source file:org.telegram.ui.LaunchActivity.java
private void fixLayout() { if (containerView != null) { ViewTreeObserver obs = containerView.getViewTreeObserver(); obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override//from ww w.jav a 2 s . c o m public void onGlobalLayout() { WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); int rotation = manager.getDefaultDisplay().getRotation(); int height; int currentActionBarHeight = getSupportActionBar().getHeight(); if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) { height = currentActionBarHeight; } else { height = Utilities.dp(48); if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { height = Utilities.dp(40); } } if (notificationView != null) { notificationView.applyOrientationPaddings( rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height); } if (Build.VERSION.SDK_INT < 16) { containerView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { containerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } }
From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java
private void setupCustomScrolling() { mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); }/*from w w w . j a v a 2s.com*/ }
From source file:com.gelakinetic.mtgfam.fragments.LifeCounterFragment.java
/** * Get UI element references, set onClickListeners for the toolbar, clear the measurement data and attach a * ViewTreeObserver to measure the UI when it is drawn. Get the life/poison mode from the savedInstanceState if the * fragment is persisting. Save the current brightness. Players are not added here. * * @param inflater The LayoutInflater object that can be used to inflate any views in the fragment, * @param container If non-null, this is the parent view that the fragment's UI should be attached to. The * fragment should not add the view itself, but this can be used to generate the * LayoutParams of the view. * @param savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state as given * here./*ww w .ja v a 2 s . com*/ * @return The inflated view */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mListSizeWidth = -1; mListSizeHeight = -1; View myFragmentView = inflater.inflate(R.layout.life_counter_frag, container, false); assert myFragmentView != null; mGridLayout = myFragmentView.findViewById(R.id.playerList); mDisplayMode = Integer.parseInt(PreferenceAdapter.getDisplayMode(getContext())); mCommanderPlayerView = myFragmentView.findViewById(R.id.commander_player); if (null != myFragmentView.findViewById(R.id.playerScrollView_horz)) { mScrollView = myFragmentView.findViewById(R.id.playerScrollView_horz); } else { mScrollView = myFragmentView.findViewById(R.id.playerScrollView_vert); } ViewTreeObserver viewTreeObserver = mScrollView.getViewTreeObserver(); assert viewTreeObserver != null; viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { if (isVisible()) { boolean changed = false; if (mListSizeHeight < mScrollView.getHeight()) { mListSizeHeight = mScrollView.getHeight(); changed = true; } if (mListSizeWidth < mScrollView.getWidth()) { mListSizeWidth = mScrollView.getWidth(); changed = true; } if (changed) { if (getActivity().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { if (mDisplayMode == DISPLAY_COMMANDER) { /* Conveniently takes care of re-adding the sized views in the right number of rows */ changeDisplayMode(false); } } for (LcPlayer player : mPlayers) { player.setSize(mListSizeWidth, mListSizeHeight, mDisplayMode, getActivity().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); } } } } }); mPoisonButton = myFragmentView.findViewById(R.id.poison_button); mPoisonButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { setStatDisplaying(STAT_POISON); } }); mLifeButton = myFragmentView.findViewById(R.id.life_button); mLifeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { setStatDisplaying(STAT_LIFE); } }); mCommanderButton = myFragmentView.findViewById(R.id.commander_button); mCommanderButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { setStatDisplaying(STAT_COMMANDER); } }); myFragmentView.findViewById(R.id.reset_button).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { showDialog(LifeCounterDialogFragment.DIALOG_RESET_CONFIRM); } }); if (savedInstanceState != null) { mStatDisplaying = savedInstanceState.getInt(DISPLAY_MODE, STAT_LIFE); } return myFragmentView; }
From source file:com.yahala.ui.LaunchActivity.java
private void fixLayout() { if (containerView != null) { ViewTreeObserver obs = containerView.getViewTreeObserver(); obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override// w w w . j a v a 2s .c o m public void onGlobalLayout() { WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); int rotation = manager.getDefaultDisplay().getRotation(); int height; int currentActionBarHeight = getSupportActionBar().getHeight(); if (currentActionBarHeight != OSUtilities.dp(48) && currentActionBarHeight != OSUtilities.dp(40)) { height = currentActionBarHeight; } else { height = OSUtilities.dp(48); if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { height = OSUtilities.dp(40); } } if (notificationView != null) { notificationView.applyOrientationPaddings( rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height); } if (Build.VERSION.SDK_INT < 16) { containerView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { containerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } }
From source file:com.ycl.framework.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(final ImageView imageView) { mImageView = new WeakReference<ImageView>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;/* w ww.j a va2 s .c o m*/ } // Create Gesture Detectors... mScaleDragDetector = com.ycl.framework.photoview.gestures.VersionedGestureDetector .newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); // Finally, update the UI so that we're zoomable setZoomable(true); }
From source file:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java
private void updateViews() { //?/* w ww .ja v a 2s .c om*/ mBinding.comicAuthorComicDetails.setVisibility(View.VISIBLE); mBinding.comicAuthorComicDetails.setText(mComic.getAuthor()); mBinding.comicVolStatusComicDetails.setText(mComic.getComicStatus()); mBinding.comicFavoriteNumberComicDetails.setText(mComic.getComicFavorite()); mBinding.comicUpdateTimeComicDetails.setText(mComic.getComicUpdateTime()); // mBinding.comicDescriptionComicDetails.setText(mComic.getDescription()); //? mBinding.comicDescriptionComicDetailsBack.setVisibility(View.VISIBLE); mBinding.comicDescriptionComicDetailsBack.setText(mComic.getDescription()); final ViewTreeObserver vto1 = mBinding.comicDescriptionComicDetails.getViewTreeObserver(); vto1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mDetailsHeight = mBinding.comicDescriptionComicDetails.getHeight(); //?? mBinding.comicDescriptionComicDetails.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); //?tv_back ViewTreeObserver vto = mBinding.comicDescriptionComicDetailsBack.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mBackHeight = mBinding.comicDescriptionComicDetailsBack.getHeight(); mBinding.comicDescriptionComicDetailsBack.getViewTreeObserver().removeGlobalOnLayoutListener(this); // if (mBackHeight > mDetailsHeight) { // mBinding.ivArrow.setVisibility(View.VISIBLE); //? mBinding.comicDescriptionComicDetails.setTag(true); isDescriptionCanOpen = true; } else { mBinding.ivArrow.setVisibility(View.GONE); isDescriptionCanOpen = false; } mBinding.comicDescriptionComicDetailsBack.setVisibility(View.GONE); } }); //? mBinding.ratingBarComicDetails.setRating((mComic.getRatingNumber() / 10.0f) * 5.0f); mBinding.ratingBarDescriptionComicDetails.setText(mComic.getRatingNumber() + "(10), " + "" + mComic.getRatingPeopleNum() + ""); // if (mComic.isMark() || mComic.isDownload()) { mVolAdapter = new VolRecyclerViewAdapter(ComicDetailsActivity.this, mComic.getChapterName(), mComic.getReadChapter(), mFinishedComicChapters); } else { mVolAdapter = new VolRecyclerViewAdapter(ComicDetailsActivity.this, mComic.getChapterName(), mFinishedComicChapters); } //?RecyclerView mBinding.recyclerViewComicDetails .setLayoutManager(new FullyGridLayoutManager(ComicDetailsActivity.this, 4)); mBinding.recyclerViewComicDetails.setItemAnimator(new DefaultItemAnimator()); mBinding.recyclerViewComicDetails.setHasFixedSize(true); mBinding.recyclerViewComicDetails.setNestedScrollingEnabled(false); mVolAdapter.setOnItemClickListener(new VolRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent intent = new Intent(ComicDetailsActivity.this, GalleryActivity.class); intent.putExtra("comic", mComic); intent.putExtra("position", position); startActivityForResult(intent, 0); } @Override public void onItemLongClick(View view, int position) { } }); mBinding.recyclerViewComicDetails.setAdapter(mVolAdapter); mBinding.recyclerViewComicDetails.setFocusable(false); mBinding.nestScrollViewComicDetails.setFocusable(true); mBinding.nestScrollViewComicDetails.smoothScrollBy(0, 0); //?? if (mComic.isMark()) { mBinding.btnFavoriteComicDetails.setImageResource(R.mipmap.my_favorite); mBinding.buttonTextFavoriteComicDetails.setText("?"); } //? mBinding.FABComicDetails.setOnClickListener(this); mBinding.readButton.setOnClickListener(this); // mBinding.btnFavorite.setOnClickListener(this); mBinding.btnShare.setOnClickListener(this); mBinding.btnFind.setOnClickListener(this); mBinding.btnDownload.setOnClickListener(this); // mBinding.comicAuthorComicDetails.setOnClickListener(this); mBinding.comicDescriptionComicDetailsLl.setOnClickListener(this); //?? mBinding.FABComicDetails .setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorAccent))); mBinding.linearLayoutComicDetails.setVisibility(View.VISIBLE); Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha_in); //? alpha.setInterpolator(new AccelerateInterpolator()); mBinding.linearLayoutComicDetails.startAnimation(alpha); }
From source file:uk.co.senab.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, PdfiumCore pdfiumCore, PdfDocument pdfDocument, int pageIndex, float pageScale, boolean zoomable) { mImageView = new WeakReference<>(imageView); this.pdfiumCore = pdfiumCore; this.pdfDocument = pdfDocument; this.pageIndex = pageIndex; pdfiumCore.openPage(pdfDocument, pageIndex); originalBitmapSize.set((int) (pageScale * pdfiumCore.getPageWidthPoint(pdfDocument, pageIndex)), (int) (pageScale * pdfiumCore.getPageHeightPoint(pdfDocument, pageIndex))); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;/*from ww w. ja va 2s . co m*/ } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.zirkler.czannotationviewsample.AnnotationView.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;/*from w w w .j a v a 2 s . co m*/ } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView(), e); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.sflib.CustomView.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<ImageView>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;/*w ww. j av a 2 s. c om*/ } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) { observer.addOnGlobalLayoutListener(this); }//from www .j a v a 2 s . c o m // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return; } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }