Example usage for android.view ViewTreeObserver addOnGlobalLayoutListener

List of usage examples for android.view ViewTreeObserver addOnGlobalLayoutListener

Introduction

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

Prototype

public void addOnGlobalLayoutListener(OnGlobalLayoutListener listener) 

Source Link

Document

Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes

Usage

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//from  www  . j a  va  2  s.c o  m
            public void onGlobalLayout() {
                circularRevealActivity(rootLayout);
                rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });
    }
}

From source file:org.iisgcp.waterwalk.fragment.AllRoutesFragment.java

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mAdapter = new AllRoutesAdapter(getActivity(), mImageFetcher, getListHeaders());

    mList.setAdapter(mAdapter);/*from w w  w  . j a  v a  2s .  co  m*/
    mList.setFastScrollEnabled(true);
    mList.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            RowItem rowItem = (RowItem) mAdapter.getChild(groupPosition, childPosition);

            Intent intent = new Intent(AllRoutesFragment.this.getActivity(),
                    PointOfInterestDetailActivity.class);
            intent.putExtra(Constants.INTENT_TITLE, rowItem.getTitle());
            intent.putExtra(Constants.INTENT_RES_ID, rowItem.getResId());
            intent.putExtra(Constants.INTENT_DRAWER_POSITION, 1);
            AllRoutesFragment.this.startActivity(intent);
            return false;
        }

    });

    ViewTreeObserver vto = mList.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
                mList.setIndicatorBounds(mList.getRight() - 70, mList.getWidth());
            } else {
                mList.setIndicatorBoundsRelative(mList.getRight() - 70, mList.getWidth());
            }
        }
    });
}

From source file:org.opensmc.mytracks.cyclesmc.ShowMap.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapview);/*from  ww  w  .  j a va 2  s  .c  o m*/

    try {
        if (mapTracks != null) {
            mapTracks.clear();
        } else {
            mapTracks = new ArrayList<Polyline>();
        }

        Bundle cmds = getIntent().getExtras();
        long tripid = cmds.getLong("showtrip");
        TripData trip = TripData.fetchTrip(this, tripid);

        // map bounds
        final LatLngBounds bounds = new LatLngBounds.Builder().include(new LatLng(trip.lathigh, trip.lgtlow))
                .include(new LatLng(trip.latlow, trip.lgthigh)).build();

        // check if already instantiated
        if (mMap == null) {
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
            layout = (LinearLayout) findViewById(R.id.LinearLayout01);
            ViewTreeObserver vto = layout.getViewTreeObserver();
            vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    // Center & zoom the map after map layout completes
                    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 5));
                }
            });
        } else {
            mMap.clear();
        }

        // check if got map
        if (mMap == null) {
            Log.d("Couldn't get map fragment!", "No map fragment");
            return;
        }

        // customize info window
        mMap.setInfoWindowAdapter(new BikeRackInfoWindow(getLayoutInflater()));

        // Show trip details
        TextView t1 = (TextView) findViewById(R.id.TextViewT1);
        TextView t2 = (TextView) findViewById(R.id.TextViewT2);
        TextView t3 = (TextView) findViewById(R.id.TextViewT3);
        t1.setText(trip.purp);
        t2.setText(trip.info);
        t3.setText(trip.fancystart);

        if (gpspoints == null) {
            AddPointsToMapLayerTask maptask = new AddPointsToMapLayerTask();
            maptask.execute(trip);
        } else {
            mapTracks.add(gpspoints);
        }

        if (trip.status < TripData.STATUS_SENT && cmds != null && cmds.getBoolean("uploadTrip", false)) {
            // And upload to the cloud database, too!  W00t W00t!
            TripUploader uploader = new TripUploader(ShowMap.this);
            uploader.execute(trip.tripid);
            Log.d("trip status", "status not sent!");
        } else {
            Log.d("trip status", "Status " + trip.status);

        }

    } catch (Exception e) {
        Log.d("Map error", e.toString(), e);
    }
}

From source file:gr.plushost.prototypeapp.widgets.LabelView.java

public void setTargetView(View target, int distance, Gravity gravity) {

    if (!replaceLayout(target)) {
        return;/* w w  w .j  av a  2 s  .com*/
    }

    final int d = dip2Px(distance);
    final Gravity g = gravity;
    final View v = target;

    ViewTreeObserver vto = getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < 16) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            calcOffset(getMeasuredWidth(), d, g, v.getMeasuredWidth(), false);
        }
    });

}

From source file:com.limewoodmedia.nsdroid.fragments.WACouncilFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.wa_council, null, false);
    atVote = (TextView) root.findViewById(R.id.at_vote_text);
    title = (TextView) root.findViewById(R.id.council_header);
    title.setText(legend != -1 ? legend : R.string.general_assembly);
    votes = (TextView) root.findViewById(R.id.at_vote_votes);
    below = (TextView) root.findViewById(R.id.at_vote_below);
    layout = (ViewGroup) root.findViewById(R.id.layout);
    ViewTreeObserver observer = title.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override/*from   w  w w. j  av  a 2 s .  c o m*/
        public void onGlobalLayout() {
            layout.setPadding(layout.getPaddingLeft(),
                    title.getHeight() - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15,
                            getResources().getDisplayMetrics()),
                    layout.getPaddingRight(), layout.getPaddingBottom());
        }
    });
    format.setMaximumFractionDigits(0);

    LoadingHelper.startLoading((com.limewoodmedia.nsdroid.views.LoadingView) root.findViewById(R.id.loading));

    return root;
}

From source file:com.ouyangzn.view.RefreshLayout.java

