Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

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

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

From source file:net.evecom.androidecssp.activity.pub.EmergencyNotification.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.emergency_info_activity);

    // 1/*from  ww w. jav  a2s .c  o m*/
    viewpager = (ViewPager) findViewById(R.id.my_viewpager_id);
    // 4DepthPageTransformer
    // viewpager.setPageTransformer(true, new DepthPageTransformer());
    viewpager.setPageTransformer(true, new RotateDownTransformer());
    // 2
    viewpager.setAdapter(new PagerAdapter() {
        @Override
        // item page
        public Object instantiateItem(ViewGroup container, int position) {
            //  switchpage
            ImageView imageView = new ImageView(EmergencyNotification.this);
            imageView.setImageResource(imagesId[position]);
            // 
            imageView.setScaleType(ScaleType.CENTER_CROP);

            // imageViewcontainer page
            container.addView(imageView);
            // imageViewlist
            imageViews.add(imageView);
            // imageView
            return imageView;
        }

        @Override
        // destroyItem
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(imageViews.get(position));
        }

        @Override
        //  adapter
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        // 
        public int getCount() {
            return imagesId.length;
        }
    });

}

From source file:android.support.v7.widget.ActionMenuPresenter.java

@Override
public void updateMenuView(boolean cleared) {
    final ViewGroup menuViewParent = (ViewGroup) ((View) mMenuView).getParent();
    if (menuViewParent != null) {
        ActionBarTransition.beginDelayedTransition(menuViewParent);
    }//  w  ww .ja v a2 s.c  o  m
    super.updateMenuView(cleared);

    ((View) mMenuView).requestLayout();

    if (mMenu != null) {
        final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems();
        final int count = actionItems.size();
        for (int i = 0; i < count; i++) {
            final ActionProvider provider = actionItems.get(i).getSupportActionProvider();
            if (provider != null) {
                provider.setSubUiVisibilityListener(this);
            }
        }
    }

    final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? mMenu.getNonActionItems() : null;

    boolean hasOverflow = false;
    if (mReserveOverflow && nonActionItems != null) {
        final int count = nonActionItems.size();
        if (count == 1) {
            hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
        } else {
            hasOverflow = count > 0;
        }
    }

    if (hasOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
        }
        ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
        if (parent != mMenuView) {
            if (parent != null) {
                parent.removeView(mOverflowButton);
            }
            ActionMenuView menuView = (ActionMenuView) mMenuView;
            menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams());
        }
    } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) {
        ((ViewGroup) mMenuView).removeView(mOverflowButton);
    }

    ((ActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow);
}

From source file:de.manumaticx.crouton.Manager.java

/**
 * Removes the {@link Crouton}'s view after it's display
 * durationInMilliseconds./*ww  w.j a  v a2 s  .co m*/
 *
 * @param crouton
 *     The {@link Crouton} added to a {@link ViewGroup} and should be
 *     removed.
 */
protected void removeCrouton(Crouton crouton) {
    View croutonView = crouton.getView();
    ViewGroup croutonParentView = (ViewGroup) croutonView.getParent();

    if (null != croutonParentView) {
        if (Looper.myLooper() == Looper.getMainLooper()) {

            croutonView.startAnimation(crouton.getOutAnimation());
            // Remove the Crouton from the queue.
            Crouton removed = croutonQueue.poll();

            // Remove the crouton from the view's parent.
            croutonParentView.removeView(croutonView);
            if (null != removed) {
                removed.detachActivity();
                removed.detachViewGroup();
                if (null != removed.getLifecycleCallback()) {
                    removed.getLifecycleCallback().onRemoved();
                }
                removed.detachLifecycleCallback();
            }

            // Send a message to display the next crouton but delay it by the out
            // animation duration to make sure it finishes
            sendMessageDelayed(crouton, Messages.DISPLAY_CROUTON, crouton.getOutAnimation().getDuration());
        } else {
            final View mCroutonView = croutonView;
            final ViewGroup mCroutonParentView = croutonParentView;
            final Crouton mCrouton = crouton;
            crouton.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mCroutonView.startAnimation(mCrouton.getOutAnimation());
                    // Remove the Crouton from the queue.
                    Crouton removed = croutonQueue.poll();

                    // Remove the crouton from the view's parent.
                    mCroutonParentView.removeView(mCroutonView);
                    if (null != removed) {
                        removed.detachActivity();
                        removed.detachViewGroup();
                        if (null != removed.getLifecycleCallback()) {
                            removed.getLifecycleCallback().onRemoved();
                        }
                        removed.detachLifecycleCallback();
                    }

                    // Send a message to display the next crouton but delay it by the out
                    // animation duration to make sure it finishes
                    sendMessageDelayed(mCrouton, Messages.DISPLAY_CROUTON,
                            mCrouton.getOutAnimation().getDuration());
                }
            });
        }
    }
}

