예제 #1
0
  private void getMeasurePostion() {

    _viewTreeObsvr = _frameDurationSeekBar.getViewTreeObserver();
    _viewTreeObsvr.addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            ViewTreeObserver obs = _frameDurationSeekBar.getViewTreeObserver();
            _nLocationXYArray = new int[2];
            _frameDurationSeekBar.getLocationOnScreen(_nLocationXYArray);
            _positionPoint = new Point();
            _positionPoint.x = _nLocationXYArray[0];
            _positionPoint.y = _nLocationXYArray[1];
            obs.removeOnGlobalLayoutListener(this);
          }
        });

    _viewTreeObsvr = _txtVideoLengthView.getViewTreeObserver();
    _viewTreeObsvr.addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            ViewTreeObserver obs = _txtVideoLengthView.getViewTreeObserver();
            _nLocationXYArray = new int[2];
            _txtVideoLengthView.getLocationOnScreen(_nLocationXYArray);
            _positionPointyImage = new Point();
            _positionPointyImage.x = _nLocationXYArray[0];
            _positionPointyImage.y = _nLocationXYArray[1];
            obs.removeOnGlobalLayoutListener(this);
          }
        });
  }
 /** 填充数据 */
 private void initData() {
   // Sku2 defaultSku = product.getSkuList().get(0);
   txtName.setText(product.getName());
   txtDesc.setText(product.getDesc());
   txtPrice.setText(product.getPrice());
   txtPriceMarket.setText("市场价:" + product.getPrice());
   txtSalesAmount.setText(product.getBuyerCount() + "人购买");
   initViewPager(); // 图片循环
   initServiceList(); // 服务列表
   initPromotionList(); // 促销列表
   initCommentList(); // 评论列表
   mWebView.loadUrl("http://www.baidu.com");
   ViewTreeObserver vto2 = txtPriceMarket.getViewTreeObserver();
   vto2.addOnGlobalLayoutListener(
       new ViewTreeObserver.OnGlobalLayoutListener() {
         @Override
         public void onGlobalLayout() {
           txtPriceMarket.getViewTreeObserver().removeGlobalOnLayoutListener(this);
           View view = findViewById(R.id.product_details_price_market_line);
           view.setVisibility(View.VISIBLE);
           ViewGroup.LayoutParams params = view.getLayoutParams();
           params.width = txtPriceMarket.getWidth();
           view.setLayoutParams(params);
         }
       });
 }
예제 #3
0
  public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);

    View anchor = mAnchorView;
    if (anchor != null) {
      final boolean addGlobalListener = mTreeObserver == null;
      mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
      if (addGlobalListener) mTreeObserver.addOnGlobalLayoutListener(this);
      mPopup.setAnchorView(anchor);
      mPopup.setDropDownGravity(mDropDownGravity);
    } else {
      return false;
    }

    if (!mHasContentWidth) {
      mContentWidth = measureContentWidth();
      mHasContentWidth = true;
    }

    mPopup.setContentWidth(mContentWidth);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
  }
예제 #4
0
  private void configureScrollView() {
    mScrollView.setScrollViewCallbacks(this);
    mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    mScrollView.setOnFlingListener(
        new ScrollFling.OnFlingListener() {
          @Override
          public void onFlingStarted() {
            if (goingUp && !mIsToolbarShown) {
              showFullToolbar(50);
            }
          }

          @Override
          public void onFlingStopped() {}
        });

    ViewTreeObserver vto = mTitle.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
              mTitle.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
              mTitle.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            updateFlexibleSpaceText(0);
          }
        });
  }
