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:Main.java

/**
 * set status bar translucency//from w  ww.  j a  v a2 s .  c o  m
 */
public static void setTranslucentStatus(Activity activity, boolean on) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window win = activity.getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
}

From source file:Main.java

public static void setBrightness(Activity activity, int brightness) {
    if (activity != null) {
        try {//from   w  ww.  java 2  s  .c  o m
            WindowManager.LayoutParams params = activity.getWindow().getAttributes();
            params.screenBrightness = brightness / 100f;
            activity.getWindow().setAttributes(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

/**
 * Play video file from res folder.//from w w w.  jav a2  s  . co m
 * Then call video.start();
 * @param activity - current Activity
 * @param videoViewId R.id.introVideo
 * @param videoResourceId R.raw.intro - res/raw/intro.mp4
 * @return VideoView
 */
public static VideoView playVideo(Activity activity, int videoViewId, int videoResourceId,
        MediaPlayer.OnCompletionListener listener) {
    activity.getWindow().setFormat(PixelFormat.TRANSLUCENT);
    VideoView view = (VideoView) activity.findViewById(videoViewId);
    view.setVideoURI(
            Uri.parse("android.resource://" + activity.getPackageName() + File.separator + videoResourceId));
    view.setKeepScreenOn(true);
    view.setMediaController(null);
    view.setOnCompletionListener(listener);
    view.requestFocus();
    return view;
}

From source file:Main.java

private static void setTransparentForWindow(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        activity.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }/* w w w . j ava2s  .  co  m*/
}

From source file:Main.java

@TargetApi(19)
public static void transparencyBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window window = activity.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }//ww  w.  ja  v a2s .com
}

From source file:Main.java

public static void hiddenTitleBarAndFullScreen(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setFlags(flag, flag);

}

From source file:Main.java

public static void setStatusBarColor(Activity activity, int colorResource) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(colorResource);
    }//w  w w  . ja v  a  2  s .  c o m
}

From source file:Main.java

public static void setStatusBarColor(Activity activity, int colorId) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        //      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(activity.getResources().getColor(colorId));
    }/*  w  ww. j  a  v  a2 s  .co  m*/
}

From source file:Main.java

public static void setLayout(Activity context, int layout, int titleBar) {
    context.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    context.setContentView(layout);//  w  w  w.j a  v  a  2  s  .co m
    context.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, titleBar);
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null && activity.getWindow().getCurrentFocus() != null) {
        imm.hideSoftInputFromWindow(activity.getWindow().getCurrentFocus().getWindowToken(), 0);
    }/*from   www.  j ava  2  s  . c o m*/

}