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.mishiranu.dashchan.ui.gallery.GalleryActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void applyStatusNavigationTranslucency() {
    if (C.API_LOLLIPOP) {
        Window window = getWindow();
        int color = ACTION_BAR_COLOR;
        window.setStatusBarColor(color);
        window.setNavigationBarColor(color);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    }//w  w  w.j a v  a  2  s .co m
}

From source file:com.adityarathi.muo.utils.Common.java

/**
 * Returns the view container for the ActionBar.
 * @return//  w w  w.  j av a 2s.  co m
 */
public View getActionBarView(Activity activity) {
    Window window = activity.getWindow();
    View view = window.getDecorView();
    int resId = getResources().getIdentifier("action_bar_container", "id", "android");

    return view.findViewById(resId);
}

From source file:com.example.haizhu.myvoiceassistant.ui.RobotChatActivity.java

private void setStatusBarTranslate() {
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }/* w w w. j  ava  2s . co m*/
}

From source file:com.xxxifan.devbox.core.util.ViewUtils.java

/**
 * set status bar icon to light theme, which is called dark mode.
 * should be called in onCreate()/* w w w.  j ava 2s  .  c om*/
 */
public static void setStatusBarLightMode(Activity activity, boolean lightMode) {
    if (activity == null || activity.getWindow() == null) {
        return;
    }

    Window window = activity.getWindow();
    boolean changed = false;
    // try miui
    try {
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        int darkIcon = field.getInt(layoutParams);
        Method extraFlagField = window.getClass().getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, lightMode ? darkIcon : 0, darkIcon);
        changed = true;
    } catch (Exception ignored) {
    }

    // try flyme
    try {
        WindowManager.LayoutParams lp = window.getAttributes();
        Field darkIcon = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
        Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
        darkIcon.setAccessible(true);
        meizuFlags.setAccessible(true);
        int bit = darkIcon.getInt(null);
        int value = meizuFlags.getInt(lp);
        if (lightMode) {
            value |= bit;
        } else {
            value &= ~bit;
        }
        meizuFlags.setInt(lp, value);
        window.setAttributes(lp);
        changed = true;
    } catch (Exception ignored) {
    }

    if (!changed && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int visibility = window.getDecorView().getSystemUiVisibility();
        if (lightMode) {
            visibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        } else {
            visibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        window.getDecorView().setSystemUiVisibility(visibility);
    }
}

From source file:cz.metaverse.android.bilingualreader.helper.BookPanelOnTouchListener.java

/**
 * The entry method for any touch-related event.
 * @param view The WebView where the swipe took place
 * @param event The MotionEvent of the swipe
 *///w  ww .  ja  v a2  s  .com
@Override
public boolean onTouch(View view, MotionEvent event) {
    // Provide data to the GestureDetector.
    gestureDetector.onTouchEvent(event);

    /*
     * Handle Double Tap Swipe in real time.
     *  This handling isn't in onDoubleTapEvent() because that method has a limit how many times
     *  it gets called after which it isn't called at all until the user lifts the finger in which
     *  case it gets called one last time. That is not workable for on-the-fly resizing of panels.
     */
    if (isDoubleTapSwipe) {
        float absDiffX = Math.abs(doubleTapOriginX - event.getX());
        float absDiffY = Math.abs(doubleTapOriginY - event.getY());

        // If the swipe was over predefined threshold value high and it was higher than wider,
        // or if the swipe was over predefined threshold value wide and it was wider than higher.
        if (doubleTapSwipeEscapedBounds ||
        // Bounds for PORTRAIT orientation.
                (absDiffY > threshold_swipe_up_or_down_change_panel_size_px && absDiffY > absDiffX
                        && doubleTapSwipe_orientation == Configuration.ORIENTATION_PORTRAIT)
                ||
                // Bounds for LANDSCAPE orientation.
                (absDiffX > threshold_swipe_left_right_change_panel_size_px && absDiffX > absDiffY
                        && doubleTapSwipe_orientation != Configuration.ORIENTATION_PORTRAIT)) {

            if (!doubleTapSwipeEscapedBounds) {
                // This is the first time doubleTapSwipe escaped it's bounds
                // - we're officially in the set-panels-size mode.
                doubleTapSwipeEscapedBounds = true;

                // Find out and save the relevant dimensions of our view/display
                Window window = activity.getWindow();

                if (doubleTapSwipe_orientation == Configuration.ORIENTATION_PORTRAIT) {
                    doubleTapSwipe_contentStartsAtHeight = window.findViewById(Window.ID_ANDROID_CONTENT)
                            .getTop();
                    doubleTapSwipe_viewHeight = window.getDecorView().getHeight();
                } else {
                    doubleTapSwipe_contentStartsAtHeight = window.findViewById(Window.ID_ANDROID_CONTENT)
                            .getLeft();
                    doubleTapSwipe_viewHeight = window.getDecorView().getWidth();
                }
            }

            // Compute the panels weight
            float useCoordinate = (doubleTapSwipe_orientation == Configuration.ORIENTATION_PORTRAIT)
                    ? event.getRawY()
                    : event.getRawX();

            newPanelsWeight = (useCoordinate - doubleTapSwipe_contentStartsAtHeight)
                    / (doubleTapSwipe_viewHeight - doubleTapSwipe_contentStartsAtHeight);

            // If the weight is close to 0.5, let it stick to it.
            if (Math.abs(0.5 - newPanelsWeight) < PANEL_RESIZE_SNAP_WEIGHT_AROUND_HALF) {
                newPanelsWeight = 0.5f;
            }

            // Assure that the weight is between the allowed minimum and maximum.
            newPanelsWeight = Func.minMaxRange(Func.PANEL_WEIGHT_MIN, newPanelsWeight, Func.PANEL_WEIGHT_MAX);

            // Change relative panel size on the fly.
            governor.changePanelsWeight(newPanelsWeight);

            //Log.v(LOG, "[" + panelPosition + "] doubleTapSwipe " + newPanelsWeight);
            //+ " = (" + event.getRawY() + " - " + contentViewTop + ") / " + (height - contentViewTop));
        }
    }

    /*
     * Handle ACTION_UP event for scrolling, because onScroll (almost?) never gets
     * called with the last MotionEvent.ACTION_UP.
     * Don't forget to mirror any changes made here in the onScroll() method as well, to be safe.
     */
    if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_UP) {
        Log.d(LOG, "[" + panelPosition + "] OnTouchListener --> onTouch ACTION_UP - scrollY: "
                + webView.getScrollY());

        // Only if it's not DoubleTapSwipe, that is handled separately.
        if (!isDoubleTapSwipe) {
            // Evaluate if the scroll that has just ended constitutes some gesture.
            handleScrollEnd(event);
        }
    }

    // Modify the event so that it is passed on in a state where the X coordinate hasn't changed at all.
    // This prevents the "over scroll glow effect" on pages that have some (hidden) horizontal scroll.
    //  -- Disabled because it causes the wrong scroll position to be loaded after opening a page
    //     sometimes (but not every time), for some unknown reason.
    //event.setLocation(touchOriginX, event.getY());

    view.performClick(); // Android system mandates we pass the baton to the onClick listener now.

    return view.onTouchEvent(event);
}