예제 #5
0
  public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
      // 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(mImageView.get());
                  }
                }
              });

      mGestureDetector.setOnDoubleTapListener(this);

      // Finally, update the UI so that we're zoomable
      setZoomable(true);
    }
  }
  private void runLayoutListener() {
    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {

            int maxHeight = (int) (getScreenHeight() * menu.getHalfScreenMaxHeightKoef());
            int height = view.findViewById(R.id.main_view).getHeight();

            ViewTreeObserver obs = view.getViewTreeObserver();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
              obs.removeOnGlobalLayoutListener(this);
            } else {
              obs.removeGlobalOnLayoutListener(this);
            }

            if (!menu.isLandscapeLayout() && height > maxHeight) {
              ViewGroup.LayoutParams lp = view.getLayoutParams();
              lp.height = maxHeight;
              view.setLayoutParams(lp);
              view.requestLayout();
            }
          }
        });
  }
예제 #7
0
    @Override
    protected void onAttachedToWindow() {
      // This is called when the view is attached to a window.
      // At this point it has a Surface and will start drawing.
      if (DBG) mSlidingCardManager.log("WindowAttachNotifierView: onAttachedToWindow!");
      super.onAttachedToWindow();

      // The code in showPopup() needs to know the sizes and
      // positions of some views in the mMainFrame view hierarchy,
      // in order to set the popup window's size and position.  That
      // means that showPopup() needs to be called *after* the whole
      // in-call UI has been measured and laid out.  At this point
      // that hasn't happened yet, so we can't directly call
      // mSlidingCardManager.showPopup() from here.
      //
      // Also, to reduce flicker onscreen, we'd like the PopupWindow
      // to appear *before* any of the main view hierarchy becomes
      // visible.  So we use the main view hierarchy's
      // ViewTreeObserver to get notified *after* the layout
      // happens, but before anything gets drawn.

      // Get the ViewTreeObserver for the main InCallScreen view
      // hierarchy.  (You can only call getViewTreeObserver() after
      // the view tree gets attached to a Window, which is why we do
      // this here rather than in InCallScreen.onCreate().)
      final ViewTreeObserver viewTreeObserver = getViewTreeObserver();
      // Arrange for the SlidingCardManager to get called after
      // the main view tree has been laid out.
      // (addOnPreDrawListener() would also be basically equivalent here.)
      viewTreeObserver.addOnGlobalLayoutListener(mSlidingCardManager);

      // See SlidingCardManager.onGlobalLayout() for the next step.
    }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    final FrameLayout frameLayout = (FrameLayout) getActivity().findViewById(R.id.framelayout);
    ViewTreeObserver observer = frameLayout.getViewTreeObserver();

    // Listen for rotation change
    observer.addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            if (started) {
              drawVisualization(frameLayout, "start");
              refreshKeyboard();
              drawKeyboard();
            } else {
              drawVisualization(frameLayout, "");
              refreshKeyboard();
              drawKeyboard();
            }
            frameLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top_level);

    mNavigationDrawerFragment =
        (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    // Set up the container size of the expanded video player
    final View view = findViewById(R.id.container);
    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            mVideoFrag.setContainerSize(view.getHeight(), view.getWidth());
          }
        });

    mVideoFrag = (VideoFragment) getFragmentManager().findFragmentById(R.id.special_fragment);
  }
  /** 设置头部的view */
  private void setHeaderView() {
    mHeaderBlock.mHeaderIv.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            // 跳转到某个位置
            mWaterFallRcv.scrollToPosition(10);
          }
        });

    ViewTreeObserver vto = mHeaderBlock.mHeaderIv.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
              mHeaderBlock.mHeaderIv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
              mHeaderBlock.mHeaderIv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            mHeaderHeight = mHeaderBlock.mHeaderIv.getHeight();
            LogUtils.d("headerHeight" + mHeaderHeight);
          }
        });
  }
예제 #11
0
  private void initView() {

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.add(R.id.fragment1, new NaviStart3Activity());
    transaction.add(R.id.fragment2, new MusicPlayer());
    transaction.commit();

    rll1 = (MyRelaLayout) findViewById(R.id.rll1);
    rll2 = (MyRelaLayout) findViewById(R.id.rll2);
    rll2.setStyle(1);
    rll1.inputActivity(this);
    rll2.inputActivity(this);
    params1 = rll1.getLayoutParams();
    params2 = rll2.getLayoutParams();

    ViewTreeObserver observer = findViewById(R.id.main).getViewTreeObserver();
    observer.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            findViewById(R.id.main).getViewTreeObserver().removeOnGlobalLayoutListener(this);
            int h = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getHeight();
            height = h;
            params1.height = rll1.getHeight();
            params2.height = rll2.getHeight();
          }
        });

    img0 = (ImageView) findViewById(R.id.img0);
    img1 = (ImageView) findViewById(R.id.img1);
    img0.setOnClickListener(this);
    img1.setOnClickListener(this);
  }
