Java Code Examples for android.view.ViewGroup#indexOfChild()

The following examples show how to use android.view.ViewGroup#indexOfChild() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xposed-rimet   File: SettingsPlugin.java    License: Apache License 2.0 6 votes vote down vote up
private void onHnalderSettings(Activity activity) {

        View view = activity.findViewById(ResourceUtil.getId(activity, "setting_msg_notice"));
        ViewGroup viewGroup = (ViewGroup) view.getParent();

        final int index = viewGroup.indexOfChild(view);

        SimpleItemView viewDing = new SimpleItemView(activity);
        viewDing.getNameView().setTextSize(17);
        viewDing.setName(Constant.Name.TITLE);
        viewDing.setExtend("v" + BuildConfig.VERSION_NAME);
        viewDing.setOnClickListener(v -> {
            // 打开设置
            openSettings(activity);
        });
        viewGroup.addView(viewDing, index);
    }
 
Example 2
/**
 * Set the content view to an explicit view. If the content view was installed earlier,
 * the content will be replaced with a new view.
 *
 * @param view The desired content to display. Value can't be null.
 * @see #setContentView(int)
 * @see #getContentView()
 */
public void setContentView(View view) {
    ensureContent();
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        if (mContentView == null) {
            contentContainer.addView(view);
        } else {
            int index = contentContainer.indexOfChild(mContentView);
            // replace content view
            contentContainer.removeView(mContentView);
            contentContainer.addView(view, index);
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}
 
Example 3
@Override
public void onPlayerError(ExoPlaybackException error) {
    Throwable cause = error.getCause();
    if (textureView != null && cause instanceof SurfaceNotValidException) {
        if (player != null) {
            ViewGroup parent = (ViewGroup) textureView.getParent();
            if (parent != null) {
                int i = parent.indexOfChild(textureView);
                parent.removeView(textureView);
                parent.addView(textureView,i);
            }
            player.clearVideoTextureView(textureView);
            player.setVideoTextureView(textureView);
            if (loopingMediaSource) {
                preparePlayerLoop(videoUri, videoType, audioUri, audioType);
            } else {
                preparePlayer(videoUri, videoType);
            }
            play();
        }
    } else {
        delegate.onError(this, error);
    }
}
 
Example 4
Source Project: StatusView   File: StatusView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 用 StatusView 替换要使用多状态布局的 View
 */
private static StatusView init(View contentView) {
    if (contentView == null) {
        throw new RuntimeException("ContentView can not be null!");
    }
    ViewGroup parent = (ViewGroup) contentView.getParent();
    if (parent == null) {
        throw new RuntimeException("ContentView must have a parent view!");
    }
    ViewGroup.LayoutParams lp = contentView.getLayoutParams();
    int index = parent.indexOfChild(contentView);
    parent.removeView(contentView);
    StatusView statusView = new StatusView(contentView.getContext());
    statusView.addView(contentView);
    statusView.setContentView(contentView);
    parent.addView(statusView, index, lp);
    return statusView;
}
 
Example 5
@Override
public void onPlayerError(ExoPlaybackException error) {
    Throwable cause = error.getCause();
    if (textureView != null && cause instanceof SurfaceNotValidException) {
        if (player != null) {
            ViewGroup parent = (ViewGroup) textureView.getParent();
            if (parent != null) {
                int i = parent.indexOfChild(textureView);
                parent.removeView(textureView);
                parent.addView(textureView,i);
            }
            player.clearVideoTextureView(textureView);
            player.setVideoTextureView(textureView);
            if (loopingMediaSource) {
                preparePlayerLoop(videoUri, videoType, audioUri, audioType);
            } else {
                preparePlayer(videoUri, videoType);
            }
            play();
        }
    } else {
        delegate.onError(this, error);
    }
}
 
Example 6
Source Project: LoyalNativeSlider   File: MaterialRippleLayout.java    License: MIT License 5 votes vote down vote up
public MaterialRippleLayout create() {
    MaterialRippleLayout layout = new MaterialRippleLayout(context);
    layout.setRippleColor(rippleColor);
    layout.setDefaultRippleAlpha((int) rippleAlpha);
    layout.setRippleDelayClick(rippleDelayClick);
    layout.setRippleDiameter((int) dpToPx(context.getResources(), rippleDiameter));
    layout.setRippleDuration(rippleDuration);
    layout.setRippleFadeDuration(rippleFadeDuration);
    layout.setRippleHover(rippleHover);
    layout.setRipplePersistent(ripplePersistent);
    layout.setRippleOverlay(rippleOverlay);
    layout.setRippleBackground(rippleBackground);
    layout.setRippleInAdapter(rippleSearchAdapter);
    layout.setRippleRoundedCorners((int) dpToPx(context.getResources(), rippleRoundedCorner));

    ViewGroup.LayoutParams params = child.getLayoutParams();
    ViewGroup parent = (ViewGroup) child.getParent();
    int index = 0;

    if (parent != null && parent instanceof MaterialRippleLayout) {
        throw new IllegalStateException("MaterialRippleLayout could not be created: parent of the view already is a MaterialRippleLayout");
    }

    if (parent != null) {
        index = parent.indexOfChild(child);
        parent.removeView(child);
    }

    layout.addView(child, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    if (parent != null) {
        parent.addView(layout, index, params);
    }

    return layout;
}
 
Example 7
Source Project: react-native-navigation   File: TestUtils.java    License: MIT License 5 votes vote down vote up
public static <T extends View> T spyOn(T child) {
    ViewGroup parent = (ViewGroup) child.getParent();
    int indexOf = parent.indexOfChild(child);
    parent.removeView(child);
    T spy = Mockito.spy(child);
    parent.addView(spy, indexOf);
    return spy;
}
 
Example 8
Source Project: a   File: BadgeView.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attach the BadgeView to the target view
 * @param target the view to attach the BadgeView
 */
public void setTargetView(View target) {
    if (getParent() != null) {
        ((ViewGroup) getParent()).removeView(this);
    }

    if (target == null) {
        return;
    }

    if (target.getParent() instanceof FrameLayout) {
        ((FrameLayout) target.getParent()).addView(this);

    } else if (target.getParent() instanceof ViewGroup) {
        // use a new Framelayout container for adding badge
        ViewGroup parentContainer = (ViewGroup) target.getParent();
        int groupIndex = parentContainer.indexOfChild(target);
        parentContainer.removeView(target);

        FrameLayout badgeContainer = new FrameLayout(getContext());
        ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams();

        badgeContainer.setLayoutParams(parentLayoutParams);
        target.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams);
        badgeContainer.addView(target);

        badgeContainer.addView(this);
    }

}
 
Example 9
Source Project: UltimateAndroid   File: UnfoldableView.java    License: Apache License 2.0 5 votes vote down vote up
private void switchViews(View origin, View replacement, ViewGroup.LayoutParams params) {
    ViewGroup parent = (ViewGroup) origin.getParent();

    if (params == null) params = origin.getLayoutParams();

    int index = parent.indexOfChild(origin);
    parent.removeViewAt(index);
    parent.addView(replacement, index, params);
}
 
Example 10
Source Project: FamilyChat   File: ParallaxTransformer.java    License: Apache License 2.0 5 votes vote down vote up
private void bringViewToFront(View view) {
    ViewGroup group = (ViewGroup) view.getParent();
    int index = group.indexOfChild(view);
    if (index != group.getChildCount() - 1) {
        view.bringToFront();
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            view.requestLayout();
            group.invalidate();
        }
    }
}
 
