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

The following examples show how to use android.view.ViewGroup#removeAllViews() . 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 File: ProjectManagerActivity.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initLeftNavigationView(@NonNull NavigationView nav) {
    super.initLeftNavigationView(nav);
    if (mProject == null) {
        mProject = JavaProjectManager.getLastProject(this);
    }

    String tag = FolderStructureFragment.TAG;
    FolderStructureFragment folderStructureFragment = FolderStructureFragment.newInstance(mProject);
    ViewGroup viewGroup = nav.findViewById(R.id.left_navigation_content);
    viewGroup.removeAllViews();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.left_navigation_content, folderStructureFragment, tag).commit();
    mFilePresenter = new ProjectFilePresenter(folderStructureFragment);

}
 
Example 2
Source File: LibraryActivity.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreateLayout(@Nullable Bundle savedInstanceState) {
    super.onCreateLayout(savedInstanceState);
    ViewGroup contentViewContainer = findViewById(android.R.id.content);
    View root = contentViewContainer.getChildAt(0);
    contentViewContainer.removeAllViews();

    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_library);
    ViewGroup contentContainer = findViewById(R.id.library_content_container);
    contentContainer.addView(root);

    mBinding.libraryDrawerNavigationView.setNavigationItemSelectedListener(item -> {
        mBinding.libraryDrawerLayout.closeDrawers();
        onNavigationItemSelected(item.getItemId());
        return true;
    });
}
 
Example 3
Source File: HomeFragment.java    From white-label-event-app with Apache License 2.0 6 votes vote down vote up
private void updateHappeningNowCard() {
    ViewGroup time_groups = (ViewGroup) cardHappeningNow.findViewById(R.id.vg_time_groups);
    time_groups.removeAllViews();

    final SortedMap<DateRange, List<AgendaItem>> happening =
        AgendaItems.happeningNow(agenda.getItems().values(), timeAtUpdate);

    if (happening.size() > 0) {
        populateTimeGroups(happening, time_groups);
        cardHappeningNow.setVisibility(View.VISIBLE);
        happeningNowStartTime = happening.firstKey().start;
    }
    else {
        cardHappeningNow.setVisibility(View.GONE);
    }
}
 
Example 4
Source File: CropViewContainerHelper.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
public void refreshAllState(ImageItem currentImageItem, List<ImageItem> selectList,
                            ViewGroup invisibleContainer,
                            boolean isFitState,
                            ResetSizeExecutor executor) {
    invisibleContainer.removeAllViews();
    invisibleContainer.setVisibility(View.VISIBLE);
    for (ImageItem imageItem : selectList) {
        if (imageItem == currentImageItem) {
            continue;
        }
        CropImageView picBrowseImageView = cropViewList.get(imageItem);
        if (picBrowseImageView != null) {
            invisibleContainer.addView(picBrowseImageView);
            if (executor != null) {
                executor.resetAllCropViewSize(picBrowseImageView);
            }
            if (isFitState) {
                imageItem.setCropMode(ImageCropMode.ImageScale_FILL);
                picBrowseImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            }
            cropViewList.put(imageItem, picBrowseImageView);
        }
    }
    invisibleContainer.setVisibility(View.INVISIBLE);
}
 
Example 5
Source File: WebRtcCallView.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static void setRenderer(@NonNull ViewGroup container, @Nullable View renderer) {
  if (renderer == null) {
    container.removeAllViews();
    return;
  }

  ViewParent parent = renderer.getParent();
  if (parent != null && parent != container) {
    ((ViewGroup) parent).removeAllViews();
  }

  if (parent == container) {
    return;
  }

  container.addView(renderer);
}
 
Example 6
Source File: ExoVideoPlaybackControlView.java    From ExoVideoView with Apache License 2.0 6 votes vote down vote up
/**
 * add your view to controller
 *
 * @param customViewType the target view type
 * @param customView     the view you want to add
 * @param removeViews    remove all views in target view before add  if true
 **/
