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.gosuncn.core.util.view.StatusBarUtils.java

/**
 * DrawerLayout ???//from   www .  ja  v a  2  s.  com
 *
 * @param activity       ?activity
 * @param drawerLayout   DrawerLayout
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color,
        int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // ????
    //  statusBarView 
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
        contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
        StatusBarView statusBarView = createStatusBarView(activity, color);
        contentLayout.addView(statusBarView, 0);
    }
    // ? LinearLayout ,padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(contentLayout.getPaddingLeft(),
                getStatusBarHeight(activity) + contentLayout.getPaddingTop(), contentLayout.getPaddingRight(),
                contentLayout.getPaddingBottom());
    }
    // 
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);

    addTranslucentView(activity, statusBarAlpha);
}

From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java

/**
 * Create a {@link FabTransition} from the supplied {@code activity} extras and set as its
 * shared element enter/return transition.
 *//*from w  w w  . j a  va 2 s  .  c  o m*/
public static boolean setup(@NonNull Activity activity, @Nullable View target) {
    final Intent intent = activity.getIntent();
    if (!intent.hasExtra(EXTRA_FAB_COLOR) || !intent.hasExtra(EXTRA_FAB_ICON_RES_ID)) {
        return false;
    }

    final int color = intent.getIntExtra(EXTRA_FAB_COLOR, Color.TRANSPARENT);
    final int icon = intent.getIntExtra(EXTRA_FAB_ICON_RES_ID, -1);
    final FabTransition sharedEnter = new FabTransition(color, icon);
    if (target != null) {
        sharedEnter.addTarget(target);
    }
    activity.getWindow().setSharedElementEnterTransition(sharedEnter);
    return true;
}

From source file:com.silentcircle.common.util.ViewUtil.java

public static void setBlockScreenshots(final Activity activity) {
    if (activity == null) {
        return;/*from   w  w  w.j  ava 2s .  c o  m*/
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    boolean areScreenshotsDisabled = prefs.getBoolean(SettingsFragment.BLOCK_SCREENSHOTS, false);

    if (areScreenshotsDisabled) {
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                WindowManager.LayoutParams.FLAG_SECURE);
    } else {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
    }
}

From source file:com.tlongdev.bktf.util.Utility.java

public static void hideKeyboard(Activity activity) {
    if (activity == null) {
        return;/*from ww  w  .  j av a 2  s .c  o m*/
    }

    //overkill?
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

From source file:com.jungle.base.utils.MiscUtils.java

@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static void setImmersiveMode(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    int option = decorView.getSystemUiVisibility();

    if (Build.VERSION.SDK_INT >= 14) {
        option ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }//w  w w  .j  av a2s .c  o  m

    if (Build.VERSION.SDK_INT >= 16) {
        option ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
    }

    if (Build.VERSION.SDK_INT >= 19) {
        //option ^= View.SYSTEM_UI_FLAG_IMMERSIVE;
    }

    decorView.setSystemUiVisibility(option);
}

From source file:com.amazon.android.utils.Helpers.java

/**
 * Handles the activity's enter fade transition.
 *
 * @param activity     The activity./*w w w . ja v  a2 s .  c  om*/
 * @param fadeDuration The fade duration in milliseconds.
 */
public static void handleActivityEnterFadeTransition(Activity activity, int fadeDuration) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Transition changeTransform = TransitionInflater.from(activity)
                .inflateTransition(R.transition.change_image_transform);
        Transition fadeTransform = TransitionInflater.from(activity)
                .inflateTransition(android.R.transition.fade);
        fadeTransform.setStartDelay(0);
        fadeTransform.setDuration(fadeDuration);
        activity.getWindow().setSharedElementEnterTransition(changeTransform);
        activity.getWindow().setEnterTransition(fadeTransform);
    }
}

From source file:com.jungle.base.utils.MiscUtils.java

public static void switchScreenOnOff(Context context, boolean keepOn) {
    if (context instanceof Activity) {
        Activity activity = (Activity) context;

        if (keepOn) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {//from  ww  w  . j av a 2  s  . co m
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    }
}

From source file:de.dreier.mytargets.utils.transitions.FabTransform.java

/**
 * Create a {@link FabTransform} from the supplied {@code activity} extras and set as its
 * shared element enter/return transition.
 *//*from  www  . j a v  a 2  s.c  o m*/
static boolean setup(@NonNull Activity activity, @Nullable View target) {
    final Intent intent = activity.getIntent();
    if (!intent.hasExtra(EXTRA_FAB_COLOR_RES) || !intent.hasExtra(EXTRA_FAB_ICON_RES_ID)) {
        return false;
    }

    final int colorRes = intent.getIntExtra(EXTRA_FAB_COLOR_RES, R.color.colorAccent);
    final int icon = intent.getIntExtra(EXTRA_FAB_ICON_RES_ID, -1);
    final int color = ContextCompat.getColor(activity, colorRes);
    final FabTransform sharedEnter = new FabTransform(color, icon);
    if (target != null) {
        sharedEnter.addTarget(target);
    }
    activity.getWindow().setSharedElementEnterTransition(sharedEnter);
    return true;
}

From source file:org.huxizhijian.sdk.util.StatusBarUtil.java

/**
 *  ImageView ????/*from  w  w  w .  ja v  a 2s.  co  m*/
 *
 * @param activity       ?activity
 * @param statusBarAlpha ???
 * @param needOffsetView ???? View
 */
public static void setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    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);
        if (activity instanceof TabActivity) {
            activity.getWindow()//TabActivity
                    .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                            WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    } else {
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    addTranslucentView(activity, statusBarAlpha);
    if (needOffsetView != null) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView
                .getLayoutParams();
        if (layoutParams != null) {
            layoutParams.setMargins(0, getStatusBarHeight(activity), 0, 0);
        }
    }
}

From source file:com.google.samples.apps.iosched.util.UIUtils.java

/**
 * Sets the status bar of the given {@code activity} based on the given {@code color}. Note that
 * {@code color} will be adjusted per {@link #adjustColorForStatusBar(int)}.
 *
 * @param activity The activity to set the status bar color for.
 * @param color    The color to be adjusted and set as the status bar background.
 *//*  w  ww .java  2s  . com*/
public static void adjustAndSetStatusBarColor(@NonNull Activity activity, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(adjustColorForStatusBar(color));
    }
}