public KeyboardUtil(Activity act, View contentView) { this.decorView = act.getWindow().getDecorView(); this.contentView = contentView; //only required on newer android versions. it was working on API level 19 if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); } }
/** * BindView annotated fields and methods in the specified {@code target} using the {@code source} * {@link Activity} as the view root. * * @param target Target class for view binding. * @param source Activity on which IDs will be looked up. */ @NonNull @UiThread public static Unbinder bind(@NonNull Object target, @NonNull Activity source) { View sourceView = source.getWindow().getDecorView(); return bind(target, sourceView); }
/** * BindView annotated fields and methods in the specified {@link Activity}. The current content * view is used as the view root. * * @param target Target activity for view binding. */ @NonNull @UiThread public static Unbinder bind(@NonNull Activity target) { View sourceView = target.getWindow().getDecorView(); return bind(target, sourceView); }
/** * BindView annotated fields and methods in the specified {@link Activity}. The current content * view is used as the view root. * * @param target Target activity for view binding. */ @NonNull @UiThread public static Unbinder bind(@NonNull Activity target) { View sourceView = target.getWindow().getDecorView(); return bind(target, sourceView); }
/** * BindView annotated fields and methods in the specified {@code target} using the {@code source} * {@link Activity} as the view root. * * @param target Target class for view binding. * @param source Activity on which IDs will be looked up. */ @NonNull @UiThread public static Unbinder bind(@NonNull Object target, @NonNull Activity source) { View sourceView = source.getWindow().getDecorView(); return bind(target, sourceView); }
/** * Invoke this method to unregister a view hierarchy. * * @param activity * The activity whose view hierarchy/window to unregister * * @see #addWindow(Activity) * @see #removeWindow(View) */ public void removeWindow(Activity activity) { removeWindow(activity.getWindow().getDecorView()); }
/** * Invoke this method to change the currently focused window. * * @param activity * The activity whose view hierarchy/window hasfocus, or null to * remove focus */ public void setFocusedWindow(Activity activity) { setFocusedWindow(activity.getWindow().getDecorView()); }
/** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */ public static void darkMode(Activity activity) { darkMode(activity.getWindow(), DEFAULT_COLOR, DEFAULT_ALPHA); }
@Override public void onTransitionEnd(Transition transition) { // we only want these content transitions in certain cases so clear out when done. host.getWindow().setReenterTransition(null); } });
public static void immersive(Activity activity, int color) { immersive(activity.getWindow(), color, 1f); }
private static boolean isDecorViewOfActivity(View view, List<WeakReference<Activity>> references) { Util.throwIfNull(references); for (WeakReference<Activity> reference : references) { Activity activity = reference.get(); if (activity == null) { continue; } if (activity.getWindow().getDecorView() == view) { return true; } } return false; }
public static void darkMode(Activity activity, boolean dark) { if (isFlyme4Later()) { darkModeForFlyme4(activity.getWindow(), dark); } else if (isMIUI6Later()) { darkModeForMIUI6(activity.getWindow(), dark); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { darkModeForM(activity.getWindow(), dark); } }
public static void immersive(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { immersive(activity.getWindow(), color, alpha); }
public static void darkMode(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { darkMode(activity.getWindow(), color, alpha); }
@Override protected void onGetChildren(Activity element, Accumulator<Object> children) { getDialogFragments(FragmentCompat.getSupportLibInstance(), element, children); getDialogFragments(FragmentCompat.getFrameworkInstance(), element, children); Window window = element.getWindow(); if (window != null) { children.store(window); } }
@Before public void setUp() throws Exception { activity = Robolectric.setupActivity(Activity.class); window = activity.getWindow(); }
@Test public void getFlag_shouldReturnWindowFlags() throws Exception { Activity activity = Robolectric.buildActivity(Activity.class).create().get(); Window window = activity.getWindow(); assertThat(shadowOf(window).getFlag(WindowManager.LayoutParams.FLAG_FULLSCREEN)).isFalse(); window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); assertThat(shadowOf(window).getFlag(WindowManager.LayoutParams.FLAG_FULLSCREEN)).isTrue(); window.setFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); assertThat(shadowOf(window).getFlag(WindowManager.LayoutParams.FLAG_FULLSCREEN)).isTrue(); }
@Test public void getTitle_shouldReturnWindowTitle() throws Exception { Activity activity = Robolectric.buildActivity(Activity.class).create().get(); Window window = activity.getWindow(); window.setTitle("My Window Title"); assertThat(shadowOf(window).getTitle()).isEqualTo("My Window Title"); }
@Test public void getProgressBar_returnsTheProgressBar() { Activity activity = Robolectric.buildActivity(TestActivity.class).create().get(); ProgressBar progress = shadowOf(activity.getWindow()).getProgressBar(); assertThat(progress.getVisibility()).isEqualTo(View.INVISIBLE); activity.setProgressBarVisibility(true); assertThat(progress.getVisibility()).isEqualTo(View.VISIBLE); activity.setProgressBarVisibility(false); assertThat(progress.getVisibility()).isEqualTo(View.GONE); }