예제 #12
0
 private void initDialog(final Context context) {
   this.context = context;
   LayoutInflater layoutInflater = ((Activity) context).getLayoutInflater();
   View dialogView = layoutInflater.inflate(R.layout.layout_dialog, null);
   ViewTreeObserver viewTreeObserver = dialogView.getViewTreeObserver();
   viewTreeObserver.addOnGlobalLayoutListener(
       new ViewTreeObserver.OnGlobalLayoutListener() {
         @Override
         public void onGlobalLayout() {
           // 当View可以获取宽高的时候,设置view的位置
           relocation(location);
         }
       });
   rlOutsideBackground = (RelativeLayout) dialogView.findViewById(R.id.rlOutsideBackground);
   setTouchOutsideDismiss(true);
   ivTriangle = (ImageView) dialogView.findViewById(R.id.ivTriangle);
   llContent = (LinearLayout) dialogView.findViewById(R.id.llContent);
   dialog =
       new Dialog(
           context,
           isFullScreen()
               ? android.R.style.Theme_Translucent_NoTitleBar_Fullscreen
               : android.R.style.Theme_Translucent_NoTitleBar);
   dialog.setContentView(dialogView);
   animatorSetForDialogShow = new AnimatorSet();
   animatorSetForDialogDismiss = new AnimatorSet();
   objectAnimatorsForDialogShow = new ArrayList<>();
   objectAnimatorsForDialogDismiss = new ArrayList<>();
   ini();
 }
예제 #13
0
 public boolean tryShow() {
   boolean flag = false;
   mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
   mPopup.setOnDismissListener(this);
   mPopup.setOnItemClickListener(this);
   mPopup.setAdapter(mAdapter);
   mPopup.setModal(true);
   View view = mAnchorView;
   if (view != null) {
     if (mTreeObserver == null) {
       flag = true;
     }
     mTreeObserver = view.getViewTreeObserver();
     if (flag) {
       mTreeObserver.addOnGlobalLayoutListener(this);
     }
     mPopup.setAnchorView(view);
     mPopup.setDropDownGravity(mDropDownGravity);
     if (!mHasContentWidth) {
       mContentWidth = measureContentWidth();
       mHasContentWidth = true;
     }
     mPopup.setContentWidth(mContentWidth);
     mPopup.setInputMethodMode(2);
     mPopup.show();
     mPopup.getListView().setOnKeyListener(this);
     return true;
   } else {
     return false;
   }
 }
