1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 @file:JvmName("WindowInfoTrackerRx") 17 18 package androidx.window.rxjava2.layout 19 20 import android.app.Activity 21 import android.content.Context 22 import androidx.annotation.UiContext 23 import androidx.window.core.ExperimentalWindowApi 24 import androidx.window.layout.WindowInfoTracker 25 import androidx.window.layout.WindowLayoutInfo 26 import io.reactivex.Flowable 27 import io.reactivex.Observable 28 import kotlinx.coroutines.rx2.asFlowable 29 import kotlinx.coroutines.rx2.asObservable 30 31 /** 32 * Return an [Observable] stream of [WindowLayoutInfo]. 33 * 34 * @see WindowInfoTracker.windowLayoutInfo 35 */ windowLayoutInfoObservablenull36fun WindowInfoTracker.windowLayoutInfoObservable(activity: Activity): Observable<WindowLayoutInfo> { 37 return windowLayoutInfo(activity).asObservable() 38 } 39 40 /** 41 * Return a [Flowable] stream of [WindowLayoutInfo]. 42 * 43 * @see WindowInfoTracker.windowLayoutInfo 44 */ windowLayoutInfoFlowablenull45fun WindowInfoTracker.windowLayoutInfoFlowable(activity: Activity): Flowable<WindowLayoutInfo> { 46 return windowLayoutInfo(activity).asFlowable() 47 } 48 49 /** 50 * Return an [Observable] stream of [WindowLayoutInfo]. 51 * 52 * @see WindowInfoTracker.windowLayoutInfo 53 */ 54 @OptIn(ExperimentalWindowApi::class) windowLayoutInfoObservablenull55fun WindowInfoTracker.windowLayoutInfoObservable( 56 @UiContext context: Context 57 ): Observable<WindowLayoutInfo> { 58 return windowLayoutInfo(context).asObservable() 59 } 60 61 /** 62 * Return a [Flowable] stream of [WindowLayoutInfo]. 63 * 64 * @see WindowInfoTracker.windowLayoutInfo 65 */ 66 @OptIn(ExperimentalWindowApi::class) windowLayoutInfoFlowablenull67fun WindowInfoTracker.windowLayoutInfoFlowable( 68 @UiContext context: Context 69 ): Flowable<WindowLayoutInfo> { 70 return windowLayoutInfo(context).asFlowable() 71 } 72