Example usage for android.view Window getDecorView

List of usage examples for android.view Window getDecorView

Introduction

In this page you can find the example usage for android.view Window getDecorView.

Prototype

public abstract View getDecorView();

Source Link

Document

Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager.

Usage

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 ava  2  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;
}

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

/**
 * Creates and returns the layout params, which should be used by the dialog's root view.
 *
 * @return The layout params, which have been created, as an instance of the class {@link
 * RelativeLayout.LayoutParams}//from   w w  w .  j  a  v  a  2  s .  c o  m
 */
private RelativeLayout.LayoutParams createLayoutParams() {
    Rect windowDimensions = new Rect();
    Window window = getWindow();
    assert window != null;
    window.getDecorView().getWindowVisibleDisplayFrame(windowDimensions);
    int shadowWidth = isFullscreen() ? 0
            : getContext().getResources().getDimensionPixelSize(R.dimen.dialog_shadow_width);
    int leftInset = isFitsSystemWindowsLeft() && isFullscreen() && windowInsets != null ? windowInsets.left : 0;
    int topInset = isFitsSystemWindowsTop() && isFullscreen() && windowInsets != null ? windowInsets.top : 0;
    int rightInset = isFitsSystemWindowsRight() && isFullscreen() && windowInsets != null ? windowInsets.right
            : 0;
    int bottomInset = isFitsSystemWindowsBottom() && isFullscreen() && windowInsets != null
            ? windowInsets.bottom
            : 0;
    int leftMargin = getLeftMargin() - shadowWidth + leftInset;
    int topMargin = getTopMargin() - shadowWidth + topInset;
    int rightMargin = getRightMargin() - shadowWidth + rightInset;
    int bottomMargin = getBottomMargin() - shadowWidth + bottomInset;
    int width = getLayoutDimension(getWidth(), leftMargin + rightMargin, windowDimensions.right);
    int height = getLayoutDimension(getHeight(), topMargin + bottomMargin, windowDimensions.bottom);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
    layoutParams.leftMargin = leftMargin;
    layoutParams.topMargin = topMargin;
    layoutParams.rightMargin = rightMargin;
    layoutParams.bottomMargin = bottomMargin;

    if ((getGravity() & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) {
        layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    }

    if ((getGravity() & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) {
        layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    }

    if ((getGravity() & Gravity.LEFT) == Gravity.LEFT) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    }

    if ((getGravity() & Gravity.TOP) == Gravity.TOP) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    }

    if ((getGravity() & Gravity.RIGHT) == Gravity.RIGHT) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    }

    if ((getGravity() & Gravity.BOTTOM) == Gravity.BOTTOM) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    }

    return layoutParams;
}

From source file:paulscode.android.mupen64plusae.game.GameFragment.java

private void showSystemBars() {
    if (getActivity() != null) {

        final Window window = getActivity().getWindow();

        window.clearFlags(LayoutParams.FLAG_FULLSCREEN | LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | LayoutParams.FLAG_KEEP_SCREEN_ON);

        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    }/*from  w  w  w .j a  va2s.  co  m*/
}

From source file:lewa.support.v7.app.ActionBarActivityDelegateBase.java

