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:org.telegram.ui.ChatProfileActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.chat_profile_layout, container, false);

        listView = (ListView) fragmentView.findViewById(R.id.listView);
        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override//from   w  ww  . j a va2 s  .c  o  m
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                int size = 0;
                if (info != null) {
                    size += info.participants.size();
                }
                if (i > 6 && i < size + 7) {
                    TLRPC.TL_chatParticipant user = info.participants.get(sortedUsers.get(i - 7));
                    if (user.user_id == UserConfig.clientUserId) {
                        return false;
                    }
                    if (info.admin_id != UserConfig.clientUserId
                            && user.inviter_id != UserConfig.clientUserId) {
                        return false;
                    }
                    selectedUser = user;

                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                    CharSequence[] items = new CharSequence[] { getStringEntry(R.string.KickFromGroup) };

                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (i == 0) {
                                kickUser(selectedUser);
                            }
                        }
                    });
                    builder.show().setCanceledOnTouchOutside(true);

                    return true;
                }
                return false;
            }
        });

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i == 2) {
                    SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                            Activity.MODE_PRIVATE);
                    String key = "notify_" + (-chat_id);
                    boolean value = preferences.getBoolean(key, true);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putBoolean(key, !value);
                    editor.commit();
                    listView.invalidateViews();
                } else if (i == 3) {
                    try {
                        Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                                RingtoneManager.TYPE_NOTIFICATION);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
                        SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                                Activity.MODE_PRIVATE);
                        Uri currentSound = null;

                        String defaultPath = null;
                        Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                        if (defaultUri != null) {
                            defaultPath = defaultUri.getPath();
                        }

                        String path = preferences.getString("sound_chat_path_" + chat_id, defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }

                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                        startActivityForResult(tmpIntent, 15);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else if (i == 5) {
                    MediaActivity fragment = new MediaActivity();
                    Bundle bundle = new Bundle();
                    bundle.putLong("dialog_id", -chat_id);
                    fragment.setArguments(bundle);
                    ((ApplicationActivity) parentActivity).presentFragment(fragment, "media_chat_" + chat_id,
                            false);
                } else {
                    int size = 0;
                    if (info != null) {
                        size += info.participants.size();
                    }
                    if (i > 6 && i < size + 7) {
                        int user_id = info.participants.get(sortedUsers.get(i - 7)).user_id;
                        if (user_id == UserConfig.clientUserId) {
                            return;
                        }
                        UserProfileActivity fragment = new UserProfileActivity();
                        Bundle args = new Bundle();
                        args.putInt("user_id", user_id);
                        fragment.setArguments(args);
                        ((ApplicationActivity) parentActivity).presentFragment(fragment, "user_" + user_id,
                                false);
                    } else {
                        if (size + 7 == i) {
                            if (info.participants.size() < 200) {
                                openAddMenu();
                            } else {
                                kickUser(null);
                            }
                        } else if (size + 7 == i + 1) {
                            kickUser(null);
                        }
                    }
                }
            }
        });

        listView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

public void setZoomControlEnable(boolean allowPinchZoom, boolean showZoomButtons) {
    final ViewGroup zoomParent = (ViewGroup) webview.getParent().getParent();
    if (zoom.getParent() == zoomParent)
        zoomParent.removeView(zoom);
    webview.getSettings().setBuiltInZoomControls(allowPinchZoom);
    webview.setAllowZoomButtons(false);//from w  ww  . ja va 2s.c om
    webview.setAllowPinchZoom(allowPinchZoom);
    if (showZoomButtons) {
        if (allowPinchZoom) {
            webview.setAllowZoomButtons(true);
        } else {
            zoomParent.addView(zoom, ZOOM_PARAMS);
            zoom.setVisibility(View.GONE);
        }
    }
}

From source file:com.gcssloop.diycode.activity.ImageActivity.java

/**
 * ? View ? initDatas ?//from  w  w  w. j av  a  2  s. c o m
 *
 * @param holder
 * @param root
 */
@Override
protected void initViews(ViewHolder holder, View root) {
    setTitle("");
    mCache = new DiskImageCache(this);
    if (mCurrentMode == MODE_ERROR) {
        //TODO 
        return;
    }
    // TODO ??
    // 
    ViewPager viewPager = holder.get(R.id.view_pager);

    Logger.e("Size" + images.size());
    final LayoutInflater inflater = getLayoutInflater();

    viewPager.setAdapter(new PagerAdapter() {
        @Override
        public int getCount() {
            return images.size();
        }

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

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = (PhotoView) inflater.inflate(R.layout.item_image, container, false);
            photoView.enable();
            String url = images.get(position);
            if (mCache.hasCache(url)) {
                String file = mCache.getDiskPath(url);
                Glide.with(ImageActivity.this).load(file).into(photoView);
            } else {
                Glide.with(ImageActivity.this).load(images.get(position)).into(photoView);
            }
            container.addView(photoView);
            Logger.e("Item");
            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            PhotoView photoView = (PhotoView) container.findViewById(R.id.photo_view);
            container.removeView(photoView);
        }
    });

    viewPager.setCurrentItem(current_image_position);
}