public void addCustomView(@CustomViewType int customViewType, View customView, boolean removeViews) {
    ViewGroup viewGroup = null;
    if (customViewType == CUSTOM_VIEW_TOP && topCustomView != null) {
        viewGroup = topCustomView;
    } else if (customViewType == CUSTOM_VIEW_TOP_LANDSCAPE && topCustomView != null) {
        viewGroup = topCustomViewLandscape;
    } else if (customViewType == CUSTOM_VIEW_BOTTOM_LANDSCAPE && topCustomView != null) {
        viewGroup = bottomCustomViewLandscape;
    }

    if (viewGroup != null) {
        if (removeViews) {
            viewGroup.removeAllViews();
        }
        viewGroup.addView(customView);
    }

}
 
Example 7
Source File: ListBindingAdapters.java    From android-ui-toolkit-demos with Apache License 2.0 6 votes vote down vote up
/**
 * Clears all Views in {@code parent} and fills it with a View for
 * each item in {@code entries}, bound to the item. If layoutId
 * is 0, no Views will be added.
 *
 * @param parent The ViewGroup to contain the list of items.
 * @param layoutId The layout ID to inflate for the child Views.
 * @param entries The list of items to bind to the inflated Views. Each
 *                item will be bound to a different child View.
 */
private static void resetViews(ViewGroup parent, int layoutId,
        List entries) {
    parent.removeAllViews();
    if (layoutId == 0) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (int i = 0; i < entries.size(); i++) {
        Object entry = entries.get(i);
        ViewDataBinding binding = bindLayout(inflater, parent,
                layoutId, entry);
        parent.addView(binding.getRoot());
    }
}
 
Example 8
Source File: VideoListLayout.java    From MD with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (videoLayout == null)
        return;
    if (smallLayout == null)
        return;
    if (smallLayout.getVisibility() == View.VISIBLE) {
        smallLayout.setVisibility(View.GONE);
        videoLayout.removeAllViews();
    }

    if (postion != -1) {
        ViewGroup view = (ViewGroup) videoItemView.getParent();
        if (view != null) {
            view.removeAllViews();
        }
    }
    videoItemView.stop();
    videoItemView.release();
    videoItemView.onDestroy();
    videoItemView = null;
}
 
Example 9
Source File: VideoListFragment.java    From ZZShow with Apache License 2.0 6 votes vote down vote up
/**
 * 离开此Fragment 或 不可见 时
 */
public void onDetachFromWindow(){
    if(mVideoPlayView != null){
        ViewGroup parent = (ViewGroup) mVideoPlayView.getParent();
        if(parent != null){
            parent.removeAllViews();
            if (mLastPosition <= mLayoutManager.findLastVisibleItemPosition()
                    && mLastPosition >= mLayoutManager.findFirstVisibleItemPosition()) {
                View view = mVideoListView.findViewHolderForAdapterPosition(mLastPosition).itemView;
                FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.item_layout_video);
                frameLayout.removeAllViews();
                view.findViewById(R.id.video_cover_layout).setVisibility(View.VISIBLE);
            }
        }
        mVideoPlayView.stop();
        mVideoPlayView.release();
    }
    mLastPosition = -1;
}
 
Example 10
Source File: StatisticsFragment.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_statistics, container, false);
    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (actionBar != null) {
        //actionBar.setSubtitle(R.string.action_main);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    container.removeAllViews();

    ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager);
    setupViewPager(viewPager);

    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);

    setHasOptionsMenu(true);
    return view;
}
 