예제 #14
0
  // equivalent to document.ready in jQuery
  private final void initViewReady() {
    /*
    		View root = getWindow().getDecorView().getRootView();

    		if (root != null) {
    			final VaporView<View, ?> vaporRoot = $.View(root);

    			ViewTreeObserver vto = vaporRoot.treeObserver();
    			vto.addOnGlobalLayoutListener(new $$layout() {

    				@Override
    				public void onGlobalLayout() {
    					// When the layout has been calculated we fire this event to
    					// show the View is ready
    					$.hook(VIEW_READY).fire(ACT_HOOK_ADMIN, baseHookArgs);
    					// delete this hook after we fire it, it is only fired once
    					// per activity

    					//$.hook(VIEW_READY).delete(ACT_HOOK_ADMIN);
    					vaporRoot.treeObserver().removeOnGlobalLayoutListener(this);
    				}
    			});
    		}
    */

    // Create the View ready hook
    $.hook(
        VIEW_READY,
        $.Bundle()
            .put(VaporHook.ADMIN_AUTH, ACT_HOOK_ADMIN) // password protect
            // against admin changes
            // to these hooks
            .put(VaporHook.AUTO_DELETE, false) // these hooks will not be auto
            // deleted when hookeeCount
            // drops to 0
            .put(VaporHook.DELETEABLE, true) // this hook is deleted when fired
        );

    View root = getWindow().getDecorView().getRootView();

    if (root != null) {
      final VaporView<View, ?> vaporRoot = $.View(root);
      ViewTreeObserver vto = vaporRoot.treeObserver();
      vto.addOnGlobalLayoutListener(
          new $$layout() {

            @Override
            public void onGlobalLayout() {
              // When the layout has been calculated we fire this event to
              // show the View is ready
              $.hook(VIEW_READY).fire(ACT_HOOK_ADMIN, baseHookArgs);
              // delete this hook after we fire it, it is only fired once
              // per activity
              $.hook(VIEW_READY).delete(ACT_HOOK_ADMIN);
              vaporRoot.treeObserver().removeOnGlobalLayoutListener(this);
            }
          });
    }
  }
예제 #15
0
  public void testAddOnGlobalLayoutListener() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
    mViewTreeObserver = layout.getViewTreeObserver();

    MockOnGlobalLayoutListener listener = new MockOnGlobalLayoutListener();
    assertFalse(listener.hasCalledOnGlobalLayout());
    mViewTreeObserver.addOnGlobalLayoutListener(listener);
    mViewTreeObserver.dispatchOnGlobalLayout();
    assertTrue(listener.hasCalledOnGlobalLayout());
  }
 public void setupListener() {
   final ViewTreeObserver viewTreeObserver = mView.getViewTreeObserver();
   if (viewTreeObserver != null) {
     viewTreeObserver.addOnGlobalLayoutListener(this);
     viewTreeObserver.addOnGlobalFocusChangeListener(this);
     viewTreeObserver.addOnPreDrawListener(this);
     viewTreeObserver.addOnScrollChangedListener(this);
     viewTreeObserver.addOnTouchModeChangeListener(this);
   }
 }
예제 #17
0
  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
    Item item = items.get(paramInt);

    final ViewHolder localViewHolder;
    if (paramView == null) {
      paramView = this.inflater.inflate(R.layout.flip_item, paramViewGroup, false);

      localViewHolder = new ViewHolder();

      localViewHolder.celebrityIdentity = (TextView) paramView.findViewById(R.id.celeb_identity);
      localViewHolder.celebrityDetails = (TextView) paramView.findViewById(R.id.celeb_details);
      localViewHolder.readMore = (TextView) paramView.findViewById(R.id.more_read);
      localViewHolder.celebrityType = (TextView) paramView.findViewById(R.id.celeb_type);
      localViewHolder.celebrityImg = (ImageView) paramView.findViewById(R.id.celeb_img);

      localViewHolder.celebrityIdentity.setTypeface(futuraTypeface);
      localViewHolder.celebrityDetails.setTypeface(futuraTypeface);
      localViewHolder.readMore.setTypeface(muktiTypeface);
      localViewHolder.celebrityType.setTypeface(muktiTypeface);

      paramView.setTag(localViewHolder);
    } else {
      localViewHolder = (ViewHolder) paramView.getTag();
    }

    localViewHolder.celebrityIdentity.setText(item.getIdentity());
    localViewHolder.celebrityType.setText(item.getType());
    localViewHolder.celebrityDetails.setText(item.getDetails());
    localViewHolder.celebrityImg.setImageResource(item.getImage());

    localViewHolder.readMore.setText("আরো পড়ুন");

    ViewTreeObserver vto = localViewHolder.celebrityDetails.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            localViewHolder
                .celebrityDetails
                .getViewTreeObserver()
                .removeGlobalOnLayoutListener(this);

            int height = localViewHolder.celebrityDetails.getMeasuredHeight();
            int numLineHight = localViewHolder.celebrityDetails.getLineHeight();

            int txtHeight = (int) (height / numLineHight);

            localViewHolder.celebrityDetails.setMaxLines(txtHeight);
          }
        });

    return paramView;
  }
