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:de.mrapp.android.dialog.decorator.WizardDialogDecorator.java

/**
 * Inflates the tab layout, which indicates the currently shown fragment.
 *///from w ww .  j a  v  a  2  s.  c  o m
private void inflateTabLayout() {
    if (getDialogRootView() != null) {
        LayoutInflater layoutInflater = LayoutInflater.from(getContext());
        ViewGroup headerContainer = (ViewGroup) getDialogRootView().findViewById(R.id.header);
        ViewGroup contentContainer = (ViewGroup) getDialogRootView().findViewById(R.id.content_container);

        if (tabLayout != null) {
            headerContainer.removeViewInLayout(tabLayout);
            contentContainer.removeView(tabLayout);
            tabLayout = null;
        }

        if (getDialog().isHeaderShown() && getTabPosition() != TabPosition.NO_HEADER
                && ((TextUtils.isEmpty(getDialog().getTitle()) && TextUtils.isEmpty(getDialog().getMessage()))
                        || getTabPosition() == TabPosition.PREFER_HEADER)) {
            tabLayout = (TabLayout) layoutInflater.inflate(R.layout.wizard_dialog_tab_layout, headerContainer,
                    false);
            headerContainer.addView(tabLayout);
        } else {
            tabLayout = (TabLayout) layoutInflater.inflate(R.layout.wizard_dialog_tab_layout, contentContainer,
                    false);
            contentContainer.addView(tabLayout, 0);
        }

        tabLayout.setupWithViewPager(viewPager);
    }
}

From source file:org.michaelbel.bottomsheet.BottomSheet.java

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

    if (backgroundColor == 0) {
        backgroundColor = darkTheme ? 0xFF424242 : 0xFFFFFFFF;
    }//from  w ww  .java  2 s  .c o m

    if (titleTextColor == 0) {
        titleTextColor = darkTheme ? 0xB3FFFFFF : 0x8A000000;
    }

    if (itemTextColor == 0) {
        itemTextColor = darkTheme ? 0xFFFFFFFF : 0xDE000000;
    }

    if (iconColor == 0) {
        iconColor = darkTheme ? 0xFFFFFFFF : 0x8A000000;
    }

    if (itemSelector == 0) {
        itemSelector = darkTheme ? R.drawable.selectable_dark : R.drawable.selectable_light;
    }

    Window window = getWindow();
    window.setWindowAnimations(R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        if (Build.VERSION.SDK_INT >= 16) {
            containerView.setBackground(shadowDrawable);
        } else {
            containerView.setBackgroundDrawable(shadowDrawable);
        }
        containerView.setPadding(0, backgroundPaddingTop, 0, Utils.dp(getContext(), 8));
    }

    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }

    containerView.setVisibility(View.INVISIBLE);
    containerView.setBackgroundColor(backgroundColor);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM;

    containerView.setLayoutParams(params);
    container.addView(containerView, 0);

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }

        FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) containerView.getLayoutParams();
        params1.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params1.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params1.gravity = Gravity.START | Gravity.TOP;

        containerView.addView(customView, params1);
    } else {
        int topOffset = 0;

        if (titleText != null) {
            TextView titleTextView = new TextView(getContext());
            titleTextView.setLines(1);
            titleTextView.setMaxLines(1);
            titleTextView.setSingleLine(true);
            titleTextView.setText(titleText);
            titleTextView.setTextColor(titleTextColor);
            titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleTextView.setGravity(Gravity.CENTER_VERTICAL);

            FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    Utils.dp(getContext(), 56));
            params0.gravity = Gravity.START | Gravity.TOP;
            params0.leftMargin = Utils.dp(getContext(), 16);
            params0.rightMargin = Utils.dp(getContext(), 16);

            titleTextView.setLayoutParams(params0);
            containerView.addView(titleTextView);
            titleTextView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 56;
        }

        BottomSheetAdapter adapter = new BottomSheetAdapter();

        if (mItems != null || mItemsRes != null) {
            if (contentType == LIST) {
                FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                params2.topMargin = Utils.dp(getContext(), topOffset);

                ListView listView = new ListView(getContext());
                listView.setSelector(itemSelector);
                listView.setDividerHeight(0);
                listView.setAdapter(adapter);
                listView.setDrawSelectorOnTop(true);
                listView.setVerticalScrollBarEnabled(false);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        dismissWithButtonClick(i);
                    }
                });
                listView.setLayoutParams(params2);
                containerView.addView(listView);
            } else if (contentType == GRID) {
                FrameLayout.LayoutParams params3 = new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

                GridView gridView = new GridView(getContext());
                gridView.setSelector(itemSelector);
                gridView.setAdapter(adapter);
                gridView.setNumColumns(3);
                gridView.setVerticalScrollBarEnabled(false);
                gridView.setVerticalSpacing(Utils.dp(getContext(), 16));
                gridView.setPadding(Utils.dp(getContext(), 0), Utils.dp(getContext(), topOffset + 8),
                        Utils.dp(getContext(), 0), Utils.dp(getContext(), 16));
                gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        dismissWithButtonClick(i);
                    }
                });
                gridView.setLayoutParams(params3);
                containerView.addView(gridView);
            }

            if (mItems != null) {
                for (int a = 0; a < mItems.length; a++) {
                    items.add(new Item(mItems[a], mIcons != null ? mIcons[a] : 0));
                }
            } else {
                for (int a = 0; a < mItemsRes.length; a++) {
                    items.add(new Item(getContext().getText(mItemsRes[a]), mIcons != null ? mIcons[a] : 0));
                }
            }

            adapter.notifyDataSetChanged();
        }
    }

    WindowManager.LayoutParams params4 = window.getAttributes();
    params4.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params4.gravity = Gravity.TOP | Gravity.START;
    params4.dimAmount = 0;
    params4.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params4.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params4.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params4);
}

