Example usage for android.view ViewGroup indexOfChild

List of usage examples for android.view ViewGroup indexOfChild

Introduction

In this page you can find the example usage for android.view ViewGroup indexOfChild.

Prototype

public int indexOfChild(View child) 

Source Link

Document

Returns the position in the group of the specified child view.

Usage

From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java

private void updateHeaderAmPm() {
    if (mIs24HourView) {
        mAmPmLayout.setVisibility(View.GONE);
    } else {/*from ww  w  .j a v a  2 s  .co  m*/
        // Ensure that AM/PM layout is in the correct position.
        final String dateTimePattern = getBestTimePattern(mCurrentLocale, false);
        final boolean amPmAtStart = dateTimePattern.startsWith("a");
        final ViewGroup parent = (ViewGroup) mAmPmLayout.getParent();
        final int targetIndex = amPmAtStart ? 0 : parent.getChildCount() - 1;
        final int currentIndex = parent.indexOfChild(mAmPmLayout);
        if (targetIndex != currentIndex) {
            parent.removeView(mAmPmLayout);
            parent.addView(mAmPmLayout, targetIndex);
        }

        updateAmPmLabelStates(mInitialHourOfDay < 12 ? AM : PM);
    }
}

From source file:com.androzic.MapFragment.java

private void onUpdateNavigationState() {
    boolean isNavigating = application.navigationService != null
            && application.navigationService.isNavigating();
    boolean isNavigatingViaRoute = isNavigating && application.navigationService.isNavigatingViaRoute();

    View rootView = getView();/*from   w  ww. j a va 2  s.c o m*/

    // waypoint panel
    rootView.findViewById(R.id.waypointinfo).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // route panel
    rootView.findViewById(R.id.routeinfo).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);
    // distance
    distanceValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    rootView.findViewById(R.id.distancelt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // bearing
    bearingValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    rootView.findViewById(R.id.bearinglt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // turn
    turnValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    rootView.findViewById(R.id.turnlt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // xtk
    xtkValue.setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);
    rootView.findViewById(R.id.xtklt).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);

    // we hide elevation in portrait mode due to lack of space
    if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        if (isNavigatingViaRoute && elevationValue.getVisibility() == View.VISIBLE) {
            elevationValue.setVisibility(View.GONE);
            rootView.findViewById(R.id.elevationlt).setVisibility(View.GONE);

            ViewGroup row = (ViewGroup) rootView.findViewById(R.id.movingrow);
            int pos = row.indexOfChild(elevationValue);
            View xtklt = rootView.findViewById(R.id.xtklt);
            row.removeView(xtkValue);
            row.removeView(xtklt);
            row.addView(xtklt, pos);
            row.addView(xtkValue, pos);
            row.getParent().requestLayout();
        } else if (!isNavigatingViaRoute && elevationValue.getVisibility() == View.GONE) {
            elevationValue.setVisibility(View.VISIBLE);
            rootView.findViewById(R.id.elevationlt).setVisibility(View.VISIBLE);

            ViewGroup row = (ViewGroup) rootView.findViewById(R.id.movingrow);
            int pos = row.indexOfChild(xtkValue);
            View elevationlt = rootView.findViewById(R.id.elevationlt);
            row.removeView(elevationValue);
            row.removeView(elevationlt);
            row.addView(elevationlt, pos);
            row.addView(elevationValue, pos);
            row.getParent().requestLayout();
        }
    }

    if (isNavigatingViaRoute) {
        routeName.setText("\u21d2 " + application.navigationService.navRoute.name);
    }
    if (isNavigating) {
        waypointName.setText("\u2192 " + application.navigationService.navWaypoint.name);
    }

    updateMapViewArea();
    map.refreshMap();
}

From source file:net.gaast.giggity.ScheduleViewActivity.java

public void finishNavDrawer() {
    if (sched == null) {
        Log.e("finishNavDrawer", "Called before critical was loaded?");
        return;//from  ww  w.  j a v  a  2  s.c  o  m
    }

    LinkedList<Date> days = sched.getDays();
    TextView dr = (TextView) drawerLayout.findViewById(R.id.date_range);
    dr.setText(Giggity.dateRange(days.getFirst(), days.getLast()));

    if (sched.getLinks() != null) {
        ViewGroup menu = (LinearLayout) drawerLayout.findViewById(R.id.menu);
        View sep = menu.findViewById(R.id.custom_sep);
        sep.setVisibility(View.VISIBLE);
        for (final Schedule.Link link : sched.getLinks()) {
            TextView item = (TextView) getLayoutInflater().inflate(R.layout.burger_menu_item, null);
            item.setText(link.getTitle());
            item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    openLink(link, true);
                    drawerLayout.closeDrawers();
                }
            });
            menu.addView(item, menu.indexOfChild(sep));
        }
    }
}

From source file:com.androzic.MapActivity.java

