List of usage examples for android.view ViewTreeObserver removeOnGlobalLayoutListener
public void removeOnGlobalLayoutListener(OnGlobalLayoutListener victim)
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); }//www. ja va 2 s. c om 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:ca.zadrox.dota2esportticker.ui.LiveContentView.java
@Override protected void onDestroy() { super.onDestroy(); if (mGameUpdaterRunnable != null) { mHandler.removeCallbacks(mGameUpdaterRunnable); }//ww w .j a v a2s. c o m if (mGameResultRunnable != null) { mHandler.removeCallbacks(mGameResultRunnable); } if (mScrollView == null) { return; } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.removeOnGlobalLayoutListener(mGlobalLayoutListener); } }
From source file:com.saulcintero.moveon.fragments.Summary1.java
private void fitMapToMarkers() { final BoundingBoxE6 mOverlayItemsBounds = BoundingBoxE6.fromGeoPoints(gPointsList); if (mapView.getHeight() > 0) { mapView.zoomToBoundingBox(mOverlayItemsBounds); } else {//w w w . j a v a 2 s. c o m ViewTreeObserver vto1 = mapView.getViewTreeObserver(); vto1.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { mapView.zoomToBoundingBox(mOverlayItemsBounds); ViewTreeObserver vto2 = mapView.getViewTreeObserver(); vto2.removeOnGlobalLayoutListener(this); } }); } }
From source file:ca.zadrox.dota2esportticker.ui.MatchDetailActivity.java
@Override protected void onDestroy() { super.onDestroy(); if (mScrollView == null) { return;//from ww w .ja v a 2 s. c o m } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.removeOnGlobalLayoutListener(mGlobalLayoutListener); } }
From source file:com.italankin.dictionary.ui.main.MainActivity.java
private void setupInputLayout() { mInputLayout.setOnClickListener(new View.OnClickListener() { @Override//from w w w. jav a2 s. c om public void onClick(View v) { mInput.requestFocus(); mInputManager.showSoftInput(mInput, 0); } }); ViewTreeObserver vto = mInputLayout.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= 16) { ViewTreeObserver vto = mInputLayout.getViewTreeObserver(); vto.removeOnGlobalLayoutListener(this); } updateInputLayoutPosition(); } }); mInput.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { lookupNext(mInput.getText().toString()); return true; } return false; } }); }
From source file:org.puder.trs80.EmulatorActivity.java
private void initKeyboardView() { stopAccelerometer();//from w w w .j av a2 s.co m keyboardContainer = (ViewGroup) findViewById(R.id.keyboard_container); keyboardContainer.removeAllViews(); final KeyboardLayout keyboardType = getKeyboardType(); showKeyboardHint(keyboardType); if (keyboardType == KEYBOARD_GAME_CONTROLLER || keyboardType == KEYBOARD_EXTERNAL) { keyboardContainer.getRootView().findViewById(R.id.switch_keyboard).setVisibility(View.GONE); return; } keyboardContainer.getRootView().findViewById(R.id.switch_keyboard).setVisibility(View.VISIBLE); // if (android.os.Build.VERSION.SDK_INT >= // Build.VERSION_CODES.HONEYCOMB) { // root.setMotionEventSplittingEnabled(true); // } currentHardware.computeKeyDimensions(windowRect, getKeyboardType()); int layoutId = 0; switch (keyboardType) { case KEYBOARD_LAYOUT_COMPACT: layoutId = R.layout.keyboard_compact; break; case KEYBOARD_LAYOUT_ORIGINAL: layoutId = R.layout.keyboard_original; break; case KEYBOARD_LAYOUT_JOYSTICK: layoutId = R.layout.keyboard_joystick; break; case KEYBOARD_TILT: layoutId = R.layout.keyboard_tilt; break; } getLayoutInflater().inflate(layoutId, keyboardContainer, true); /* * The following code is a hack to work around a problem with the * keyboard layout in Android. The second keyboard should have * visibility GONE initially when the keyboard layout is inflated. * However, doing so messes up the layout of the second keyboard * (R.id.keyboard_view_2). This does not happen when visibility is * VISIBLE. So, to work around this issue, the initial visibility in the * keyboard layout is VISIBLE and we use a layout listener to make it * GONE after the layout has been computed and just before it will be * rendered. */ ViewTreeObserver vto = keyboardContainer.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { View kb2 = keyboardContainer.findViewById(R.id.keyboard_view_2); if (kb2 != null) { kb2.setVisibility(View.GONE); } ViewTreeObserver obs = keyboardContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obs.removeGlobalOnLayoutListener(this); } } }); keyboardContainer.requestLayout(); if (keyboardType == KEYBOARD_TILT) { startAccelerometer(); } }
From source file:org.ciasaboark.tacere.activity.fragment.EventsFragment.java
private void showFirstRunWizardIfNeeded() { if (prefs.isFirstRun()) { prefs.disableFirstRun();/*from w w w . j a va 2 s . c o m*/ final ViewTreeObserver viewTreeObserver = ((Activity) context).getWindow().getDecorView() .getViewTreeObserver(); viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (!showingTutorial) { showingTutorial = true; startActivity(new Intent(context.getApplicationContext(), TutorialActivity.class)); } if (viewTreeObserver.isAlive()) { if (Build.VERSION.SDK_INT >= 16) { viewTreeObserver.removeOnGlobalLayoutListener(this); } else { viewTreeObserver.removeGlobalOnLayoutListener(this); } } } }); } }
From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override//from w ww . j a v a 2 s . c o m public void onDestroyView() { super.onDestroyView(); if (mScrollView == null) { return; } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { //noinspection deprecation if (UIUtils.hasJellyBean()) { vto.removeOnGlobalLayoutListener(mGlobalLayoutListener); } else { vto.removeGlobalOnLayoutListener(mGlobalLayoutListener); } } }
From source file:com.miz.functions.MizLib.java
/** * Helper method to remove a ViewTreeObserver correctly, i.e. * avoiding the deprecated method on API level 16+. * @param vto// ww w . java2s . c om * @param victim */ @SuppressWarnings("deprecation") public static void removeViewTreeObserver(ViewTreeObserver vto, OnGlobalLayoutListener victim) { if (MizLib.hasJellyBean()) { vto.removeOnGlobalLayoutListener(victim); } else { vto.removeGlobalOnLayoutListener(victim); } }
From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java
/** * Removes global layout listener added in {@link #addGlobalLayoutListener()}. *//* ww w .j a v a 2s . c om*/ private void removeGlobalLayoutListener() { final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver(); if (viewTreeObserver.isAlive()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { viewTreeObserver.removeOnGlobalLayoutListener(mGlobalLayoutListener); } else { //noinspection deprecation viewTreeObserver.removeGlobalOnLayoutListener(mGlobalLayoutListener); } } }