From source file:com.github.pennyfive.sqlitestudio.ui.PackagesFragment.java

@Override
public void onLoadFinished(Loader<Result> resultLoader, Result result) {
    TextView databaseCountHeader = (TextView) View.inflate(getActivity(), R.layout.header_text, null);
    databaseCountHeader.setText(getResources().getQuantityString(R.plurals.databases_header_num_databases,
            result.getTotalNumDatabases(), result.getTotalNumDatabases()));
    listView.addHeaderView(databaseCountHeader, null, false);

    listView.setAdapter(new BinderAdapter<ScannedPackage>(getActivity(), result.getScannedPackages()) {
        @Override//from w  w  w .j a v  a 2 s .  c o m
        protected View newView(LayoutInflater inflater, ViewGroup parent) {
            return inflater.inflate(R.layout.item_package, parent, false);
        }

        @Override
        protected void bindView(View view, final ScannedPackage item, int position) {
            Drawable applicationIcon = getApplicationIcon(item.getPackageName());
            ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(applicationIcon);

            String applicationName = getApplicationName(item.getPackageName());
            ((TextView) view.findViewById(R.id.application_name)).setText(applicationName);

            ((TextView) view.findViewById(R.id.package_name)).setText(item.getPackageName());

            ((TextView) view.findViewById(R.id.num_databases)).setText(String.valueOf(item.getNumDatabases()));

            final ViewGroup databaseLayout = (ViewGroup) view.findViewById(R.id.database_layout);
            databaseLayout.removeAllViews();

            final LayoutInflater inflater = LayoutInflater.from(getActivity());

            final int databasesCount = item.getNumDatabases();
            int initialItemCount = databasesCount > NUM_DATABASES_WHEN_COLLAPSED + 1
                    ? NUM_DATABASES_WHEN_COLLAPSED
                    : databasesCount;
            for (int i = 0; i < initialItemCount; i++) {
                databaseLayout
                        .addView(inflateDatabaseItem(inflater, databaseLayout, item.getDatabasePaths().get(i)));
            }

            if (databasesCount > initialItemCount) {
                View showAllFooter = inflater.inflate(R.layout.item_package_show_all_extra, null);
                databaseLayout.addView(showAllFooter);
                showAllFooter.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        databaseLayout.removeView(v);
                        for (int i = databaseLayout.getChildCount(); i < databasesCount; i++) {
                            databaseLayout.addView(inflateDatabaseItem(inflater, databaseLayout,
                                    item.getDatabasePaths().get(i)));
                        }
                    }
                });
            }
        }

        private View inflateDatabaseItem(LayoutInflater inflater, ViewGroup parent, final String databasePath) {
            View databaseItem = inflater.inflate(R.layout.item_package_database_extra, parent, false);
            String databaseFileName = databasePath.substring(databasePath.lastIndexOf('/') + 1,
                    databasePath.length());
            ((TextView) databaseItem.findViewById(R.id.text)).setText(databaseFileName);
            databaseItem.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    onDatabaseSelected(databasePath);
                }
            });
            return databaseItem;
        }
    });
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