Example 11
Source File: BasicDispatcher.java    From flowless with Apache License 2.0 5 votes vote down vote up
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
    Log.d("BasicDispatcher", "dispatching " + traversal);
    Object dest = traversal.destination.top();

    ViewGroup frame = (ViewGroup) activity.findViewById(R.id.basic_activity_frame);

    if(traversal.origin != null) {
        if(frame.getChildCount() > 0) {
            traversal.getState(traversal.origin.top()).save(frame.getChildAt(0));
            frame.removeAllViews();
        }
    }

    @LayoutRes final int layout;
    if(dest instanceof HelloScreen) {
        layout = R.layout.hello_screen;
    } else if(dest instanceof WelcomeScreen) {
        layout = R.layout.welcome_screen;
    } else {
        throw new AssertionError("Unrecognized screen " + dest);
    }

    View incomingView = LayoutInflater.from(traversal.createContext(dest, activity)) //
            .inflate(layout, frame, false);

    frame.addView(incomingView);
    traversal.getState(traversal.destination.top()).restore(incomingView);

    callback.onTraversalCompleted();
}
 
Example 12
Source File: NeopixelActivity.java    From Bluefruit_LE_Connect_Android with MIT License 5 votes vote down vote up
private void createBoardUI() {
    if (mBoard != null) {
        final ViewGroup canvasView = mBoardContentView;

        canvasView.removeAllViews();

        final int kLedSize = (int) MetricsUtils.convertDpToPixel(this, kLedPixelSize);
        final int canvasViewWidth = canvasView.getWidth();
        final int canvasViewHeight = canvasView.getHeight();
        final int boardWidth = mBoard.width * kLedSize;
        final int boardHeight = mBoard.height * kLedSize;

        final int marginLeft = (canvasViewWidth - boardWidth) / 2;
        final int marginTop = (canvasViewHeight - boardHeight) / 2;

        for (int j = 0, k = 0; j < mBoard.height; j++) {
            for (int i = 0; i < mBoard.width; i++, k++) {
                View ledView = LayoutInflater.from(this).inflate(R.layout.layout_neopixel_led, canvasView, false);
                Button ledButton = (Button) ledView.findViewById(R.id.ledButton);
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(kLedSize, kLedSize);
                layoutParams.leftMargin = i * kLedSize + marginLeft;//mBoardMargin.left;
                layoutParams.topMargin = j * kLedSize + marginTop;//mBoardMargin.top;
                ledView.setLayoutParams(layoutParams);
                ledButton.setTag(k);

                setViewBackgroundColor(ledButton, kDefaultLedColor);
                canvasView.addView(ledView);
            }
        }



        // Setup initial scroll and scale
        resetScaleAndPanning();
    }
}
 
Example 13
Source File: WebViewActivity.java    From Simpler with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    // 解决android webview ZoomButtonsController 导致android.view.WindowLeaked
    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.removeAllViews();
    super.onDestroy();
}
 
Example 14
Source File: MenuDrawer.java    From Roid-Library with Apache License 2.0 5 votes vote down vote up
/**
 * Attaches the menu drawer to the window.
 */
private static void attachToDecor(Activity activity, MenuDrawer menuDrawer) {
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0);

    decorView.removeAllViews();
    decorView.addView(menuDrawer, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    menuDrawer.mContentContainer.addView(decorChild, decorChild.getLayoutParams());
}
 