예제 #18
0
 private void setupSliderValue(final int value, final Slider slider) {
   ViewTreeObserver viewTreeObserver = slider.getViewTreeObserver();
   if (viewTreeObserver.isAlive()) {
     viewTreeObserver.addOnGlobalLayoutListener(
         new ViewTreeObserver.OnGlobalLayoutListener() {
           @Override
           public void onGlobalLayout() {
             slider.getViewTreeObserver().removeOnGlobalLayoutListener(this);
             slider.setValue(value);
           }
         });
   }
 }
  private void init() {
    setVerticalFadingEdgeEnabled(false);

    headerContainer =
        (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.ptr_header, null);
    header = (RelativeLayout) headerContainer.findViewById(R.id.ptr_id_header);
    text = (TextView) header.findViewById(R.id.ptr_id_text);
    lastUpdatedTextView = (TextView) header.findViewById(R.id.ptr_id_last_updated);
    image = (ImageView) header.findViewById(R.id.ptr_id_image);
    spinner = (ProgressBar) header.findViewById(R.id.ptr_id_spinner);

    pullToRefreshText = getContext().getString(R.string.ptr_pull_to_refresh);
    releaseToRefreshText = getContext().getString(R.string.ptr_release_to_refresh);
    refreshingText = getContext().getString(R.string.ptr_refreshing);
    lastUpdatedText = getContext().getString(R.string.ptr_last_updated);

    flipAnimation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    flipAnimation.setInterpolator(new LinearInterpolator());
    flipAnimation.setDuration(ROTATE_ARROW_ANIMATION_DURATION);
    flipAnimation.setFillAfter(true);

    reverseFlipAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseFlipAnimation.setInterpolator(new LinearInterpolator());
    reverseFlipAnimation.setDuration(ROTATE_ARROW_ANIMATION_DURATION);
    reverseFlipAnimation.setFillAfter(true);

    addHeaderView(headerContainer);
    setState(State.PULL_TO_REFRESH);
    scrollbarEnabled = isVerticalScrollBarEnabled();

    ViewTreeObserver vto = header.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new PTROnGlobalLayoutListener());

    super.setOnItemClickListener(new PTROnItemClickListener());
    super.setOnItemLongClickListener(new PTROnItemLongClickListener());
  }
예제 #20
0
  private void initWithContext(Context context) {
    mLayout = (LinearLayout) View.inflate(context, R.layout.vw_xscrollview_layout, null);
    mContentLayout = (LinearLayout) mLayout.findViewById(R.id.content_layout);

    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XScrollView need the scroll event, and it will dispatch the event to user's listener (as a
    // proxy).
    this.setOnScrollListener(this);

    // init header view
    mHeader = new XHeaderView(context);
    mHeaderContent = (RelativeLayout) mHeader.findViewById(R.id.header_content);
    mHeaderTime = (TextView) mHeader.findViewById(R.id.header_hint_time);
    LinearLayout headerLayout = (LinearLayout) mLayout.findViewById(R.id.header_layout);
    headerLayout.addView(mHeader);

    // init footer view
    mFooterView = new XFooterView(context);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    LinearLayout footLayout = (LinearLayout) mLayout.findViewById(R.id.footer_layout);
    footLayout.addView(mFooterView, params);

    // init header height
    ViewTreeObserver observer = mHeader.getViewTreeObserver();
    if (null != observer) {
      observer.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {
              mHeaderHeight = mHeaderContent.getHeight();
              ViewTreeObserver observer = getViewTreeObserver();
              if (null != observer) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  observer.removeGlobalOnLayoutListener(this);
                } else {
                  observer.removeOnGlobalLayoutListener(this);
                }
              }
            }
          });
    }

    this.addView(mLayout);
  }