private void prepareForMoving(MotionEvent ev) {
    maybeStartTracking = false;//from   w ww. j a v  a 2s  .  com
    startedTracking = true;
    startedTrackingX = (int) ev.getX();
    containerViewBack.setVisibility(View.VISIBLE);
    beginTrackingSent = false;

    BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
    View fragmentView = lastFragment.fragmentView;
    if (fragmentView == null) {
        fragmentView = lastFragment.createView(parentActivity);
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    ViewGroup parent = (ViewGroup) fragmentView.getParent();
    if (parent != null) {
        parent.removeView(fragmentView);
    }
    if (lastFragment.actionBar != null && lastFragment.actionBar.getAddToContainer()) {
        parent = (ViewGroup) lastFragment.actionBar.getParent();
        if (parent != null) {
            parent.removeView(lastFragment.actionBar);
        }
        if (removeActionBarExtraHeight) {
            lastFragment.actionBar.setOccupyStatusBar(false);
        }
        containerViewBack.addView(lastFragment.actionBar);
        lastFragment.actionBar.setTitleOverlayText(titleOverlayText);
    }
    containerViewBack.addView(fragmentView);
    ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    fragmentView.setLayoutParams(layoutParams);
    if (!lastFragment.hasOwnBackground && fragmentView.getBackground() == null) {
        fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
    }
    lastFragment.onResume();
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

private void presentFragmentInternalRemoveOld(boolean removeLast, final BaseFragment fragment) {
    if (fragment == null) {
        return;/*  www. j a  v  a2s  .  c  om*/
    }
    fragment.onPause();
    if (removeLast) {
        fragment.onFragmentDestroy();
        fragment.setParentLayout(null);
        fragmentsStack.remove(fragment);
    } else {
        if (fragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) fragment.fragmentView.getParent();
            if (parent != null) {
                parent.removeView(fragment.fragmentView);
            }
        }
        if (fragment.actionBar != null && fragment.actionBar.getAddToContainer()) {
            ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
            if (parent != null) {
                parent.removeView(fragment.actionBar);
            }
        }
    }
    containerViewBack.setVisibility(View.GONE);
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public boolean addFragmentToStack(BaseFragment fragment, int position) {
    if (delegate != null && !delegate.needAddFragmentToStack(fragment, this) || !fragment.onFragmentCreate()) {
        return false;
    }/*  ww w . j av a 2 s .c  o  m*/
    fragment.setParentLayout(this);
    if (position == -1) {
        if (!fragmentsStack.isEmpty()) {
            BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
            previousFragment.onPause();
            if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
                ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
                if (parent != null) {
                    parent.removeView(previousFragment.actionBar);
                }
            }
            if (previousFragment.fragmentView != null) {
                ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
                if (parent != null) {
                    parent.removeView(previousFragment.fragmentView);
                }
            }
        }
        fragmentsStack.add(fragment);
    } else {
        fragmentsStack.add(position, fragment);
    }
    return true;
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

private void onSlideAnimationEnd(final boolean backAnimation) {
    if (!backAnimation) {
        BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
        lastFragment.onPause();//from  ww w. j  a va  2 s .co m
        lastFragment.onFragmentDestroy();
        lastFragment.setParentLayout(null);
        fragmentsStack.remove(fragmentsStack.size() - 1);

        LinearLayoutContainer temp = containerView;
        containerView = containerViewBack;
        containerViewBack = temp;
        bringChildToFront(containerView);

        lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
        currentActionBar = lastFragment.actionBar;
        lastFragment.onResume();
        lastFragment.onBecomeFullyVisible();
    } else {
        BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
        lastFragment.onPause();
        if (lastFragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) lastFragment.fragmentView.getParent();
            if (parent != null) {
                parent.removeView(lastFragment.fragmentView);
            }
        }
        if (lastFragment.actionBar != null && lastFragment.actionBar.getAddToContainer()) {
            ViewGroup parent = (ViewGroup) lastFragment.actionBar.getParent();
            if (parent != null) {
                parent.removeView(lastFragment.actionBar);
            }
        }
    }
    containerViewBack.setVisibility(View.GONE);
    startedTracking = false;
    animationInProgress = false;
    containerView.setTranslationX(0);
    containerViewBack.setTranslationX(0);
    setInnerTranslationX(0);
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public void showLastFragment() {
    if (fragmentsStack.isEmpty()) {
        return;/*from  www. jav  a 2s  . co m*/
    }
    for (int a = 0; a < fragmentsStack.size() - 1; a++) {
        BaseFragment previousFragment = fragmentsStack.get(a);
        if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
            ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
            if (parent != null) {
                parent.removeView(previousFragment.actionBar);
            }
        }
        if (previousFragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
            if (parent != null) {
                previousFragment.onPause();
                parent.removeView(previousFragment.fragmentView);
            }
        }
    }
    BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
    previousFragment.setParentLayout(this);
    View fragmentView = previousFragment.fragmentView;
    if (fragmentView == null) {
        fragmentView = previousFragment.createView(parentActivity);
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
        if (removeActionBarExtraHeight) {
            previousFragment.actionBar.setOccupyStatusBar(false);
        }
        ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
        if (parent != null) {
            parent.removeView(previousFragment.actionBar);
        }
        containerView.addView(previousFragment.actionBar);
        previousFragment.actionBar.setTitleOverlayText(titleOverlayText);
    }
    containerView.addView(fragmentView);
    ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    fragmentView.setLayoutParams(layoutParams);
    previousFragment.onResume();
    currentActionBar = previousFragment.actionBar;
    if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
        fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
    }
}