protected void updateNavigationStatus() {
    boolean isNavigating = navigationService != null && navigationService.isNavigating();
    boolean isNavigatingViaRoute = isNavigating && navigationService.isNavigatingViaRoute();

    // waypoint panel
    findViewById(R.id.waypointinfo).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // route panel
    findViewById(R.id.routeinfo).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);
    // distance/*from  w w  w .ja  v a 2s .c  o  m*/
    distanceValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    findViewById(R.id.distancelt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // bearing
    bearingValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    findViewById(R.id.bearinglt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // turn
    turnValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    findViewById(R.id.turnlt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // xtk
    xtkValue.setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);
    findViewById(R.id.xtklt).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);

    // we hide elevation in portrait mode due to lack of space
    if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        if (isNavigatingViaRoute && elevationValue.getVisibility() == View.VISIBLE) {
            elevationValue.setVisibility(View.GONE);
            findViewById(R.id.elevationlt).setVisibility(View.GONE);

            ViewGroup row = (ViewGroup) findViewById(R.id.movingrow);
            int pos = row.indexOfChild(elevationValue);
            View xtklt = findViewById(R.id.xtklt);
            row.removeView(xtkValue);
            row.removeView(xtklt);
            row.addView(xtklt, pos);
            row.addView(xtkValue, pos);
            row.getParent().requestLayout();
        } else if (!isNavigatingViaRoute && elevationValue.getVisibility() == View.GONE) {
            elevationValue.setVisibility(View.VISIBLE);
            findViewById(R.id.elevationlt).setVisibility(View.VISIBLE);

            ViewGroup row = (ViewGroup) findViewById(R.id.movingrow);
            int pos = row.indexOfChild(xtkValue);
            View elevationlt = findViewById(R.id.elevationlt);
            row.removeView(elevationValue);
            row.removeView(elevationlt);
            row.addView(elevationlt, pos);
            row.addView(elevationValue, pos);
            row.getParent().requestLayout();
        }
    }

    if (isNavigatingViaRoute) {
        routeName.setText(" " + navigationService.navRoute.name);
    }
    if (isNavigating) {
        waypointName.setText(" " + navigationService.navWaypoint.name);
        if (application.navigationOverlay == null) {
            application.navigationOverlay = new NavigationOverlay(this);
            application.navigationOverlay.onMapChanged();
        }
    } else if (application.navigationOverlay != null) {
        application.navigationOverlay.onBeforeDestroy();
        application.navigationOverlay = null;
    }

    updateMapViewArea();
    map.update();
}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void restoreLayouts() {
    if (root != null) {
        ViewGroup wrapper = (ViewGroup) root.findViewById(R.id.detail_wrapper);
        if (root.indexOfChild(keyboardPlaceholder) != -1) {
            root.removeView(keyboardPlaceholder);
        }//from w w w. ja  v  a 2  s  .com
        keyboardPlaceholder = null;
        if (wrapper.indexOfChild(timestampsView) == -1) {
            wrapper.addView(timestampsView);
        }
    }
}

From source file:com.android.launcher2.Launcher.java

public void showFirstRunWorkspaceCling() {
    // Enable the clings only if they have not been dismissed before
    if (isClingsEnabled() && !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)
            && !skipCustomClingIfNoAccounts()) {
        // If we're not using the default workspace layout, replace workspace cling
        // with a custom workspace cling (usually specified in an overlay)
        // For now, only do this on tablets
        if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0
                && getResources().getBoolean(R.bool.config_useCustomClings)) {
            // Use a custom cling
            View cling = findViewById(R.id.workspace_cling);
            ViewGroup clingParent = (ViewGroup) cling.getParent();
            int clingIndex = clingParent.indexOfChild(cling);
            clingParent.removeViewAt(clingIndex);
            View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
            clingParent.addView(customCling, clingIndex);
            customCling.setId(R.id.workspace_cling);
        }//from   w w w.j  av a  2s .c  om
        initCling(R.id.workspace_cling, null, false, 0);
    } else {
        removeCling(R.id.workspace_cling);
    }
}

From source file:com.simas.vc.editor.player.PlayerFragment.java