예제 #21
0
  private void initViews() {
    mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation);
    mMaxHeaderElevation =
        getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation);

    mScrollView = (ObservableScrollView) getActivity().findViewById(R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
      vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }

    mScrollViewChild = getActivity().findViewById(R.id.scroll_view_child);
    mScrollViewChild.setVisibility(View.INVISIBLE);

    mDetailsContainer = getActivity().findViewById(R.id.details_container);
    mHeaderBox = getActivity().findViewById(R.id.header_session);
    mTitle = (TextView) getActivity().findViewById(R.id.session_title);
    mSubtitle = (TextView) getActivity().findViewById(R.id.session_subtitle);
    mPhotoViewContainer = getActivity().findViewById(R.id.session_photo_container);
    mPhotoView = (ImageView) getActivity().findViewById(R.id.session_photo);

    mAbstract = (TextView) getActivity().findViewById(R.id.session_abstract);

    mPlusOneIcon = (ImageView) getActivity().findViewById(R.id.gplus_icon_box);
    mTwitterIcon = (ImageView) getActivity().findViewById(R.id.twitter_icon_box);

    // Find view that shows a Videocam icon if the session is being live streamed.
    mLiveStreamVideocamIconAndText =
        (TextView) getActivity().findViewById(R.id.live_stream_videocam_icon_and_text);

    // Find view that shows a play button and some text for the user to watch the session live
    // stream.
    mLiveStreamPlayIconAndText =
        (TextView) getActivity().findViewById(R.id.live_stream_play_icon_and_text);

    mRequirements = (TextView) getActivity().findViewById(R.id.session_requirements);
    mTags = (LinearLayout) getActivity().findViewById(R.id.session_tags);
    mTagsContainer = (ViewGroup) getActivity().findViewById(R.id.session_tags_container);

    ViewCompat.setTransitionName(mPhotoView, SessionDetailConstants.TRANSITION_NAME_PHOTO);

    mAddScheduleButtonContainer = getActivity().findViewById(R.id.add_schedule_button_container);
    mAddScheduleButton =
        (CheckableFloatingActionButton) getActivity().findViewById(R.id.add_schedule_button);

    mNoPlaceholderImageLoader = new ImageLoader(getContext());
    mSpeakersImageLoader = new ImageLoader(getContext(), R.drawable.person_image_empty);
  }
예제 #22
0
  /** Runs runnable when the views getWidth() will not return 0 (after it is layed out) */
  public static void runWhenGetWidthWorks(final View view, final Runnable runnable) {
    ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();

    if (viewTreeObserver.isAlive()) {
      viewTreeObserver.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
              view.getViewTreeObserver().removeGlobalOnLayoutListener(this);

              runnable.run();
            }
          });
    }
  }
예제 #23
0
 /**
  * Add an OnGlobalLayoutListener for the view.
  *
  * <p>This is just a convenience method for using {@code
  * ViewTreeObserver.OnGlobalLayoutListener()}. This also handles removing listener when
  * onGlobalLayout is called.
  *
  * @param view The target view to add global layout listener.
  * @param runnable Runnable to be executed after the view is laid out.
  */
 public static void addOnGlobalLayoutListener(final View view, final Runnable runnable) {
   ViewTreeObserver vto = view.getViewTreeObserver();
   vto.addOnGlobalLayoutListener(
       new ViewTreeObserver.OnGlobalLayoutListener() {
         @SuppressWarnings("deprecation")
         @Override
         public void onGlobalLayout() {
           if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
             view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
           } else {
             view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
           }
           runnable.run();
         }
       });
 }
  @Override
  public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {
            createReveal(profile_image);
            view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });
    getView().setFocusableInTouchMode(true);
    getView().requestFocus();
    getView().setOnKeyListener(this);
  }