From source file:com.google.android.apps.dashclock.configuration.ConfigureAppearanceFragment.java

private void configureStylePager(final ViewPager pager, final PagerPositionStrip positionStrip,
        final String[] styleNames, final String styleComponent, final int gravity, final String preference) {
    String currentStyleName = mCurrentStyleNames.get(preference);

    final LayoutInflater inflater = getActivity().getLayoutInflater();
    pager.setAdapter(new PagerAdapter() {
        @Override/*from   w ww  .  ja va2s . com*/
        public int getCount() {
            return styleNames.length;
        }

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

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            FrameLayout wrapper = new FrameLayout(getActivity());
            ViewPager.LayoutParams wrapperLp = new ViewPager.LayoutParams();
            wrapper.setLayoutParams(wrapperLp);
            String styleName = styleNames[position];
            if (styleName.contains("analog")) {
                styleName += "_white";
            }
            View v = inflater.inflate(
                    AppearanceConfig.getLayoutByStyleName(getActivity(), styleComponent, styleName), container,
                    false);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.gravity = gravity;
            v.setLayoutParams(lp);
            wrapper.addView(v);
            container.addView(wrapper);
            return wrapper;
        }

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

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mCurrentStyleNames.put(preference, styleNames[position]);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            positionStrip.setPosition(position + positionOffset);
        }
    });

    positionStrip.setPageCount(styleNames.length);

    pager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                showPositionStrips(true, -1);
                break;

            case MotionEvent.ACTION_UP:
                showPositionStrips(false, AUTO_HIDE_DELAY_MILLIS);
                break;
            }
            return false;
        }
    });

    for (int i = 0; i < styleNames.length; i++) {
        if (currentStyleName.equals(styleNames[i])) {
            pager.setCurrentItem(i);
            positionStrip.setPosition(i);
            break;
        }
    }
}

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

