List of usage examples for android.view View getViewTreeObserver
public ViewTreeObserver getViewTreeObserver()
From source file:Main.java
private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer, final int targtetHeight) { setHeight(view, 0);// w w w . j av a 2s. co m view.setVisibility(View.VISIBLE); final Animation animation = new Animation() { private final Rect rect = new Rect(); private final Rect parentVisibleRect = new Rect(); ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener; private final Runnable checkViewRunnable = new Runnable() { @Override public void run() { checkForViewInsideVisibleArea(); } }; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); setHeight(view, neededHeight); final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); if (globalLayoutListener == null) { globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (globalLayoutListener == null) { removeGlobalLayoutListener(viewTreeObserver, this); } checkForViewInsideVisibleArea(); } }; viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener); } if (globalLayoutListener != null && interpolatedTime == 1) { runInUIThread(checkViewRunnable); globalLayoutListener = null; } view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } private void checkForViewInsideVisibleArea() { if (rootContainer.indexOfChild(parentView) == -1) { return; } parentVisibleRect.left = 0; parentVisibleRect.top = 0; parentVisibleRect.right = parentView.getWidth(); parentVisibleRect.bottom = parentView.getHeight(); rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect); if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) { rect.left = parentView.getLeft(); rect.top = parentView.getTop(); rect.right = parentView.getRight(); rect.bottom = parentView.getBottom(); parentView.requestRectangleOnScreen(rect, true); } } }; animation.setDuration(ANIMATION_DURATION); view.startAnimation(animation); }
From source file:com.example.mapdemo.LiteDemoActivity.java
/** * Called when the map is ready to add all markers and objects to the map. * * @param googleMap// w ww . j ava2s . c o m */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; addMarkers(); addPolyobjects(); final View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView(); if (mapView.getViewTreeObserver().isAlive()) { mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") // We use the new method when supported @SuppressLint("NewApi") // We check which build version we are using. @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } showAustralia(null); } }); } }
From source file:com.antonioleiva.materializeyourapp.DetailActivity.java
private void initScrollFade(final ImageView image) { final View scrollView = findViewById(R.id.scroll); setComponentsStatus(scrollView, image); scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override/*from w w w . ja v a2s. co m*/ public void onScrollChanged() { setComponentsStatus(scrollView, image); } }); }
From source file:de.janrenz.app.mediathek.RemoteImageCursorAdapter.java
@SuppressWarnings("deprecation") @Override// ww w. j a v a2 s .c o m public void bindView(View v, Context context, Cursor c) { String title = c.getString(c.getColumnIndexOrThrow("title")); String subtitle = c.getString(c.getColumnIndexOrThrow("subtitle")); String imagePath = c.getString(c.getColumnIndexOrThrow("image")); String startTime = c.getString(c.getColumnIndexOrThrow("startTime")); String startTimeAsTimestamp = c.getString(c.getColumnIndex("startTimeAsTimestamp")); String isLive = c.getString(c.getColumnIndex("isLive")); if (this.layout == R.layout.headline_item_grid) { final View vl = v; v.findViewById(R.id.thumbnail).getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { try { View imgView = vl.findViewById(R.id.thumbnail); imgView.getViewTreeObserver().removeGlobalOnLayoutListener(this); ViewGroup.LayoutParams layout = imgView.getLayoutParams(); layout.height = imgView.getWidth() / 16 * 9; imgView.setLayoutParams(layout); } catch (Exception e) { } } }); } /** * Next set the text of the entry. */ if (isLive.equalsIgnoreCase("true")) { v.findViewById(R.id.live).setVisibility(View.VISIBLE); //v.setBackgroundColor( context.getResources().getColor(R.color.highlight_live_list)); } else { v.findViewById(R.id.live).setVisibility(View.GONE); //v.setBackgroundColor( context.getResources().getColor(R.color.list_background)); } TextView title_text = (TextView) v.findViewById(R.id.text_view); if (title_text != null) { title_text.setText(title); } TextView subtitle_text = (TextView) v.findViewById(R.id.text_view_sub); if (subtitle_text != null) { subtitle_text.setText(subtitle); } TextView subtitle2_text = (TextView) v.findViewById(R.id.text_view_sub2); if (subtitle2_text != null) { Date dt = new Date(); // z.B. 'Fri Jan 26 19:03:56 GMT+01:00 2001' dt.setTime(Integer.parseInt(startTimeAsTimestamp) * 1000); dt.setHours(0); dt.setMinutes(0); dt.setSeconds(0); subtitle2_text.setText("ARD > " + startTime + " Uhr"); } /** * Set the image */ DisplayImageOptions loadingOptions = new DisplayImageOptions.Builder() ///.showStubImage(R.drawable.abs__item_background_holo_light) //.imageScaleType(ImageScaleType.EXACTLY) // .showImageForEmptyUri(R.drawable.ic_empty) // .memoryCache(new WeakMemoryCache()) .cacheInMemory() //.cacheOnDisc() .build(); ImageView image_view = (ImageView) v.findViewById(R.id.thumbnail); if (image_view != null) { if (this.layout == R.layout.headline_item_grid) { imagePath = imagePath + "/" + 320; } else { imagePath = imagePath + "/" + 150; } ImageLoader.getInstance().displayImage(imagePath, image_view, loadingOptions); } }
From source file:com.slx.funstream.ui.chat.SmileKeyboard.java
public void setSizeForSoftKeyboard() { View view = contentRoot.get(); view.getViewTreeObserver().addOnGlobalLayoutListener(() -> { Rect r = new Rect(); view.getWindowVisibleDisplayFrame(r); int screenHeight = view.getRootView().getHeight(); int heightDifference = screenHeight - (r.bottom - r.top); int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { heightDifference -= context.getResources().getDimensionPixelSize(resourceId); }/*w w w . j a v a 2 s . c om*/ if (heightDifference > 100) { softKeyBoardHeight = heightDifference - 150;// ~150 height of bottom buttons // if soft keyboard not displayed if (softKeyBoardHeight < 0) softKeyBoardHeight = 0; setSize(softKeyBoardHeight, LayoutParams.MATCH_PARENT); if (!isOpened) { if (onSoftKeyboardOpenCloseListener != null) onSoftKeyboardOpenCloseListener.onKeyboardOpen(softKeyBoardHeight); } isOpened = true; if (pendingOpen) { showAtBottom(); pendingOpen = false; } } else { isOpened = false; if (onSoftKeyboardOpenCloseListener != null) onSoftKeyboardOpenCloseListener.onKeyboardClose(); } }); }
From source file:org.cyanogenmod.designertools.ui.CreditsActivity.java
@Override protected void onResume() { super.onResume(); final View rootLayout = findViewById(R.id.activity_credits); rootLayout.setVisibility(View.INVISIBLE); ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override/*w w w . ja v a 2s . co m*/ public void onGlobalLayout() { circularRevealActivity(rootLayout); rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } }
From source file:com.vinidsl.googleioextended.ui.fragment.MapFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_map, container, false); piso1 = (TextView) rootView.findViewById(R.id.textViewFloorOne); piso2 = (TextView) rootView.findViewById(R.id.textViewFloorTwo); MapsInitializer.initialize(getActivity()); switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity())) { case ConnectionResult.SUCCESS: android.support.v4.app.FragmentManager myFM = getChildFragmentManager(); final SupportMapFragment myMAPF = (SupportMapFragment) myFM.findFragmentById(R.id.map); googlemap = myMAPF.getMap();/*from w w w . ja v a2 s . c o m*/ googlemap.setMyLocationEnabled(true); final View mapView = myFM.findFragmentById(R.id.map).getView(); if (mapView.getViewTreeObserver().isAlive()) { mapView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // TODO now can work with the map mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this); googlemap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(-16.500484, -68.134246), 25)); piso1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { piso1.setBackgroundColor(getResources().getColor(R.color.accent)); piso2.setBackgroundColor(getResources().getColor(R.color.white)); showFloorOne(); } }); piso2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { piso2.setBackgroundColor(getResources().getColor(R.color.accent)); piso1.setBackgroundColor(getResources().getColor(R.color.white)); showFloorTwo(); } }); type = PreferencesHelper.getInt(PreferencesHelper.MAP, getActivity()); PreferencesHelper.putInt(PreferencesHelper.MAP, 0, getActivity()); switch (type) { case 1: piso1.setBackgroundColor(getResources().getColor(R.color.accent)); piso2.setBackgroundColor(getResources().getColor(R.color.white)); showFloorOne(); break; case 2: piso2.setBackgroundColor(getResources().getColor(R.color.accent)); piso1.setBackgroundColor(getResources().getColor(R.color.white)); showFloorTwo(); break; case 3: piso2.setBackgroundColor(getResources().getColor(R.color.accent)); piso1.setBackgroundColor(getResources().getColor(R.color.white)); showFloorTwo(); break; } } }); } break; case ConnectionResult.SERVICE_MISSING: // Todo install google play services break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: // Todo go to playstore to upload google play services break; default: // Todo some error happends try again later } return rootView; }
From source file:net.iubris.ulysses.map.asynctask.PopulateMapAsyncTask.java
protected void autoZoom(final LatLngBounds latLngBounds) { final View mapView = ((FragmentActivity) context).getSupportFragmentManager() .findFragmentById(mapFragmentResId).getView(); if (mapView.getViewTreeObserver().isAlive()) { mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @SuppressLint("NewApi") // We check which build version we are using. @Override/*from w w w . ja v a 2 s .com*/ public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } map.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, LATLNG_BOUNDS_PADDING)); } }); } }
From source file:com.ouyangzn.view.RefreshLayout.java
private void addHeaderView(final View view) { addView(view, 0);/* w w w. ja v a 2 s .c o m*/ final ViewTreeObserver observer = view.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mHeaderHeight = view.getHeight(); } }); }
From source file:com.learn.mobile.customview.henrytao.BaseBehavior.java
private void initViewTreeObserver(final CoordinatorLayout coordinatorLayout, final AppBarLayout child, final View target) { log("initViewTreeObserver"); target.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override/*from w ww . j a v a 2 s . c o m*/ public void onScrollChanged() { if (target == BaseBehavior.this.vScrollTarget) { BaseBehavior.this.onScrollChanged(coordinatorLayout, child, target, target.getScrollY() - getCurrentScrollOffset()); } } }); }