From source file:org.telegram.ui.ApplicationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        Utilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }//from  w  w  w .j  a  v a 2  s . c o m

    NotificationCenter.Instance.postNotificationName(702, this);
    currentConnectionState = ConnectionsManager.Instance.connectionState;
    for (BaseFragment fragment : ApplicationLoader.fragmentsStack) {
        if (fragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) fragment.fragmentView.getParent();
            if (parent != null) {
                parent.removeView(fragment.fragmentView);
            }
            fragment.fragmentView = null;
        }
        fragment.parentActivity = this;
    }
    setContentView(R.layout.application_layout);
    NotificationCenter.Instance.addObserver(this, 1234);
    NotificationCenter.Instance.addObserver(this, 658);
    NotificationCenter.Instance.addObserver(this, 701);
    NotificationCenter.Instance.addObserver(this, 702);
    NotificationCenter.Instance.addObserver(this, 703);
    NotificationCenter.Instance.addObserver(this, GalleryImageViewer.needShowAllMedia);
    getSupportActionBar().setLogo(R.drawable.ab_icon_fixed2);

    statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null);
    statusBackground = statusView.findViewById(R.id.back_button_background);
    backStatusButton = statusView.findViewById(R.id.back_button);
    containerView = findViewById(R.id.container);
    statusText = (TextView) statusView.findViewById(R.id.status_text);
    statusBackground.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ApplicationLoader.fragmentsStack.size() > 1) {
                onBackPressed();
            }
        }
    });

    if (ApplicationLoader.fragmentsStack.isEmpty()) {
        MessagesActivity fragment = new MessagesActivity();
        fragment.onFragmentCreate();
        ApplicationLoader.fragmentsStack.add(fragment);
    }

    boolean pushOpened = false;

    Integer push_user_id = (Integer) NotificationCenter.Instance.getFromMemCache("push_user_id", 0);
    Integer push_chat_id = (Integer) NotificationCenter.Instance.getFromMemCache("push_chat_id", 0);
    Integer push_enc_id = (Integer) NotificationCenter.Instance.getFromMemCache("push_enc_id", 0);
    Integer open_settings = (Integer) NotificationCenter.Instance.getFromMemCache("open_settings", 0);
    photoPath = (String) NotificationCenter.Instance.getFromMemCache(533);
    videoPath = (String) NotificationCenter.Instance.getFromMemCache(534);
    sendingText = (String) NotificationCenter.Instance.getFromMemCache(535);

    if (push_user_id != 0) {
        if (push_user_id == UserConfig.clientUserId) {
            open_settings = 1;
        } else {
            ChatActivity fragment = new ChatActivity();
            Bundle bundle = new Bundle();
            bundle.putInt("user_id", push_user_id);
            fragment.setArguments(bundle);
            if (fragment.onFragmentCreate()) {
                pushOpened = true;
                ApplicationLoader.fragmentsStack.add(fragment);
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
            }
        }
    } else if (push_chat_id != 0) {
        ChatActivity fragment = new ChatActivity();
        Bundle bundle = new Bundle();
        bundle.putInt("chat_id", push_chat_id);
        fragment.setArguments(bundle);
        if (fragment.onFragmentCreate()) {
            pushOpened = true;
            ApplicationLoader.fragmentsStack.add(fragment);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
        }
    } else if (push_enc_id != 0) {
        ChatActivity fragment = new ChatActivity();
        Bundle bundle = new Bundle();
        bundle.putInt("enc_id", push_enc_id);
        fragment.setArguments(bundle);
        if (fragment.onFragmentCreate()) {
            pushOpened = true;
            ApplicationLoader.fragmentsStack.add(fragment);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
        }
    }
    if (videoPath != null || photoPath != null || sendingText != null) {
        MessagesActivity fragment = new MessagesActivity();
        fragment.selectAlertString = R.string.ForwardMessagesTo;
        fragment.animationType = 1;
        Bundle args = new Bundle();
        args.putBoolean("onlySelect", true);
        fragment.setArguments(args);
        fragment.delegate = this;
        ApplicationLoader.fragmentsStack.add(fragment);
        fragment.onFragmentCreate();
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag())
                .commitAllowingStateLoss();
        pushOpened = true;
    }
    if (open_settings != 0) {
        SettingsActivity fragment = new SettingsActivity();
        ApplicationLoader.fragmentsStack.add(fragment);
        fragment.onFragmentCreate();
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings")
                .commitAllowingStateLoss();
        pushOpened = true;
    }
    if (!pushOpened) {
        BaseFragment fragment = ApplicationLoader.fragmentsStack
                .get(ApplicationLoader.fragmentsStack.size() - 1);
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag())
                .commitAllowingStateLoss();
    }

    getWindow().setBackgroundDrawableResource(R.drawable.transparent);
    getWindow().setFormat(PixelFormat.RGB_565);
}

