List of usage examples for android.view ViewTreeObserver removeOnGlobalLayoutListener
public void removeOnGlobalLayoutListener(OnGlobalLayoutListener victim)
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 2s . 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(); }// w w w. ja 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 ww w. j a va 2 s. c o 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(); }/*from w w w. j a v a2 s . co m*/ 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 ww. jav a 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// ww w.ja v a 2 s. c om 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//ww w . j a v a 2 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() { 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); }
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 ww w .ja v a 2s .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)); } 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.openbmap.activities.WifiDetailsMap.java
/** * Initializes map components// w ww .j a v a2s .c om */ @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: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 w w.java 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; } }); }