public void testRemoveOnGlobalFocusChangeListener() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
    final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
    final ListView lv2 = (ListView) mActivity.findViewById(R.id.listview2);

    mViewTreeObserver = layout.getViewTreeObserver();
    MockOnGlobalFocusChangeListener listener = new MockOnGlobalFocusChangeListener();
    mViewTreeObserver.addOnGlobalFocusChangeListener(listener);
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            layout.requestChildFocus(lv1, lv2);
          }
        });
    mInstrumentation.waitForIdleSync();
    assertTrue(listener.hasCalledOnGlobalFocusChanged());

    listener.reset();
    mViewTreeObserver.removeOnGlobalFocusChangeListener(listener);
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            layout.requestChildFocus(lv1, lv2);
          }
        });
    mInstrumentation.waitForIdleSync();
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder viewHolder;
    if (convertView == null) {
      LayoutInflater mInflater =
          (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
      convertView = mInflater.inflate(R.layout.specimen_list_item, null);
      viewHolder = new ViewHolder();
      viewHolder.specimenImageView = (ImageView) convertView.findViewById(R.id.specimen_image);
      viewHolder.specimenTitleView = (TextView) convertView.findViewById(R.id.specimen_title);
      viewHolder.specimenScientificName = (TextView) convertView.findViewById(R.id.scientific_name);
      viewHolder.specimenLocality = (TextView) convertView.findViewById(R.id.specimen_locality);
      viewHolder.specimenDescription =
          (TextView) convertView.findViewById(R.id.specimen_description);
      viewHolder.itemLocatedView = (ImageView) convertView.findViewById(R.id.item_located);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    final SpecimenListItem specimenListItem = objects.get(position);
    if (specimenListItem.getImagePath() == null) {
      viewHolder.specimenImageView.setImageResource(specimenListItem.getSpecimenImage());
    } else {
      final ViewTreeObserver vto = viewHolder.specimenImageView.getViewTreeObserver();
      if (vto.isAlive()) {
        vto.addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
              public boolean onPreDraw() {
                if (vto.isAlive()) {
                  vto.removeOnPreDrawListener(this);
                }
                thumbnailHeight = viewHolder.specimenImageView.getMeasuredHeight();
                thumbnailWidth = viewHolder.specimenImageView.getMeasuredWidth();
                if (cancelPotentialWork(
                    specimenListItem.getImagePath(), viewHolder.specimenImageView)) {
                  final LoadThumbnailTask loadThumbnailTask =
                      new LoadThumbnailTask(viewHolder.specimenImageView);
                  final AsyncDrawable asyncDrawable =
                      new AsyncDrawable(resources, bitmapPlaceHolder, loadThumbnailTask);
                  viewHolder.specimenImageView.setImageDrawable(asyncDrawable);
                  thumbnailWidth = viewHolder.specimenImageView.getMeasuredWidth();
                  loadThumbnailTask.execute(specimenListItem.getImagePath());
                }
                return true;
              }
            });
      }
    }
    viewHolder.specimenTitleView.setText(specimenListItem.getSpecimenTitle());
    viewHolder.specimenScientificName.setText(specimenListItem.getScientificName());
    viewHolder.specimenLocality.setText(specimenListItem.getSpecimenLocality());
    viewHolder.specimenDescription.setText(specimenListItem.getSpecimenDescription());
    viewHolder.itemLocatedView.setSelected(specimenListItem.isLocated());
    if (onClickListener != null) {
      viewHolder.specimenImageView.setOnClickListener(onClickListener);
    }

    return convertView;
  }
  @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);
  }
示例#4
0
 void getSize(SizeReadyCallback cb) {
   int currentWidth = getViewWidthOrParam();
   int currentHeight = getViewHeightOrParam();
   if (isSizeValid(currentWidth) && isSizeValid(currentHeight)) {
     int paddingAdjustedWidth =
         currentWidth == WindowManager.LayoutParams.WRAP_CONTENT
             ? currentWidth
             : currentWidth - ViewCompat.getPaddingStart(view) - ViewCompat.getPaddingEnd(view);
     int paddingAdjustedHeight =
         currentHeight == LayoutParams.WRAP_CONTENT
             ? currentHeight
             : currentHeight - view.getPaddingTop() - view.getPaddingBottom();
     cb.onSizeReady(paddingAdjustedWidth, paddingAdjustedHeight);
   } else {
     // We want to notify callbacks in the order they were added and we only expect one or two
     // callbacks to
     // be added a time, so a List is a reasonable choice.
     if (!cbs.contains(cb)) {
       cbs.add(cb);
     }
     if (layoutListener == null) {
       final ViewTreeObserver observer = view.getViewTreeObserver();
       layoutListener = new SizeDeterminerLayoutListener(this);
       observer.addOnPreDrawListener(layoutListener);
     }
   }
 }
    @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.
    }
 /** 填充数据 */
 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);
         }
       });
 }
  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);
          }
        });
  }
  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();
            }
          }
        });
  }
