Example usage for android.view ViewTreeObserver removeGlobalOnLayoutListener

List of usage examples for android.view ViewTreeObserver removeGlobalOnLayoutListener

Introduction

In this page you can find the example usage for android.view ViewTreeObserver removeGlobalOnLayoutListener.

Prototype

@Deprecated
public void removeGlobalOnLayoutListener(OnGlobalLayoutListener victim) 

Source Link

Document

Remove a previously installed global layout callback

Usage

From source file:org.openbmap.activities.WifiDetailsMap.java

/**
 * Initializes map components//w  w w.j  a v  a2  s  .  c o m
 */
@SuppressLint("NewApi")
private void initMap() {
    this.mTileCache = createTileCache();

    if (MapUtils.isMapSelected(this.getActivity())) {
        final Layer offlineLayer = MapUtils.createTileRendererLayer(this.mTileCache,
                this.mMapView.getModel().mapViewPosition, getMapFile(), null, getRenderTheme());
        if (offlineLayer != null)
            this.mMapView.getLayerManager().getLayers().add(offlineLayer);
    } else {
        //this.mMapView.getModel().displayModel.setBackgroundColor(0xffffffff);
        Toast.makeText(this.getActivity(), R.string.info_using_online_map, Toast.LENGTH_LONG).show();

        final OnlineTileSource onlineTileSource = new OnlineTileSource(
                new String[] { "otile1.mqcdn.com", "otile2.mqcdn.com", "otile3.mqcdn.com", "otile4.mqcdn.com" },
                80);
        onlineTileSource.setName("MapQuest").setAlpha(false).setBaseUrl("/tiles/1.0.0/map/").setExtension("png")
                .setParallelRequestsLimit(8).setProtocol("http").setTileSize(256).setZoomLevelMax((byte) 18)
                .setZoomLevelMin((byte) 0);

        mapDownloadLayer = new TileDownloadLayer(mTileCache, mMapView.getModel().mapViewPosition,
                onlineTileSource, AndroidGraphicFactory.INSTANCE);
        mMapView.getLayerManager().getLayers().add(mapDownloadLayer);
        mapDownloadLayer.onResume();
    }

    // register for layout finalization - we need this to get width and height
    final ViewTreeObserver vto = mMapView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {

            layoutInflated = true;
            proceedAfterHeatmapCompleted();

            final ViewTreeObserver obs = mMapView.getViewTreeObserver();

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

    // Register for zoom changes
    this.mapObserver = new Observer() {
        @Override
        public void onChange() {

            final byte newZoom = mMapView.getModel().mapViewPosition.getZoomLevel();
            if (newZoom != currentZoom) {
                // update overlays on zoom level changed
                Log.i(TAG, "New zoom level " + newZoom + ", reloading map objects");
                Log.i(TAG, "Update" + updatePending);
                // cancel pending heat-maps
                //if (builder != null) {
                //   builder.cancel(true);
                //}

                // if another update is pending, wait for complete
                if (!updatePending) {
                    clearLayer();
                    proceedAfterHeatmapCompleted();
                }
                currentZoom = newZoom;
            }
        }
    };
    this.mMapView.getModel().mapViewPosition.addObserver(mapObserver);

    this.mMapView.setClickable(true);
    this.mMapView.getMapScaleBar().setVisible(true);

    /*
       Layers layers = layerManager.getLayers();
       // remove all layers including base layer
       layers.clear();
     */

    this.mMapView.getModel().mapViewPosition.setZoomLevel((byte) 16);

}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@Override
public void onDestroyView() {
    super.onDestroyView();
    if (mScrollView == null) {
        return;/*  w  w w .j  a  va  2 s . co  m*/
    }

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

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
    Resources res = activity.getResources();
    int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android");
    int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android");
    int navBarHeight = 0;

    if (navBarIdentifier > 0) {
        navBarHeight = res.getDimensionPixelSize(navBarIdentifier);
    }//from  w  w w .j ava 2s. com

    if (!bottomBar.drawBehindNavBar() || navBarHeight == 0
            || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && ViewConfiguration.get(activity).hasPermanentMenuKey()) {
        return;
    }

    /**
     * Copy-paste coding made possible by:
     * http://stackoverflow.com/a/14871974/940036
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = activity.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;

        if (!hasSoftwareKeys) {
            return;
        }
    }
    /**
     * End of delicious copy-paste code
     */

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

        if (bottomBar.useTopOffset()) {
            int offset;
            int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android");

            if (statusBarResource > 0) {
                offset = res.getDimensionPixelSize(statusBarResource);
            } else {
                offset = MiscUtils.dpToPixel(activity, 25);
            }

            if (!bottomBar.useOnlyStatusbarOffset()) {
                TypedValue tv = new TypedValue();
                if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                    offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics());
                } else {
                    offset += MiscUtils.dpToPixel(activity, 56);
                }
            }

            bottomBar.getUserContainer().setPadding(0, offset, 0, 0);
        }

        final View outerContainer = bottomBar.getOuterContainer();
        final int navBarHeightCopy = navBarHeight;
        bottomBar.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        bottomBar.shyHeightAlreadyCalculated();

                        int newHeight = outerContainer.getHeight() + navBarHeightCopy;
                        outerContainer.getLayoutParams().height = newHeight;

                        if (bottomBar.isShy()) {
                            int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0;
                            bottomBar.setTranslationY(defaultOffset);
                            ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams())
                                    .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

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

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