From source file:$.GooglePlayServicesExtension.java

public void GoogleMobileAds_RemoveBanner() {
        if (adView != null) {
            RunnerActivity.ViewHandler.post(new Runnable() {
                public void run() {
                    AbsoluteLayout layout = (AbsoluteLayout) RunnerActivity.CurrentActivity.findViewById(R.id.ad);
                    ViewGroup vg = (ViewGroup) layout;
                    if (vg != null) {
                        vg.removeView(adView);
                    }/* w  ww . java 2 s . c  om*/
                    adView.destroy();
                    adView = null;

                }
            });
        }
    }

From source file:com.appfeel.cordova.admob.AdMobAds.java

@Override
public void onDestroy() {
    if (adView != null) {
        adView.destroy();/*from  w w w. j  av a  2 s . c o  m*/
        adView = null;
    }
    if (adViewLayout != null) {
        ViewGroup parentView = (ViewGroup) adViewLayout.getParent();
        if (parentView != null) {
            parentView.removeView(adViewLayout);
        }
        adViewLayout = null;
    }
    connectivity.stopAllObservers(true);
    super.onDestroy();
}

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final void deleteView(ComponentPeerView view) {
    ViewGroup group = (ViewGroup) (view.getParent());

    if (group != null)
        group.removeView(view);
}

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final void deleteNativeSurfaceView(NativeSurfaceView view) {
    ViewGroup group = (ViewGroup) (view.getParent());

    if (group != null)
        group.removeView(view);
}

From source file:com.sabaibrowser.UI.java

protected void attachTabToContentView(Tab tab) {
    if ((tab == null) || (tab.getWebView() == null)) {
        return;//from  w w  w  .j a  v  a  2s  .com
    }
    View container = tab.getViewContainer();
    WebView mainView = tab.getWebView();
    // Attach the WebView to the container and then attach the
    // container to the content view.
    FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
    ViewGroup parent = (ViewGroup) mainView.getParent();
    if (parent != wrapper) {
        if (parent != null) {
            parent.removeView(mainView);
        }
        wrapper.addView(mainView);
    }
    parent = (ViewGroup) container.getParent();
    if (parent != mContentView) {
        if (parent != null) {
            parent.removeView(container);
        }
        mContentView.addView(container, COVER_SCREEN_PARAMS);
    }
}

From source file:istat.android.freedev.pagers.adapters.abs.AbsPagerStateAdapter.java

private void looperDestroyItem(ViewGroup container, int position, Fragment fragment) {

    PagerStateLooperAdapter adapter = ((PagerStateLooperAdapter) this);
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }//from  w w w  .j  a  v  a2s  .  c o m
    if (DEBUG)
        //         Log.v(TAG, "Removing item #" + position + ": f=" + fragment + " v="
        //               + (fragment).getView() + " TAG:" + fragment.getTag());

        while (mSavedState.size() <= position) {
            mSavedState.add(null);
        }
    mSavedState.set(position, mFragmentManager.saveFragmentInstanceState(fragment));

    if (fragment.getView() != null) {
        if (container == ((ViewGroup) fragment.getView().getParent()))
            container.removeView(fragment.getView());
        container.addView(fragment.getView());
    }

}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

@Nullable
@Override/* w ww.  j ava2  s  .c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.submissionMarkerIdList = new ArrayList<>();

    connectToGoogleApi();
    setupGoogleMap();
    createLocationRequest();

    if (this.fragmentView != null) {
        ViewGroup parent = (ViewGroup) this.fragmentView.getParent();
        if (parent != null)
            parent.removeView(this.fragmentView);
    }
    //this is needed to avoid all sorts of crashing with the map when goin back and forth between fragments
    try {
        if (this.fragmentView == null)
            this.fragmentView = inflater.inflate(R.layout.fragment_map, container, false);
        this.mapFragment = ((MapFragment) getChildFragmentManager().findFragmentById(R.id.googleMapFragment));
        //check if fragment is null. On API 19 childfragmentmanager returns null, so regular fragment manager is used
        if (this.mapFragment == null) {
            this.mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.googleMapFragment));
        }
        this.mapFragment.getMapAsync(this);

    } catch (InflateException e) {
        Log.e(TAG, "onCreateView: ", e);
        //this.mapFragment.getMapAsync(this);
    }
    setupButtons();
    return this.fragmentView;
}