private void addHeaderView(final View view) {
    addView(view, 0);//from  www.  j ava2 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.limewoodmedia.nsdroid.fragments.IssuesFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.issues, null, false);
    list = (ListView) root.findViewById(R.id.issues_list);
    title = (TextView) root.findViewById(R.id.issues_title);
    title.setText(/*from  w  w w . ja  va 2  s.co  m*/
            getResources().getString(R.string.issues_title, NationInfo.getInstance(getActivity()).getName()));
    ViewTreeObserver observer = title.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            list.setPadding(list.getPaddingLeft(),
                    title.getHeight() - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15,
                            getResources().getDisplayMetrics()),
                    list.getPaddingRight(), list.getPaddingBottom());
        }
    });
    text = (TextView) root.findViewById(R.id.issues_text);
    text.setVisibility(View.GONE);

    issues = new ArrayList<Issue>();
    listAdapter = new ArrayAdapter<Issue>(context, 0, issues) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            TextView text;

            if (convertView == null) {
                view = inflater.inflate(R.layout.issue_list_item, null);
                text = (TextView) view.findViewById(R.id.issue_item);
                text.setMovementMethod(LinkMovementMethod.getInstance());
            } else {
                view = convertView;
                text = (TextView) view.findViewById(R.id.issue_item);
            }
            Issue issue = getItem(position);
            String txt = "&#8226; <a href=\"com.limewoodMedia.nsdroid.issue://" + issue.id + "\">" + issue.name
                    + "</a> ";
            text.setText(Html.fromHtml(txt));

            return view;
        }
    };
    list.setAdapter(listAdapter);

    return root;
}

From source file:io.lqd.sdk.visual.SlideUp.java

private void setUpSlideUp() {
    LayoutInflater layoutInflater = (LayoutInflater) mContext
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    container = (ViewGroup) layoutInflater.inflate(R.layout.activity_slide_up, null);
    TextView mViewMessage = (TextView) container.findViewById(R.id.slideUpText);

    Typeface RegularLato = Typeface.createFromAsset(mContext.getAssets(), "fonts/Lato-Regular.ttf");

    // Set the font
    mViewMessage.setTypeface(RegularLato);

    // Set the message
    mViewMessage.setText(mSlideModel.getMessage());

    // Change Background Color
    container.findViewById(R.id.lowest_layout).setBackgroundColor(Color.parseColor(mSlideModel.getBgColor()));

    // Change Text Color
    ((TextView) container.findViewById(R.id.slideUpText))
            .setTextColor(Color.parseColor(mSlideModel.getMessageColor()));

    // Get View's height depending on device
    final ViewTreeObserver observer = container.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*  ww  w.j a va2 s . com*/
        public void onGlobalLayout() {
            height = container.getHeight();
        }
    });

    mPopupWindow = new PopupWindow(container, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, true);

    mPopupWindow.setFocusable(false);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Liquid.getInstance().showInAppMessages();
        }
    });
}

From source file:pl.edu.agh.schedule.details.DetailFragment.java

private void initViews() {
    mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.detail_max_header_elevation);

    mScrollView = (ObservableScrollView) getActivity().findViewById(R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }/*w  w  w  .  ja  va2  s  .  c o  m*/

    mScrollViewChild = getActivity().findViewById(R.id.scroll_view_child);
    mScrollViewChild.setVisibility(View.INVISIBLE);

    mDetailsContainer = getActivity().findViewById(R.id.details_container);
    mHeaderBox = getActivity().findViewById(R.id.header_session);
    mTitle = (TextView) getActivity().findViewById(R.id.session_title);
    mPhotoViewContainer = getActivity().findViewById(R.id.session_photo_container);
    mPhotoView = (ImageView) getActivity().findViewById(R.id.session_photo);

    mAbstract = (TextView) getActivity().findViewById(R.id.session_abstract);

    ViewCompat.setTransitionName(mPhotoView, "photo");

    mNoPlaceholderImageLoader = new ImageLoader(getContext());
}

From source file:com.csusm.twinder.Fragment.QRScanFragment.java

private void onCreateDetector(@NonNull final View view) {
    final Context context = view.getContext().getApplicationContext();
    final BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
    barcodeDetector.setProcessor(new MultiProcessor.Builder<>(new MultiProcessor.Factory<Barcode>() {
        @Override/*  w w w  .  ja v  a 2  s.  c  o  m*/
        public Tracker<Barcode> create(final Barcode barcode) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mCallback.onScanComplete(barcode.displayValue);
                    mPreview.stop();

                    Intent intent = new Intent(getContext(), ScanSuccessActivity.class);
                    intent.putExtra("BARCODE", barcode.displayValue);

                    QRScanFragment.this.startActivity(intent);

                }
            });
            return new Tracker<>();
        }
    }).build());

    if (!barcodeDetector.isOperational()) {
        IntentFilter lowStorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        if (context.registerReceiver(null, lowStorageFilter) != null) {
            // Low storage
            mCallback.onCameraError(R.string.camera_error_low_storage);
        } else {
            // Native libs unavailable
            mCallback.onCameraError(R.string.camera_error_dependencies);
        }
        return;
    }

    final ViewTreeObserver observer = view.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            CameraSource.Builder builder = new CameraSource.Builder(context, barcodeDetector)
                    .setFacing(CameraSource.CAMERA_FACING_BACK)
                    .setRequestedPreviewSize(view.getMeasuredWidth(), view.getMeasuredHeight())
                    .setRequestedFps(30.0f);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                builder = builder.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
            }

            mCameraSource = builder.build();
            startCameraSource();
        }
    });
}