Example 11
Source Project: LRecyclerView   File: PullScrollView.java    License: Apache License 2.0 5 votes vote down vote up
private void setLayout() {
    ViewGroup group = (ViewGroup) getParent();
    LinearLayout container = new LinearLayout(getContext());
    container.setOrientation(LinearLayout.VERTICAL);
    int index = group.indexOfChild(this);
    group.removeView(this);
    group.addView(container, index, getLayoutParams());

    container.addView(mRefreshHeader.getHeaderView(), new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    container.addView(this, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
 
Example 12
Source Project: umeng_community_android   File: BadgeView.java    License: MIT License 5 votes vote down vote up
private void applyTo(View target) {

        LayoutParams lp = target.getLayoutParams();
        ViewParent parent = target.getParent();
        FrameLayout container = new FrameLayout(context);

        if (target instanceof TabWidget) {
            // set target to the relevant tab child container
            target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
            this.target = target;

            ((ViewGroup) target).addView(container,
                    new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            this.setVisibility(View.GONE);
            container.addView(this);
        } else {
            ViewGroup group = (ViewGroup) parent;
            int index = group.indexOfChild(target);

            group.removeView(target);
            group.addView(container, index, lp);

            container.addView(target);

            this.setVisibility(View.GONE);
            container.addView(this);

            group.invalidate();

        }

    }
 
Example 13
private MeasurementView getNextView() {
    ViewGroup parent = (ViewGroup) getParent();
    for (int i = parent.indexOfChild(this) + 1; i < parent.getChildCount(); ++i) {
        MeasurementView next = (MeasurementView) parent.getChildAt(i);
        if (next.isVisible() && next.isEditable()) {
            return next;
        }
    }
    return null;
}
 
Example 14
public RippleLayout create() {
    RippleLayout layout = new RippleLayout(context);
    layout.setRippleColor(rippleColor);
    layout.setDefaultRippleAlpha((int) rippleAlpha);
    layout.setRippleDelayClick(rippleDelayClick);
    layout.setRippleDiameter((int) dpToPx(context.getResources(), rippleDiameter));
    layout.setRippleDuration(rippleDuration);
    layout.setRippleFadeDuration(rippleFadeDuration);
    layout.setRippleHover(rippleHover);
    layout.setRipplePersistent(ripplePersistent);
    layout.setRippleOverlay(rippleOverlay);
    layout.setRippleBackground(rippleBackground);
    layout.setRippleInAdapter(rippleSearchAdapter);
    layout.setRippleRoundedCorners((int) dpToPx(context.getResources(), rippleRoundedCorner));

    ViewGroup.LayoutParams params = child.getLayoutParams();
    ViewGroup parent = (ViewGroup) child.getParent();
    int index = 0;

    if (parent != null && parent instanceof RippleLayout) {
        throw new IllegalStateException("MaterialRippleLayout could not be created: parent of the view already is a MaterialRippleLayout");
    }

    if (parent != null) {
        index = parent.indexOfChild(child);
        parent.removeView(child);
    }

    layout.addView(child, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    if (parent != null) {
        parent.addView(layout, index, params);
    }

    return layout;
}
 
Example 15
@Override
public void animate() {
	final ViewGroup parentView = (ViewGroup) view.getParent();
	final FrameLayout slideOutFrame = new FrameLayout(view.getContext());
	final int positionView = parentView.indexOfChild(view);
	slideOutFrame.setLayoutParams(view.getLayoutParams());
	slideOutFrame.setClipChildren(true);
	parentView.removeView(view);
	slideOutFrame.addView(view);
	parentView.addView(slideOutFrame, positionView);

	switch (direction) {
	case DIRECTION_LEFT:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
				view.getTranslationX() - view.getWidth());
		break;
	case DIRECTION_RIGHT:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
				view.getTranslationX() + view.getWidth());
		break;
	case DIRECTION_UP:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y,
				view.getTranslationY() - view.getHeight());
		break;
	case DIRECTION_DOWN:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y,
				view.getTranslationY() + view.getHeight());
		break;
	default:
		break;
	}

	AnimatorSet slideSet = new AnimatorSet();
	slideSet.play(slideAnim);
	slideSet.setInterpolator(interpolator);
	slideSet.setDuration(duration);
	slideSet.addListener(new AnimatorListenerAdapter() {

		@Override
		public void onAnimationEnd(Animator animation) {
			view.setVisibility(View.INVISIBLE);
			slideAnim.reverse();
			slideOutFrame.removeAllViews();
			parentView.removeView(slideOutFrame);
			parentView.addView(view, positionView);
			if (getListener() != null) {
				getListener().onAnimationEnd(
						SlideOutUnderneathAnimation.this);
			}
		}
	});
	slideSet.start();
}
 
Example 16
Source Project: volume_control_android   File: MainActivity.java    License: MIT License 4 votes vote down vote up
private void renderProfileItems() {
    View title = findViewById(R.id.audio_types_holder_title);
    ViewGroup titlesGroup = findViewById(R.id.linearLayout);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        titlesGroup.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
    }

    int indexOfTitle = titlesGroup.indexOfChild(title);

    List<AudioType> audioTypes = AudioType.getAudioTypes(true);

    if (!Boolean.TRUE.equals(title.getTag())) {
        for (int i = 0; i < audioTypes.size(); i++) {
            AudioType type = audioTypes.get(i);

            final VolumeSliderView volumeSliderView = new VolumeSliderView(this);

            volumeSliderView.setTag(type.audioStreamName);
            titlesGroup.addView(volumeSliderView, indexOfTitle + i + 1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            volumeSliderView.setVolumeName(getString(type.nameId));
            volumeSliderView.setMaxVolume(control.getMaxLevel(type.audioStreamName));
            volumeSliderView.setMinVolume(control.getMinLevel(type.audioStreamName));
            volumeSliderView.setCurrentVolume(control.getLevel(type.audioStreamName));


            final TypeListener volumeListener = new TypeListener(type.audioStreamName) {
                @Override
                public void onChangeIndex(int audioType, int currentLevel, int max) {
                    if (currentLevel < control.getMinLevel(type)) {
                        volumeSliderView.setCurrentVolume(control.getMinLevel(type));
                    } else {
                        volumeSliderView.setCurrentVolume(currentLevel);
                    }
                }
            };

            volumeListeners.add(volumeListener);

            volumeSliderView.setListener((volume, fromUser) -> {
                if (fromUser) {
                    requireChangeVolume(type, volume);
                }
            });
        }
        title.setTag(Boolean.TRUE);
    }

    for (AudioType audioExtendedType : AudioType.getAudioExtendedTypes()) {
        titlesGroup.findViewWithTag(audioExtendedType.audioStreamName).setVisibility(isExtendedVolumesEnabled() ? View.VISIBLE : View.GONE);
    }
}
 
Example 17
public void bringChildToFront(ViewGroup vg, View child) {
	position = vg.indexOfChild(child);
	if (position != -1) {
		vg.postInvalidate();
	}
}
 
Example 18
Source Project: Luban-Circle-Demo   File: ViewUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void replaceChild(ViewGroup viewGroup, View oldChild, View newChild) {
    int index = viewGroup.indexOfChild(oldChild);
    viewGroup.removeViewAt(index);
    viewGroup.addView(newChild, index);
}
 
Example 19
private void applyTo(View target) {

        LayoutParams lp = target.getLayoutParams();
        ViewParent parent = target.getParent();
        FrameLayout container = new FrameLayout(context);

        if (target instanceof TabWidget) {

            // set target to the relevant tab child container
            target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
            this.target = target;

            ((ViewGroup) target).addView(container,
                    new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            this.setVisibility(View.GONE);
            container.addView(this);

        } else {

            // TODO verify that parent is indeed a ViewGroup
            ViewGroup group = (ViewGroup) parent;
            int index = group.indexOfChild(target);

            group.removeView(target);
            group.addView(container, index, lp);

            container.addView(target);

            this.setVisibility(View.GONE);
            container.addView(this);

            group.invalidate();

        }

    }
 
Example 20
Source Project: android-common-utils   File: BadgeView.java    License: Apache License 2.0 3 votes vote down vote up
private void applyTo(View target) {
	
	LayoutParams lp = target.getLayoutParams();
	ViewParent parent = target.getParent();
	FrameLayout container = new FrameLayout(context);
	
	if (target instanceof TabWidget) {
		
		// set target to the relevant tab child container
		target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
		this.target = target;
		
		((ViewGroup) target).addView(container, 
				new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		this.setVisibility(View.GONE);
		container.addView(this);
		
	} else {
		
		// TODO verify that parent is indeed a ViewGroup
		ViewGroup group = (ViewGroup) parent; 
		int index = group.indexOfChild(target);
		
		group.removeView(target);
		group.addView(container, index, lp);
		
		container.addView(target);

		this.setVisibility(View.GONE);
		container.addView(this);
		
		group.invalidate();
		
	}
	
}