final void ensureSubDecor() {
    Log.d("simply", "mHasActionBar:" + mHasActionBar + ",mSubDecor:" + mSubDecorInstalled
            + ",mOverlayActionBar:" + mOverlayActionBar);
    Window window = mActivity.getWindow();

    // Initializing the window decor can change window feature flags.
    // Make sure that we have the correct set before performing the test below.
    window.getDecorView();

    if (mHasActionBar && !mSubDecorInstalled) {
        //Add by Fan.Yang
        /*            *//**
                        * This needs some explanation. As we can not use the android:theme attribute
                        * pre-L, we emulate it by manually creating a LayoutInflater using a
                        * ContextThemeWrapper pointing to actionBarTheme.
                        *//*
                           TypedValue outValue = new TypedValue();
                           mActivity.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true);
                                   //  w  w w .  j  ava  2 s. c  o  m
                           Context themedContext;
                           if (outValue.resourceId != 0) {
                           themedContext = new ContextThemeWrapper(mActivity, outValue.resourceId);
                           } else {
                           themedContext = mActivity;
                           }*/
        if (mOverlayActionBar) {
            mActivity.superSetContentView(R.layout.abc_action_bar_decor_overlay);
        } else {
            mActivity.superSetContentView(R.layout.abc_action_bar_decor);
        }
        if (!isHome()) {
            mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            mActivity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

            mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
            mActivity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
        }
        mActionBarView = (ActionBarView) mActivity.findViewById(R.id.action_bar);
        mActionBarView.setWindowCallback(mActivity);
        mActionModeView = (ActionBarContextView) mActivity.findViewById(R.id.action_context_bar);
        splitActionBarView = (LewaActionBarContainer) mActivity.findViewById(R.id.split_action_bar);
        if (splitActionBarView != null) {

            splitActionBarView.setOnActionMenuDoubleClickListener(
                    new LewaActionBarContainer.OnActionMenuDoubleClickListener() {

                        @Override
                        public void onDoubleClick() {
                            // TODO Auto-generated method stub
                            Log.d(TAG, "===ActionMenuDouble===");
                            toggleActionMenuStyle(false);

                        }
                    });
            splitActionBarView.setOnActionModeMenuDoubleClickListener(
                    new LewaActionBarContainer.OnActionMenuDoubleClickListener() {

                        @Override
                        public void onDoubleClick() {
                            // TODO Auto-generated method stub
                            Log.d(TAG, "===ModeMenuDoubleClick===");
                            toggleActionMenuStyle(true);

                        }
                    });

            splitActionBarView
                    .setOnActionOptionMenuSlideListener(new LewaActionBarContainer.OnActionSlideListener() {
                        public void onSlide(boolean isUp) {
                            if (isUp) {

                                splitActionBarView.setActionOptionMenuVisibility(true);

                            } else {
                                splitActionBarView.setActionOptionMenuVisibility(false);

                            }
                        }
                    });

        }

        /**
         * Progress Bars
         */
        if (mFeatureProgress) {
            mActionBarView.initProgress();
        }
        if (mFeatureIndeterminateProgress) {
            mActionBarView.initIndeterminateProgress();
        }

        /**
         * Split Action Bar
         */
        boolean splitWhenNarrow = UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW.equals(getUiOptionsFromMetadata());
        boolean splitActionBar;

        if (splitWhenNarrow) {
            splitActionBar = mActivity.getResources().getBoolean(R.bool.abc_split_action_bar_is_narrow);
        } else {
            TypedArray a = mActivity.obtainStyledAttributes(R.styleable.Theme);
            //                splitActionBar = a
            //                        .getBoolean(R.styleable.Theme_windowActionBar, false);
            splitActionBar = true;
            a.recycle();
        }

        final ActionBarContainer splitView = (ActionBarContainer) mActivity.findViewById(R.id.split_action_bar);
        if (splitView != null) {
            mActionBarView.setSplitView(splitView);
            mActionBarView.setSplitActionBar(splitActionBar);
            mActionBarView.setSplitWhenNarrow(splitWhenNarrow);

            final ActionBarContextView cab = (ActionBarContextView) mActivity
                    .findViewById(R.id.action_context_bar);
            cab.setSplitView(splitView);
            cab.setSplitActionBar(splitActionBar);
            cab.setSplitWhenNarrow(splitWhenNarrow);
        }

        // Change our content FrameLayout to use the android.R.id.content id.
        // Useful for fragments.
        View content = mActivity.findViewById(android.R.id.content);
        content.setId(View.NO_ID);
        View abcContent = mActivity.findViewById(R.id.action_bar_activity_content);
        abcContent.setId(android.R.id.content);

        // A title was set before we've install the decor so set it now.
        if (mTitleToSet != null) {
            mActionBarView.setWindowTitle(mTitleToSet);
            mTitleToSet = null;
        }

        mSubDecorInstalled = true;
        supportInvalidateOptionsMenu();
    }
}