示例#9
0
  /**
   * Update the Start/Stop text. The button is within a view group with a transition that is needed
   * to animate the button moving. The transition also animates the the text changing, but that
   * animation does not provide a good look and feel. Temporarily disable the view group transition
   * while the text is changing and restore it afterwards.
   *
   * @param parent - View Group holding the start/stop button
   * @param textView - The start/stop button
   * @param text - Start or Stop id
   */
  private void setStartStopText(final ViewGroup parent, TextView textView, int text) {
    final LayoutTransition layoutTransition = parent.getLayoutTransition();
    // Tap into the parent layout->draw flow just before the draw
    ViewTreeObserver viewTreeObserver = parent.getViewTreeObserver();
    if (viewTreeObserver != null) {
      viewTreeObserver.addOnPreDrawListener(
          new ViewTreeObserver.OnPreDrawListener() {
            /**
             * Re-establish the transition handler Remove this listener
             *
             * @return true so that onDraw() is called
             */
            @Override
            public boolean onPreDraw() {
              parent.setLayoutTransition(layoutTransition);
              ViewTreeObserver viewTreeObserver = parent.getViewTreeObserver();
              if (viewTreeObserver != null) {
                viewTreeObserver.removeOnPreDrawListener(this);
              }
              return true;
            }
          });
    }
    // Remove the transition while the text is updated
    parent.setLayoutTransition(null);

    String textStr = getActivity().getResources().getString(text);
    textView.setText(textStr);
    textView.setContentDescription(textStr);
  }
示例#10
0
  private void initFloatingWindow() {
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mWindow = PolicyManager.makeNewWindow(mContext);
    mWindow.setWindowManager(mWindowManager, null, null);
    mWindow.requestFeature(Window.FEATURE_NO_TITLE);
    mDecor = mWindow.getDecorView();

    /// M: Get measured height of window and update. @{
    ViewTreeObserver vto = mDecor.getViewTreeObserver();
    vto.addOnPreDrawListener(
        new ViewTreeObserver.OnPreDrawListener() {
          public boolean onPreDraw() {
            mHeight = mDecor.getMeasuredHeight();
            updateFloatingWindowLayout();
            mWindowManager.updateViewLayout(mDecor, mDecorLayoutParams);
            mDecor.getViewTreeObserver().removeOnPreDrawListener(this);
            return true;
          }
        });
    /// @}

    mDecor.setOnTouchListener(mTouchListener);
    mWindow.setContentView(this);
    mWindow.setBackgroundDrawableResource(android.R.color.transparent);

    // While the media controller is up, the volume control keys should
    // affect the media stream type
    mWindow.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    setFocusable(true);
    setFocusableInTouchMode(true);
    setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    requestFocus();
  }
  @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);
          }
        });
  }
  @Test
  public void destroy_shouldCallClear_shouldRemoveListenerFromDecorView() throws Exception {
    Activity activity1 = mock(Activity.class);
    Window window = mock(Window.class);
    View decorView = mock(View.class);
    ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);

    when(activity1.getWindow()).thenReturn(window);
    when(window.getDecorView()).thenReturn(decorView);
    when(decorView.getViewTreeObserver()).thenReturn(viewTreeObserver);
    when(viewTreeObserver.isAlive()).thenReturn(true);

    subject = new VisibilityTracker(activity1, trackedViews, visibilityChecker, visibilityHandler);

    subject.addView(view, MIN_PERCENTAGE_VIEWED);
    subject.addView(view2, MIN_PERCENTAGE_VIEWED);
    assertThat(trackedViews).hasSize(2);

    subject.destroy();

    assertThat(trackedViews).isEmpty();
    verify(visibilityHandler).removeMessages(0);
    verify(viewTreeObserver).removeOnPreDrawListener(any(OnPreDrawListener.class));
    assertThat(subject.mOnPreDrawListener).isNull();
  }