Example 15
Source File: SeekBarPreference.java    From Lucid-Browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindView(View view) {
    super.onBindView(view);

    try {
        // move our seekbar to the new view we've been given
        ViewParent oldContainer = mSeekBar.getParent();
        ViewGroup newContainer = (ViewGroup) view.findViewById(R.id.seekBarPrefBarContainer);
        
        if (oldContainer != newContainer) {
            // remove the seekbar from the old view
            if (oldContainer != null) {
                ((ViewGroup) oldContainer).removeView(mSeekBar);
            }
            // remove the existing seekbar (there may not be one) and add ours
            newContainer.removeAllViews();
            newContainer.addView(mSeekBar, ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }
    catch(Exception ex) {
        Log.e(TAG, "Error binding view: " + ex.toString());
    }
    
    //if dependency is false from the beginning, disable the seek bar
    if (view != null && !view.isEnabled())
    {
        mSeekBar.setEnabled(false);
    }
    
    updateView(view);
}
 
Example 16
Source File: VideoFragment.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
 *  切换到横屏时操作
 * @return
 */
public void updateOrientationLandscape(){
    //将 VideoView 重竖屏移除
    ViewGroup viewGroup = (ViewGroup) mVideoPlayerView.getParent();
    if(viewGroup != null) {
        viewGroup.removeAllViews();
        mListener.onVideoFI(2,mVideoPlayerView);
    }
}
 
Example 17
Source File: VideoFragment.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyView() {
    super.onDestroyView();
    if (mVideoPlayerView != null) {
        ViewGroup view = (ViewGroup) mVideoPlayerView.getParent();
        if (view != null) {
            view.removeAllViews();
        }
        mVideoPlayerView.stop();
        mVideoPlayerView.release();
        mVideoPlayerView.onDestory();
        mVideoPlayerView = null;
    }
}
 
Example 18
Source File: BasicDispatcher.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
  Log.d("BasicDispatcher", "dispatching " + traversal);
  Object destKey = traversal.destination.top();

  ViewGroup frame = (ViewGroup) activity.findViewById(R.id.basic_activity_frame);

  // We're already showing something, clean it up.
  if (frame.getChildCount() > 0) {
    final View currentView = frame.getChildAt(0);

    // Save the outgoing view state.
    if (traversal.origin != null) {
      traversal.getState(traversal.origin.top()).save(currentView);
    }

    // Short circuit if we would just be showing the same view again.
    final Object currentKey = Flow.getKey(currentView);
    if (destKey.equals(currentKey)) {
      callback.onTraversalCompleted();
      return;
    }

    frame.removeAllViews();
  }

  @LayoutRes final int layout;
  if (destKey instanceof HelloScreen) {
    layout = R.layout.hello_screen;
  } else if (destKey instanceof WelcomeScreen) {
    layout = R.layout.welcome_screen;
  } else {
    throw new AssertionError("Unrecognized screen " + destKey);
  }

  View incomingView = LayoutInflater.from(traversal.createContext(destKey, activity)) //
      .inflate(layout, frame, false);

  frame.addView(incomingView);
  traversal.getState(traversal.destination.top()).restore(incomingView);

  callback.onTraversalCompleted();
}
 
Example 19
Source File: EditorDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Create the visual representation of the EditorModel.
 *
 * This would be more optimal as a RelativeLayout, but because it's dynamically generated, it's
 * much more human-parsable with inefficient LinearLayouts for half-width controls sharing rows.
 */
private void prepareEditor() {
    // Ensure the layout is empty.
    removeTextChangedListenersAndInputFilters();
    mDataView = (ViewGroup) mLayout.findViewById(R.id.contents);
    mDataView.removeAllViews();
    mFieldViews.clear();
    mEditableTextFields.clear();
    mDropdownFields.clear();

    // Add Views for each of the {@link EditorFields}.
    for (int i = 0; i < mEditorModel.getFields().size(); i++) {
        EditorFieldModel fieldModel = mEditorModel.getFields().get(i);
        EditorFieldModel nextFieldModel = null;

        boolean isLastField = i == mEditorModel.getFields().size() - 1;
        boolean useFullLine = fieldModel.isFullLine();
        if (!isLastField && !useFullLine) {
            // If the next field isn't full, stretch it out.
            nextFieldModel = mEditorModel.getFields().get(i + 1);
            if (nextFieldModel.isFullLine()) useFullLine = true;
        }

        if (useFullLine || isLastField) {
            addFieldViewToEditor(mDataView, fieldModel);
        } else {
            // Create a LinearLayout to put it and the next view side by side.
            LinearLayout rowLayout = new LinearLayout(mContext);
            mDataView.addView(rowLayout);

            View firstView = addFieldViewToEditor(rowLayout, fieldModel);
            View lastView = addFieldViewToEditor(rowLayout, nextFieldModel);

            LinearLayout.LayoutParams firstParams =
                    (LinearLayout.LayoutParams) firstView.getLayoutParams();
            LinearLayout.LayoutParams lastParams =
                    (LinearLayout.LayoutParams) lastView.getLayoutParams();

            firstParams.width = 0;
            firstParams.weight = 1;
            ApiCompatibilityUtils.setMarginEnd(firstParams, mHalfRowMargin);
            lastParams.width = 0;
            lastParams.weight = 1;

            // Align the text field and the dropdown field.
            if ((fieldModel.isTextField() && nextFieldModel.isDropdownField())
                    || (nextFieldModel.isTextField() && fieldModel.isDropdownField())) {
                LinearLayout.LayoutParams dropdownParams =
                        fieldModel.isDropdownField() ? firstParams : lastParams;
                dropdownParams.topMargin = mDropdownTopPadding;
                dropdownParams.bottomMargin = 0;
            }

            i = i + 1;
        }
    }

    // Add the footer.
    mDataView.addView(mFooter);
}
 
Example 20
Source File: AudioRecordView.java    From Audio-Recording-Animation with Apache License 2.0 4 votes vote down vote up
public void initView(ViewGroup view) {

        if (view == null) {
            showErrorLog("initView ViewGroup can't be NULL");
            return;
        }

        context = view.getContext();

        view.removeAllViews();
        view.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.record_view, null));

        timeFormatter = new SimpleDateFormat("m:ss", Locale.getDefault());

        DisplayMetrics displayMetrics = view.getContext().getResources().getDisplayMetrics();
        screenHeight = displayMetrics.heightPixels;
        screenWidth = displayMetrics.widthPixels;

        isLayoutDirectionRightToLeft = view.getContext().getResources().getBoolean(R.bool.is_right_to_left);

        viewContainer = view.findViewById(R.id.layoutContainer);
        layoutAttachmentOptions = view.findViewById(R.id.layoutAttachmentOptions);

        imageViewAttachment = view.findViewById(R.id.imageViewAttachment);
        imageViewCamera = view.findViewById(R.id.imageViewCamera);
        imageViewEmoji = view.findViewById(R.id.imageViewEmoji);
        editTextMessage = view.findViewById(R.id.editTextMessage);

        send = view.findViewById(R.id.imageSend);
        stop = view.findViewById(R.id.imageStop);
        audio = view.findViewById(R.id.imageAudio);

        imageViewAudio = view.findViewById(R.id.imageViewAudio);
        imageViewStop = view.findViewById(R.id.imageViewStop);
        imageViewSend = view.findViewById(R.id.imageViewSend);
        imageViewLock = view.findViewById(R.id.imageViewLock);
        imageViewLockArrow = view.findViewById(R.id.imageViewLockArrow);
        layoutDustin = view.findViewById(R.id.layoutDustin);
        layoutMessage = view.findViewById(R.id.layoutMessage);
        layoutAttachment = view.findViewById(R.id.layoutAttachment);
        textViewSlide = view.findViewById(R.id.textViewSlide);
        timeText = view.findViewById(R.id.textViewTime);
        layoutSlideCancel = view.findViewById(R.id.layoutSlideCancel);
        layoutEffect2 = view.findViewById(R.id.layoutEffect2);
        layoutEffect1 = view.findViewById(R.id.layoutEffect1);
        layoutLock = view.findViewById(R.id.layoutLock);
        imageViewMic = view.findViewById(R.id.imageViewMic);
        dustin = view.findViewById(R.id.dustin);
        dustin_cover = view.findViewById(R.id.dustin_cover);

        handler = new Handler(Looper.getMainLooper());

        dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, view.getContext().getResources().getDisplayMetrics());

        animBlink = AnimationUtils.loadAnimation(view.getContext(),
                R.anim.blink);
        animJump = AnimationUtils.loadAnimation(view.getContext(),
                R.anim.jump);
        animJumpFast = AnimationUtils.loadAnimation(view.getContext(),
                R.anim.jump_fast);

        setupRecording();
        setupAttachmentOptions();
    }