Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

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

Prototype

@Override
public void addView(View child, LayoutParams params) 

Source Link

Document

Adds a child view with the specified layout parameters.

Usage

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

/**
 * Parses the show ad input parameters and runs the show ad action on the UI thread.
 * //from   w  w w . j a va  2s  .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);
                    }

                    adViewLayout.addView(adView, params2);
                    adViewLayout.bringToFront();

                } else {
                    ViewGroup parentView = (ViewGroup) webView.getParent();
                    if (isBannerAtTop) {
                        parentView.addView(adView, 0);
                    } else {
                        parentView.addView(adView);
                    }
                    parentView.bringToFront();
                }

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

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

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

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

private void _showBannerAd_split(String position, String size) {
    if (webView != null) {
        ViewGroup parentView = (ViewGroup) webView.getParent();
        if (parentView != null) {
            if (position.equals("top-left") || position.equals("top-center") || position.equals("top-right")
                    || position.equals("left") || position.equals("center") || position.equals("right")) {
                parentView.addView(bannerView, 0);
            } else {
                parentView.addView(bannerView);
            }/* ww w.ja v  a 2 s.co  m*/
            //parentView.bringToFront();
        }
    }
}

From source file:de.mrapp.android.dialog.decorator.HeaderDialogDecorator.java

/**
 * Inflates the dialog's header./*from w  w  w .  ja  v a  2  s  . com*/
 */
private void inflateHeader() {
    ViewGroup rootView = getRootView();

    if (rootView != null) {
        LayoutInflater layoutInflater = LayoutInflater.from(getContext());
        headerContainer = (ViewGroup) layoutInflater.inflate(R.layout.material_dialog_header, rootView, false);
        headerBackgroundImageView = (ImageView) headerContainer.findViewById(R.id.header_background_image_view);
        headerIconImageView = (ImageView) headerContainer.findViewById(R.id.header_icon_image_view);
        headerDivider = headerContainer.findViewById(R.id.header_divider);
        rootView.addView(headerContainer, 0);
    }
}

From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java

/**
 * Called from FindActivity.onActivityResult(). Used to 
 * update the Find's View, specifically the date, lat, long,
 * and alarm icon fields.//from  w  w w. j  a va2s  . c o m
 * 
 * @param context, the calling Activity
 * @param find, the current Find
 * @param view, the FindActivity's content view
 * @param intent, the Intent that is passed to the menu activity
 */
public void onActivityResultCallback(Context context, Find find, View view, Intent intent) {
    Log.i(TAG, "onActivityResultCallbac");
    // Intent is NOT null, meaning it includes reminder
    // date and location information set by the user
    if (intent != null) {
        Bundle bundle = intent.getExtras();

        // Get date, longitude, and latitude
        String date = bundle.getString(Find.TIME);
        Double longitude = bundle.getDouble(Find.LONGITUDE);
        Double latitude = bundle.getDouble(Find.LATITUDE);

        TextView tv = (TextView) view.findViewById(R.id.isAdhocTextView);

        Integer is_adhoc = bundle.getInt(Find.IS_ADHOC);
        Log.i(TAG, "is_adhoc = " + is_adhoc);
        if (tv != null) {
            Log.i(TAG, "Setting isAdhocTextView to " + is_adhoc);
            tv.setText("" + is_adhoc);
        }

        // Display user specified longitude and latitude
        tv = (TextView) view.findViewById(R.id.longitudeValueTextView);
        tv.setText(String.valueOf(longitude));
        tv = (TextView) view.findViewById(R.id.latitudeValueTextView);
        tv.setText(String.valueOf(latitude));

        // Remove the old row that displays time and replace it
        // with a new row that include an alarm clock icon to
        // visually indicate this find has a reminder attached
        ViewGroup parent = (ViewGroup) view.findViewById(R.id.timeValueTextView).getParent();
        parent.removeAllViews();
        ImageView alarmIcon = new ImageView(context);
        alarmIcon.setImageResource(R.drawable.reminder_alarm);
        TableRow.LayoutParams lp1 = new TableRow.LayoutParams(30, 30);
        lp1.setMargins(0, 6, 80, 0);
        parent.addView(alarmIcon, lp1);
        TextView mCloneTimeTV = new TextView(context);
        mCloneTimeTV.setId(R.id.timeValueTextView);
        mCloneTimeTV.setText(date);
        mCloneTimeTV.setTextSize(12);
        TextView mTimeTV = (TextView) view.findViewById(R.id.timeValueTextView);
        mTimeTV = mCloneTimeTV;
        TableRow.LayoutParams lp2 = new TableRow.LayoutParams();
        lp2.setMargins(6, 6, 0, 0);
        parent.addView(mTimeTV, lp2);
    }
}