示例#13
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();
 }
  /** 设置头部的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);
          }
        });
  }
示例#15
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);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collage_editor);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(getString(R.string.interstitial_ad_unit_id));

    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);

    Intent i = getIntent();
    imgid = i.getIntExtra("frameId", 0);
    typeId = i.getIntExtra("typeId", 0);

    imgBackground = (ImageView) findViewById(R.id.imgBackground);
    imgBackground.setBackgroundResource(imgid);

    ViewTreeObserver vto = imgBackground.getViewTreeObserver();
    //        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    //            @SuppressLint("NewApi")
    //            @SuppressWarnings("deprecation")
    //            @Override
    //            public void onGlobalLayout() {
    //                imgBackgroundWidth = imgBackground.getWidth();
    //                imgBackgroundHeight = imgBackground.getHeight();
    //                GenerateUI();
    //
    //                if (android.os.Build.VERSION.SDK_INT >=
    // android.os.Build.VERSION_CODES.JELLY_BEAN)
    //                    imgBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    //                else
    //                    imgBackground.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    //
    //
    //            }
    //        });

    vto.addOnPreDrawListener(
        new ViewTreeObserver.OnPreDrawListener() {
          public boolean onPreDraw() {
            imgBackgroundWidth = imgBackground.getWidth();
            imgBackgroundHeight = imgBackground.getHeight();
            GenerateUI();

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
              imgBackground.getViewTreeObserver().removeOnPreDrawListener(this);
            else imgBackground.getViewTreeObserver().removeOnPreDrawListener(this);

            return true;
          }
        });

    collageEditorRelativeLayout = (RelativeLayout) findViewById(R.id.collageEditorRelativeLayout);
  }
示例#17
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);
          }
        });
  }
示例#18
0
  /**
   * Clean-up the resources attached to this object. This needs to be called when the ImageView is
   * no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or from
   * {@link android.app.Activity#onDestroy()}. This is automatically called if you are using {@link
   * uk.co.senab.photoview.PhotoView}.
   */
  @SuppressWarnings("deprecation")
  public void cleanup() {
    if (null != mImageView) {
      // Remove this as a global layout listener
      ViewTreeObserver observer = mImageView.getViewTreeObserver();
      if (null != observer && observer.isAlive()) {
        observer.removeGlobalOnLayoutListener(this);
      }

      // Remove the ImageView's reference to this
      mImageView.setOnTouchListener(null);

      // make sure a pending fling runnable won't be run
      cancelFling();
    }

    if (null != mGestureDetector) {
      mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
  }
示例#19
0
  private void initView() {

    textView = (TextView) findViewById(R.id.textview);
    ViewTreeObserver treeObserver = textView.getViewTreeObserver();
    treeObserver.addOnPreDrawListener(
        new ViewTreeObserver.OnPreDrawListener() {
          @Override
          public boolean onPreDraw() {
            if (!hasMeasure) {
              maxLines = textView.getLineCount();
              textView.setMaxLines(MAX);
              hasMeasure = true;
            }
            return true;
          }
        });

    textView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            toggle();
          }
        });
  }
  private void fixLayout() {
    ViewTreeObserver obs = fragmentView.getViewTreeObserver();
    obs.addOnPreDrawListener(
        new ViewTreeObserver.OnPreDrawListener() {
          @Override
          public boolean onPreDraw() {
            if (fragmentView == null) {
              return true;
            }
            fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
            LinearLayout layout = (LinearLayout) fragmentView;
            WindowManager manager =
                (WindowManager)
                    ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
            int rotation = manager.getDefaultDisplay().getRotation();

            if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
              layout.setOrientation(LinearLayout.HORIZONTAL);
            } else {
              layout.setOrientation(LinearLayout.VERTICAL);
            }

            fragmentView.setPadding(
                fragmentView.getPaddingLeft(),
                0,
                fragmentView.getPaddingRight(),
                fragmentView.getPaddingBottom());
            return true;
          }
        });
  }
示例#21
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);
            }
          });
    }
  }
示例#22
0
 @Override
 protected void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   final ViewTreeObserver treeObserver = getViewTreeObserver();
   if (treeObserver != null) {
     treeObserver.removeOnTouchModeChangeListener(this);
   }
 }
示例#23
0
 @Override
 protected void onAttachedToWindow() {
   super.onAttachedToWindow();
   final ViewTreeObserver treeObserver = getViewTreeObserver();
   if (treeObserver != null) {
     treeObserver.addOnTouchModeChangeListener(this);
   }
 }
 private void unregisterListener() {
   if (mSuperScrollListener != null && mViewTreeObserver != null) {
     if (mViewTreeObserver.isAlive()) {
       mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
     }
     mViewTreeObserver = null;
   }
 }
示例#25
0
 public void onDismiss() {
   mPopup = null;
   mMenu.close();
   if (mTreeObserver != null) {
     if (!mTreeObserver.isAlive()) mTreeObserver = mAnchorView.getViewTreeObserver();
     mTreeObserver.removeGlobalOnLayoutListener(this);
     mTreeObserver = null;
   }
 }
  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());
  }
示例#27
0
 private void removeObserverForView(final View view) {
   final ViewTreeObserver treeObserver = view.getViewTreeObserver();
   if (treeObserver != null && treeObserver.isAlive()) {
     if (TiC.JELLY_BEAN_OR_GREATER) {
       treeObserver.removeOnGlobalLayoutListener(this);
     } else {
       treeObserver.removeGlobalOnLayoutListener(this);
     }
   }
 }
 /**
  * Dismisses the popup window with activities.
  *
  * @return True if dismissed, false if already dismissed.
  */
 public boolean dismissPopup() {
   if (isShowingPopup()) {
     getListPopupWindow().dismiss();
     ViewTreeObserver viewTreeObserver = getViewTreeObserver();
     if (viewTreeObserver.isAlive()) {
       viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
     }
   }
   return true;
 }
示例#29
0
 /** 删除监听器 */
 @SuppressWarnings("deprecation")
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 public static final void removeOnGlobalLayoutListener(
     ViewTreeObserver viewTreeObserver,
     ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener) {
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
     viewTreeObserver.removeGlobalOnLayoutListener(onGlobalLayoutListener);
   } else {
     viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener);
   }
 }
  @Override
  public void onDestroy() {
    super.onDestroy();
    if (mScrollView == null) {
      return;
    }

    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
      vto.removeGlobalOnLayoutListener(mGlobalLayoutListener);
    }
  }