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.google.samples.apps.ourstreets.view.ViewUtils.java

/**
 * Set the status bar color of an activity to a specified value.
 *
 * @param activity The activity to set the colorResId for.
 * @param colorResId The value to use.//from   w w  w  . j  av a2s.c o  m
 */
public static void setStatusBarColor(@NonNull Activity activity, @ColorRes int colorResId) {
    //noinspection ConstantConditions
    if (activity == null) {
        return;
    }
    final int backgroundColor = ContextCompat.getColor(activity, colorResId);
    activity.getWindow().setStatusBarColor(backgroundColor);
}

From source file:edu.com.mvplibrary.ui.widget.StatusBarUtil.java

/**
 * ???//from   w ww.  ja  v a2s.co m
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void transparentStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
}

From source file:android.support.v7ox.app.AppCompatDelegate.java

/**
 * Create a {@link android.support.v7ox.app.AppCompatDelegate} to use with {@code activity}.
 *
 * @param callback An optional callback for AppCompat specific events
 */// w  ww .j a  v  a2s.com
public static AppCompatDelegate create(Activity activity, AppCompatCallback callback) {
    return create(activity, activity.getWindow(), callback);
}

From source file:com.andremion.louvre.preview.PreviewActivity.java

@SafeVarargs
private static Pair[] concatToSystemSharedElements(@NonNull Activity activity,
        @NonNull Pair<View, String>... activitySharedElements) {

    List<Pair<View, String>> sharedElements = new ArrayList<>();
    sharedElements.addAll(Arrays.asList(activitySharedElements));

    View decorView = activity.getWindow().getDecorView();
    View statusBackground = decorView.findViewById(android.R.id.statusBarBackground);
    View navigationBarBackground = decorView.findViewById(android.R.id.navigationBarBackground);

    sharedElements.add(Pair.create(statusBackground, ViewCompat.getTransitionName(statusBackground)));
    if (navigationBarBackground != null) {
        sharedElements.add(/*w  w  w. j av a2 s.  co  m*/
                Pair.create(navigationBarBackground, ViewCompat.getTransitionName(navigationBarBackground)));
    }

    Pair[] result = new Pair[sharedElements.size()];
    sharedElements.toArray(result);
    return result;
}

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

/**
 * Same as {@link #injectFragmentViews(android.support.v4.app.Fragment, Class)}, where the given
 * <var>activity</var> will be used as context into which will be views injected.
 *  <p>//www. j a  v  a 2 s . co  m
 * <b>Note</b>, that views to inject will be obtained from the current root content view of the
 * given activity ({@code activity.getWindow().getDecorView().findViewById(android.R.id.content)}).
 *
 * @param activity        An instance of the activity into which context should be views injected.
 * @param maxSuperClass   If {@code not null}, this method will be called (recursively)
 *                        for all super classes of the given activity (max to the specified
 *                        <var>maxSuperClass</var>), otherwise only fields of the given activity's
 *                        class will be iterated.
 * @param onClickListener An instance of OnClickListener which should be set to injected views
 *                        if {@link com.wit.android.support.fragment.annotation.InjectView#clickable() @InjectView.clickable()}
 *                        flag is set to {@code true}.
 * @throws java.lang.IllegalStateException If view with the {@link android.R.id#content} id can
 *                                         not be found within the given activity's view hierarchy.
 * @throws RuntimeException                If one of the marked fields of the given activity (or its
 *                                         super) to inject is not instance of {@link android.view.View}.
 */
public static void injectActivityViews(@NonNull Activity activity, @Nullable Class<?> maxSuperClass,
        @NonNull View.OnClickListener onClickListener) {
    final View content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
    if (content != null) {
        injectViews(activity, ((Object) activity).getClass(), content, maxSuperClass, onClickListener);
    } 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:de.baumann.hhsmoodle.helper.helper_main.java

public static void onStart(final Activity activity) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, R.color.colorPrimaryDark));
    }/* www .  j  a  va  2  s. c om*/
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static void tintStatusBar(int argColor, Activity argActivity) {
    if (Build.VERSION.SDK_INT >= 22) {
        Window window = argActivity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(argColor);
    }//from   w  w  w.j  a v  a  2  s  .c  o  m
}

From source file:edu.com.mvplibrary.ui.widget.StatusBarUtil.java

/**
 * ???(5.0??,?)//from  w  ww .j  a va2s  . com
 * <p/>
 * ?,???
 *
 * @param activity ?activity
 */
public static void setTranslucentDiff(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // ???
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        setRootView(activity);
    }
}

From source file:edu.com.mvplibrary.ui.widget.StatusBarUtil.java

/**
 * ??/*from   w  ww .  j a  va2s  . com*/
 *
 * @param activity       ?activity
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColor(Activity activity, int color, int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // ????
        View statusView = createStatusBarView(activity, color, statusBarAlpha);
        //  statusView 
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        decorView.addView(statusView);
        setRootView(activity);
    }
}

From source file:edu.com.mvplibrary.ui.widget.StatusBarUtil.java

/**
 * ??(5.0??,?)//from   ww w . j a v  a 2s.co  m
 *
 * @param activity ? activity
 * @param color    ??
 */
public static void setColorDiff(Activity activity, int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    // ????
    View statusView = createStatusBarView(activity, color);
    //  statusView 
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    decorView.addView(statusView);
    setRootView(activity);
}