From source file:at.ac.uniklu.mobile.sportal.MensaMenuFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    MensaActivity ma = (MensaActivity) getActivity();

    if (ma.isDataAvailable()) {
        final MenuCategory mc = ma.getMenuCategory(mIndex);
        ViewGroup container = (ViewGroup) getView().findViewById(R.id.menu_items_container);
        LayoutInflater inflater = getLayoutInflater(getArguments());

        container.findViewById(R.id.mensa_website).setOnClickListener(new View.OnClickListener() {
            @Override/*from  w  w w.  jav  a 2  s .  c o m*/
            public void onClick(View v) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mc.link)));
            }
        });

        for (MenuItem mi : mc.menuItems) {
            View menuItem = inflater.inflate(R.layout.mensa_menu_item, container, false);

            if (StringUtils.isEmpty(mi.title)) {
                menuItem.findViewById(R.id.text_title).setVisibility(View.GONE);
            } else {
                ((TextView) menuItem.findViewById(R.id.text_title)).setText(mi.title);
            }

            ((TextView) menuItem.findViewById(R.id.text_description)).setText(mi.description);

            if (!StringUtils.isEmpty(mi.description)) {
                container.addView(menuItem, container.getChildCount() - 1);
            }
        }
    }
}

From source file:com.dldzkj.app.renxing.SplashActivity.java

private void initView() {
    vp = (ViewPager) findViewById(R.id.viewPager);
    ViewGroup group = (ViewGroup) findViewById(R.id.viewGroup);
    //?ID/*  www .  j a v  a2  s .c o  m*/
    imgIdArray = new int[] { R.drawable.w1, R.drawable.w2, R.drawable.w3 };
    tips = new ImageView[imgIdArray.length];
    for (int i = 0; i < tips.length; i++) {
        ImageView imageView = new ImageView(this);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(10, 10));
        tips[i] = imageView;
        if (i == 0) {
            tips[i].setBackgroundResource(R.drawable.dot_focus);
        } else {
            tips[i].setBackgroundResource(R.drawable.dot_blur);
        }

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        layoutParams.leftMargin = 15;
        layoutParams.rightMargin = 15;
        layoutParams.bottomMargin = 20;
        group.addView(imageView, layoutParams);
    }
    //
    mImageViews = new ImageView[imgIdArray.length];
    for (int i = 0; i < mImageViews.length; i++) {
        ImageView imageView = new ImageView(this);
        mImageViews[i] = imageView;
        imageView.setBackgroundResource(imgIdArray[i]);
    }
    mImageViews[mImageViews.length - 1].setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SplashActivity.this, EnterActivity.class));
            finish();
        }
    });

    //Adapter
    vp.setAdapter(new MyAdapter());
    //??
    vp.setOnPageChangeListener(this);
    //ViewPager, 100??
    vp.setCurrentItem(0);

}

From source file:com.albedinsky.android.ui.navigation.NavigationLayout.java