예제 #25
0
 public void moveToLeft() {
   if (getWidth() == 0 || getHeight() == 0) {
     final ViewTreeObserver observer = getViewTreeObserver();
     observer.addOnGlobalLayoutListener(
         new OnGlobalLayoutListener() {
           public void onGlobalLayout() {
             moveToLeft();
             getViewTreeObserver().removeOnGlobalLayoutListener(this);
           }
         });
   }
   final RectF edges = mTempEdges;
   getEdgesHelper(edges);
   final float scale = mRenderer.scale;
   mCenterX += Math.ceil(edges.left / scale);
   updateCenter();
 }
  private void initializeScrollForRtl() {
    final HorizontalScrollView scroll =
        (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);

    if (scroll.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
      final ViewTreeObserver observer = scroll.getViewTreeObserver();
      observer.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            public void onGlobalLayout() {
              LinearLayout masterWallpaperList =
                  (LinearLayout) findViewById(R.id.master_wallpaper_list);
              scroll.scrollTo(masterWallpaperList.getWidth(), 0);
              scroll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
          });
    }
  }
예제 #27
0
파일: ActjBox2d_1.java 프로젝트: xkp/XKP
 private void bindViews() {
   // TIPS: create an observer for notify layout updated
   layoutapplication = (XKPLayout) findViewById(R.id.layoutapplication);
   ViewTreeObserver mainLayoutViewTreeObserver = layoutapplication.getViewTreeObserver();
   if (mainLayoutViewTreeObserver.isAlive()) {
     mainLayoutViewTreeObserver.addOnGlobalLayoutListener(
         new OnGlobalLayoutListener() {
           @Override
           public void onGlobalLayout() {
             if (!mLayoutStarted) {
               mLayoutStarted = true;
               onLayoutStarted();
             }
             onLayoutUpdated();
           }
         });
   }
 }
예제 #28
0
  private void runLayoutListener() {
    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {

            ViewTreeObserver obs = view.getViewTreeObserver();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
              obs.removeOnGlobalLayoutListener(this);
            } else {
              obs.removeGlobalOnLayoutListener(this);
            }

            if (getActivity() == null) {
              return;
            }

            int newMenuTopViewHeight = view.findViewById(R.id.context_menu_top_view).getHeight();
            menuTopShadowHeight = view.findViewById(R.id.context_menu_top_shadow).getHeight();
            menuTopShadowAllHeight =
                view.findViewById(R.id.context_menu_top_shadow_all).getHeight();
            menuFullHeight = view.findViewById(R.id.context_menu_main).getHeight();

            int dy = 0;
            if (!menu.isLandscapeLayout() && menuTopViewHeight != 0) {
              dy = Math.max(0, newMenuTopViewHeight - menuTopViewHeight);
            }
            menuTopViewHeight = newMenuTopViewHeight;
            menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
            menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();

            menuFullHeightMax = menuTitleHeight + menuBottomViewHeight;

            if (origMarkerX == 0 && origMarkerY == 0) {
              origMarkerX = view.getWidth() / 2;
              origMarkerY = view.getHeight() / 2;
            }

            doLayoutMenu();
          }
        });
  }
  private void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    super.setOnScrollListener(this);

    // init header view
    mHeader = new XHeaderView(context);
    mHeaderContent = (RelativeLayout) mHeader.findViewById(R.id.header_content);
    mHeaderTime = (TextView) mHeader.findViewById(R.id.header_hint_time);
    addHeaderView(mHeader);

    // init footer view
    mFooterView = new XFooterView(context);
    mFooterLayout = new LinearLayout(context);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    mFooterLayout.addView(mFooterView, params);

    // init header height
    ViewTreeObserver observer = mHeader.getViewTreeObserver();
    if (null != observer) {
      observer.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation")
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onGlobalLayout() {
              mHeaderHeight = mHeaderContent.getHeight();
              ViewTreeObserver observer = getViewTreeObserver();

              if (null != observer) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  observer.removeGlobalOnLayoutListener(this);
                } else {
                  observer.removeOnGlobalLayoutListener(this);
                }
              }
            }
          });
    }
  }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_available, parent, false);
    ButterKnife.bind(this, view);

    mToggleBackgroundButton.setEnabled(false);
    mToggleForegroundButton.setEnabled(false);

    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            setState(mUser.isAvailable());
            mToggleBackgroundButton.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });

    return view;
  }