1 /* 2 * Copyright (C) 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 package android.app.stubs.shared 17 18 import android.R 19 import android.app.Activity 20 import android.os.Bundle 21 import android.view.View 22 import android.widget.FrameLayout 23 import android.widget.FrameLayout.LayoutParams 24 import android.widget.RemoteViews 25 26 class NotificationHostActivity : Activity() { onCreatenull27 override fun onCreate(savedInstanceState: Bundle?) { 28 super.onCreate(savedInstanceState) 29 val views = (intent.getParcelableExtra(EXTRA_REMOTE_VIEWS) as RemoteViews?)!! 30 val height = intent.getIntExtra(EXTRA_HEIGHT, LayoutParams.WRAP_CONTENT) 31 setContentView(FrameLayout(this).also { 32 val child = views.apply(this, it) 33 it.id = R.id.content 34 it.addView(child, LayoutParams(LayoutParams.MATCH_PARENT, height)) 35 }) 36 } 37 38 val notificationRoot: View 39 get() = requireViewById<FrameLayout>(R.id.content).getChildAt(0) 40 41 companion object { 42 const val EXTRA_REMOTE_VIEWS = "remote_views" 43 const val EXTRA_HEIGHT = "height" 44 } 45 }