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 17 package com.android.egg.widget 18 19 import android.app.Activity 20 import android.content.res.Configuration 21 import android.os.Bundle 22 import android.widget.FrameLayout 23 24 /** 25 * Activity to show off the current dynamic system theme in all its glory. 26 */ 27 class PaintChipsActivity : Activity() { 28 private lateinit var layout: FrameLayout 29 onCreatenull30 override fun onCreate(savedInstanceState: Bundle?) { 31 super.onCreate(savedInstanceState) 32 33 window.navigationBarColor = 0 34 window.statusBarColor = 0 35 actionBar?.hide() 36 37 layout = FrameLayout(this) 38 layout.setPadding(dp2px(8f), dp2px(8f), dp2px(8f), dp2px(8f)) 39 rebuildGrid() 40 41 setContentView(layout) 42 } 43 dp2pxnull44 fun dp2px(dp: Float): Int { 45 return (dp * resources.displayMetrics.density).toInt() 46 } 47 onResumenull48 override fun onResume() { 49 super.onResume() 50 51 rebuildGrid() 52 } 53 onConfigurationChangednull54 override fun onConfigurationChanged(newConfig: Configuration) { 55 super.onConfigurationChanged(newConfig) 56 57 rebuildGrid() 58 } 59 rebuildGridnull60 private fun rebuildGrid() { 61 layout.removeAllViews() 62 val grid = buildFullWidget(this, ClickBehavior.SHARE) 63 val asView = grid.apply(this, layout) 64 layout.addView(asView, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 65 FrameLayout.LayoutParams.MATCH_PARENT)) 66 } 67 } 68