/**
 * Parses the show ad input parameters and runs the show ad action on the UI thread.
 * //from  w ww.j a  va2 s  .  c o m
 * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input
 *          parameters.
 * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see
 *         if an ad was successfully retrieved.
 */
private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) {
    if (adView == null) {
        return new PluginResult(Status.ERROR, "adView is null, call createBannerView first.");
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (show == isBannerVisible) {
                // no change

            } else if (show) {
                if (adView.getParent() != null) {
                    ((ViewGroup) adView.getParent()).removeView(adView);
                }

                if (isBannerOverlap) {
                    RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                    if (isOffsetStatusBar) {
                        int titleBarHeight = 0;
                        Rect rectangle = new Rect();
                        Window window = AdMobAds.this.cordova.getActivity().getWindow();
                        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);

                        if (isBannerAtTop) {
                            if (rectangle.top == 0) {
                                int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                                titleBarHeight = contentViewTop - rectangle.top;
                            }
                            params2.topMargin = titleBarHeight;

                        } else {
                            if (rectangle.top > 0) {
                                int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT)
                                        .getBottom();
                                titleBarHeight = contentViewBottom - rectangle.bottom;
                            }
                            params2.bottomMargin = titleBarHeight;
                        }

                    } else if (isBannerAtTop) {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_TOP);

                    } else {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    }

                    if (adViewLayout == null) {
                        adViewLayout = new RelativeLayout(cordova.getActivity());
                        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.MATCH_PARENT,
                                RelativeLayout.LayoutParams.MATCH_PARENT);
                        if (CORDOVA_4) {
                            ((ViewGroup) webView.getView().getParent()).addView(adViewLayout, params);
                        } else {
                            ((ViewGroup) webView).addView(adViewLayout, params);
                        }
                    }
                    adViewLayout.addView(adView, params2);
                    adViewLayout.bringToFront();

                } else {
                    if (CORDOVA_4) {
                        ViewGroup wvParentView = (ViewGroup) webView.getView().getParent();

                        if (parentView == null) {
                            parentView = new LinearLayout(webView.getContext());
                        }

                        if (wvParentView != null && wvParentView != parentView) {
                            wvParentView.removeView(webView.getView());
                            ((LinearLayout) parentView).setOrientation(LinearLayout.VERTICAL);
                            parentView.setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                            ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
                            webView.getView().setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                            ViewGroup.LayoutParams.MATCH_PARENT, 1.0F));
                            parentView.addView(webView.getView());
                            cordova.getActivity().setContentView(parentView);
                        }

                    } else {
                        parentView = (ViewGroup) ((ViewGroup) webView).getParent();
                    }

                    if (isBannerAtTop) {
                        parentView.addView(adView, 0);
                    } else {
                        parentView.addView(adView);
                    }
                    parentView.bringToFront();
                    parentView.requestLayout();

                }

                adView.setVisibility(View.VISIBLE);
                isBannerVisible = true;

            } else {
                adView.setVisibility(View.GONE);
                isBannerVisible = false;
            }

            if (callbackContext != null) {
                callbackContext.success();
            }
        }
    });
    return null;
}