void toggleFullscreen() {
    // Disable touch listener (to prevent multiple toggles until done)
    getContainer().setOnTouchListener(null);
    final ViewGroup root = (ViewGroup) getActivity().findViewById(android.R.id.content);
    final View progressOverlay = (getActivity() instanceof MainActivity)
            ? ((MainActivity) getActivity()).getProgressOverlay()
            : null;/*from   w  ww. ja  va  2  s  .  com*/
    if (progressOverlay != null) {
        progressOverlay.setVisibility(View.VISIBLE);
        ViewGroup progressParent = (ViewGroup) progressOverlay.getParent();
        if (progressParent != null) {
            progressParent.removeView(progressOverlay);
        }
    }

    // Toggle state
    mFullscreen = !isFullscreen();

    if (isFullscreen()) {
        // Add preview to the root view
        if (progressOverlay != null) {
            root.addView(progressOverlay);
        }

        // All APIs can go fullscreen
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Low profile is only for APIs 14+
        if (Build.VERSION.SDK_INT >= 14) {
            // Enable the low profile mode
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        }

    } else {
        // Add preview to the default parent
        if (mDefaultContainerParent != null && progressOverlay != null) {
            mDefaultContainerParent.addView(progressOverlay);
        }

        // All APIs can go fullscreen
        getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Low profile is only for APIs 14+
        if (Build.VERSION.SDK_INT >= 14) {
            // Remove low profile
            getActivity().getWindow().getDecorView().setSystemUiVisibility(ViewGroup.SYSTEM_UI_FLAG_VISIBLE);
        }
    }

    final Runnable changeContainerParent = new Runnable() {
        @Override
        public void run() {
            // Hide surface view while doing all the work, this is to make sure it's not being re-drawn
            mSurfaceView.setVisibility(View.GONE);

            // Controls should be hidden while working
            final boolean controlsWereShown = getControls().isShown();
            getControls().hide();

            // Video should be paused while working
            boolean playing = false;
            if (getPlayer().getState() == Player.State.STARTED) {
                // Pause if started
                playing = true;
                getPlayer().pause();
            }
            final boolean wasPlaying = playing;

            // Expand or collapse the PlayerView
            if (isFullscreen()) {
                // Save current params
                mDefaultContainerParams = new ViewGroup.LayoutParams(getContainer().getLayoutParams());

                // Remove from current parent
                mDefaultContainerParent = (ViewGroup) getContainer().getParent();
                mDefaultContainerParent.removeView(getContainer());

                // Set new params
                ViewGroup.LayoutParams params = getContainer().getLayoutParams();
                params.width = LinearLayout.LayoutParams.MATCH_PARENT;
                params.height = LinearLayout.LayoutParams.MATCH_PARENT;

                // Re-measure the SurfaceView
                invalidateSurface();

                // Add to the root view before the progressOverlay (if it's added)
                int progressIndex = root.indexOfChild(progressOverlay);
                root.addView(getContainer(), progressIndex);
                getContainer().requestFocus();
            } else {
                if (mDefaultContainerParams != null && mDefaultContainerParent != null) {
                    // Remove from current parent
                    ((ViewGroup) getContainer().getParent()).removeView(getContainer());

                    // Restore params
                    getContainer().setLayoutParams(mDefaultContainerParams);

                    // Re-measure the SurfaceView
                    invalidateSurface();

                    // Add as the first child to the default parent
                    mDefaultContainerParent.addView(getContainer(), 0);
                }
            }

            getContainer().post(new Runnable() {
                @Override
                public void run() {
                    mSurfaceView.setVisibility(View.VISIBLE);
                    // Check if fragment and player data sources match
                    if (getItem() != null
                            && getItem().getFile().getPath().equals(getPlayer().getDataSource())) {
                        switch (getPlayer().getState()) {
                        case PAUSED:
                        case PREPARED:
                        case STARTED:
                            if (wasPlaying) {
                                getPlayer().start();
                            } else {
                                updatePreview();
                            }
                            break;
                        }
                    } else {
                        setPreviewVisible(true);
                    }
                    if (controlsWereShown) {
                        getControls().show();
                    }
                    if (progressOverlay != null) {
                        progressOverlay.setVisibility(View.INVISIBLE);
                    }
                    // Re-enable touch listener
                    getContainer().post(new Runnable() {
                        @Override
                        public void run() {
                            getContainer().setOnTouchListener(PlayerFragment.this);
                        }
                    });
                }
            });
        }
    };

    if (getPlayer().getState() == Player.State.PREPARING) {
        getPlayer().addOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                changeContainerParent.run();
            }
        });
    } else {
        changeContainerParent.run();
    }
}

From source file:com.android.soma.Launcher.java

public void showFirstRunCling() {
    if (isClingsEnabled() && !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false)
            && !skipCustomClingIfNoAccounts()) {
        // If we're not using the default workspace layout, replace workspace cling
        // with a custom workspace cling (usually specified in an overlay)
        // For now, only do this on tablets
        if (!DISABLE_CUSTOM_CLINGS) {
            if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0
                    && getResources().getBoolean(R.bool.config_useCustomClings)) {
                // Use a custom cling
                View cling = findViewById(R.id.workspace_cling);
                ViewGroup clingParent = (ViewGroup) cling.getParent();
                int clingIndex = clingParent.indexOfChild(cling);
                clingParent.removeViewAt(clingIndex);
                View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
                clingParent.addView(customCling, clingIndex);
                customCling.setId(R.id.workspace_cling);
            }//from   w w w . j  a v a2  s.  c o  m
        }
        Cling cling = (Cling) findViewById(R.id.first_run_cling);
        if (cling != null) {
            String sbHintStr = getFirstRunClingSearchBarHint();
            String ccHintStr = getFirstRunCustomContentHint();
            if (!sbHintStr.isEmpty()) {
                TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
                sbHint.setText(sbHintStr);
                sbHint.setVisibility(View.VISIBLE);
            }
            setCustomContentHintVisibility(cling, ccHintStr, true, false);
        }
        initCling(R.id.first_run_cling, 0, false, true);
    } else {
        removeCling(R.id.first_run_cling);
    }
}