From source file:dheeraj.sachan.advancedandroidshit.test.CustomActionMenuPresenter.java

@Override
public void updateMenuView(boolean cleared) {
    final ViewGroup menuViewParent = (ViewGroup) ((View) mMenuView).getParent();
    if (menuViewParent != null) {
        ActionBarTransition.beginDelayedTransition(menuViewParent);
    }/* w  w  w . j  a  v  a 2s  .  co  m*/
    super.updateMenuView(cleared);

    ((View) mMenuView).requestLayout();

    if (mMenu != null) {
        final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems();
        final int count = actionItems.size();
        for (int i = 0; i < count; i++) {
            final ActionProvider provider = actionItems.get(i).getSupportActionProvider();
            if (provider != null) {
                provider.setSubUiVisibilityListener(this);
            }
        }
    }

    final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? mMenu.getNonActionItems() : null;

    boolean hasOverflow = false;
    if (mReserveOverflow && nonActionItems != null) {
        final int count = nonActionItems.size();
        if (count == 1) {
            hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
        } else {
            hasOverflow = count > 0;
        }
    }

    if (hasOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
        }
        ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
        if (parent != mMenuView) {
            if (parent != null) {
                parent.removeView(mOverflowButton);
            }
            CustomActionMenuView menuView = (CustomActionMenuView) mMenuView;
            menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams());
        }
    } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) {
        ((ViewGroup) mMenuView).removeView(mOverflowButton);
    }

    ((CustomActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow);
}

From source file:com.nextgis.maplibui.activity.ModifyAttributesActivity.java

protected void createLocationPanelView(final IGISApplication app) {
    if (null == mGeometry && mFeatureId == NOT_FOUND) {
        mLatView = (TextView) findViewById(R.id.latitude_view);
        mLongView = (TextView) findViewById(R.id.longitude_view);
        mAltView = (TextView) findViewById(R.id.altitude_view);
        mAccView = (TextView) findViewById(R.id.accuracy_view);
        final ImageButton refreshLocation = (ImageButton) findViewById(R.id.refresh);
        mAccurateLocation = (SwitchCompat) findViewById(R.id.accurate_location);
        mAccurateLocation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override/*from   www.  j  a va 2  s .co m*/
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (mAccurateLocation.getTag() == null) {
                    refreshLocation.performClick();
                    mAccurateLocation.setTag(new Object());
                }
            }
        });
        mAccuracyCE = (AppCompatSpinner) findViewById(R.id.accurate_ce);

        refreshLocation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnimation.setDuration(500);
                rotateAnimation.setRepeatCount(1);
                refreshLocation.startAnimation(rotateAnimation);

                if (mAccurateLocation.isChecked()) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(ModifyAttributesActivity.this);
                    View layout = View.inflate(ModifyAttributesActivity.this,
                            R.layout.dialog_progress_accurate_location, null);
                    TextView message = (TextView) layout.findViewById(R.id.message);
                    final ProgressBar progress = (ProgressBar) layout.findViewById(R.id.progress);
                    final TextView progressPercent = (TextView) layout.findViewById(R.id.progress_percent);
                    final TextView progressNumber = (TextView) layout.findViewById(R.id.progress_number);
                    final CheckBox finishBeep = (CheckBox) layout.findViewById(R.id.finish_beep);
                    builder.setView(layout);
                    builder.setTitle(R.string.accurate_location);

                    final AccurateLocationTaker accurateLocation = new AccurateLocationTaker(view.getContext(),
                            100f, mMaxTakeCount, MAX_TAKE_TIME, PROGRESS_DELAY,
                            (String) mAccuracyCE.getSelectedItem());

                    progress.setIndeterminate(true);
                    message.setText(R.string.accurate_taking);
                    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            accurateLocation.cancelTaking();
                        }
                    });
                    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            accurateLocation.cancelTaking();
                        }
                    });
                    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            ControlHelper.unlockScreenOrientation(ModifyAttributesActivity.this);
                        }
                    });

                    final AlertDialog dialog = builder.create();
                    accurateLocation
                            .setOnProgressUpdateListener(new AccurateLocationTaker.OnProgressUpdateListener() {
                                @SuppressLint("SetTextI18n")
                                @Override
                                public void onProgressUpdate(Long... values) {
                                    int value = values[0].intValue();
                                    if (value == 1) {
                                        progress.setIndeterminate(false);
                                        progress.setMax(mMaxTakeCount);
                                    }

                                    if (value > 0)
                                        progress.setProgress(value);

                                    progressPercent.setText(value * 100 / mMaxTakeCount + " %");
                                    progressNumber.setText(value + " / " + mMaxTakeCount);
                                }
                            });

                    accurateLocation.setOnGetAccurateLocationListener(
                            new AccurateLocationTaker.OnGetAccurateLocationListener() {
                                @Override
                                public void onGetAccurateLocation(Location accurateLocation, Long... values) {
                                    dialog.dismiss();
                                    if (finishBeep.isChecked())
                                        playBeep();

                                    setLocationText(accurateLocation);
                                }
                            });

                    ControlHelper.lockScreenOrientation(ModifyAttributesActivity.this);
                    dialog.setCanceledOnTouchOutside(false);
                    dialog.show();
                    accurateLocation.startTaking();
                } else if (null != app) {
                    GpsEventSource gpsEventSource = app.getGpsEventSource();
                    Location location = gpsEventSource.getLastKnownLocation();
                    setLocationText(location);
                }
            }
        });
    } else {
        //hide location panel
        ViewGroup rootView = (ViewGroup) findViewById(R.id.controls_list);
        rootView.removeView(findViewById(R.id.location_panel));
    }
}