/**
 * This method is used to setup the various object configurations
 *
 * @param context      can be also referenced through {@link #getContext()}
 * @param keyboardRows//w  ww. ja  va 2s. co  m
 */
private void initialize(Context context, List<KeyboardRow> keyboardRows) {
    mKeyboardRows = keyboardRows;
    verifyInitMode();
    mActivity = (Activity) context;
    mWindow = mActivity.getWindow();
    mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    setOrientation(VERTICAL);
    setVisibility(GONE);
    setWillNotDraw(true);
    setBackgroundColor(Color.parseColor("#a1a6aa"));

    //mCharTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/nyala.ttf");
    mRootView = (ViewGroup) mWindow.getDecorView().findViewById(android.R.id.content);
    mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            ViewTreeObserver viewTreeObserver = mRootView.getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    viewTreeObserver.removeOnGlobalLayoutListener(this);
                } else {
                    viewTreeObserver.removeGlobalOnLayoutListener(this);
                }
            }
            createKeyboard(mKeyboardRows);
        }
    });
    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Consume event[intercept touch for not letting pass and click views under the keyboard]
            return true;
        }
    });
}

From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
    Resources res = activity.getResources();
    int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android");
    int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android");
    int navBarHeight = 0;

    if (navBarIdentifier > 0) {
        navBarHeight = res.getDimensionPixelSize(navBarIdentifier);
    }/*  w  w  w .j ava  2 s  .  c  o m*/

    if (!bottomBar.drawBehindNavBar() || navBarHeight == 0
            || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && ViewConfiguration.get(activity).hasPermanentMenuKey()) {
        return;
    }

    /**
     * Copy-paste coding made possible by:
     * http://stackoverflow.com/a/14871974/940036
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = activity.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;

        if (!hasSoftwareKeys) {
            return;
        }
    }
    /**
     * End of delicious copy-paste code
     */

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

        if (bottomBar.useTopOffset()) {
            int offset;
            int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android");

            if (statusBarResource > 0) {
                offset = res.getDimensionPixelSize(statusBarResource);
            } else {
                offset = MiscUtils.dpToPixel(activity, 25);
            }

            if (!bottomBar.useOnlyStatusbarOffset()) {
                TypedValue tv = new TypedValue();
                if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                    offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics());
                } else {
                    offset += MiscUtils.dpToPixel(activity, 56);
                }
            }

            bottomBar.getUserContainer().setPadding(0, offset, 0, 0);
        }

        final View outerContainer = bottomBar.getOuterContainer();
        final int navBarHeightCopy = navBarHeight;
        bottomBar.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        bottomBar.shyHeightAlreadyCalculated();

                        int newHeight = outerContainer.getHeight() + navBarHeightCopy;
                        outerContainer.getLayoutParams().height = newHeight;

                        if (bottomBar.isShy()) {
                            int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0;
                            bottomBar.setTranslationY(defaultOffset);
                            ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams())
                                    .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset,
                                            bottomBar.isShy(), bottomBar.mIsTabletMode));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

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

From source file:fr.rolandl.smartshareactionprovider.SmartActivityChooserView.java

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    SmartActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        dataModel.unregisterObserver(mModelDataSetOberver);
    }//from w  w  w  . j av  a  2 s.  co m
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    if (isShowingPopup()) {
        dismissPopup();
    }
    mIsAttachedToWindow = false;
}

From source file:com.example.FilteredActivityChooserView.java

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    FilteredActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        dataModel.unregisterObserver(mModelDataSetOberver);
    }// w  w  w  .j  a va  2s  .c o m
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    if (isShowingPopup()) {
        dismissPopup();
    }
    mIsAttachedToWindow = false;
}

From source file:com.google.samples.apps.iosched.session.SessionDetailFragment.java

@Override
public void onDestroy() {
    super.onDestroy();
    if (mScrollView == null) {
        return;/*w  w  w . j a  va 2s  .c  om*/
    }

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

From source file:android.support.v7.internal.widget.ActivityChooserView.java

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    ActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        dataModel.unregisterObserver(mModelDataSetOberver);
    }//  w  w w  .j  a  v a 2  s. c om
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    if (isShowingPopup()) {
        dismissPopup();
    }
    mIsAttachedToWindow = false;
}

From source file:com.actionbarsherlock.widget.ActivityChooserView.java

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    ActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        dataModel.unregisterObserver(mModelDataSetOberver);
    }//from   ww  w  . j a  v  a  2s  . c  o m
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    mIsAttachedToWindow = false;
}