Example usage for android.app Activity addContentView

List of usage examples for android.app Activity addContentView

Introduction

In this page you can find the example usage for android.app Activity addContentView.

Prototype

public void addContentView(View view, ViewGroup.LayoutParams params) 

Source Link

Document

Add an additional content view to the activity.

Usage

From source file:Main.java

public static LinearLayout setProgressBarLayout(Activity activity) {

    LinearLayout progressBarLayout = new LinearLayout(activity);
    progressBarLayout.setGravity(Gravity.CENTER);
    ProgressBar spinner = new ProgressBar(activity);
    progressBarLayout.addView(spinner);/*from  ww  w . j av  a  2 s.c  om*/
    activity.addContentView(progressBarLayout,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    return progressBarLayout;
}

From source file:com.javielinux.facebook.FacebookHandler.java

public FacebookHandler(Activity activity) {
    if (activity != null) {
        this.activity = activity;

        layout = new LinearLayout(activity);
        activity.addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        isWebViewShown = false;/*from  w  ww.jav a  2 s .co  m*/
    }
}

From source file:com.google.unity.AdMobPlugin.java

/**
 * Creates an {@link AdView} to old ads.
 *
 * @param activity The activity to place the {@code AdView}.
 * @param publisherId Your publisher ID from the AdMob or DFP console
 * @param adSizeString A string ad size constant representing  the desired ad size.
 * @param positionAtTop True to position the ad at the top of the screen. False to position
 *     the ad at the bottom of the screen.
 *///w ww  . j  a  va  2s .  c  om
public static void createBannerView(final Activity activity, final String publisherId,
        final String adSizeString, final boolean positionAtTop) {
    Log.d(LOGTAG, "called createBannerView in Java code");
    final AdMobPlugin plugin = AdMobPlugin.instance();
    plugin.activity = activity;
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            AdSize adSize = AdMobPlugin.adSizeFromSize(adSizeString);
            if (adSize == null) {
                Log.e(AdMobPlugin.LOGTAG, "AdSize is null. Did you use an AdSize constant?");
                return;
            }
            plugin.adView = new AdView(activity, adSize, publisherId);
            plugin.adView.setAdListener(plugin);
            LinearLayout layout = new LinearLayout(activity);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            layoutParams.gravity = positionAtTop ? Gravity.TOP : Gravity.BOTTOM;
            activity.addContentView(layout, layoutParams);
            LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
            layout.addView(plugin.adView, adParams);
        }
    });
}

From source file:com.yixia.zi.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/* w w  w .  j av  a2  s  . c  om*/
 *   The {@link Crouton} that should be added.
 */
private void addCroutonToView(Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }
    croutonView.startAnimation(crouton.getInAnimation());
    announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
    if (Style.DURATION_INFINITE != crouton.getStyle().durationInMilliseconds) {
        sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                crouton.getStyle().durationInMilliseconds + crouton.getInAnimation().getDuration());
    }
}

From source file:com.prashant.custom.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton//from  w w  w. j a va  2 s . c o m
 *   The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            croutonView.startAnimation(crouton.getInAnimation());
            announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
            if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                        crouton.getConfiguration().durationInMilliseconds
                                + crouton.getInAnimation().getDuration());
            }
        }
    });
}

From source file:com.machine.custom.view.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*  w w  w  .  j  a va  2s  . c o  m*/
 *   The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            //        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            //        } else {
            //          croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            //        }

            croutonView.startAnimation(crouton.getInAnimation());
            announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
            if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                        crouton.getConfiguration().durationInMilliseconds
                                + crouton.getInAnimation().getDuration());
            }
        }
    });
}

From source file:com.elephant.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * ./*w w  w  .j ava  2s . com*/
 * 
 * @param crouton
 *            The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align
            // with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
    // the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            croutonView.startAnimation(crouton.getInAnimation());
            announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
            if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                        crouton.getConfiguration().durationInMilliseconds
                                + crouton.getInAnimation().getDuration());
            }
        }
    });
}

From source file:com.partynetwork.iparty.app.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * .//from w  ww .ja v  a  2 s  .  co m
 * 
 * @param crouton
 *            The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align
            // with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }

            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
    // the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {

                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:com.arta.lib.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*from w  w  w  . j  av a 2  s .  c  o  m*/
 *     The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:com.example.androidannotationtesttwo.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * .//from w w  w.  j  a v  a  2  s  .com
 * 
 * @param crouton The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align
            // with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
                                 // the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}