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:com.example.google.maps.folding_map.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    // Map can be null if there is a Google Play services issue.
    if (mMap != null) {
        // Wait until the map has loaded before we allow it to be folded.
        mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
            @Override// www .  j  av a2  s .  com
            public void onMapLoaded() {
                mMapAction.setEnabled(true);
            }
        });
    }

    mFoldingLayout = (FoldingLayout) findViewById(R.id.folding_layout);

    // Wait until the FoldingLayout has be laid out; it needs dimensions.
    mFoldingLayout.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @SuppressWarnings("deprecation")
                @SuppressLint("NewApi")
                @Override
                public void onGlobalLayout() {
                    mFoldingLayout.setNumberOfFolds(3);
                    mFoldingLayout.setBackgroundColor(Color.BLACK);
                    mFoldingLayout.setFoldListener(MainActivity.this);

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

    mImageView = (ImageView) findViewById(R.id.image_view);
}

From source file:com.wenhui.syncedListView.demo.demo.SyncListViewContainerFragment.java

private void removeGlobalLayoutListenerWrapper(ViewTreeObserver observer, OnGlobalLayoutListener listener) {
    if (Build.VERSION.SDK_INT >= 16) {
        observer.removeOnGlobalLayoutListener(listener);
    } else {// w  w  w  .  java2 s.  c o  m
        observer.removeGlobalOnLayoutListener(listener);
    }
}

From source file:com.abcs.haiwaigou.yyg.view.ReadMoreTextView.java

private void onGlobalLayoutLineEndIndex() {
    if (trimMode == TRIM_MODE_LINES) {
        getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override//w  w  w  .  j av  a 2s.  c o m
            public void onGlobalLayout() {
                ViewTreeObserver obs = getViewTreeObserver();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    obs.removeOnGlobalLayoutListener(this);
                } else {
                    obs.removeGlobalOnLayoutListener(this);
                }
                refreshLineEndIndex();
                setText();
            }
        });
    }
}

From source file:com.androcast.illusion.illusionmod.fragments.BaseFragment.java

public void onViewCreated(View view, Bundle saved) {
    super.onViewCreated(view, saved);
    final ViewTreeObserver observer = view.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                    observer.removeOnGlobalLayoutListener(this);
                else
                    observer.removeGlobalOnLayoutListener(this);

                onViewCreated();/* ww  w  . j  a  v a  2 s.  c o m*/
            } catch (Exception ignored) {
            }
        }
    });
}

From source file:com.nexa.cityseason.fragment.HotelDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
    if (getActivity() instanceof RootActivity) {
        activity = (RootActivity) getActivity();
    }/*from  www .  j  a  v a  2 s .c  o m*/

    super.onCreate(savedInstanceState);
    View rootView = inflater.inflate(R.layout.fragment_hotel_details, container, false);

    mContext = container.getContext();

    mStickyView = (RelativeLayout) rootView.findViewById(R.id.sticky);
    FontHelper.applyFont(mContext, mStickyView, "fonts/GothamRnd-Medium.otf");

    //   mStickyView.setText("aa");

    mListView = (ListView) rootView.findViewById(R.id.listView);

    mItemTop = rootView.findViewById(R.id.itemTop);

    //LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.fragment_roomsuies_top_layout, null);

    mPlaceholderView = v.findViewById(R.id.placeholder);
    mListView.addHeaderView(v);

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            onScrollChanged();

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

    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            onScrollChanged();
        }
    });

    // Create and set the adapter for the listView.
    SimpleAdapter simpleAdpt = new HotelDetailsAdapter(mContext, createListViewData(), R.layout.list_item,
            new String[] { "item" }, new int[] { R.id.txtTitle });
    mListView.setAdapter(simpleAdpt);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {

            openFragment(position);
        }
    });

    return rootView;
}

From source file:com.nexa.cityseason.fragment.RoomDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
    if (getActivity() instanceof RootActivity) {
        activity = (RootActivity) getActivity();
    }/*from   w ww  .  j  a  v  a 2s .co  m*/

    super.onCreate(savedInstanceState);
    View rootView = inflater.inflate(R.layout.fragment_room_details, container, false);

    mContext = container.getContext();

    mStickyView = (RelativeLayout) rootView.findViewById(R.id.sticky);
    FontHelper.applyFont(mContext, mStickyView, "fonts/GothamRnd-Medium.otf");

    //   mStickyView.setText("aa");

    mListView = (ListView) rootView.findViewById(R.id.listView);

    mItemTop = rootView.findViewById(R.id.itemTop);

    //LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.fragment_room_toplayout, null);

    mPlaceholderView = v.findViewById(R.id.placeholder);
    mListView.addHeaderView(v);

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            onScrollChanged();

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

    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            onScrollChanged();
        }
    });

    // Create and set the adapter for the listView.
    //SimpleAdapter simpleAdpt = new RoomDetailsAdapter(mContext, createListViewData(), R.layout.fragment_room_details_item, new String[] {"item"}, new int[] {R.id.txtSamle});      

    RoomDetailsAdapter simpleAdpt = new RoomDetailsAdapter(mContext, createListViewData());
    mListView.setAdapter(simpleAdpt);

    /*mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            
       @Override
       public void onItemClick(AdapterView<?> parent, final View view,
       int position, long id) {
            
    openFragment(position);
       }
    });
     */

    return rootView;
}