/**
 * Ensures that a toolbar widget is contained within the current view hierarchy of this navigation
 * layout. If not it will be inflated from a layout resource presented within the current theme
 * and inserted into this layout at the proper place.
 *//*from  w  ww .  j ava 2s . c om*/
private void ensureToolbarWithinLayout() {
    final View toolbar = findViewById(R.id.ui_toolbar);
    if (toolbar == null) {
        final ViewGroup contentLayout = (ViewGroup) findViewById(R.id.ui_navigation_layout_content);
        if (contentLayout != null) {
            final Context context = getContext();
            final TypedValue typedValue = new TypedValue();
            if (context.getTheme().resolveAttribute(R.attr.uiNavigationToolbarLayout, typedValue, true)) {
                // Insert the Toolbar above the content container.
                contentLayout.addView(mLayoutInflater.inflate(typedValue.resourceId, contentLayout, false), 0);
            }
        }
    }
}

From source file:com.uowd.sport.nestdrecylerviews_vert_horizontal.ImagePagerAdapterMixCatalouge.java

@Override
public Object instantiateItem(ViewGroup view, final int position) {
    final View imageLayout = inflater.inflate(R.layout.horizontal_item, view, false);
    final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.random_image_view);
    final ProgressBar pBar = (ProgressBar) imageLayout.findViewById(R.id.progressBar);
    pBar.setVisibility(View.VISIBLE);
    pBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(ac, R.color.ColorPrimary),
            android.graphics.PorterDuff.Mode.MULTIPLY);
    imageView.setTag(position);//  w w w .  j  a  v a  2 s.  c o m

    String mCollectionType = "2";

    Picasso.with(ac.getApplicationContext())
            .load("https://gizbo.ae/GizboApp/GizboImages/catalogues/1155/" + mCollectionType + "/"
                    + _mImagesName.get(position).replace("/thumbnails", ""))
            .into(imageView, new com.squareup.picasso.Callback() {
                @Override
                public void onSuccess() {
                    pBar.setVisibility(View.GONE);
                }

                @Override
                public void onError() {
                    //pBar.setVisibility(View.GONE);
                }
            });
    view.addView(imageLayout, 0);
    return imageLayout;
}

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);/*from www  .j a v a  2 s.  c o m*/
    webview.getSettings().setBuiltInZoomControls(allowPinchZoom);
    webview.setAllowZoomButtons(false);
    webview.setAllowPinchZoom(allowPinchZoom);
    if (showZoomButtons) {
        if (allowPinchZoom) {
            webview.setAllowZoomButtons(true);
        } else {
            zoomParent.addView(zoom, ZOOM_PARAMS);
            zoom.setVisibility(View.GONE);
        }
    }
}

From source file:com.philliphsu.bottomsheetpickers.date.PagingMonthAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    MonthView v;//from  w w  w . j  a  va2  s  . com
    HashMap<String, Integer> drawingParams = null;
    v = createMonthView(mContext, mThemeDark, mAccentColor);
    // Set up the new view
    v.setClickable(true);
    v.setOnDayClickListener(this);
    if (drawingParams == null) {
        drawingParams = new HashMap<>();
    }
    drawingParams.clear();

    final int month = getMonth(position);
    final int year = getYear(position);

    int selectedDay = -1;
    if (isSelectedDayInMonth(year, month)) {
        selectedDay = mSelectedDay.day;
    }

    // Invokes requestLayout() to ensure that the recycled view is set with the appropriate
    // height/number of weeks before being displayed.
    v.reuse();

    drawingParams.put(MonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
    drawingParams.put(MonthView.VIEW_PARAMS_YEAR, year);
    drawingParams.put(MonthView.VIEW_PARAMS_MONTH, month);
    drawingParams.put(MonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek());
    v.setMonthParams(drawingParams);
    v.invalidate();
    container.addView(v, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
    mMonthYearTitles.append(position, v.getMonthAndYearString());
    mMonthViews.add(v);
    return v;
}