From source file:com.actionbarsherlock.internal.app.ActionBarImpl.java

public ActionBarImpl(Activity activity, int features) {
    mActivity = activity;/*from w w w  .  j a  v  a  2 s.c  o  m*/
    Window window = activity.getWindow();
    View decor = window.getDecorView();
    init(decor);

    //window.hasFeature() workaround for pre-3.0
    if ((features & (1 << Window.FEATURE_ACTION_BAR_OVERLAY)) == 0) {
        mContentView = (NineFrameLayout) decor.findViewById(android.R.id.content);
    }
}

From source file:com.tandong.sa.sherlock.internal.app.ActionBarImpl.java

public ActionBarImpl(Activity activity, int features) {
    mActivity = activity;/*  www . j a  v  a  2  s. co m*/
    Window window = activity.getWindow();
    View decor = window.getDecorView();
    init(decor);

    // window.hasFeature() workaround for pre-3.0
    if ((features & (1 << Window.FEATURE_ACTION_BAR_OVERLAY)) == 0) {
        mContentView = (NineFrameLayout) decor.findViewById(android.R.id.content);
    }
}

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 ww . ja va  2  s  .  c  om*/
 * @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:onion.chat.MainActivity.java

void showQR() {
    String name = db.getName();//w ww.  j a va  2s . c o  m
    String txt = "Its Ur's " + tor.getID() + " " + name;

    QRCode qr;

    try {
        //qr = Encoder.encode(txt, ErrorCorrectionLevel.H);
        qr = Encoder.encode(txt, ErrorCorrectionLevel.M);
    } catch (Exception ex) {
        throw new Error(ex);
    }

    ByteMatrix mat = qr.getMatrix();
    int width = mat.getWidth();
    int height = mat.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = mat.get(x, y) != 0 ? Color.BLACK : Color.WHITE;
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);

    bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * 8, bitmap.getHeight() * 8, false);

    ImageView view = new ImageView(this);
    view.setImageBitmap(bitmap);

    int pad = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16,
            getResources().getDisplayMetrics());
    view.setPadding(pad, pad, pad, pad);

    Rect displayRectangle = new Rect();
    Window window = getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
    int s = (int) (Math.min(displayRectangle.width(), displayRectangle.height()) * 0.9);
    view.setMinimumWidth(s);
    view.setMinimumHeight(s);
    new AlertDialog.Builder(this)
            //.setMessage(txt)
            .setView(view).show();
}

From source file:org.godotengine.godot.Godot.java

@Override
protected void onResume() {
    super.onResume();
    if (!godot_initialized) {
        if (null != mDownloaderClientStub) {
            mDownloaderClientStub.connect(this);
        }/*from   ww w.j av a2  s.  c o  m*/
        return;
    }

    mView.onResume();
    mView.queueEvent(new Runnable() {
        @Override
        public void run() {
            GodotLib.focusin();
        }
    });
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);

    if (use_immersive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+
        Window window = getWindow();
        window.getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // hide nav bar
                        View.SYSTEM_UI_FLAG_FULLSCREEN | // hide status bar
                        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }

    for (int i = 0; i < singleton_count; i++) {

        singletons[i].onMainResume();
    }
}