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:com.github.michaelins.lightstatusbar.LightStatusBar.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action//w  w w .j a  v  a  2s .c  om
 *            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;
}

From source file:br.com.hotforms.StatusBarManager.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            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.
 *//*w  ww  . ja  va 2 s  . c  o m*/
@Override
public boolean execute(String action, 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 ("_ready".equals(action)) {
        boolean statusBarVisible = (window.getAttributes().flags
                & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
    } else if ("show".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
        });
        return true;
    } else if ("hide".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

                if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                }
            }
        });
        return true;
    } else if ("setTranslucent".equals(action)) {
        if (currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT) {
            this.cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                        window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                    }

                    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                }
            });
            return true;
        } else {
            return false;
        }
    } else if ("setTransparent".equals(action)) {
        if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            this.cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

                    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                }
            });
            return true;
        } else {
            return false;
        }
    } else if ("setColor".equals(action)) {
        if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            this.setColor(args.getInt(0), args.getInt(1), args.getInt(2));
            return true;
        } else {
            return false;
        }
    }

    return false;
}

From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java

/**
 * Adds the specified GuidedStepListFragment as content of Activity; no backstack entry is added so
 * the activity will be dismissed when BACK key is pressed.  The method is typically called in
 * Activity.onCreate() when savedInstanceState is null.  When savedInstanceState is not null,
 * the Activity is being restored,  do not call addAsRoot() to duplicate the Fragment restored
 * by FragmentManager.//from w ww .jav  a2 s  . co m
 * {@link #UI_STYLE_ACTIVITY_ROOT} is assigned.
 * <p/>
 * Note: currently fragments added using this method must be created programmatically rather
 * than via XML.
 *
 * @param activity The Activity to be used to insert GuidedStepListFragment.
 * @param fragment The GuidedStepListFragment to be inserted into the fragment stack.
 * @param id       The id of container to add GuidedStepListFragment, can be android.R.id.content.
 * @return The ID returned by the call FragmentTransaction.commit, or -1 there is already
 * GuidedStepListFragment.
 */
public static int addAsRoot(Activity activity, GuidedStepListFragment fragment, int id) {
    // Workaround b/23764120: call getDecorView() to force requestFeature of ActivityTransition.
    activity.getWindow().getDecorView();
    FragmentManager fragmentManager = activity.getFragmentManager();
    if (fragmentManager.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT) != null) {
        Log.w(TAG, "Fragment is already exists, likely calling "
                + "addAsRoot() when savedInstanceState is not null in Activity.onCreate().");
        return -1;
    }
    FragmentTransaction ft = fragmentManager.beginTransaction();
    fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT);
    return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static Drawable getCompatToolbarOverlay(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return null;
    final Window window = activity.getWindow();
    final View view = window.findViewById(android.support.v7.appcompat.R.id.decor_content_parent);
    if (!(view instanceof ActionBarOverlayLayout)) {
        final View contentLayout = window
                .findViewById(android.support.v7.appcompat.R.id.action_bar_activity_content);
        if (contentLayout instanceof ContentFrameLayout) {
            return ((ContentFrameLayout) contentLayout).getForeground();
        }/* w w w  .j ava  2s.c  o  m*/
        return null;
    }
    try {
        final Field field = ActionBarOverlayLayout.class.getDeclaredField("mWindowContentOverlay");
        field.setAccessible(true);
        return (Drawable) field.get(view);
    } catch (Exception ignore) {
    }
    return null;
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void setWindowOverlayViewOverlay(Activity activity, Drawable overlay) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return;//  w  w  w . j  ava  2 s . c om
    final Window window = activity.getWindow();
    final View windowOverlay = window.findViewById(R.id.window_overlay);
    if (windowOverlay == null) {
        return;
    }
    ViewSupport.setBackground(windowOverlay, overlay);
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void setCompatContentViewOverlay(Activity activity, Drawable overlay) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return;/*from  w  ww  .ja v a 2  s . co m*/
    final Window window = activity.getWindow();
    View contentLayout = window.findViewById(android.support.v7.appcompat.R.id.action_bar_activity_content);
    if (contentLayout == null) {
        contentLayout = window.findViewById(android.R.id.content);
    }
    if (contentLayout instanceof ContentFrameLayout) {
        ((ContentFrameLayout) contentLayout).setForeground(overlay);
    }
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void setCompatToolbarOverlay(Activity activity, Drawable overlay) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return;//from   w w  w  .j ava 2s .  c o m
    final Window window = activity.getWindow();
    final View view = window.findViewById(android.support.v7.appcompat.R.id.decor_content_parent);
    if (!(view instanceof ActionBarOverlayLayout))
        return;
    try {
        final Field field = ActionBarOverlayLayout.class.getDeclaredField("mWindowContentOverlay");
        field.setAccessible(true);
        field.set(view, overlay);
    } catch (Exception ignore) {
    }
}

From source file:net.olejon.mdapp.MyTools.java

public void setStatusbarColor(Activity activity, int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(mContext, color));
}

From source file:org.androidui.app.ActionBarImpl.java

public ActionBarImpl(Activity activity) {
    Window window = activity.getWindow();
    View decor = window.getDecorView();
    init(decor);
}

From source file:uk.co.placona.selfie.Selfie.java

/**
 * This method is responsible for taking the screenshot and creating a file
 *
 * @param activity Activity used by Selfie.
 * @return {@code true} if the screenshot was taken, false otherwise.
 *//* w  ww  .j av  a  2s.  c o  m*/
private boolean takeScreenShot(Activity activity) {
    Date now = new Date();
    android.text.format.DateFormat.format(fileFormat, now);

    // create bitmap screen capture
    View v1 = activity.getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    // image naming and path to include sd card appending name you choose for file
    File imageFile = new File(path, now + ".jpg");

    try {
        FileOutputStream outputStream = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (IOException ex) {
        return false;
    }

    return true;
}