Example usage for android.app Activity getWindow

List of usage examples for android.app Activity getWindow

Introduction

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

Prototype

public Window getWindow() 

Source Link

Document

Retrieve the current android.view.Window for the activity.

Usage

From source file:me.henrytao.mdcore.core.MdCompat.java

public static void enableTranslucentStatus(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }/*w w  w.j a  v  a  2  s  .c  o  m*/
}

From source file:enterprayz.megatools.Tools.java

public static void setStatusBarColor(Activity activity, int resColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setTranslucentStatus(activity, true);
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.setStatusBarColor(ContextCompat.getColor(activity, resColor));
    }/*from  www.ja  v a2s  .c o m*/
}

From source file:nth.com.ares.utils.Utils.java

public static void showSoftKeyboard(Activity activity, View view) {
    try {//from  w w w  .j a v a 2  s  .  c o  m
        InputMethodManager keyboard = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        //            keyboard.showSoftInput(view, 0);
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        //            inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
        //            e.printStackTrace();
    }
}

From source file:com.cardvlaue.sys.util.ScreenUtil.java

/**
 * ?????MIUI 6?/* w ww.j a va 2 s . co  m*/
 */
public static void setStatusBarDarkMode(boolean darkmode, Activity activity) {
    Class<? extends Window> clazz = activity.getWindow().getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag);
    } catch (Exception e) {
        // e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Hide soft key board./*from   w ww.  j  a v  a2s. c om*/
 *
 * @param activity the activity
 */
public static void hideSoftKeyBoard(Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        IBinder windowToken = currentFocus.getWindowToken();
        inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
    } else {
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}

From source file:com.chromium.fontinstaller.util.ViewUtils.java

public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;/*  w  w  w .ja  va 2 s  .com*/
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView()
                .getOverlay();

        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);

        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);

        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;

        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();

        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
                    revealCenterY, 0.0f, revealRadius);
            revealAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });

            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}

From source file:com.wit.android.support.fragment.util.FragmentAnnotations.java

/**
 * Same as {@link #injectActivityViews(android.app.Activity, Class, android.view.View.OnClickListener)}
 * with without <var>onClickListener</var>.
 *//*from ww  w. ja v  a  2  s. c  o  m*/
public static void injectActivityViews(@NonNull Activity activity, @Nullable Class<?> maxSuperClass) {
    final View content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
    if (content != null) {
        injectViews(activity, ((Object) activity).getClass(), content, maxSuperClass, null);
    } else {
        throw new IllegalStateException("Can not to inject views. Activity(" + activity
                + ") does not have root view with id(android.R.id.content).");
    }
}

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()//from ww  w. ja v a 2  s  . 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:com.mattermost.service.Promise.java

public static PopupWindow show() {
    Activity currentActivity = AppActivity.current;
    PopupWindow pw = new PopupWindow(currentActivity);
    pw.setFocusable(false);/* w w  w  .j  a va  2 s. co m*/
    pw.setBackgroundDrawable(new ColorDrawable(0));
    ImageView img = new ImageView(currentActivity);
    pw.setContentView(img);
    View view = currentActivity.getWindow().getDecorView();
    pw.setWidth(60);
    pw.setHeight(60);
    AnimatedCircleDrawable a = new AnimatedCircleDrawable(Color.RED, 5, Color.TRANSPARENT, 30);
    img.setImageDrawable(a);
    pw.showAtLocation(view, Gravity.LEFT | Gravity.TOP, view.getWidth() / 2 - 30, view.getHeight() / 2 - 30);
    a.start();

    return pw;
}

From source file:Main.java

public static int getStatusHeight(Activity activity) {
    int statusBarHeight = 0;
    try {//from  w ww . j a va 2 s.c om
        Class<?> c = Class.forName("com.android.internal.R$dimen");
        Object o = c.newInstance();
        Field field = c.getField("status_bar_height");
        int x = (Integer) field.get(o);
        statusBarHeight = activity.getResources().getDimensionPixelSize(x);
    } catch (Exception e) {
        e.printStackTrace();
        Rect frame = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        statusBarHeight = frame.top;
    }
    return statusBarHeight;
}