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:com.desno365.mods.Tabs.FragmentTab4.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab4, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_turrets_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.turrets.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.turrets_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.turrets.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.turrets_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.turrets.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab4); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w ww  . j  a  v  a  2s. com*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab5.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab5, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_jukebox_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.jukebox.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.jukebox_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.jukebox.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.jukebox_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.jukebox.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab5); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from   w ww .  jav  a 2  s  . c  o m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab6.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab6, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_guns_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.desnoGuns.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.guns_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.desnoGuns.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.guns_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.desnoGuns.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab6); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  w w .j  a va2 s .  com*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab7.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab7, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_unreal_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.unreal.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.unreal_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.unreal.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.unreal_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.unreal.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab7); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/*from  www . j a  v a2s. c o  m*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:io.digibyte.presenter.fragments.FragmentTransactionDetails.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ViewTreeObserver observer = txViewPager.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//from   w  w w .  ja v  a 2 s .  c  o  m
        public void onGlobalLayout() {
            observer.removeGlobalOnLayoutListener(this);
            BRAnimator.animateBackgroundDim(backgroundLayout, false);
            BRAnimator.animateSignalSlide(txViewPager, false, null);
        }
    });

}

From source file:desipride.socialshaadi.shadiviews.EventsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.event_list, container, false);

    parentRelativeLayout = (RelativeLayout) view.findViewById(R.id.events_container);
    ViewTreeObserver vto = parentRelativeLayout.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(this);

    recyclerEventView = (RecyclerView) view.findViewById(R.id.eventlist);
    recyclerEventView.setHasFixedSize(true);

    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerEventView.setLayoutManager(llm);

    ArrayList<Event> eventList = EventData.getEvents(getActivity());
    EventAdapter eventAdapter = new EventAdapter(eventList, getActivity());
    recyclerEventView.setAdapter(eventAdapter);
    recyclerEventView.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
                @Override/*w  ww.ja v  a 2  s.  c om*/
                public void onItemClick(View view, int position) {
                    Intent i = new Intent(getActivity(), EventActivity.class);
                    i.putExtra(EventActivity.EVENT_INDEX, position);
                    startActivity(i);
                }
            }));

    return view;
}

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

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.regional_happenings, null, false);
    title = (TextView) root.findViewById(R.id.regional_happenings_header);
    list = (ListView) root.findViewById(R.id.regional_happenings_list);
    layout = (ViewGroup) root.findViewById(R.id.layout);
    ViewTreeObserver observer = title.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override/* www . j av a2 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());
        }
    });

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

            if (convertView == null) {
                view = inflater.inflate(R.layout.event, null);
                msg = (TextView) view.findViewById(R.id.event_message);
                msg.setMovementMethod(LinkMovementMethod.getInstance());
            } else {
                view = convertView;
                msg = (TextView) view.findViewById(R.id.event_message);
            }
            RegionHappening event = getItem(position);
            long timestamp = event.timestamp;
            String time = TagParser.parseTimestamp(getContext(), timestamp);
            String text = time + ": " + event.text;
            //              text = text.replaceAll("@@([a-z\\d_]+)@@",
            //                    "<a href=\"com.limewoodMedia.nsdroid.nation://$1\">$1</a>");
            //              text = text.replaceAll("%%([a-z\\d_]+)%%",
            //                    "<a href=\"com.limewoodMedia.nsdroid.region://$1\">$1</a>");
            msg.setText(Html.fromHtml(text));

            return view;
        }
    };
    list.setAdapter(listAdapter);
    LoadingHelper.startLoading((com.limewoodmedia.nsdroid.views.LoadingView) root.findViewById(R.id.loading));

    return root;
}

From source file:com.unipiazza.material2stepslogin.fragments.SecondStepFragment.java

@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override//  w  w w  . ja  va2 s .com
        public void onGlobalLayout() {
            createReveal(profile_image);
            view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
    getView().setFocusableInTouchMode(true);
    getView().requestFocus();
    getView().setOnKeyListener(this);
}

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

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.national_happenings, null, false);
    list = (ListView) root.findViewById(R.id.national_happenings_list);
    layout = (ViewGroup) root.findViewById(R.id.layout);
    title = (TextView) root.findViewById(R.id.national_happenings_header);
    ViewTreeObserver observer = title.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override//  ww  w.j  a v  a 2 s. co  m
        public void onGlobalLayout() {
            layout.setPadding(layout.getPaddingLeft(),
                    title.getHeight() - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15,
                            getResources().getDisplayMetrics()),
                    layout.getPaddingRight(), layout.getPaddingBottom());
        }
    });

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

            if (convertView == null) {
                view = inflater.inflate(R.layout.event, null);
                msg = (TextView) view.findViewById(R.id.event_message);
                msg.setMovementMethod(LinkMovementMethod.getInstance());
            } else {
                view = convertView;
                msg = (TextView) view.findViewById(R.id.event_message);
            }
            NationHappening event = getItem(position);
            long timestamp = event.timestamp;
            String time = TagParser.parseTimestamp(getContext(), timestamp);
            String text = time + ": " + event.text;
            //             text = text.replaceAll("@@("+nation.toLowerCase().replace(' ', '_')+")@@",
            //                    "<a href=\"com.limewoodMedia.nsdroid.nation://$1\">"+nation+"</a>");
            //             text = text.replaceAll("@@([a-z\\d_]+)@@",
            //                    "<a href=\"com.limewoodMedia.nsdroid.nation://$1\">$1</a>");
            //             text = text.replaceAll("%%("+region.toLowerCase().replace(' ', '_')+")%%",
            //                    "<a href=\"com.limewoodMedia.nsdroid.region://$1\">"+region+"</a>");
            //              text = text.replaceAll("%%([a-z\\d_]+)%%",
            //                    "<a href=\"com.limewoodMedia.nsdroid.region://$1\">$1</a>");
            //              text = text.replaceAll("%%([a-z\\d_]+)%rmb%%",
            //                    "<a href=\"com.limewoodMedia.nsdroid.region.rmb://$1\">Regional Message Board</a>");
            msg.setText(Html.fromHtml(text));

            return view;
        }
    };
    list.setAdapter(listAdapter);
    LoadingHelper.startLoading((com.limewoodmedia.nsdroid.views.LoadingView) root.findViewById(R.id.loading));

    return root;
}

From source file:com.tobrun.vision.qr.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. jav  a2s  .  co  m
        public Tracker<Barcode> create(final Barcode barcode) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mCallback.onScanComplete(barcode.displayValue);
                    mPreview.stop();
                }
            });
            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();
        }
    });
}