From source file:com.hxqc.mall.auto.fragment.CenterEditAutoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (rootView == null) {
        rootView = inflater.inflate(R.layout.fragment_center_add_auto_info, container, false);
    }/*from   w ww  . j ava2s.c  o  m*/
    ViewGroup parent = (ViewGroup) rootView.getParent();
    if (parent != null) {
        parent.removeView(rootView);
    }

    return rootView;
}

From source file:com.appsimobile.appsii.AbstractSidebarPagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    PageController controller = (PageController) object;

    HotspotPageEntry page = controller.getPage();

    Bundle savedControllerState = mSavedControllerStates.get(page);
    if (savedControllerState == null) {
        savedControllerState = new Bundle();
        mSavedControllerStates.put(page, savedControllerState);
    } else {/*from w  w w  .  j ava 2s.  c  o  m*/
        savedControllerState.clear();
    }
    controller.performPause();
    controller.performSaveInstanceState(savedControllerState);
    controller.performStop();
    controller.performOnDetach();
    container.removeView(controller.getView());
    controller.performDestroy();

    if (mDontCachePages) {
        mActivePageControllers.remove(position);
        HotspotPageEntry e = controller.getPage();
        mCachedControllers.remove(e);
    }

}

From source file:individual.leobert.calendar.CalendarDateView.java

private void init() {
    final int[] dateArr = CalendarUtil.getYMD(new Date());

    setAdapter(new PagerAdapter() {
        @Override/*from w ww .j  a v a  2  s  .c  om*/
        public int getCount() {
            return Integer.MAX_VALUE;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, final int position) {

            CalendarView view;

            if (!cache.isEmpty()) {
                view = cache.removeFirst();
            } else {
                view = new CalendarView(container.getContext(), row);
            }

            view.setOnItemClickListener(onItemClickListener);
            view.setAdapter(mAdapter);

            view.setData(getMonthOfDayList(dateArr[0], dateArr[1] + position - Integer.MAX_VALUE / 2),
                    position == Integer.MAX_VALUE / 2);
            container.addView(view);
            views.put(position, view);

            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
            cache.addLast((CalendarView) object);
            views.remove(position);
        }
    });

    addOnPageChangeListener(new SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);

            if (onItemClickListener != null) {
                CalendarView view = views.get(position);
                Object[] obs = view.getSelect();
                onItemClickListener.onItemClick((View) obs[0], (int) obs[1], (CalendarBean) obs[2]);
            }

            mCalendarLayoutChangeListener.onLayoutChange(CalendarDateView.this);
        }
    });
}