From source file:android.support.v17.leanback.app.BackgroundManager.java

/**
 * Makes the background visible on the given Window.  The background manager must be attached
 * when the background is set.//  w  w  w .j a  v a2  s  .com
 */
public void attach(Window window) {
    if (USE_SEPARATE_WINDOW) {
        attachBehindWindow(window);
    } else {
        attachToView(window.getDecorView());
    }
}

From source file:android.support.v7.app.WindowDecorActionBar.java

public WindowDecorActionBar(Activity activity, boolean overlayMode) {
    mActivity = activity;//from w  w w  .  j av a 2s. co m
    Window window = activity.getWindow();
    View decor = window.getDecorView();
    init(decor);
    if (!overlayMode) {
        mContentView = decor.findViewById(android.R.id.content);
    }
}

From source file:lewa.support.v7.internal.app.WindowDecorActionBar.java

public WindowDecorActionBar(ActionBarActivity activity, boolean overlayMode) {
    mActivity = activity;// w w w  . j  a va  2s .c  om
    Window window = activity.getWindow();
    View decor = window.getDecorView();
    init(decor);
    if (!overlayMode) {
        mContentView = decor.findViewById(android.R.id.content);
    }
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    final Window window = getWindow();
    final Rect rect = new Rect();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    final View contentView = window.findViewById(android.R.id.content);
    final int statusBarHeight = rect.top;
    contentView.getWindowVisibleDisplayFrame(rect);
    final int paddingTop = statusBarHeight + Utils.getActionBarHeight(this) - rect.top;
    contentView.setPadding(contentView.getPaddingLeft(), paddingTop, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
    return true;/*from  w  w  w .  j a  v a2s  .  com*/
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    final Window window = getWindow();
    final Rect rect = new Rect();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    final int actionBarHeight = ThemeUtils.getActionBarHeight(this);
    final View contentView = window.findViewById(android.R.id.content);
    final int[] location = new int[2];
    contentView.getLocationOnScreen(location);
    if (location[1] > actionBarHeight) {
        contentView.setPadding(contentView.getPaddingLeft(), 0, contentView.getPaddingRight(),
                contentView.getPaddingBottom());
        return true;
    }//from ww w  . j  a va  2 s.  c om
    final int statusBarHeight = rect.top;
    contentView.getWindowVisibleDisplayFrame(rect);
    final int paddingTop = statusBarHeight + actionBarHeight - rect.top;
    contentView.setPadding(contentView.getPaddingLeft(), paddingTop, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
    return true;
}

From source file:com.github.michaelins.lightstatusbar.LightStatusBar.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action/*w w  w.j  a va 2  s.  co  m*/
 *            The action to execute.
 * @param args
 *            JSONArry of arguments for the plugin.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return True if the action was valid, false otherwise.
 */
@Override
public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {

    LOG.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("isSupported".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M || SystemBarTintManager.IsMiuiV6Plus()) {
                    callbackContext.success("true");
                } else {
                    callbackContext.success("false");
                }
            }
        });
        return true;
    }

    if ("setStatusBarColor".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    webView.getView().setFitsSystemWindows(true);
                    if (SystemBarTintManager.IsMiuiV6Plus()) {
                        // MIUI6+ light status bar
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                            setTranslucentStatus(window, true);
                        }
                        SystemBarTintManager tintManager = new SystemBarTintManager(activity);
                        tintManager.setStatusBarTintEnabled(true);
                        tintManager.setStatusBarTintColor(Color.parseColor(args.getString(0)));
                        tintManager.setStatusBarDarkMode(true, activity);
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        // 6.0+ light status bar
                        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                        int uiOptions = window.getDecorView().getSystemUiVisibility()
                                | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                        window.getDecorView().setSystemUiVisibility(uiOptions);
                        setStatusBarBackgroundColor(args.getString(0));
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        setStatusBarBackgroundColor(args.getString(0));
                    }
                } catch (JSONException ignore) {
                    LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'");
                }
            }
        });
        return true;
    }

    if ("enable".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
        return true;
    }

    if ("disable".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
        return true;
    }
    return false;
}