From source file:com.nexa.cityseason.fragment.ResturantDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
    if (getActivity() instanceof RootActivity) {
        activity = (RootActivity) getActivity();
    }//w  w  w .jav  a 2  s  . c om

    super.onCreate(savedInstanceState);
    View rootView = inflater.inflate(R.layout.fragment_resturant_details, container, false);

    mContext = container.getContext();

    mStickyView = (RelativeLayout) rootView.findViewById(R.id.sticky);
    FontHelper.applyFont(mContext, mStickyView, "fonts/GothamRnd-Medium.otf");

    //   mStickyView.setText("aa");

    mListView = (ListView) rootView.findViewById(R.id.listView);

    mItemTop = rootView.findViewById(R.id.itemTop);

    //LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.fragment_resturant_toplayout, null);

    mPlaceholderView = v.findViewById(R.id.placeholder);
    mListView.addHeaderView(v);

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            onScrollChanged();

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

    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            onScrollChanged();
        }
    });

    // Create and set the adapter for the listView.
    //SimpleAdapter simpleAdpt = new RoomDetailsAdapter(mContext, createListViewData(), R.layout.fragment_room_details_item, new String[] {"item"}, new int[] {R.id.txtSamle});      

    ResturantDetailsAdapter simpleAdpt = new ResturantDetailsAdapter(mContext, createListViewData());
    mListView.setAdapter(simpleAdpt);

    /*mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            
       @Override
       public void onItemClick(AdapterView<?> parent, final View view,
       int position, long id) {
            
    openFragment(position);
       }
    });
     */

    return rootView;
}

From source file:com.nexa.cityseason.fragment.FacilityDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
    if (getActivity() instanceof RootActivity) {
        activity = (RootActivity) getActivity();
    }/*from   w  w w .j  a va  2 s .c o  m*/

    super.onCreate(savedInstanceState);
    View rootView = inflater.inflate(R.layout.fragment_faicility_details, container, false);

    mContext = container.getContext();

    mStickyView = (RelativeLayout) rootView.findViewById(R.id.sticky);
    FontHelper.applyFont(mContext, mStickyView, "fonts/GothamRnd-Medium.otf");

    //   mStickyView.setText("aa");

    mListView = (ListView) rootView.findViewById(R.id.listView);

    mItemTop = rootView.findViewById(R.id.itemTop);

    //LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.fragment_facility_details_toplayout, null);

    mPlaceholderView = v.findViewById(R.id.placeholder);
    mListView.addHeaderView(v);

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            onScrollChanged();

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

    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            onScrollChanged();
        }
    });

    // Create and set the adapter for the listView.
    //SimpleAdapter simpleAdpt = new RoomDetailsAdapter(mContext, createListViewData(), R.layout.fragment_room_details_item, new String[] {"item"}, new int[] {R.id.txtSamle});      

    FacilityDetailsAdapter simpleAdpt = new FacilityDetailsAdapter(mContext, createListViewData());
    mListView.setAdapter(simpleAdpt);

    /*mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            
       @Override
       public void onItemClick(AdapterView<?> parent, final View view,
       int position, long id) {
            
    openFragment(position);
       }
    });
     */

    return rootView;
}

From source file:com.trellmor.mocklocationpicture.MLPActivity.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override//w  w  w  .  ja  v  a2s. c  o  m
public void onGlobalLayout() {
    ViewTreeObserver obs = mImagePreview.getViewTreeObserver();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        obs.removeOnGlobalLayoutListener(this);
    } else {
        obs.removeGlobalOnLayoutListener(this);
    }

    if (mImageUri != null) {
        setImageUri(mImageUri);
    }
}

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

/**
 * Initializes map components/*from w ww .ja  va 2 s .  com*/
 */
@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() {

            mLayoutInflated = 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.mMapObserver = new Observer() {
        @Override
        public void onChange() {

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

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

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

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