Debian Codegraph @

tests/SilkFX/src/com/android/test/silkfx/app/BaseDemoActivity.kt

raw
1 /*
2 * Copyright (C) 2020 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
17 package com.android.test.silkfx.app
18
19 import android.app.Activity
20 import android.content.Context
21 import android.os.Bundle
22 import android.util.AttributeSet
23 import android.view.LayoutInflater
24 import android.view.MenuItem
25 import android.view.View
26
27 open class BaseDemoActivity : Activity() {
28 override fun onCreate(savedInstanceState: Bundle?) {
29 super.onCreate(savedInstanceState)
30
31 val inflater = LayoutInflater.from(this)
32 inflater.factory2 = object : LayoutInflater.Factory2 {
33 private val sClassPrefixList = arrayOf(
34 "android.widget.",
35 "android.webkit.",
36 "android.app.",
37 null
38 )
39 override fun onCreateView(
40 parent: View?,
41 name: String,
42 context: Context,
43 attrs: AttributeSet
44 ): View? {
45 return onCreateView(name, context, attrs)
46 }
47
48 override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
49 for (prefix in sClassPrefixList) {
50 try {
51 val view = inflater.createView(name, prefix, attrs)
52 if (view != null) {
53 if (view is WindowObserver) {
54 view.setWindow(window)
55 }
56 return view
57 }
58 } catch (e: ClassNotFoundException) { }
59 }
60 return null
61 }
62 }
63 }
64
65 override fun onStart() {
66 super.onStart()
67 actionBar?.setDisplayHomeAsUpEnabled(true)
68 }
69
70 override fun onOptionsItemSelected(item: MenuItem): Boolean {
71 if (item.itemId == android.R.id.home) {
72 onBackPressed()
73 return true
74 }
75 return super.onOptionsItemSelected(item)
76 }
77 }